I have jpg image 640x480. I want to draw that image so that it completely covers a 640x480 window. Then I want to draw 3d cube to whatever distance and I still want to have the cube drawn over the image. When the player moves around in 3D space then that image still covers entire window.
(I called it a skydome because I had no other idea what to put for the headline).
How can I do that? Can You point me somewhere? Java, C or C++ example would be great
a good example on sky domes can be found here : http://www.spheregames.com/index.php?p=templates/pages/tutorials
if u want to put a background in ur 3d scene u can do like this :
glMatrixMode(GL_PROEJCTION)
glPushMatrix();
glLoadIdentity();
glortho(…);
//here u draw ur texture on the screen
DrawQuadTexture();
glPopMatrix();'//go back to perspective projection
glClear(GL_DEPTH_BUFFER_BIT);
Draw3DScene();
Thank you for the quick reply. Since I am doing it in Java, I asked a lwjgl forum also and got this kind of solutoion from there. And it works :).
I just tried it out with small example that does yet not cover entire window:
gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
gl.glLoadIdentity(); //Reset The Current Modelview Matrix
//Drawing
gl.glDepthMask(false);
gl.glTranslatef(0.0f, 0.0f, -6.0f); //Move down 1.2 Unit And Into The Screen 6.0
square.draw(gl);
gl.glDepthMask(true);
gl.glLoadIdentity();
gl.glTranslatef(0.0f, 0.0f, -7.0f); //Move up 2.5 Units
triangle.draw(gl);
Altough the triangle is behind the square, it still gets drawn over it
But yeah, I think i will need to use glOrtho if I want to move around in space.
the code u posted work and ur triangle pixels should overwrite the quad pixels.
the orthographic projection in this case is used to set a background image that will be always visible .
I had to put the gl.glMatrixMode(GL10.GL_MODELVIEW); to the end because otherwise my world was messed up. I didn’t know at first what the GL_MODELVIEW and GL_PROJECTION are, but now i think that the projection is a 2D projecton of the 3d scene to the screen, so modelview probably is the real 3D way of displaying stuff. Now I am trying to figure out from some examples how to apply the textures on that square. And I don’t really know what the 6 parameters of glOrtho do either.
In fact it is not true what u said about MODELVIEW and PROJECTION matrix stacks.
You use MODELVIEW matrix to define how ur 3d models are positioned in 3D space ( rotation translation…) , the PROJECTION matrix define how ur object or model will be projected to the camera screen, u can project them with a perspective view ( as the human eyes do ) using glFrustum or gluPerspective or as an orthographic with glOrtho, this is a parallel projection.
so back to ur code , u first define somewhere ur perspective transformation
glMatrixMode(GL_PROJECTION)
glLoadIdentity()
//setup a perspective transformation!
glFrustum(…)
than before drawing ur texture u do :
glMatrixMode(GL_PROJECTION)
//save current perspective transf
glPushMatrix();
glLoadIdentity()
//setup a parallel projection
glOrtho(0,texture->width,0,texture->height,znear,zfar)
//reset view model transformation
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
DrawTexture();
//go back to perspective transformation
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW)
glLoadIdentity()
//translate rotate ur 3d models
//draw 3d
Thank You! My goal is put video from webcam to the background.The webcam sends a jpg image to local http server. Now I want to change the background texture while the program is running, the first texture is currently loaded and binded at initialization.
Only solution that I can think of is putting the texture loading to the main gl loop. So with each frame the texture is downloaded and binded.