LWJGL Forum

Programming => Lightweight Java Gaming Library => Topic started by: Kokoni on August 11, 2004, 09:54:20

Title: Ortho Mode
Post by: Kokoni on August 11, 2004, 09:54:20
Hi,

I have a strange result when I switch Perspective/Ortho mode to (try to) draw my UI, I have 2 metodes :


private void orthoMode(int left, int top, int right, int bottom) {
       GL11.glMatrixMode(GL11.GL_PROJECTION);
       GL11.glPushMatrix();
       GL11.glLoadIdentity();
       GL11.glOrtho(left, right, bottom, top, 0, 1);
       GL11.glMatrixMode(GL11.GL_MODELVIEW);
       GL11.glLoadIdentity();
}
private void perspectiveMode() {
       GL11.glMatrixMode(GL11.GL_PROJECTION);
       GL11.glPopMatrix();
       GL11.glMatrixMode(GL11.GL_MODELVIEW);
}


I use these methodes in my render methode :


private void render() {
       GL11.glClear(GL11.GL_COLOR_BUFFER_BIT |     GL11.GL_DEPTH_BUFFER_BIT);

       GL11.glLoadIdentity();

getActiveCamera().look();

       GL11.glEnable(GL11.GL_TEXTURE_2D);
renderOctree();

       orthoMode(0, 0, width, height);

       GL11.glDisable(GL11.GL_DEPTH_TEST);
       ui.render();
       GL11.glEnable(GL11.GL_DEPTH_TEST);
       perspectiveMode();
}


When I use themethode orthoMode and perspectiveMode, my octree (in fact I have one little mesh into) is partially drawed. when I remove these methodes, all is ok.

Someone can help me please ?
Title: Ortho Mode
Post by: Gavia on August 11, 2004, 16:56:53
I see two things that might be causing you grief:

It looks like your bottom and top might be flipped when calling your orthoMode() method. You are setting bottom = height and top =0. Usually you set your bottom to zero and top to height. I'm not sure if what you did will just flip the Y axis or not but it could cause problems if you aren't expecting it.

If your ui.render() is drawing your objects centerered around the origin when you are in ortho mode, the object is going to show up in the bottom left (or in your case perhaps the top left) of your viewport and will look cutoff. When you go into ortho mode your are setting the bottom left of your screen to be the origin (0,0), so any parts of your ui drawn in the negative x or negative y directions will not be visible. If you want the origin to be centered in your view you'll need to call ortho with:

glOrtho(-width/2, width/2, -height/2, height/2, 0,1).

That should put your origin in the center of the screen.


Hope that helps,
-Michael
Title: Ortho Mode
Post by: Kokoni on August 11, 2004, 17:40:56
Hi Michael,

My pb is in the "3D mode", I dont know why switching in ortho mode cause this :

with ui.render() :
(http://nicolas.esteban.free.fr/avecpb.jpg)

without ui.render() :
(http://nicolas.esteban.free.fr/sanspb.jpg)


thx anyways for your answer.
Title: Ortho Mode
Post by: Gavia on August 11, 2004, 20:07:57
Yeah, that does look like a different problem. Perhaps try pushing your Modelview matrix before loading identity in orthoMode and popping it in perspectiveMode.

btw is your ui.render() just drawing a single quad with your model texture on it?

-Michael
Title: Ortho Mode
Post by: Kokoni on August 11, 2004, 20:44:56
Quotebtw is your ui.render() just drawing a single quad with your model texture on it?

yep, just drawing a textured quad, this texture is a test for me.

I try to change the order of my instructions in the methode orthoMode/persective with no success.
Title: Ortho Mode
Post by: napier on August 12, 2004, 01:40:53
Hi Kokoni,

Some thoughts:

Where are you setting up your perspective view?  I'm assuming that's in getActiveCamera().look().  I notice that when you exit from render() your matrixMode is MODELVIEW.  Do you switch back to PROJECTION before seting up your view?

I've had no problem combining ortho and perspective, but I don't push the projection matrix and pop it.  I call gluOrtho2D before rendering ui, then I call gluPerspective to go back to 3D rendering. I'm using version .8, but (I hope) that doesn't matter here.

napier
Title: Ortho Mode
Post by: Kokoni on August 12, 2004, 06:27:08
Hi napier,

I have the same result when I change the methodes ortho/perspective by :


private void orthoMode(int left, int top, int right, int bottom) {
       GL11.glMatrixMode(GL11.GL_PROJECTION);
       GL11.glLoadIdentity();
       GL11.glOrtho(left, right, bottom, top, 0, 1);
       GL11.glMatrixMode(GL11.GL_MODELVIEW);
       GL11.glLoadIdentity();
}
private void perspectiveMode() {
       GL11.glMatrixMode(GL11.GL_PROJECTION);
       GL11.glLoadIdentity();
       GLU.gluPerspective(45.0f, (float) Display.getWidth()
               / (float) Display.getHeight(), 0.1f, 500.0f);
       GL11.glMatrixMode(GL11.GL_MODELVIEW);
       GL11.glLoadIdentity();
   }


In my getActiveCamera().look(), I use gluLookAt.

Thx for your answer anyways.

Kokoni
Title: Ortho Mode
Post by: Kokoni on August 12, 2004, 14:00:50
I use the same way that I found in this post http://puppygames.net/forums/viewtopic.php?t=657

but a part of my robot is cutted, I decided to block the prunning of my octree and my robot full appear with the good ui, and I don't know why !

maybe my octree is wrong, I have to test it.

Kokoni.