GL 3.0 and GLH

Back to glh main page

Well, GL 3.0 was announced in August 2008 and a lot of things are declared deprecated.
Among those are glMatrixMode, glFrustum, glOrtho, glLoadMatrixf.
How can GLH help?
GLH has long since offered a software matrix implementation.
Keep in mind that this is not really a bad thing because GPUs don't support glFrustum, glTranslate, glRotate and all that.
The drivers would compute the matrix and upload them to some GPU registers.
So now, you should do the same : compute your matrix and upload to a uniform for your shader to use.
A uniform is basically a series of GPU registers.
A GPU register is 4 floats, so a 4x4 matrix will take 4 registers.

Examples:
//The old way
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0, aspectRatio, zNear, zFar);

//The new way
float mymatrix[16];
glhLoadIdentityf2(mymatrix);
//Notice that this is one of the rare cases where GLH accepts angles in degrees
glhPerspectivef2(mymatrix, 45.0, aspectRatio, zNear, zFar);
//Now use mymatrix!

//The old way
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0.0, 0.0, 1.0);
glRotatef(45.0, 0.0, 1.0, 0.0);
glRotatef(45.0, 0.0, 0.0, 1.0);

//The new way
float mymatrix[16];
glhLoadIdentityf2(mymatrix);
glhTranslatef2(mymatrix, 0.0, 0.0, 1.0);
glhRotateAboutYf2(mymatrix, 45.0//YOU MUST CONVERT TO RADIANS);
glhRotateAboutZf2(mymatrix, 45.0//YOU MUST CONVERT TO RADIANS);

//Let's say you want to combine PROJECTION and MODELVIEW
glhMultMatrixf2(ProjectionMatrix, ModelviewMatrix);
//ProjectionMatrix received the result!

//If you want to make use of SSE, special conditions must be met
//Your array must start at a 16 bytes boundary
//Allocate your array to insure that condition is met
float *mymatrix=(float *)_aligned_malloc(16*sizeof(float), 16/*memory alignement*/);
float *translate=(float *)_aligned_malloc(4*sizeof(float), 16/*memory alignement*/);
glhLoadIdentityf2(mymatrix);
translate[0]=0.0;
translate[1]=0.0;
translate[2]=1.0;
translate[3]=1.0; //w should be 1.0
glhTranslatef2_SSE_Aligned(mymatrix, translate);
_aligned_free(mymatrix);
_aligned_free(translate);









This page is gl3_to_glh.html
Copyright (C) 2008 Vrej M. All Rights Reserved.