Projection / Zbuffer problems...

Member
Posts: 110
Joined: 2002.04
Post: #1
I need GL help... GL is all new to me...

1. projection...
I need to know how to set up a projection matrix or view port or what ever...
that will let me supply primitives to draw WITH OUT doing any projection
to the primitives...

So far Im using

// left, right, bottom, top, near, far
glOrtho( 0.0, in_view_port->right, in_view_port->bottom, 0.0, -1, 10);

With this... BANG! is running fine as a OS-X RB plug in except for one thing
and that is the zbuffer seems not to be working at all.

What am I doing wrong...

Im digging through books but they all seem to be using GL projection...
which is not what I need since the shapes sent to GL are already projected etc..

- Mac Lead ZeniMax Online Studios
- Owner Plaid World Studios
- Resume: http://www.chrisdillman.com
Quote this message in a reply
Member
Posts: 110
Joined: 2002.04
Post: #2
OK I think I found the bug...

It is like my coordinate system is like inside out under open GL compared to RAVE....

Now I thought I had my engine set up to use the GL style coordinate system...

hmmmm Sad

- Mac Lead ZeniMax Online Studios
- Owner Plaid World Studios
- Resume: http://www.chrisdillman.com
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #3
That may well be the case. There's an essentially arbitrary decision to be made for any 3D API as to whether the coordinate system is right-handed or left-handed. OpenGL and Direct3D chose opposite conventions.

You might be able to fix your problem by issuing a glScalef(1.0f, 1.0f, -1.0f) before drawing any of your objects.
Quote this message in a reply
Member
Posts: 110
Joined: 2002.04
Post: #4
Quote:Originally posted by OneSadCookie
That may well be the case. There's an essentially arbitrary decision to be made for any 3D API as to whether the coordinate system is right-handed or left-handed. OpenGL and Direct3D chose opposite conventions.

You might be able to fix your problem by issuing a glScalef(1.0f, 1.0f, -1.0f) before drawing any of your objects.

Turns out my Z is back wards.

I just tested it with glScalef(1.0f, 1.0f, -1.0f)

Fixes it fine.

Is there any reason not to use glScalef(1.0f, 1.0f, -1.0f)
and just do the -z in my code instead?

- Mac Lead ZeniMax Online Studios
- Owner Plaid World Studios
- Resume: http://www.chrisdillman.com
Quote this message in a reply
Mars_999
Unregistered
 
Post: #5
You shouldn't have to use glScalef() all the time, are you sure your using glLoadIdentity()? To reset the matrix projection? You should be able to setup the glOrtho() to appear correctly so you shouldn't have to put a glScalef(0.0f, 0.0f, -10.0f). AFAIK you use glScalef() to shrink or explode your polygons and not your view. Seems to a bubble gum fix? I might be wrong on the whole subject to!! =) Anyway thats my opinion I guess.
Quote this message in a reply
Member
Posts: 110
Joined: 2002.04
Post: #6
Quote:Originally posted by Mars_999
You shouldn't have to use glScalef() all the time, are you sure your using glLoadIdentity()? To reset the matrix projection? You should be able to setup the glOrtho() to appear correctly so you shouldn't have to put a glScalef(0.0f, 0.0f, -10.0f). AFAIK you use glScalef() to shrink or explode your polygons and not your view. Seems to a bubble gum fix? I might be wrong on the whole subject to!! =) Anyway thats my opinion I guess.

You are. ;-)

But heres why...

1. your are correct most apps should never need to use glScalef(0.0f, 0.0f, -10.0f)
they can set up glOrtho.

2. My problem is that my engine is Renderer and API independant.
So in my case the Z value was basically backwards... where as GL's is negativve to move the
camera forward... which seems wrong to me... not that there is really any correct
way to do this...

Cookies fix of using glScalef(0.0f, 0.0f, -1.0f) will simply reverse the Z values of
everything ran through the matrix. There by fixing my problem.

- Mac Lead ZeniMax Online Studios
- Owner Plaid World Studios
- Resume: http://www.chrisdillman.com
Quote this message in a reply
Member
Posts: 304
Joined: 2002.04
Post: #7
>>
Is there any reason not to use glScalef(1.0f, 1.0f, -1.0f)
<<
no, none.

>>
You shouldn't have to use glScalef() all the time...
AFAIK you use glScalef() to shrink or explode your polygons and not your view.
<<
Rookie mistake. Its called the *modelview* matrix b/c you can think of it as the model's transformation or the view's transformation. Whether you think about it as moving the objects two units to the left - or think about it as moving the camera two units to the right - its the same modelview matrix. When you 'explode' your polygons - you could also think about it that you are 'shrinking' your view. Six of one, half a dozen of the other.

Here is a quote from one of many opengl faqs:
>>>
9.150 Can I make OpenGL use a left-handed coordinate space?


OpenGL doesn't have a mode switch to change from right- to left-handed coordinates. However, you can easily obtain a left-handed coordinate system by multiplying a negative Z scale onto the ModelView matrix. For example:


glMatrixMode (GL_MODELVIEW);
glLoadIdentity ();
glScalef (1., 1., -1.);
/* multiply view transforms as usual... */
/* multiply model transforms as usual... */
<<<

I d/l this opengl faq from ftp://ftp.frii.com/pub/martz/outgoing/oglfaq.zip

hth,
Codemattic
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Projection Matrix vs. Animation Speed jbirac 0 1,713 Dec 20, 2005 12:50 AM
Last Post: jbirac
  Projection matrix : Strange thing ? Ole 4 2,986 Sep 13, 2003 02:38 AM
Last Post: Ole
  switching projection modes Muffinking 1 2,171 Aug 10, 2003 08:34 PM
Last Post: OneSadCookie
  Interpolating Ortho projection to 3d arekkusu 8 5,601 Feb 27, 2003 04:53 AM
Last Post: codemattic