PDA

View Full Version : [OpenGL/JEDI-SDL] Display Modes



WILL
13-03-2009, 09:43 PM
I'm trying to expand my usage of OpenGL a little. I've been using OpenGL for ortho mode drawing only, however I'd like to get into some actual 3D stuff. So... I have some questions.

How do I setup to draw in perspective mode with JEDI-SDL?

How can I draw in both Ortho and perspective mode one after the other in one frame? I'd like to draw in perspective then ortho on top.

paul_nicholls
14-03-2009, 02:06 AM
Hi WILL :)

I use the routines below to switch between 3d and 2d (ortho) views.


Procedure TRenderEngineGL.Set3dView(FOV,NearPlane,FarPlane: Single);
Begin
// 3d view.
glMatrixMode(GL_PROJECTION); // Select the projection matrix.
glLoadIdentity; // Reset the projection matrix.

// Set up the perspective projection matrix
gluPerspective(FOV,FWidth/FHeight,NearPlane,FarPlane);

glMatrixMode(GL_MODELVIEW); // Select the modelview matrix.
glLoadIdentity; // Reset the modelview matrix.
End;
{................................................. ......}

{................................................. ......}
Procedure TRenderEngineGL.Set2dView;
Begin
glMatrixMode(GL_PROJECTION); // Select the projection matrix.
glLoadIdentity; // Reset the projection matrix.

// Set up the perspective projection matrix.
gluOrtho2d(0,FWidth,FHeight,0);

glMatrixMode(GL_MODELVIEW); // Select the modelview matrix.
glLoadIdentity; // Reset the modelview matrix.
End;


Use like so:



Set3dView(...);
//draw 3d scene
Set2dView;


Where :

FWidth and FHeight are the size of my window where the opengl graphics are being drawn.
FOV is the vertical field of view...eg. 45 degrees
NearPlane (near clipping plane) = a value > 0...eg. 0.1
FarPlane (far clipping plane) = a value > NearPlane...eg. 1000

I hope this helps you :)
cheers,
Paul

WILL
15-03-2009, 02:52 PM
Thanks Paul your advice helped a lot. I actually learned a lot while playing around with this stuff. Here is a follow-up question though; what's the trick to drawing in ortho mode on top of an already drawn 3D view? What functions do I have to avoid and what's my limitations?

JSoftware
15-03-2009, 04:15 PM
You must make sure that you are certain wether you draw the 2d stuff without depth testing or not. Typically you would draw 2d stuff without depth testing and just render it back to front. Either that or clear the depth buffer after you've done your 3d stuff, and then render your 2d stuff with z coordinates

paul_nicholls
15-03-2009, 09:51 PM
You must make sure that you are certain wether you draw the 2d stuff without depth testing or not. Typically you would draw 2d stuff without depth testing and just render it back to front. Either that or clear the depth buffer after you've done your 3d stuff, and then render your 2d stuff with z coordinates


;D I couldn't have said it better myself :)

cheers,
Paul

WILL
16-03-2009, 04:27 AM
I've figure out how to do this now. :) You guys are right about the depth. I had to adjust my own graphics unit so that when I switched to Ortho mode it would set the farthest depth distance back enough that I can still see what I drew.

Thanks guys! ;)

paul_nicholls
16-03-2009, 05:34 AM
I've figure out how to do this now. :) You guys are right about the depth. I had to adjust my own graphics unit so that when I switched to Ortho mode it would set the farthest depth distance back enough that I can still see what I drew.

Thanks guys! ;)


Glad to help chief :)
cheers,
Paul