Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 7 of 7

Thread: Sort of SkyDome(but not really) with OpenGL

  1. #1
    Junior Member Newbie
    Join Date
    Jan 2010
    Posts
    18

    Sort of SkyDome(but not really) with OpenGL

    Hi.

    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

  2. #2
    Intern Contributor Abdallah DIB's Avatar
    Join Date
    Feb 2009
    Location
    France
    Posts
    70

    Re: Sort of SkyDome(but not really) with OpenGL

    a good example on sky domes can be found here :
    http://www.spheregames.com/index.php...ages/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();

  3. #3
    Junior Member Newbie
    Join Date
    Jan 2010
    Posts
    18

    Re: Sort of SkyDome(but not really) with OpenGL

    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.

  4. #4
    Intern Contributor Abdallah DIB's Avatar
    Join Date
    Feb 2009
    Location
    France
    Posts
    70

    Re: Sort of SkyDome(but not really) with OpenGL

    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 .

  5. #5
    Junior Member Newbie
    Join Date
    Jan 2010
    Posts
    18

    Re: Sort of SkyDome(but not really) with OpenGL

    I converted Your advice to my Java code:

    gl.glLoadIdentity();
    gl.glMatrixMode(GL10.GL_PROJECTION);
    gl.glPushMatrix();
    gl.glLoadIdentity();
    gl.glOrthof(0.0f, 1.0f, 0.2f, 1.0f,-1.0f,1.0f);
    square.draw(gl);
    gl.glPopMatrix();
    gl.glClear(GL10.GL_DEPTH_BUFFER_BIT);
    gl.glMatrixMode(GL10.GL_MODELVIEW);
    gl.glLoadIdentity();
    world.draw(gl, filter);

    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!

  6. #6
    Intern Contributor Abdallah DIB's Avatar
    Join Date
    Feb 2009
    Location
    France
    Posts
    70

    Re: Sort of SkyDome(but not really) with OpenGL

    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

  7. #7
    Junior Member Newbie
    Join Date
    Jan 2010
    Posts
    18

    Re: Sort of SkyDome(but not really) with OpenGL

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •