Displaying a 2D picture
What''s the easiest way to display a 2D picture from a file ?
I don''t want it to load it as a texture, just to display each pixel of it in an opengl window.
Adrien Constant
Map it onto a quad, or don't use GL.
EDIT:You're right enigma...
-~-The Cow of Darkness-~-
[edited by - cowsarenotevil on March 16, 2003 10:46:09 AM]
EDIT:You're right enigma...
-~-The Cow of Darkness-~-
[edited by - cowsarenotevil on March 16, 2003 10:46:09 AM]
-~-The Cow of Darkness-~-
glDrawPixels(GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid* pixels)
Enigma
Enigma
Am I correct that you have to be in glOrtho mode to be able to do raster graphics?
Isn''t there a way to "combine" a 2d image and a 3d image, like the border around the screen in Quake? Every time I switch between ortho and perspective, whatever was in the other one disappears - any tips on how to combine them?
Thanks
Isn''t there a way to "combine" a 2d image and a 3d image, like the border around the screen in Quake? Every time I switch between ortho and perspective, whatever was in the other one disappears - any tips on how to combine them?
Thanks
Love means nothing to a tennis player
My nothing-to-write-home-about OpenGL webpage. (please pardon the popups!)
you don''t need to be in ortho mode to use glDrawPixels. You really also should only consider draw pixels as a last resort unless it''s a 1 time operation.
for drawing a background, simply setup ortho mode (or your own variant), draw the background, then setup your camera, and draw again. If you want to only draw to a box, use glViewPort and glScissor, this applies to both parts of this method.
| - Project-X - my mega project.. getting warmer
- | - adDeath - an ad blocker I made - | - email me - |
for drawing a background, simply setup ortho mode (or your own variant), draw the background, then setup your camera, and draw again. If you want to only draw to a box, use glViewPort and glScissor, this applies to both parts of this method.
| - Project-X - my mega project.. getting warmer

