Weird Error Loading Texture

Started by
2 comments, last by McGrane 5 years, 9 months ago

Hey

My laptop recently decided to die, so Ive been transferring my project to my work laptop just to get it up to date, and commit it. I was banging my head against the wall all day, as my textures where not displaying in my program- I was getting no errors and no indication of why it was occurring so I have been just trying to figure it out- I know the image loading was working ok, as im using image data elsewhere, I was pretty confident that the code was fine also, as ive never had an issue with displaying textures before, so I thought it might be the drivers on this laptop, (my old one was just using the built in IntelHD, while this laptop has a NVIDIA graphics card) but all seems to be up to date.

Below are my basic shaders:

Vertex Shader


#version 330 core 

layout(location = 0) in vec3 position; 
layout(location = 1) in vec3 color; 
layout(location = 2) in vec3 normal; 
layout(location = 3) in vec2 texCoord;

uniform mat4 Projection;
uniform mat4 Model;

out vec3 Color;
out vec3 Normal;
out vec2 TexCoord;

void main() 
{ 	
	gl_Position = Projection * Model * vec4( position, 1.0 );
	
	Color    = color;	
	Normal   = normal;
	TexCoord = vec2( texCoord.x, texCoord.y);
}

Fragment Shader


#version 330 core 
in vec3 Color;
in vec3 Normal;
in vec2 TexCoord;

uniform sampler2D textureData;

void main()
{
	vec4 textureColor = texture( textureData, TexCoord );
		
	vec4 finalColor = textureColor * vec4( Color, 1.0f); 
	
	gl_FragColor = finalColor;
}

Calling Code


glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, textureID);
glUniform1i(glGetUniformLocation(shaderID, "textureData"), textureID);

Now this is the part i dont understand, I worked through my program, until I got to the above 'Calling Code'. This just displays a black texture.. my original issue. Out of desperation, I just tried changing the name in glGetUniformLocation from "textureData" to "textureData_invalid" to see if my error checks would through up something, but in actual fact, it is now displaying the texture as expected. Can anyone fathom a guess as too why this is occurring.. im assuming the random text is just picking up the correct location by c++ witchcraft, but why is the original one not getting picked up correctly and/or not working as expected

I realize more code is probably needed to see how it all hangs together.. but it seems to come down to this as the issue

Advertisement

where are you uploading the texture to the gpu?

Ok, never-mind.. re-reading the post for my inevitable bad spelling and grammar i see the issue...


glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, textureID);
glUniform1i(glGetUniformLocation(shaderID, "textureData"), textureID);

The glGetUniformLocation should not be taking the textureID- this both solves the issue and makes sense to me.

Thanks gamedev anyway, solved my problem :)

This topic is closed to new replies.

Advertisement