PDA

View Full Version : [OpenGL] 3D Objects and Effects in Ortho



WILL
01-09-2009, 04:51 PM
Hey does anyone know how to go about drawing something in 3D in Ortho mode? I'm having a bit of trouble. My standard way of setting up Ortho Mode doesn't seem to allow this.

I use the following...


procedure BeginOrtho;
var
Width, Height: Single;
ViewPort: TViewPortArray;
begin
glGetIntegerv(GL_VIEWPORT, @ViewPort[0]);
Width := ViewPort[2];
Height := ViewPort[3];

glDisable(GL_DEPTH_TEST); //turn off z buffer
glMatrixMode(GL_PROJECTION); //set projection matrix
glPushMatrix; //push it
glLoadIdentity(); //reset
glOrtho(0, Width, Height, 0, 0, 100); //ortho view
glMatrixMode(GL_MODELVIEW); //return to modelview
glLoadIdentity(); //reset
end;

procedure EndOrtho;
begin
glEnable(GL_DEPTH_TEST); //turn on z buffer
glMatrixMode(GL_PROJECTION); //set projection matrix
glPopMatrix; //restore projection
glMatrixMode(GL_MODELVIEW); //set modelview matrix
glLoadIdentity(); //reset
end;

I then would use it somewhat like this...


BeginOrtho;
glPushMatrix; //Save Current Matrix
glTranslatef((ScreenWidth div 2 - TileSize div 2) - (Player.X * TileSize) + ScreenX,
(ScreenHeight div 2 - TileSize div 2) - (Player.Y * TileSize) + ScreenY, 0);
if (OLD_WATER) then
glCallList(List_DrawWater[AniCounter mod 18]);
glCallList(List_DrawFloor);
glCallList(List_DrawSwitches);
glPopMatrix;
EndOrtho;

Any ideas or information appreciated. Thanks.

noeska
01-09-2009, 05:49 PM
What is not working? E.g. you cannot draw 3d in ortho mode. You can however use the z buffer for layering 2D.
I do not like your glortho setup. You could try this:

glViewport(0,0,800,600); //optional
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0,800,0,600,-100,100);
glMatrixMode(GL_MODELVIEW);

de_jean_7777
01-09-2009, 06:58 PM
E.g. you cannot draw 3d in ortho mode.

As I understand ortho(orthographic) mode, you should be able to render 3D objects in it, though there is no perspective(things do not get smaller with distance). You render it the way you normally do for perspective projections.

The trick is in the glOrtho() call as this sets up your viewing frustum. The glOrtho call is like this:

procedure glOrtho(left, right, bottom, top, near, far: GLdouble);

You must make sure you render your model within the coordinates(frustum) you passed to the glOrtho call, and that your model fits into the frustum. Any polygons outside the frustum are not rendered. This requires a bit of experimentation.

For 3D rendering with ortho I usually do this glOrtho(-x, x, -y, y, znear, zfar) where x is the half the frustum width, y is half the frustum height. znear and zfar is the frustum length(starting and ending point). The orthographic frustum is a box, unlike the perspective frustum which usually widens with depth.

Other than the frustum, there is no difference with perspective and orthographic projection when it comes to rendering. For example, the Blender program can use both perspective and ortographic projections to render the scene and all models there are(it's 3D in either case).