I am having alot of trouble getting texturing to work with GLSL and my VAO's, I managed to get lighting and color with GLSL working earlier(using an individuale VBO for ther verts, color, and normals) so i know my view/projection/model matrixies are all okay. I manually generate all the verticies of a cube into v[108] (im not using TRIAGLE_STRIPS right now so its 2 tri's a side) and then the tex coords for each vertex into t[72]. Since each vertex of 3 floats only requires two tex coords right? Might be useful to know im going off Swiftless's OpenGL 4 GLSL tutorials so I'm using glm and glew.
Also I use glBindAttribute to always pass the vertices position as a vec3 and to pass the tex coords as a vec2 into my Shader program(the same way i passed verts, color and normals earlier)
Any way heres some code:
This generates my VAO from 2 VBO's, one fro my verts and the other tex coords.
glGenVertexArrays(1, &vaoID); glBindVertexArray(vaoID); glGenBuffers(2, &vboID[0]); //Verticies glBindBuffer(GL_ARRAY_BUFFER, vboID[0]); glBufferData(GL_ARRAY_BUFFER, 108 * sizeof(GLfloat), v, GL_STATIC_DRAW); glVertexAttribPointer((GLuint)0, 3, GL_FLOAT, GL_FALSE, 0, 0); glEnableVertexAttribArray(0); //Tex Coords glBindBuffer(GL_ARRAY_BUFFER, vboID[1]); glBufferData(GL_ARRAY_BUFFER, 72 * sizeof(GLfloat), t, GL_STATIC_DRAW); glVertexAttribPointer((GLuint)1, 2, GL_FLOAT, GL_FALSE, 0, 0); glEnableVertexAttribArray(1); glBindVertexArray(0);
Then I draw the cube like so:
shader->bind(); int projectionMatrixLocation = glGetUniformLocation(shader->id(), "projectionMatrix"); int viewMatrixLocation = glGetUniformLocation(shader->id(), "viewMatrix"); int modelMatrixLocation = glGetUniformLocation(shader->id(), "modelMatrix"); int texture_location = glGetUniformLocation(shader->id(), "texture_color"); glUniformMatrix4fv(projectionMatrixLocation, 1, GL_FALSE, &projectionMatrix[0][0]); glUniformMatrix4fv(viewMatrixLocation, 1, GL_FALSE, &viewMatrix[0][0]); glUniformMatrix4fv(modelMatrixLocation, 1, GL_FALSE, &modelMatrix[0][0]); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, texture[0]); glUniform1i(texture_location, 0); glBindVertexArray(vaoID); glDrawArrays(GL_TRIANGLES, 0, 36); glBindVertexArray(0); shader->unbind();
...and my Vertex and Pixel(fragment) shaders respectivley:
#version 150 core
uniform mat4 projectionMatrix;
uniform mat4 viewMatrix;
uniform mat4 modelMatrix;
in vec3 in_Position;
in vec2 in_TexCoord;
void main(void){
gl_TexCoord[0] = in_TexCoord;
gl_Position = projectionMatrix * viewMatrix * modelMatrix * vec4(in_Position, 1.0);
}
#version 150 core
uniform sampler2D texture_color;
void main(void){
gl_FragColor = texture2D(texture_color, gl_TexCoord[0].st);
}
The result is a white cube that seems to lose its scaleing compared to when I specify a solid gl_FragColorMy assumtion is something to do with gl_TexCoord[0] not being a vec2 like in_TexCoord but I can't seem to find much/any documentaion on GLSL when using custom arrays for everything. All the examples I've seen use gl_MultiTexCoord[0] to pull the tex coords from the now depriciated glMultiTexCoordxx()... I think
I can post the vertex and tex coords initialization routine if that would help but its alot of crap lol.
I apologize if I'm not giving enough info or too much lol. I greatly appreciate any help given!!






