PDA

View Full Version : Problems with Ortho2D



Clayton
11-18-2003, 02:48 PM
I'm having a few problems with using ortho2d. I made a quickie test program, barebones that is nothing but the draw and the settings, and it worked fine. The 2D image came out marvolously (I'm rendering a number of small rectangles) however, upon attempting to implement it into the program I'm writing, I ran into a few issues. The program uses many different camera modes (Mostly Orthographic projection) and the camera mode and rotations/zoom are easily changeable. However in the program, when I use essentailly the exact same transformations (Setting the viewport, setting the ortho2d) I recieve nothing but the clear color(black).

If I switch the perspective back to orthographic, and rotate, I can see my object as a 2D plane, and see what I've drawn (It comes out correctly) but on one side it is easily visible from all angles, and on the other, when I move the plane to be Parallel to the camera the picture begins to turn to black (Starting from the bottom and moving up as I make the plane more parallel). Is there anything that should/could be causing this?

I suppose my very basic question would be what translations and effects (Anything from gl_cull_face to the depth buffer) really effects glOrtho2d projection that could be left as a globabl variable (I'm almost 100% sure that the problem is not a matter of me forgetting that I've accidentally not cleared the MODELVIEW Matrix or something similar)

Deiussum
11-19-2003, 05:23 AM
The way you describe one side of your plane turning black when it faces the camera sounds like maybe you have face culling enabled and you are drawing the plane with the wrong winding order. By default, when you enable GL_CULL_FACE, faces with a counter-clockwise winding order are considered the front face, and back faces will be culled.

It could also be a matter of lighting problems. Do you have lighting enabled? Did you specify normals?

Or it could really be that your matrices aren't what you think they are, and nothing is falling into your viewing volume. Without code, there's not much for us to go on, though.

Clayton
11-25-2003, 01:24 PM
I'd post code, but we'd be looking at code that's interweived with thousands of lines. I don't have a cull Enabled, I don't have lighting on, Here is a very basic picture of the draw Loop.
SetCamera()
{
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glClearColor(0.0,0.0,0.0,0.0);
glClear(GL_COLOR_BUFFER_BIT);
}
paintGL()
{
SetCamera();
glDrawDisplay();

}
resizeGL()
{
glViewport( 0, 0, (GLint)w, (GLint)h );
//TODO: lookup functions to get w and h;
m_width = w;
m_height = h;
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0,m_width,0,m_height);
glMatrixMode(GL_MODELVIEW);

}
glDrawDisplay()
{
CallDrawList. I'm confident that this is not the problem, as I have used it in a different window context and it worked perfectly.
}

Is there anything that could most likely be causing this?

Deiussum
11-25-2003, 01:26 PM
gluOrtho2D(0,m_width,0,m_height);

This will set your near/far clip planes to -1.0/1.0 respectively. When you are turning your object, you are possibly seeing it getting clipped by these planes.

Clayton
11-25-2003, 01:34 PM
First of all, I am not wishing to rotate the object in Ortho2D, I am switching to a perspective drawing when I rotate it and see this problem, I was wondering if this was a sign to why the render does not show up when I do draw it in Ortho2D

Deiussum
11-25-2003, 01:44 PM
You could still be seeing your object clipped by the near plane. The reason you don't see it show up at all when using gluOrtho2D is probably because it's not within the viewing volume that you specify, but it is in the viewing volume of your perspective mode. (The viewing volume of your ortho mode in this case is only 2 units deep!) You don't show the parameters you use for perspective mode, so there's no way for me to know for sure how else they differ, though.

Clayton
11-25-2003, 02:11 PM
I do clear both the projection and modelview matricies before I attempt the Ortho2D projection, and when I switch modes to perspective and back all of those matricies are cleared, so I doubt the problem could be in a translation (such as a zoom) in the Perspective mode, or is there something I'm missing?

zeckensack
11-25-2003, 11:14 PM
Ummm ... glDisable(GL_DEPTH_TEST); ?

Deiussum
11-26-2003, 05:27 AM
Originally posted by Clayton:
I do clear both the projection and modelview matricies before I attempt the Ortho2D projection, and when I switch modes to perspective and back all of those matricies are cleared, so I doubt the problem could be in a translation (such as a zoom) in the Perspective mode, or is there something I'm missing?

Ok, maybe I'm not being clear here. A viewing volume setup by gluOrtho2D, and a viewing volume setup by gluPerspective are going to have very different volumes. Anything outside the volumes, WILL NOT BE SHOWN. That means that if you are drawing something with a Z value less than -1, or greater than 1 (the default near/far that gluOrtho2D uses), you will see NOTHING with gluOrtho2D unless you translate it to be within that range.

Example:



glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0, w, 0, h);
//gluPerspective(60, w/h, 0.1, 100);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

// The following will fall behind the far clip plane!!
glPushMatrix();
glTranslatef(0.0, 0.0, -6.0);
glutSolidSphere();
glPopMatrix();

// The following will be clipped by the left clip plane!!
glPushMatrix();
glTranslatef(-4.0, 0.0, 0.0);
glutSolidSphere();
glPopMatrix();


If you were to comment out the gluOrtho2D call above, and uncomment the gluPerspective call, the first sphere would be visible, but the second one would be clipped by the near clip plane, and therefore wouldn't be fully visible.

So, unless you show how you setup your projection matrix for perspective mode, there is not much more I can do to help you. Showing what sort of transformations you do with the MODELVIEW matrix would also be good.