I'm glad

Fac5bafe9a916c23f8b7f66a85e2667e
0
devkaiser 101 Jan 23, 2003 at 12:47

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

8 Replies

Please log in or register to post a reply.

Fdbdc4176840d77fe6a8deca457595ab
0
dk 158 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(); 
glLoadIdentity();
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.

2940f695c41efc6cd617f2dbf7d2c065
0
woz1010 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.

F7485e361f5412896a7e3be4c15038c4
0
Luke 101 Jan 24, 2003 at 22:11

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

D491261d0cdbea6f1f04129ba87f4d09
0
void 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.

2940f695c41efc6cd617f2dbf7d2c065
0
woz1010 101 Jan 25, 2003 at 16:21

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

944699b365de3645578c5806f661f2f9
0
godEcho 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.

D12838c45a4840e6c05bf94d8bb5e135
0
Morgoth 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…

2940f695c41efc6cd617f2dbf7d2c065
0
woz1010 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)