RipTorn,
Would you happen to know what I''m doing wrong here? Here''s my Render routine:
void Render()
{
glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity(); //glOrtho(0.0f, width - 1.0, 0.0, height - 1.0, -1.0, 1.0);
glRasterPos2i(200,200);
glDrawPixels(bitmapData->sizeX, bitmapData->sizeY, GL_RGB, GL_UNSIGNED_BYTE, bitmapData->data);
// calculate aspect ratio of window
gluPerspective(54.0f,(GLfloat)width/(GLfloat)height,1.0f,1000.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity(); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity();
glRotatef(angle, 0.0f, 1.0f, 0.0f);
glTranslatef(translatex, -2.0f, translatez);
myRobot.DrawRobot();
glFlush();
SwapBuffers(g_HDC);
}
If I leave the glOrtho line commented out I can see my robot but not the bitmap. If I uncomment the glOrtho line I can''t see ANYTHING. I know my bitmap data is correctly loaded because I''ve mapped it onto the robot''s face.
The entire app is at http://home.att.net/~tennisman5/TryingToCombine.zip.
All I''m trying to do is just have the bitmap on the back of the screen like a background no matter where the robot is.
Any thoughts?
Thanks
Would you happen to know what I''m doing wrong here? Here''s my Render routine:
void Render()
{
glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity(); //glOrtho(0.0f, width - 1.0, 0.0, height - 1.0, -1.0, 1.0);
glRasterPos2i(200,200);
glDrawPixels(bitmapData->sizeX, bitmapData->sizeY, GL_RGB, GL_UNSIGNED_BYTE, bitmapData->data);
// calculate aspect ratio of window
gluPerspective(54.0f,(GLfloat)width/(GLfloat)height,1.0f,1000.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity(); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity();
glRotatef(angle, 0.0f, 1.0f, 0.0f);
glTranslatef(translatex, -2.0f, translatez);
myRobot.DrawRobot();
glFlush();
SwapBuffers(g_HDC);
}
If I leave the glOrtho line commented out I can see my robot but not the bitmap. If I uncomment the glOrtho line I can''t see ANYTHING. I know my bitmap data is correctly loaded because I''ve mapped it onto the robot''s face.
The entire app is at http://home.att.net/~tennisman5/TryingToCombine.zip.
All I''m trying to do is just have the bitmap on the back of the screen like a background no matter where the robot is.
Any thoughts?
Thanks
Love means nothing to a tennis player
My nothing-to-write-home-about OpenGL webpage. (please pardon the popups!)
Here''s a modification/rearrangement that will work:
I''ll leave you to play around a little and figure out why and how this works. If you want something about it explained, just ask.
void Render(){ // clear screen and depth buffer glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glViewport(0, 0, width, height); // reset the viewport to new dimensions glMatrixMode(GL_PROJECTION); glLoadIdentity(); glPushAttrib(GL_ALL_ATTRIB_BITS); glPushMatrix(); glOrtho(0.0f, width - 1.0, 0.0, height - 1.0, -1.0, 1.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glDisable(GL_DEPTH_TEST); glRasterPos2i(200,200); glDrawPixels(bitmapData->sizeX, bitmapData->sizeY, GL_RGB, GL_UNSIGNED_BYTE, bitmapData->data); glPopMatrix(); glPopAttrib(); glLoadIdentity(); // reset projection matrix gluPerspective(54.0f,(GLfloat)width/(GLfloat)height,1.0f,1000.0f); glMatrixMode(GL_MODELVIEW); // set modelview matrix glLoadIdentity(); // reset modelview matrix float angle = rotangle + 90.0f; if (angle < 0.0f) angle = angle + 360.0f; if (angle >= 360.0f) angle = angle - 360.0f; glRotatef(angle, 0.0f, 1.0f, 0.0f); //Now the translation. Remember, the camera stays put //and the world''s axes move. So to simulate moving the //camera 8 to the right and 8 down, we would move the //world''s axes 8 to the left and 8 up. float translatex = -personx; float translatez = -personz; glTranslatef(translatex, -2.0f, translatez); // perform transformations // draw our smooth shaded triangle glBegin(GL_TRIANGLES); glColor3f(1.0f, 0.0f, 0.0f); // red vertex glVertex3f(-1.0f, -1.0f, -.5f); glColor3f(0.0f, 1.0f, 0.0f); // green vertex glVertex3f(2.0f, -1.0f, -.5f); glColor3f(0.0f, 0.0f, 1.0f); // blue vertex glVertex3f(-1.0f, 2.0f, -.5f); glEnd(); myRobot.DrawRobot(); glFlush(); SwapBuffers(g_HDC); // bring backbuffer to foreground}
I''ll leave you to play around a little and figure out why and how this works. If you want something about it explained, just ask.

Thank you very much Nemesis - I appreciate it. I''ll look at this tonight, I have to go back to my DAY JOB right now (yiiiippeeeeeeeee).
So is this the "generally accepted" method for doing things like the little translator messageboxes that pop up in Unreal and the borders around the screens in quake/wolf 3d et al? If not, do you know of some other topics I could read up on?
Appreciation
Joe
So is this the "generally accepted" method for doing things like the little translator messageboxes that pop up in Unreal and the borders around the screens in quake/wolf 3d et al? If not, do you know of some other topics I could read up on?
Appreciation
Joe
Love means nothing to a tennis player
My nothing-to-write-home-about OpenGL webpage. (please pardon the popups!)
I have no idea if it''s the "generally accepted" method or not. This is one I came up with to make a GUI for my program just a few weeks ago. I''m only a beginner myself. This is my fourth week of working with OpenGL. If someone with more experience wants to recommend something better, I''m all ears.

Hey Nemesis,
I took another look at my code and I think what happened was, it was actually working the whole time but the robot was *behind* the bitmap. Your depthtest hint was what I needed - thanks.
I guess I need to play around a little more with it just to figure out how ortho and depth testing work together, because I''d think that for something like putting an arbitrarily-sized border around the screen like in Quake you''d want the bitmap to be always on *top* - not always in the *back*. (I wanted the bitmap in the back in this case just for the fun of it).
Do you happen to know off the top of your head, what is the "depth" of something you draw in ortho mode supposed to be, i.e. by default is it always considered to be "right in front of the camera''s face"?
Boy whoever told me to replace the glDrawPixels call with mapping to a quad wasn''t kidding - using glDrawPixels I was getting 2 seconds per frame - not 2 frames per second, 2 seconds per frame!
I''ll keep playing - thanks.
Joe
// clear screen and depth buffer
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0.0f, width - 1.0, 0.0, height - 1.0, -1.0, 1.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity(); // reset modelview matrix
glRasterPos2i(20,20);
glTranslatef(0.0f, 0.0f, 1.0f);
glDisable(GL_DEPTH_TEST);
//glDrawPixels(bitmapData->sizeX, bitmapData->sizeY, GL_RGB, GL_UNSIGNED_BYTE, bitmapData->data);
glBindTexture(GL_TEXTURE_2D, textures[1]);
glColor3f(1.0f, 1.0f, 1.0f);
glBegin(GL_QUADS);
glTexCoord2f(1.0, 0.0);
glVertex3f(200, 200, 0);
glTexCoord2f(0.0, 0.0);
glVertex3f(200 + bitmapData->sizeX, 200, 0);
glTexCoord2f(0.0, 1.0);
glVertex3f(200 + bitmapData->sizeX, 200 + bitmapData->sizeY, 0);
glTexCoord2f(1.0, 1.0);
glVertex3f(200, 200 + bitmapData->sizeY, 0);
glEnd();
glEnable(GL_DEPTH_TEST);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(54.0f,(GLfloat)width/(GLfloat)height,1.0f,1000.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glRotatef(angle, 0.0f, 1.0f, 0.0f);
glTranslatef(translatex, -2.0f, translatez);
myRobot.DrawRobot();
glFlush();
SwapBuffers(g_HDC); // bring backbuffer to foreground
I took another look at my code and I think what happened was, it was actually working the whole time but the robot was *behind* the bitmap. Your depthtest hint was what I needed - thanks.
I guess I need to play around a little more with it just to figure out how ortho and depth testing work together, because I''d think that for something like putting an arbitrarily-sized border around the screen like in Quake you''d want the bitmap to be always on *top* - not always in the *back*. (I wanted the bitmap in the back in this case just for the fun of it).
Do you happen to know off the top of your head, what is the "depth" of something you draw in ortho mode supposed to be, i.e. by default is it always considered to be "right in front of the camera''s face"?
Boy whoever told me to replace the glDrawPixels call with mapping to a quad wasn''t kidding - using glDrawPixels I was getting 2 seconds per frame - not 2 frames per second, 2 seconds per frame!
I''ll keep playing - thanks.
Joe
// clear screen and depth buffer
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0.0f, width - 1.0, 0.0, height - 1.0, -1.0, 1.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity(); // reset modelview matrix
glRasterPos2i(20,20);
glTranslatef(0.0f, 0.0f, 1.0f);
glDisable(GL_DEPTH_TEST);
//glDrawPixels(bitmapData->sizeX, bitmapData->sizeY, GL_RGB, GL_UNSIGNED_BYTE, bitmapData->data);
glBindTexture(GL_TEXTURE_2D, textures[1]);
glColor3f(1.0f, 1.0f, 1.0f);
glBegin(GL_QUADS);
glTexCoord2f(1.0, 0.0);
glVertex3f(200, 200, 0);
glTexCoord2f(0.0, 0.0);
glVertex3f(200 + bitmapData->sizeX, 200, 0);
glTexCoord2f(0.0, 1.0);
glVertex3f(200 + bitmapData->sizeX, 200 + bitmapData->sizeY, 0);
glTexCoord2f(1.0, 1.0);
glVertex3f(200, 200 + bitmapData->sizeY, 0);
glEnd();
glEnable(GL_DEPTH_TEST);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(54.0f,(GLfloat)width/(GLfloat)height,1.0f,1000.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glRotatef(angle, 0.0f, 1.0f, 0.0f);
glTranslatef(translatex, -2.0f, translatez);
myRobot.DrawRobot();
glFlush();
SwapBuffers(g_HDC); // bring backbuffer to foreground
Love means nothing to a tennis player
My nothing-to-write-home-about OpenGL webpage. (please pardon the popups!)
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement