Jump to content

  • Log In with Google      Sign In   
  • Create Account


#ActualShotoReaper

Posted 12 October 2012 - 09:55 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?

#1ShotoReaper

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:

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

Can anyone see the error?

PARTNERS