gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

DS development > glPopMatrix?!?

#45896 - blaisef01 - Thu Jun 16, 2005 6:57 am

Hi,

In the NDSLib glPopMatrix Function what does the index parameter symbolize.
Is it
a) the index of matrix being used (GL_MODELVIEW, GL_TEXTURE)?
or
b) the index of the matrix being popped.

Cheers

#45907 - duencil - Thu Jun 16, 2005 11:23 am

I think its the number of matrices in the stack to pop from the top. It operates on the current matrix stack .. modelview/projection/or texture.

#89852 - walaber - Tue Jun 27, 2006 12:01 am

could someone please clarify this?

what does the index value mean? after some fiddling around, I think you need to keep track of the total number of matrices pushed, and use this as the index. for example:

[pseudocode]

glReset();
glLookAt( something ); // sets the initial matrix.
glPushMatrix(); // saves current matrix into index 1.

drawSomeStuff();

glTransform( 3, 2, 1 );
glPushMatrix(); // saves current matrix into index 2.

drawSomeStuff();

glTransform( 5, 0 -1 );
glPushMatrix(); // saves current matrix into index 3.

drawSomeStuff();

glPopMatrix(2); // takes us back to the state saved in index 2.

drawMoreStuff();

glPopMatrix(1); .. returns to original.

[/pseudocode]

I'm trying to setup a simple scene graph system, and with a system similar to this, I have it *almost* working properly, but I would love it if someone more experienced would share the "right" way to be using multiple levels of glPushMatrix and glPopMatrix(), particularly in a situation like a scene graph.
_________________
Go Go Gadget NDS!

#89867 - ecurtz - Tue Jun 27, 2006 2:10 am

glPopMatrix() pops the given number off the top. glRestoreMatrix() goes to the specified matrix.

#89882 - walaber - Tue Jun 27, 2006 4:34 am

OK thanks. I had some serious strangeness going on in my code.

does anyone know how full the 3D emulation in Dualis is? I'm getting some weird results from what I think *should* work... I'll test it on the hardware tomorrow to make sure it's my code, and not Dualis.
_________________
Go Go Gadget NDS!

#89928 - ikaris - Tue Jun 27, 2006 2:29 pm

walaber wrote:
OK thanks. I had some serious strangeness going on in my code.

does anyone know how full the 3D emulation in Dualis is? I'm getting some weird results from what I think *should* work... I'll test it on the hardware tomorrow to make sure it's my code, and not Dualis.


My experience is that Dualis doesn't play well with Display Lists...

However, for simple immediate mode OpenGL command I think it works OK.

#90032 - ikaris - Wed Jun 28, 2006 12:12 am

I should add:

Is there a really simple and really good tutorial out there that explains popping and matrices and glTranslate and all that...

Could even just be an OpenGL or DX3D tutorial... it's all the same, but as long as the concepts are explained... I'm not quite sure I understand how all that works... I can get things moving around, but not without some guesswork and trying lots of different things...

#90087 - walaber - Wed Jun 28, 2006 8:14 am

just to update... I have a generic scene graph working... as long as I never go above 2 levels (root->child->child), Dualis works fine. but if I add another level (more children to children), Dualis meses up. it works great on the hardware however, so it's not a big issue.

I would also love to see a nice GL tutorial that goes beyond simple rendering, although that I have now might be enough for my next project.
_________________
Go Go Gadget NDS!

#90175 - edwdig - Wed Jun 28, 2006 7:48 pm

Try taking a look at the NeHe OpenGL tutorials. They start off with simple stuff and work up to much more complicated things.

http://nehe.gamedev.net/

#90232 - wickedtrickster - Wed Jun 28, 2006 11:52 pm

walaber wrote:
OK thanks. I had some serious strangeness going on in my code.

does anyone know how full the 3D emulation in Dualis is? I'm getting some weird results from what I think *should* work... I'll test it on the hardware tomorrow to make sure it's my code, and not Dualis.


Dualis doesn't support 4x4 matrix multiplication in "hardware" and don't like colored vertex... It may not support other things, but without 4x4 matrix, you won't go anywhere in 3d :)

#90311 - silent_code - Thu Jun 29, 2006 4:07 pm

does anyone know how "deep" the nds hardware stack goes? is there a hw stack (or is it a libnds feature)? like in openGL (most accelerators have a depth of 32, afaik).

#90319 - wickedtrickster - Thu Jun 29, 2006 6:01 pm

silent_code wrote:
does anyone know how "deep" the nds hardware stack goes? is there a hw stack (or is it a libnds feature)? like in openGL (most accelerators have a depth of 32, afaik).


The stack is hardware, but I don't know what the stack depth is. You could test it with the matrix control register.

#92135 - dak - Tue Jul 11, 2006 7:06 pm

So just to clarify; Do we need to keep track of our Push/Pop indices? One of my tests went nuts on me when I tried using only glPopMatrix(0) for everything (assuming it meant pop the topmost). ;) I hope for laziness' sake I'm just missing something!

-dak

#92164 - wickedtrickster - Tue Jul 11, 2006 10:37 pm

glPopMatrix(1) for everything if you want to pop the topmost matrix ! :)

No need to keep track of push/pop in this case.

#92165 - Mighty Max - Tue Jul 11, 2006 10:40 pm

Programming in ogl, you should keep track of your matrix pushes and pops the same way you keep track braces
_________________
GBAMP Multiboot

#92187 - wickedtrickster - Tue Jul 11, 2006 11:57 pm

wickedtrickster wrote:
No need to keep track of push/pop in this case.


I agree with Mighty Max, this was pretty confusioning :)

What I meant is you do not need to keep track of the heigth of the stack like I saw in walaber's example. However, you need to call a pop for each push you do

glPushMatrix // push 1 matrix - 1 matrix on stack
glPushMatrix // push 1 matrix - 2 matrix on stack
glPopMatrix(1) // pop 1 matrix - 1 matrix on stack
glPopMatrix(1) // pop 1 matrix - 0 matrix on stack

or

glPushMatrix // push 1 matrix - 1 matrix on stack
glPushMatrix // push 1 matrix - 2 matrix on stack
glPopMatrix(2) // pop 2 matrix - 0 matrix on stack

is also good.

Sorry for the misunderstanding :)