Hello,
I have this weird problem that I assume is really simple to fix but I can’t figure it out. Basically my textures are being loaded per “triangle” when I use them in OpenGL.
Thank you in advance for any assistance you can provide.
Here is how I am loading them into OpenGL:
glGenTextures(1, &TextureObject_ID); // section being edited by CKoeber to pull in material files
glActiveTexture(GL_TEXTURE0 + 1);
glBindTexture(GL_TEXTURE_2D, TextureObject_ID);
GLsizei iFormat = BytesPerPixel == 24 ? GL_BGR : BytesPerPixel == 8 ? GL_LUMINANCE : 0;
GLsizei iInternalFormat = BytesPerPixel == 24 ? GL_RGB : GL_DEPTH_COMPONENT;
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB,
WidthOfTexture, HeightOfTexture, 0, iFormat,
GL_UNSIGNED_BYTE, bytesDataPointer);
glGenerateMipmap(GL_TEXTURE_2D);
FreeImage_Unload(loadedImage);
glGenSamplers(1, &TextureSamplerObject_ID);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
setFiltering(TEXTURE_FILTER_MAG_BILINEAR, TEXTURE_FILTER_MIN_BILINEAR_MIPMAP);
HasMipsBeenGenerated = true;
glActiveTexture(GL_TEXTURE0 + 0);
glBindTexture(GL_TEXTURE_2D, NULL);
I am sending my UV coordinates to OpenGL like so:
glBufferSubData(GL_ARRAY_BUFFER, UVOffset, UVBufferSize, UVs);
glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, 0, 0);
glEnableVertexAttribArray(2);
I am buffering my vertices and normals in similar fashion as I am drawing fine.
Also,
Here is the relevant section in the graphics card for the fragment shader:
/*
In Fragment Shader...
*/
uniform sampler2D MainTextureSampler;
in vec2 TextureCoordinates;
out vec4 finalColor;
void Main() {
vec4 MaterialTextureColor = texture2D(MainTextureSampler, TextureCoordinates);
finalColor = MaterialTextureColor;
}
Below is an example image: