Original Post
Hi,
I''m trying to find examples of how to display a 2D bitmap in an ortho screen.
Silly thing is I know how to do if they''re in a display list (as for bitmapped fonts), but I can''t find anything on doing it for a single bitmap (texture). It works in 3D space, but then putting them at exact screen locations is more difficult.
Anyone know of an example or which OpenGL routine to use instead of the glListBase & glCallLists to display a single bitmap in 2D space ?
Thanks,
Ivan
Here''s the code (based on NeHe''s) that works for a list :
GLvoid isDisplayBitmap(GLint x, GLint y, char BitmapID, float scale)
{
// we''re using a display list, originally intended for fonts,
// which expects a string, while we''ll only be passing 1 char as
// the bitmap id, so make it into a 2 character string
// Not the most elegant solution, but it works...
char bitmap[2];
bitmap[0]=BitmapID;
bitmap[1]=0;
// set up for rendering bitmaps
glBindTexture(GL_TEXTURE_2D, texture); // Select Our Bitmap texture
glDisable(GL_DEPTH_TEST); // Disables Depth Testing
glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
glPushMatrix(); // Store The Projection Matrix
glLoadIdentity(); // Reset The Projection Matrix
// following line needs the parameters for glortho
// passed based on the scale (see in is_Font.cpp how to do that)
int v_width, v_height;
if (scale == 100.0f)
{
// for 100% scale, assigning is faster than computing
// like what is done for scaled display
v_width = VIRTUAL_WIDTH;
v_height = VIRTUAL_HEIGHT;
}
else
{
// compute the size of the ortho screen,
// so the bitmap will be displayed scaled
// bigger values for v_width & v_height means smaller bitmap
v_width = (int)((float(VIRTUAL_WIDTH) * 100.0f) / scale);
v_height = (int)((float(VIRTUAL_HEIGHT) * 100.0f) / scale);
}
glOrtho(0,v_width,0,v_height,-1,1); // Set Up An Ortho Screen (depending on scale)
glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
glPushMatrix(); // Store The Modelview Matrix
glListBase(base); // Choose The Font Set (0 or 1)
glLoadIdentity(); // Reset The Modelview Matrix
glTranslated(x,y,0); // Position The Bitmap (0,0 = Bottom Left)
glCallLists(1,GL_BYTE,bitmap); // Place the bitmap on the screen
glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
glPopMatrix(); // Restore The Old Projection Matrix
glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
glPopMatrix(); // Restore The Old Projection Matrix
glEnable(GL_DEPTH_TEST); // Enables Depth Testing
}