8 replies to this topic

### #1devkaiser

New Member

• Members
• 1 posts

Posted 23 January 2003 - 12:47 PM

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

### #2Dia

DevMaster Staff

• 1120 posts

Posted 23 January 2003 - 03:51 PM

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.

### #3woz1010

New Member

• Members
• 24 posts

Posted 24 January 2003 - 09:43 PM

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.
<a href='http://www.sf-games.com' target='_blank'>SF Games</a>
<a href='http://www.c3command.com' target='_blank'>C3 Command</a>

### #4Luke

New Member

• Members
• 7 posts

Posted 24 January 2003 - 10:11 PM

BTW Ortho mode has no Z axis so theres no point trying to do translations on it.
On Demand IT Solutions - http://www.odits.com.au

### #5void

New Member

• Members
• 22 posts

Posted 24 January 2003 - 11:56 PM

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

### #6woz1010

New Member

• Members
• 24 posts

Posted 25 January 2003 - 04:21 PM

Also check out Game Tutorials
http://www.gametutorials.com
<a href='http://www.sf-games.com' target='_blank'>SF Games</a>
<a href='http://www.c3command.com' target='_blank'>C3 Command</a>

### #7godEcho

New Member

• Members
• 9 posts

Posted 25 January 2003 - 07:59 PM

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.
-luke

### #8Morgoth

New Member

• Members
• 9 posts

Posted 31 January 2003 - 11:08 AM

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...

### #9woz1010

New Member

• Members
• 24 posts

Posted 31 January 2003 - 04:21 PM

Quote

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)
<a href='http://www.sf-games.com' target='_blank'>SF Games</a>
<a href='http://www.c3command.com' target='_blank'>C3 Command</a>

#### 1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users