OpenGL - mixing perspective & orthographic projections

Member
Posts: 31
Joined: 2004.09
Post: #1
Hi all,

is it possible to mix perspective and orthographic projection in OpenGL?

What I have in mind is perspective projection for 3D game objects, and an overlaid orthographic projection for precise drawing of UI elements (e.g. scores, buttons, icons, text, HUD, etc.).

thanks.
Quote this message in a reply
Member
Posts: 177
Joined: 2002.08
Post: #2
Yes, you can change the perspective and modelview matrices at any time and it only affects drawing done afterwards.
Quote this message in a reply
Member
Posts: 31
Joined: 2004.09
Post: #3
Excellent!

Is there any major performance hit for doing this, or can I pretty much do it at will?

thanks for the help.
Quote this message in a reply
Moderator
Posts: 365
Joined: 2002.04
Post: #4
There shouldn't be any performance hit except in the sense that the more stuff you draw, the slower it'll be!

Don't forget that if you're using Z-buffering, you also need to clear the depth buffer between drawing your perspective stuff and drawing the orthographic overlay, otherwise your GUI elements will get sliced up by the 3D scene.

Neil Carter
Nether - Mac games and comic art
Quote this message in a reply
Member
Posts: 145
Joined: 2002.06
Post: #5
Quote:Originally posted by NCarter
Don't forget that if you're using Z-buffering, you also need to clear the depth buffer between drawing your perspective stuff and drawing the orthographic overlay, otherwise your GUI elements will get sliced up by the 3D scene.

Some of the old Pangea games suffered from this actually Smile

Anyway, a better thing to do would be just turn off depth testing and do your drawing in the order you want it layered. Clearing the depth buffer has a non-trivial overhead involved. Infact to avoid the overhead of clearing the depth buffer some games do an interesting trick where they use half of the depth range each frame and flip the direction and range in the depth buffer used for the odd frames.

"He who breaks a thing to find out what it is, has left the path of wisdom."
- Gandalf the Gray-Hat

Bring Alistair Cooke's America to DVD!
Quote this message in a reply
Member
Posts: 196
Joined: 2002.04
Post: #6
Yep, turning depth testing off is how I got my frames counter up and running. I found the code in a demo named particle.c in the GLUT Examples from the OS X dev CD.

Iceman
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  OpenGL Perspective Screen to Obj Coordinates Mapping Question WhatMeWorry 5 9,184 Feb 17, 2011 05:40 PM
Last Post: Holmes
  problem mixing 3d with 2d render wolfra 0 1,880 Feb 24, 2010 02:14 AM
Last Post: wolfra
  Turning off mixing iPod music dsk00 0 2,682 Jun 4, 2009 10:25 PM
Last Post: dsk00
  Mixing obj-c and c++ DesertPenguin 2 3,506 Aug 29, 2006 07:47 AM
Last Post: TomorrowPlusX
  getting the perspective i want dave05 15 5,917 May 9, 2006 10:51 AM
Last Post: unknown