In my shader program, I have my attributes and uniforms added to a map for each. What I have displayed is a heightmap, but cant seem to connect the graphic texture to display.
mUniformList
(std::string, GLuint) contains all the uniforms added from my shader (8 total). The problem is that retrieving and connecting the sampler2D named "groundTexture."
void Terrain::init()
{
....
....
// VAO
glGenVertexArrays(1, &mVAO);
glBindVertexArray(mVAO);
// VBO
glGenBuffers(1, &mVBO);
glBindBuffer(GL_ARRAY_BUFFER, mVBO);
glBufferData(GL_ARRAY_BUFFER, sizeof(mVertices), &mVertices[0], GL_STATIC_DRAW);
glEnableVertexAttribArray(shader["position"]);
glVertexAttribPointer(shader["position"], 3, GL_FLOAT, GL_FALSE, 0, (void*)0);
// IBO
glGenBuffers(1, &mIBO);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, mIBO);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(mIndices), &mIndices[0], GL_STATIC_DRAW);
// Load Heightmap texture
mTexture.loadTexture(heightMapFilePath, mHeightMapTextureID, 0);
// Texture coordinates
glGenBuffers(1, &mTexCoordID);
glBindBuffer(GL_ARRAY_BUFFER, mTexCoordID);
glBufferData(GL_ARRAY_BUFFER, sizeof(mTexCoords), &mTexCoords[0], GL_STATIC_DRAW);
glEnableVertexAttribArray(shader["texCoord"]);
glVertexAttribPointer(shader["texCoord"], 2, GL_FLOAT, GL_FALSE, 0, (void*)0);
// load ground texture
mTexture.loadTexture(groundTextureFilePath, mTextureID, 0);
shader.connectTexture(mTextureID);
}
With connectTexture being:
void TerrainShader::connectTexture(GLuint id)
{
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, id);
glUniform1i(mUniformList["backgroundTexture"], 0);
glBindBuffer(GL_ARRAY_BUFFER, 0);
}
UPDATE
Fixed dereferencable error pertaining to the mUniformList
. No errors of any kind whatsoever, but still nothing displayed.
terrainfrag.glsl
#version 330 core
layout (location = 0) out vec4 color;
smooth in vec2 TexCoord;
smooth in vec3 Normal;
uniform sampler2D backgroundTexture;
void main()
{
vec3 normalized = normalize(Normal);
color = texture(backgroundTexture, TexCoord);
color += vec4(1, 1, 1, 1);
}
color += vec4(1,1,1,1);
is that meant to be there just to see the terrain white for the bottom image? \$\endgroup\$ – mythos Dec 28 '15 at 6:43