Problem with getting uniform sampler2D location

can anyone please tell me, if shader program 100% exists, it was compiled and linked successfully , then you activate shader program and try to get locations of some uniforms, but get -1. And these uniforms are being used in shader program. Also, as i know, by default smapler2D uniform stores 0 value, but binding texture to GL_TEXTURE2D and GL_TEXTURE0 resulting in “error with black screen” any assumptions, please.

Are they being used in a way that contributes to the shader’s outputs? Because if not, they can be culled.

#version 440 core

out vec4 FragColor;

in vec2 texCoords;

uniform sampler2D tex;

void main(){
FragColor = texture(tex,texCoords);
}
thats fragment shader, i cant get location of “tex” , shader program is as simple as it can be, no errors , all compiles well. I 100% activate program, that 100% exists and 100% correct, also glsl shouldnt make it inaccessible. Also, dont think that posting full source code is good idea, its big enough. Also, texture i use is framebuffer’s texture, but its complete, no errors.

Do you have tried to get uniform locations exactly after linking the program? Or are you getting it on the fly and trying to use? Also, use names with 4 or more characters. There is a issue with the name length in some silly implementations.

1 Like

hello, thnaks for advice about names, thats interesting. i couldnt get location because i created temporary(anonymous) instance of class which creates program(but also it’s destructor deletes program) and did memberwise clone into another instance like : shaderProgram screenShaderProgram = shaderProgram(std::string pathToShaderSources[2]); i feel tupid, spent 5 hours to spot it

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.