Jump to content
  • Advertisement
Sign in to follow this  
Jack83

OpenGL Ortho Projection

This topic is 3947 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I started working with openGL a month ago and it was not as difficult as I thought. But now, I ran into a problem. We are using http://worldwind.arc.nasa.gov/java/ and the JOGL library as basis. I build a small programm to load 3DS Models into openGL and display them in a small window. Everything works perfect including textures. Now I'm trying to load the model and use it as part of an UI and here comes the problem. Here is the code that loads the model in 3D without the Java / JOGL specific parts:

init:
gl.glShadeModel(GL.GL_SMOOTH);							
gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
gl.glClearDepth(1.0);									
gl.glDepthFunc(GL.GL_LEQUAL);							
gl.glEnable(GL.GL_DEPTH_TEST);							

		
gl.glHint(GL.GL_PERSPECTIVE_CORRECTION_HINT, GL.GL_NICEST);
		
gl.glEnable(GL.GL_BLEND);  
gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
gl.glEnable(GL.GL_CULL_FACE);
gl.glEnable(GL.GL_LIGHTING);
gl.glEnable(GL.GL_LIGHT0);
gl.glEnable(GL.GL_DEPTH_TEST);
gl.glEnable(GL.GL_NORMALIZE);	  
gl.glEnable(GL.GL_TEXTURE_2D);
		
renderer = new ModelRendere();		
		
renderer.loadModel(gl,"C:/projekte/3dTest/cube/cube2.3DS");



Reshape:
if(height <= 0)
    height = 1;

		
gl.glViewport(0, 0, width, height);
gl.glMatrixMode(GL.GL_PROJECTION);								
gl.glLoadIdentity();									
			
glu.gluPerspective(45.0f, width / height, 0.1f, 1000.0f);	
gl.glMatrixMode(GL.GL_MODELVIEW);				
gl.glLoadIdentity();	


display:

gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);	
gl.glLoadIdentity();					
				
gl.glTranslatef(0, 0.0f, zOffset);		
		
gl.glRotatef(rotX, 1.0f, 0.0f, 0.0f);
gl.glRotatef(rotY, 0.0f, 0.0f, 1.0f);
gl.glRotatef(rotZ, 0.0f, 1.0f, 0.0f);
gl.glScalef(scale, scale, scale);
				
renderer.render(gl);


This works perfect. The model is drawn using a display list created in renderer.load(gl) Now I tryed to project this as part of a UI. My first thought was to change the "glu.gluPerspective(45.0f, width / height, 0.1f, 1000.0f);" into "glu.gluOrtho2D(0, width, height, 0 );" and translate the model according to screen coordinates.(400,400,0 to center it on a 800x800 screen) But all i get is a black screen. Is this at least the right approach? Thanks for your help Jack

Share this post


Link to post
Share on other sites
Advertisement
As always, found the error after posting ;)

1. the scale was wrong (but already tryed this)
2. GL_LIGHTNING seems not to work with ortho projection, so i got a black face...
And what do you see of a back face on a black background.. :(

Searched one day for this, bu it finaly works now.

Share this post


Link to post
Share on other sites
Quote:
Original post by Jack83
...GL_LIGHTNING seems not to work with ortho projection...
There's no such thing as GL_LIGHTNING, but lighting certainly does work with an orthographic projection. The only difference between orthographic and perspective projections is the projection matrix.

Share this post


Link to post
Share on other sites
Maybe the problem in glu.gluOrtho2D(0, width, height, 0 ); is that you pass "height" as bottom and 0 as top which mirrors the OpenGL coordinate frame and therefore the lighting fails to work. I think backface culling could also cull the wrong faces this way.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!