View Full Version : Sort of SkyDome(but not really) with OpenGL
01-22-2010, 11:51 AM
I want to do the following in OpenGL:
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
01-22-2010, 02:29 PM
a good example on sky domes can be found here :
if u want to put a background in ur 3d scene u can do like this :
//here u draw ur texture on the screen
glPopMatrix();'//go back to perspective projection
01-23-2010, 12:31 AM
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
gl.glTranslatef(0.0f, 0.0f, -6.0f); //Move down 1.2 Unit And Into The Screen 6.0
gl.glTranslatef(0.0f, 0.0f, -7.0f); //Move up 2.5 Units
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.
01-23-2010, 01:32 AM
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 .
01-23-2010, 03:08 AM
I converted Your advice to my Java code:
gl.glOrthof(0.0f, 1.0f, 0.2f, 1.0f,-1.0f,1.0f);
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.
Anyways, thank You!
01-23-2010, 03:54 AM
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
//setup a perspective transformation!
than before drawing ur texture u do :
//save current perspective transf
//setup a parallel projection
//reset view model transformation
//go back to perspective transformation
//translate rotate ur 3d models
01-24-2010, 01:25 AM
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.
Powered by vBulletin® Version 4.2.3 Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.