Hi Everyone, I've been tearing my hair out over this issue.
I have been having a persistant issue for the past couple of days, where a texture is loaded in, and keeps showing up white. I ran the program in gDEBbugger and it clearly shows that the texture is properly loading in, so the issue must be on the actual usage side.
My Object initialization code (for buffers and vertex attribute pointers) is
glBindVertexArray(_VAO);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _EBO);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(GLuint) * _indices.size(), &_indices[0], GL_STATIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, _VBO);
glBufferData(GL_ARRAY_BUFFER, sizeof(GLVertex) * _vertices.size(), &_vertices[0], GL_STATIC_DRAW);
glEnableVertexAttribArray(0);
glEnableVertexAttribArray(1);
glEnableVertexAttribArray(2);
glEnableVertexAttribArray(3);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(GLVertex), (void*)offsetof(GLVertex, position));
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(GLVertex), (void*)offsetof(GLVertex, uv));
glVertexAttribPointer(2, 3, GL_FLOAT, GL_FALSE, sizeof(GLVertex), (void*)offsetof(GLVertex, normal));
glVertexAttribPointer(3, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(GLVertex), (void*)offsetof(GLVertex, color));
glDisableVertexAttribArray(0);
glDisableVertexAttribArray(1);
glDisableVertexAttribArray(2);
glDisableVertexAttribArray(3);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
glBindVertexArray(0);
My Object rendering code is as follows (It uses an EBO)
VPloc = shader.getUniformLocation("cameraMatrix");
glUniformMatrix4fv(VPloc, 1, GL_FALSE, &camera.getMatrix()[0][0]);
Mloc = shader.getUniformLocation("modelMatrix");
glUniformMatrix4fv(Mloc, 1, GL_FALSE, &_modelMatrix[0][0]);
glBindVertexArray(_VAO);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _EBO);
glBindBuffer(GL_ARRAY_BUFFER, _VBO);
glActiveTexture(GL_TEXTURE0 + _texture->id);
glUniform1i(shader.getUniformLocation("sampler"), _texture->id);
glEnableVertexAttribArray(0);
glEnableVertexAttribArray(1);
glEnableVertexAttribArray(2);
glEnableVertexAttribArray(3);
glBindTexture(GL_TEXTURE_2D, _texture->id);
glDrawElements(GL_TRIANGLES, _indices.size(), GL_UNSIGNED_INT, (void*)0);
glBindTexture(GL_TEXTURE_2D, 0);
_modelMatrix = glm::mat4(1.0f);
glDisableVertexAttribArray(0);
glDisableVertexAttribArray(1);
glDisableVertexAttribArray(2);
glDisableVertexAttribArray(3);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
glBindVertexArray(0);
While the actual render loop looks like this
glEnable(GL_MULTISAMPLE);
glEnable(GL_LINE_SMOOTH);
glEnable(GL_POLYGON_SMOOTH);
if (_glWireframe) {
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
}
else {
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
}
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
//Diffuse draw
_diffuseShader.use();
//_testSprite->scale(0.5f);
_testSprite->draw(_diffuseShader, _gameCamera);
_diffuseShader.unuse();
_window->SwapBuffers();
glDisable(GL_MULTISAMPLE);
glDisable(GL_LINE_SMOOTH);
glDisable(GL_POLYGON_SMOOTH);
I've been able to resolve the issue in the past, but as soon as I change a few things in my Mesh code, everything breaks. I can't figure out what the issue is.