Sort of a skydome, but not really a skydome

Started by betwixt666, January 22, 2010, 20:06:23

Previous topic - Next topic

betwixt666

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.

How can I do that? Can You point me somewhere? A Java or C++ example would be great.

Kai

Hi,

first, draw your fullscreen texture without depth-write (disable depth-writing via GL11.glDepthMask(false)). You just need to draw a quad (or two triangles) that cover the whole screen. The simplest way to draw something that covers the whole screen is to use vertex positions -1 and +1 for x and y each that are already the vertices clipping positions, so you GL11.glLoadIdentity() both the modelview and projection matrices before drawing the quad.

Everything that you draw afterwards will always be in front of the previously drawn fullscreen quad (it will simply overwrite it, if not getting clipped away, of course). You may want to enable depth-writing again in order to have correct z-buffering for the 3D geometry that you draw then.

betwixt666

Juhheiii!!! Heh, It works. Thank You! I can't belive it was this simple. 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 :)