Drawing a 2d image in 3d mode

Started by
2 comments, last by rm3 21 years, 4 months ago
I was wondering if someone could tell me how to simply draw an image to the 2D window before I begin 3D drawing without setting orthographic mode? What I want to do is like a skybox but simpler, just clipping an image onto the screen then drawing polygons over it. Is there a way to draw to the window using OGL before any polygons are drawn? This would hopefully also eliminate a need to clear the color buffer. I''m supposing that setting orthographic mode and drawing into that and then changing back to projection would lose any data drawn in orthographic and/or be very slow. Could someone give me any tips?
Advertisement
>>I was wondering if someone could tell me how to simply draw an image to the 2D window before I begin 3D drawing without setting orthographic mode? What I want to do is like a skybox but simpler, just clipping an image onto the screen then drawing polygons over it.<<

it is much simplier to just setup an orthographic view.

>>Is there a way to draw to the window using OGL before any polygons are drawn? This would hopefully also eliminate a need to clear the color buffer.<<

this is how q3/UT + other older engines done things
start of render loop
dont clear screen
in 3d just draw the skybox (it will cover everything)

but nowadays with fast clears youre better off,
clearingthe screen, drawing the scene + then drawing the skybox last!

>>I''m supposing that setting orthographic mode and drawing into that and then changing back to projection would lose any data drawn in orthographic<<

no

>>and/or be very slow. Could someone give me any tips? <<

its very quick. drawing one triangle is far slower than changing from 3d->2d->3d.
quake3 (+ all other commerical engines do thuis)

http://uk.geocities.com/sloppyturds/kea/kea.html
http://uk.geocities.com/sloppyturds/gotterdammerung.html
May be evil, but doesn''t need to.


  void DrawSprite(void * pSprite, unsigned short usX, unsigned short usY){  sprite_info_t * pInfo = (sprite_info_t *) pSprite;  double dX = (double) usX, dY = (double) usY;  glMatrixMode(GL_PROJECTION);	glPushMatrix();		{		glLoadIdentity();		glOrtho(0.0, 1024.0, 768.0, 0.0, -0.01, 100.0);    gluLookAt(.0f, .0f, -5.0f, .0f, .0f, .0f, .0f, 1.0f, .0f);    SelectTexture(pInfo->nTexture);		    glBegin(GL_QUADS);		{			glTexCoord2f(.0f, 1.0f);			glVertex2d(dX, dY + (double) pInfo->usHeight);			glTexCoord2f(1.0f, 1.0f);			glVertex2d(dX + (double) pInfo->usWidth, dY + (double) pInfo->usHeight);			glTexCoord2f(1.0f, .0f);			glVertex2d(dX + (double) pInfo->usWidth, dY);			glTexCoord2f(.0f, .0f);			glVertex2d(dX, dY);		}		glEnd();	}	glPopMatrix();	glMatrixMode(GL_MODELVIEW);}  
Thank you everyone for your help. I wanted to use a skybox but it seems to not work. I position the camera using a few rotates and a translate then I draw a world using quads. If I use gluLookAt the skybox works when I draw it but the vertices of the quads aren''t drawn right, and if I use the translate and rotates the vertices are drawn right but not the skybox. Can anyone help me with this? I''m loading quads from a file with the xyz and texture coords and then drawing them from arrays. I know the vertices are correct but the way it''s drawn seems dependent on how I position the camera. I want to use a skybox, can someone help me with this?

And thank you blacklight for your code example!

This topic is closed to new replies.

Advertisement