Okay so… my apologies for the multiple threads lately… I’m not much of a graphics programmer at all and I’ve been thrust into the position of being one lately after someone quit and I’ve been handed several years worth of buggy, undocumented, uncommented code, and been told to figure it out and make it work. So… believe me when I say any SCRAPS of wisdom you guys can offer me around here is EXTREMELY appreciated.
I’m trying to build a small standalone project to test a few ideas out and having a little difficulty… I’m getting a lot of -1s for glGetUniformLocation calls that as far as I know should work fine…
Here’s my EXTREMELY simplified fragment shader code:
uniform samplerRect Something;
uniform vec3 testtest;
uniform vec4 blah;
void main(void) {
gl_FragColor = gl_Color;
}
And the relevant parts of the CPU side:
/**
* Render Initialize Shaders
*
*/
void Render::InitializeShaders() {
glewInit();
// Create the vertex and fragment shader
m_ShaderProgram = glCreateProgram();
m_VertexShader = glCreateShader( GL_VERTEX_SHADER );
m_FragmentShader = glCreateShader( GL_FRAGMENT_SHADER );
// create the vert and fragment shader pointers
string vertShaderText;
string fragShaderText;
// read the vertex and fragment shader files in
ReadShaderFile(vertShaderText, "vertexshader.vert");
ReadShaderFile(fragShaderText, "fragshader.frag");
// set up some const char pointers to pass to ShaderSource
const char* vsSource = vertShaderText.c_str();
const char* fsSource = fragShaderText.c_str();
// specify the shader source for the shaders
glShaderSource( m_VertexShader, 1, &vsSource, NULL );
glShaderSource( m_FragmentShader, 1, &fsSource, NULL );
// compile the shaders
glCompileShader( m_VertexShader );
glCompileShader( m_FragmentShader );
// check for Errors
checkCompileErrors( m_VertexShader, "Vertex" );
checkCompileErrors( m_FragmentShader, "Fragment" );
// attach the shaders
glAttachShader( m_ShaderProgram, m_VertexShader );
glAttachShader( m_ShaderProgram, m_FragmentShader );
// link & use the shaders
glLinkProgram( m_ShaderProgram );
glUseProgram( m_ShaderProgram );
}
/**
* Render constructor
*
*/
Render::Render() {
Initialize();
InitializeShaders();
GLint i = glGetUniformLocation(m_ShaderProgram, "Something");
GLint j = glGetUniformLocation(m_ShaderProgram, "testtest");
GLint z = glGetUniformLocation(m_ShaderProgram, "blah");
}
When I run this, I get:
i = 0, j = -1, k = -1.
Any suggestions as to why?
Second question - I’m EXTREMELY confused about interfacing textures and the shader… I’ve been tasked with trying to implement using a texture as a lookup table in the shader code. I’ve looked at a lot of shader tutorials, but I’m still a little confused as to how I’d go about this.
The guy I inherited this project from was trying something similar. The best I could gather was that he was using a samplerRect to reference inside it to get values… I’m just really confused about how you pass a texture into the shader or whatnot though. I understand how you set vector / float / etc values, but textures confuse me a bit and I’m not sure how to make the shader know what texture to read from.
The main thing is I don’t want to actually APPLY the texture to any object. Just… generate a row/column table and turn it into a texture to be passed into the shader for quick lookup. I’m… a bit confused as to how to go about it though. As I said above… any even small SCRAPS of help are AWESOME.