Replacing glMultMatrixd with Shaders ...


First, thanks to everyone for their help with my earlier posts. Much appreciated…

So, my current question has to do with replacing deprecated code.

I currently have a dirty mix of old and new stuff that goes like this:


Somewhere in an initialize function


// Create VBOs
glGenBuffers(VBO_COUNT - 1, mVBONames);

// Save vertex attributes into GPU
glBufferData(GL_ARRAY_BUFFER, lPolygonVertexCount * VERTEX_STRIDE * sizeof(float), lVertices, GL_STATIC_DRAW);
delete[] lVertices;

if (mHasNormal)
	glBufferData(GL_ARRAY_BUFFER, lPolygonVertexCount * NORMAL_STRIDE * sizeof(float), lNormals, GL_STATIC_DRAW);
	delete[] lNormals;

if (mHasUV)
	glBindBuffer(GL_ARRAY_BUFFER, mVBONames[UV_VBO]);
	glBufferData(GL_ARRAY_BUFFER, lPolygonVertexCount * UV_STRIDE * sizeof(float), lUVs, GL_STATIC_DRAW);
	delete[] lUVs;

glBufferData(GL_ELEMENT_ARRAY_BUFFER, lPolygonCount * TRIANGLE_VERTEX_COUNT * sizeof(unsigned int), lIndices, GL_STATIC_DRAW);

delete[] lIndices;

And when I am about to draw later in code


glMultMatrixd((const double*)pGlobalPosition);


glGenVertexArrays(1, &mVBONames[INDEX_VAO]);


const GLsizei lElementCount = mSubMeshes[pMaterialIndex]->TriangleCount * 3;
glDrawElements(GL_TRIANGLES, lElementCount, GL_UNSIGNED_INT, reinterpret_cast<const GLvoid *>(lOffset));




I really want to move to shaders and thus remove myself completely from the glPush-Pop stuff and the glMultMatrixd stuff but I am not exactly sure at the moment how.

It seems like I would just:

[li]Create another array buffer[/li][li]send my global position into that array buffer[/li][li]multiply the buffered vertice data with the global position buffer in a shader[/li][li]and then go from there[/li][/ol]

But is that right?

I didn’t see an exact tutorial online or writeup on how to replace the glMultMatrixd functionality in shaders as I searched.

Any help is appreciated.

Thank you for your time.

There is a useful library called glm that provides a replacement for gl-matrix functions (among other things)

It depends on your needs but basically:

[li]Write or choose a matrix library to use (e.g. glm)[/li][li]Replace your matrix ops with calls to this library[/li][li]When you need to pass the matrix value into the shader, explicitly populate a mat4 (or other matrix type) uniform using a glUniformMatrix* call (e.g. glUniformMatrix4fv)[/li][li]Instead of referencing gl_ModelViewMatrix and similar in your matrix, reference your new mat4 uniform variable (e.g. myModelViewMatrix).[/li][/ol]

Thank you, thanks to folks on this forum I got this working!