0
101 Jan 23, 2003 at 12:47

I’m newbie with OpenGL
How do you draw bitmap sprites in
OpenGL

#### 8 Replies

0
157 Jan 23, 2003 at 15:51

If I understand your question correctly, you are trying to draw 2D images. Right?
Well, you will have to use ortho mode like this:

glGetFloatv(GL_VIEWPORT, viewportdata);
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glOrtho(viewportdata[0],viewportdata[2],viewportdata[1],viewportdata[3],-100,100);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();   // Reset The Current Modelview Matrix

// Now you are in 2D...
// Draw something....

// Ending ortho mode...
glPopMatrix();
glMatrixMode( GL_PROJECTION );
glPopMatrix();
glMatrixMode( GL_MODELVIEW );


I hope that helps.

0
101 Jan 24, 2003 at 21:43

After going into ortho mode, you may want to display a texture on say a quad, to represent your sprite.

No code handy to show, as I am at work, but I am sure someone can show you if needed.

0
101 Jan 24, 2003 at 22:11

BTW Ortho mode has no Z axis so theres no point trying to do translations on it.

0
101 Jan 24, 2003 at 23:56

If your an OpenGL newbie, check out nehe.gamedev.net it has probably the best introductory and intermediate OpenGL tutorials on the net.

0
101 Jan 25, 2003 at 16:21

Also check out Game Tutorials
http://www.gametutorials.com

0
101 Jan 25, 2003 at 19:59

Rendering a 2d sprite is as simple (or not simple depending on how you look at it ;) as rendering a quad with some texture coordinates. I’d suggest looking into getting the OpenGL Programming Guide (3rd ed), usually refered to as “the open red book”. I find nehe’s tutorials a really awful way to learn opengl.

Its also occured to me you might be asking about a technique called “billboarding.” Billboarding is where a 2d sprite is rendered so its always facing the player. That topic is a little more involved, so I wont bother unless thats what you were asking about.

0
101 Jan 31, 2003 at 11:08

glOrtho is just a projection mode. z axis is specified (otherwise why specify near and far cliping planes with glOrtho?) but of course z translations are not visible for one single object. If you depth-test your objects, you’ll see that far objects are occluded by near ones.

Besides using textured quads with glOrtho for sprites, and IFF it’s only 2d images you want, there is also glDrawPixels, but it’s too rigid to do anything fancy with it. Just puts a rectangular pixel area on screen…

0
101 Jan 31, 2003 at 16:21

If you depth-test your objects, you’ll see that far objects are occluded by near ones.

Here is a compiled, and source code version of a OpenGL ortho mode project I was doing to see how fast I could get OpenGL on low end graphics cards, as well as learn OpenGL vertex arrays.

The demo also shows the far objects occluded by the card that zooms to and away from the screen as well you can see the mipmap (level of detail) effects on the cards as the zooming card goes back to its farthest point.

ftp://sf-games.com/MBTest.zip (source)
ftp://sf-games.com/MBTest2.zip (executable)