Here is my updated function:
// Enable the attributes of the shader (Values are hard coded)glEnableVertexAttribArray(0);glEnableVertexAttribArray(1);//glEnableVertexAttribArray(2); //Enable the texture coordinate attribute// VertexglBindBuffer(GL_ARRAY_BUFFER, m_uiVertexBufferID[staticObject->id]);//glVertexPointer(3, GL_FLOAT, 0, (char *) NULL);glVertexAttribPointer((GLint)0, 3, GL_FLOAT, GL_FALSE, 0, 0); // Using shaders (new way) //ColorglBindBuffer(GL_ARRAY_BUFFER, m_uiColorBufferID[staticObject->id]);//glColorPointer(3, GL_FLOAT, 0, 0);glVertexAttribPointer((GLint)1, 3, GL_FLOAT, GL_FALSE, 0, 0); // Using shaders (new way)// Texture (TBI)//glBindBuffer(GL_ARRAY_BUFFER, m_fTextureBufferID[staticObject->id]);//glVertexAttribPointer((GLint)2, 2, GL_FLOAT, GL_FALSE, 0, 0); // IndexglBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_uiVertexIndexBufferID[staticObject->id]); // Only for closed polygons, no lines or pointsglDrawElements(GL_TRIANGLES, m_uiNumIndices[staticObject->id], GL_UNSIGNED_INT, static_cast< void * >(0)); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);glBindBuffer(GL_ARRAY_BUFFER, 0);// Disable the attributes of the shaderglDisableVertexAttribArray(0);glDisableVertexAttribArray(1);
If I comment out the "Table" line in my game loop code (shown above), it does render the second box, but only that. As for my shader, here is the code that sets up my two custom variables:
//Bind the attribute locationsm_GLSLProgram->bindAttrib(0, "a_Vertex");m_GLSLProgram->bindAttrib(1, "a_Color");//m_GLSLProgram->bindAttrib(2, "a_TexCoord"); //Re link the programm_GLSLProgram->linkProgram(); m_GLSLProgram->bindShader(); //Enable our shader
I am using a class to manage GLSL. The bindAttrib function takes the index and the name of the variable. I have passed this in manually (0 and 1) earlier in the program when I loaded the simple vertex and fragment shaders. My simple VERTEX shader program is shown below:
#version 120uniform mat4 projection_matrix;uniform mat4 modelview_matrix;attribute vec3 a_Vertex;attribute vec3 a_Color;varying vec4 color;void main(void) { color = vec4(a_Color, 1.0); vec4 pos = modelview_matrix * vec4(a_Vertex, 1.0); gl_Position = projection_matrix * pos; }
My simple FRAGMENT shader program is shown below (pass in and pass out the color):
#version 120varying vec4 color;void main(void) { gl_FragColor = color; }
I've verified that the vertex information is read in and stored correctly in each file. As I mentioned before, I am use Vertex Buffer Objects to store the data on the graphics card. This program did work when I used VBOs and the "glVertexPointer()" function (the commented out items). Thanks for your help so far...my code is a little messy because I am worried more about function than form right now.