Texture Loading "Per Triangle" versus all of the Triangles Called with glDrawElements

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:

Hmm, to me it looks like texture coords are not what you expect them to be. Is it possible that the two triangles have inconsitent winding (i.e. one is clockwise, the other counter-clockwise)?

Hmmm, wouldn’t that cause the triangles themselves to not be drawn correctly?

As shown the drawing is displayed, it’s just the materials that aren’t being drawn on the whole object.

I could be wrong, I am just not sure if there is a problem with the winding order…

Hmmm, wouldn’t that cause the triangles themselves to not be drawn correctly?

As always: it depends :wink: For sure if you enable back face culling and the triangles have inconsistent winding one of them will get culled. Of course, it’s possible this is something else entirely, but from the picture you posted I’d start looking if the tex-coords are what they are supposed to be.