PDA

View Full Version : Switch from 2d to 3d



Bonesteel
05-11-2010, 07:16 PM
Hi, I'm working on a project where I need to draw a profile of a solid then extrude it and show it in 3d. Currently I start out using glOrtho2d then after I draw my profile I'm switching to glOrtho to show it in 3d. It this the correct way to do it? I can't get anything to show up in my window and I'm not sure why.
I start out with this:
glMatrixMode(GL_PROJECTION); // three lines to be explained later
glLoadIdentity();
gluOrtho2D(0.0, (GLdouble)screenWidth, 0.0, (GLdouble)screenHeight);

Then after I draw my profile I do this:
glShadeModel(GL_SMOOTH); // Set type of shading
glEnable(GL_DEPTH_TEST); // Determine depth for visibility
glEnable(GL_NORMALIZE); // Correct reflection angles
glViewport(0, 0, 640, 640);

// Set up the GL_PROJECTION matrix
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-320, 320, -320, 320, 0.0, 6400);

// Set up the GL_MODELVIEW matrix
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(2400, -2400, 2400, 0, 0, 0, 0.0, 0.0, 0.0);

Thanks for the help.

strattonbrazil
05-12-2010, 08:27 AM
First, both those calls are in 3D. By 3D, I guess you mean perspective as opposed to orthographic. Keep in mind that gluOrtho2D is essentially the same thing as glOrtho with a default z value. If you read the docs on gluOrtho2D, it's equivalent to glOrtho with a z between -1 and 1. I personally don't ever use gluOrtho2D as I think it's easier for the code reader to know that that z values are between (even if they're -1 to 1).

Anyway, back to your question. First, do you use that gluLookAt in both renders? Your gluOrtho2D call creates a box the size of your screen (let's say 1000x800) and you say you can see your solid, so I'm assuming your solid is somewhere in that range. When you use glOrtho, you are moving the camera over a bit from (0-1000) to (-320,320). Is your solid in that range? You also switch your z-range from (-1,1) from gluOrtho2D to (0,6400). That seems really strange to me. Are you cutting it off here? How big is your solid in world coordinates?

Bonesteel
05-12-2010, 04:33 PM
Well, I am drawing my profile in the 640x640 window using those points with the axis in the lower left corner. So my solid is going to end up something less than 640x640x640. I wanted to make sure my camera was out far enough to see this big of an object so I had it zoomed out to 2000 and I wanted to make sure the depth was enough to see the object.

Bonesteel
05-12-2010, 04:35 PM
Oh, and I didn't use gluLookAt in both renders just the second.