PDA

View Full Version : glPushMatrix / glPopMatrix & vertex program?



A027298
03-28-2003, 03:37 AM
Hi guys,

I am using a vertex program to perform specific transformation on the scene. My render function calls glPushMatrix and glPopMatrix() a couple of times. Somehow the result doesn't look proper anymore.

When I turn off my vertex program then it works. Is this normal, or am I doing some mistake in my vp?

Thanks

vincoof
03-28-2003, 03:50 AM
In your vp, make sure you're using the right matrices. To project vertex from object-space to eye-space, use modelview. To project it from object-space to clip-space, use mvp. To project normals for object-space to eye-space, use the inverse transpose of the modelview ie modelview.invtrans

What do you mean by "Somehow the result doesn't look proper anymore" ? Do the vertices move/stretch/turn ? Is lighting messed up ? Texturing messed up ? Fog messed up ?

[Edit] btw which vertex programs are you using ? NV or ARB ?

[This message has been edited by vincoof (edited 03-28-2003).]

sanjo
03-28-2003, 04:28 AM
if you're using vp you completely bypass the ogl matrix ops (push,pop,mul ...).
so you have do it yourself in the vp.

knackered
03-28-2003, 05:22 AM
Slightly misleading that.
You don't bypass push,pop,mul at all - you simply have to transform the vertex yourself using the final modelview/projection matrices. Are you tracking the modelview and projection matrices with the relavant glTrackMatrix functions? This simply loads the modelview and/or projection matrices into vertex program constant registers.

A027298
03-28-2003, 05:49 AM
@vincoof
Thanks...the light is messed up, areas which supposed to be in light aren't, so ok the normals transformation should then be wrong in my code. I gonna check it. I am using arb_vertex_program.

@sanjo
If this would be true, that push,pop has no effect anymore by using vp, then a vp would be very restricted, e.g. a snippet from a render routine:

loadIdentity();
setCamera();

push();
changeModelViewMatrix();
drawStuff();
pop();

push();
changeModelViewMatrix();
drawOtherStuff();
pop();

If the above snippet didn't work anymore, then I would have to transform my geometry "by hand".

...knackered mentioned that.

@knackered
yes I am tracking the matrices properly.


...ok, I go back to work and try it and catch ya l8er. :-)

vincoof
03-28-2003, 06:18 AM
There is an example of lighting in ARB_vertex_program specification, in issue #73.
It's limited to one light, infinite light and infinite viewer, but still it's a very good example.

A027298
03-28-2003, 09:44 AM
Actually I know about this example. I implemented it, but somehow it looks crappy...so I implemented std ogl lighting...actually it works pretty good, except that objects which I transfom with glTranslatef()..., are not lightened properly, they appear black. The rest of the scene is lightened correctly.



[This message has been edited by A027298 (edited 03-28-2003).]

vincoof
03-28-2003, 10:34 AM
For those "good" objects that are not transformed with glTranslatef, are they not transformed at all or is it still some camera setting on top of the modelview matrix ?

Do you setup the camera position/orientation in the projection or the modelview matrix ?

A027298
03-28-2003, 11:03 AM
The "good" objects are not transformed at all, meaning no translate/rotate and stuff...only if I make change on the modelview matrix for the "bad" objects, then they are not lightened correctly. I guess I mess some stuff up in my vp.

Yes in my app. modelviel constists of the normal modelview and projection matrix. The actual projection is on identity. Don't ask why I am doing this :-) I just need that adjustment.

[This message has been edited by A027298 (edited 03-28-2003).]

vincoof
03-28-2003, 12:32 PM
I guess that your non-transformed objects are aligned through the identity modelview matrix, so this could be revelant of matrix misusage. Since the inverse of the identity, the transpose of the identity, and the inverse transpose of the identity are all the same matrices, you could probably use the wrong matrix without noticing it.

Could you post the vertex program (or at least the part of it that makes lighting) ?

A027298
03-28-2003, 07:30 PM
...ohohoh push and pop still doesn't work. If I perform stuff like in the above snippet, parts which shouldn't be affected due to push and pop are affected, it's looking really funny.

In the following I show the part of my vp, where I transform a vertex to clip space:

!!ARBvp1.0

PARAM mvp[4] = {state.matrix.mvp};
PARAM mvinv[4] = {state.matrix.modelview.invtrans};
PARAM mv[4] = {state.matrix.modelview};
...

# light attributes #########
...

# material attributes ######
...

ATTRIB inNormal = vertex.normal;

#######################

ATTRIB inPosition = vertex.position;
ATTRIB inColor = vertex.color;

OUTPUT outPosition = result.position;
OUTPUT outColor = result.color;

DP4 outPosition.x, mvp[0], inPosition;
DP4 outPosition.y, mvp[1], inPosition;
DP4 outPosition.z, mvp[2], inPosition;
DP4 outPosition.w, mvp[3], inPosition;

END

vincoof
03-31-2003, 01:38 AM
I think this program snippet does correctly compute the vertex output. But what about colors ? Don't you compute them in the vertex program ?

FYI, you can't setup a program that computes eg vertex and texcoord and let the standard OpenGL pipeline compute eg lighting and fog.