PDA

View Full Version : Getting ready for opengl 3.1 and beyond



kellogs
03-27-2009, 09:16 AM
Hi, I've been using opengl on and off for a couple of years now as a hobbyist and as I have no real maths background I've come to rely on the glMatrix stack for all my transforming needs. As this is all getting stripped out of the spec I was wondering if there's anyway to start getting use to using my own matrix class for transforms using my current setup, as my card doesn't support opengl 3.0.

Say for example my old glinit and render loop functions looked something like this:


glinit()
{
glClearColor(0.6, 0.6, 0.6, 1);
glViewport(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(FOV, WIDTH/HEIGHT, 0.0f, 100.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}

renderLoop()
{
glClear(GL_COLOR_BUFFER_BIT);
glPushMatrix();
{
glTranslatef(z, y, z);
make some glVertex3f calls();
}
glPopMatrix();
}


What I'd like to do now is something like this I think:


glinit()
{
glClearColor(0.6, 0.6, 0.6, 1);
glViewport(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
myProjection.setProjection(FOV, WIDTH/HEIGHT, 0.0f, 100.0f);
myTransform.transform(0, 0, -50);
myModel.transform( myProjection * myTransform);
}

renderLoop()
{
glClear(GL_COLOR_BUFFER_BIT);
myModel.draw();
}


But when using the above method I can't seem to see anything as, I think, this has to do with the default clipping planes setup? However if I do as in the below example all appears how I expect it to, but obviously this uses the deprecated functions:


glinit()
{
glClearColor(0.6, 0.6, 0.6, 1);
glViewport(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
myProjection.setProjection(FOV, WIDTH/HEIGHT, 0.0f, 100.0f);
myTransform.transform(0, 0, -50);
myModel.transform( myTransform);
}

renderLoop()
{
glClear(GL_COLOR_BUFFER_BIT);
glPushMatrix();
glLoadMatrixf(myProjection);
myModel.draw();
glPopMatrix();
}


So if anyone knows how I can get this working so I'm able to view my transformed model without the use of the fixed function matrix stack it would be a huge help to me, and I'm sure many others in my boat. Just like to point out at this stage myModel.draw is still making glVertex3f calls but this is ok for testing purposes only I hope?

Cheers.

scratt
03-27-2009, 10:00 AM
Firstly it will be a while before OpenGL3.1 is adopted widely, and most manufacturers have said they will continue to support the deprecated commands, which is there prerogative.

Based on that assertion and the fact that GL_ARB_compatibility is detailed in the OpenGL3.1 spec I think its very likely that the major manufacturers will continue to offer these "old" commands for some time to come. GL_ARB_compatibility *if* provided will continue to offer the old commands even in OpenGL3.1

Having said that it's a good idea to get ready for the future.

To answer your question..
Check this instruction out... glUniformMatrix4fv

If you don't have that then...
http://www.opengl.org/sdk/docs/man/xhtml/glVertexAttribPointer.xml
You upload your matrix in chunks of 4 floats.

There is a thread disussing it here..
http://www.opengl.org/discussion_boards/ubbthreads.php?ubb=showflat&Number=234615

kellogs
03-27-2009, 12:25 PM
Ah cheers, all clear now. I've only briefly played with shaders in the past but it all makes sense.
Must admit, I'm probably in the minority here but I'm glad about the GL_ARB_compatibility option, as I found the glmatrix stacks a really nice introduction to transforms, so its nice to think that it it will be around for a little while at least, if only as a stepping stone for new comers. Viva la Red book :)

Ilian Dinev
03-27-2009, 01:18 PM
With nvMath, replacing those stacks is a breeze.

scratt
03-27-2009, 09:49 PM
I too am happy that the old stuff is still there.. Even though I came to OpenGL on the cusp of the 'shader revolution' I still find the direct mode commands handy for prototyping quickly.

The funny thing is I really don't know much about the old lighting and texturing commands because I always did that in shaders, but I still use glLoadMatrix and the like on a daily basis.