Jump to content

  • Log In with Google      Sign In   
  • Create Account


glGetUniformLocation error 1282


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
5 replies to this topic

#1 ShotoReaper   Members   -  Reputation: 149

Like
0Likes
Like

Posted 12 October 2012 - 09:51 AM

Hi!
I try to get the uniform location from shader, but it give me an error 1282(GL_INVALID_OPERATION)
This is the code:

Shader.hpp

class Shader : public object
{
    public:
	    Shader();
	    virtual ~Shader();
	    GLuint ID;
	    void Load(const char* filename);
    protected:
    private:
	    GLuint vertexShaderID,
			   fragmentShaderID;
	    void Initialize(void);
	    GLuint CreateShader(std::string shader, GLenum type_shader);
}
;

Shader.cpp

void Shader::Load(const char* filename)
{
ifstream in(filename, ios::binary);
if(!in)
    {
		    cerr << "Could open file" << filename << endl;    // Lanzamos un mensaje de error
		    exit(1);    // exit(1) usado para abortar el programa
    }
   
    std::string glsl_source((std::istreambuf_iterator<char>(in)),
												    std::istreambuf_iterator<char>());
   
    in.close();
   
    if(glsl_source.length() == 0)
    {
		    exit(1);
    }
    std::string fs_shader = "#define COMPILING_FS\n" + glsl_source;
    std::string vs_shader = "#define COMPILING_VS\n" + glsl_source;
    std::cout<<vs_shader<<std::endl;
    ID = glCreateProgram();
    CreateShader(fragmentShaderID,fs_shader,GL_FRAGMENT_SHADER);
    CreateShader(vertexShaderID,vs_shader,GL_VERTEX_SHADER);
    Initialize();
}
GLuint Shader::CreateShader(std::string shader, GLenum type_shader)
{
   GLuint shader_id = 0;
    shader_id = glCreateShader(type_shader);
    const char* glsl_cstr;
    glShaderSource(shader_id, 1, &(glsl_cstr=shader.c_str()),NULL);
    glCompileShader(shader_id);
    ExitOnGLError("Could compile shader");

     return shader_id;
}
void Shader::Initialize(void)
{
    glAttachShader(ID, fragmentShaderID);
    ExitOnGLError("Could attach fragmentshader");
    glAttachShader(ID, vertexShaderID);
    ExitOnGLError("Could attach vertexshader");
    glLinkProgram(ID);
    ExitOnGLError("Could link program");
}

main

ModelMatrixUniformLocation = glGetUniformLocation(shader->ID, "ModelMatrix");     //Error in here
cout<<glGetError()<<endl;	 // output '1282'
cout<<shader->ID<<endl;	 // output '1'

Can anyone see the error?

Edited by ShotoReaper, 12 October 2012 - 09:55 AM.


Sponsor:

#2 Brother Bob   Moderators   -  Reputation: 7870

Like
1Likes
Like

Posted 12 October 2012 - 10:30 AM

One condition for glGetUniformLocation to fail with that error code is that your program didn't link correctly. You should add checks to your code to see if there are compile and/or link errors.

Add this after compiling each shader file.
GLint compiled = 0;
GLint length = 0;
glGetShaderiv(shader, GL_COMPILE_STATUS, &compiled);
glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &length);

if(length > 1) {
	 std::string log(length, '\0');
	 glGetShaderInfoLog(shader, length, &length, &log[0]);
}
Likewise after attempting to link the shader, but replace GL_COMPILE_STATUS with GL_LINK_STATUS and the shader ID with the program ID.

#3 ShotoReaper   Members   -  Reputation: 149

Like
0Likes
Like

Posted 13 October 2012 - 02:39 PM

With gl_compile_status I don't have any error, but with gl_link_status the function glGetShaderiv return 0 and the log is empty.

#4 ShotoReaper   Members   -  Reputation: 149

Like
0Likes
Like

Posted 13 October 2012 - 02:57 PM

Sorry, I was using glGetShaderiv instead of glGetProgramiv

#5 Brother Bob   Moderators   -  Reputation: 7870

Like
0Likes
Like

Posted 13 October 2012 - 02:58 PM

I apologize, I quickly glanced over my own code to verify the code I posted but didn't notice the obvious that the functions are different; you need to use glGetProgramiv and glGetProgramInfoLog when querying the program object and its link status. The code otherwise should be the same.

edit: Good, you apparently found and corrected my mistake already.

Edited by Brother Bob, 13 October 2012 - 03:00 PM.


#6 ShotoReaper   Members   -  Reputation: 149

Like
0Likes
Like

Posted 13 October 2012 - 03:17 PM

Even so your code helped me a lot.
thanks!!




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS