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&#<span class="java-number">47</span>;3dTest&#<span class="java-number">47</span>;cube&#<span class="java-number">47</span>;cube2.3DS"</span>);
Reshape:
<span class="java-keyword">if</span>(height <= <span class="java-number">0</span>)
height = <span class="java-number">1</span>;
gl.glViewport(<span class="java-number">0</span>, <span class="java-number">0</span>, width, height);
gl.glMatrixMode(GL.GL_PROJECTION);
gl.glLoadIdentity();
glu.gluPerspective(<span class="java-number">45</span>.0f, width / height, <span class="java-number">0</span>.1f, <span class="java-number">1000</span>.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(<span class="java-number">0</span>, <span class="java-number">0</span>.0f, zOffset);
gl.glRotatef(rotX, <span class="java-number">1</span>.0f, <span class="java-number">0</span>.0f, <span class="java-number">0</span>.0f);
gl.glRotatef(rotY, <span class="java-number">0</span>.0f, <span class="java-number">0</span>.0f, <span class="java-number">1</span>.0f);
gl.glRotatef(rotZ, <span class="java-number">0</span>.0f, <span class="java-number">1</span>.0f, <span class="java-number">0</span>.0f);
gl.glScalef(scale, scale, scale);
renderer.render(gl);
</pre></div><!--ENDSCRIPT-->
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
Ortho Projection
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:
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.
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.
Quote:Original post by Jack83There'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.
...GL_LIGHTNING seems not to work with ortho projection...
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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement