Jump to content

  • Log In with Google      Sign In   
  • Create Account


#ActualShotoReaper

Posted 12 October 2012 - 08:31 AM

Cornstalks,I try use your method.
Thanks for the answers!

#1ShotoReaper

Posted 12 October 2012 - 08:28 AM

Cornstalks,I use your method but when I get the uniform locations from shader, I get an error:

Engine.cpp

shader = content.Load<Shader>("Shaders/simpleshader.glsl");     //it call load method from shader.

ModelMatrixUniformLocation = glGetUniformLocation(shader->ID, "ModelMatrix");
ViewMatrixUniformLocation = glGetUniformLocation(shader->ID, "ViewMatrix");
ProjectionMatrixUniformLocation = glGetUniformLocation(shader->ID, "ProjectionMatrix");
ExitOnGLError("ERROR: Could get uniform locations");

Shader.cpp

void Shader::Load(const char* filename)
{
ifstream in(filename, ios::binary);
if(!in)
    {
	    cerr << "Could open file" << filename << endl;    
	    exit(1);   
    }
    
    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;

    ID = glCreateProgram();
    CreateShader(fragmentShaderID,fs_shader,GL_FRAGMENT_SHADER);
    CreateShader(vertexShaderID,vs_shader,GL_VERTEX_SHADER);
    Initialize();
}

void Shader::CreateShader(GLuint shader_id, std::string shader, GLenum type_shader)
{
    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 the shader");
}

void Shader::Initialize(void)
{
    glAttachShader(ID, fragmentShaderID);
    glAttachShader(ID, vertexShaderID);
    glLinkProgram(ID);
}

PARTNERS