Jump to content

  • Log In with Google      Sign In   
  • Create Account


#Actualthecheeselover

Posted 13 April 2013 - 07:05 PM

Hello,

 

I had been following this tutorial on how to create/compile/link shader http://arcsynthesis.org/gltut/Basics/Tut01%20Making%20Shaders.html until I tested the code. I tried to compile the same vertex and fragment shaders as the author but I got some errors which I naturally didn't understand. I have uploaded the errors I got from OpenGL as an attached image to my post. I don't think the mistakes come from the shaders themselves but more likely from the C++ code. Do you know what are my mistakes?

 

VertexShader.vert

#version 330

layout(location = 0) in vec4 position;
void main()
{
    gl_Position = position;
}

 

FragmentShader.frag

#version 330

void main()
{
    gl_FragColor = vec4(0.7, 0.7, 0.6, 1.0);
}

 

My code:

GLuint CreateShader(GLenum eShaderType, const std::string &strShaderFile)
{
    GLuint shader = glCreateShader(eShaderType);
    const char *strFileData = strShaderFile.c_str();
    glShaderSource(shader, 1, &strFileData, NULL);

    glCompileShader(shader);

    GLint status;
    glGetShaderiv(shader, GL_COMPILE_STATUS, &status);
    if (status == GL_FALSE)
    {
        GLint infoLogLength;
        glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &infoLogLength);

        GLchar *strInfoLog = new GLchar[infoLogLength + 1];
        glGetShaderInfoLog(shader, infoLogLength, NULL, strInfoLog);

        const char *strShaderType = NULL;
        switch(eShaderType)
        {
        case GL_VERTEX_SHADER: strShaderType = "vertex"; break;
        case GL_GEOMETRY_SHADER: strShaderType = "geometry"; break;
        case GL_FRAGMENT_SHADER: strShaderType = "fragment"; break;
        }

        std::cout << "Compile failure in " << strShaderType << "shader:\n" << strInfoLog << "\n";

        delete[] strInfoLog;
    }

 return shader;
}


GLuint CreateProgram(const std::vector<GLuint> &shaderList)
{
    GLuint program = glCreateProgram();

    for(size_t iLoop = 0; iLoop < shaderList.size(); iLoop++)
     glAttachShader(program, shaderList[iLoop]);

    glLinkProgram(program);

    GLint status;
    glGetProgramiv (program, GL_LINK_STATUS, &status);
    if (status == GL_FALSE)
    {
        GLint infoLogLength;
        glGetProgramiv(program, GL_INFO_LOG_LENGTH, &infoLogLength);

        GLchar *strInfoLog = new GLchar[infoLogLength + 1];
        glGetProgramInfoLog(program, infoLogLength, NULL, strInfoLog);
        std::cout << "Linker failure: " << strInfoLog << "\n";
        delete[] strInfoLog;
    }

    for(size_t iLoop = 0; iLoop < shaderList.size(); iLoop++)
        glDetachShader(program, shaderList[iLoop]);

    return program;
}


int main()

{

...

shaderList.push_back(CreateShader(GL_VERTEX_SHADER, "VertexShader.vert"));
shaderList.push_back(CreateShader(GL_FRAGMENT_SHADER, "FragmentShader.frag"));

GLuint shaderProgram = CreateProgram(shaderList);

std::for_each(shaderList.begin(), shaderList.end(), glDeleteShader);

...

}


 

Thank you smile.png

thecheeselover


#4thecheeselover

Posted 13 April 2013 - 06:41 PM

Hello,

 

I had been following this tutorial on how to create/compile/link shader http://arcsynthesis.org/gltut/Basics/Tut01%20Making%20Shaders.html until I tested the code. I tried to compile the same vertex and fragment shaders as the author but I got some errors which I naturally didn't understand. I have uploaded the errors I got from OpenGL as an attached image to my post. I don't think the mistakes come from the shaders themselves but more likely from the C++ code. Do you know what are my mistakes?

 

VertexShader.vert

#version 330

layout(location = 0) in vec4 position;
void main()
{
    gl_Position = position;
}

 

FragmentShader.frag

#version 330

void main()
{
    gl_FragColor = vec4(0.7, 0.7, 0.6, 1.0);
}

 

My code:

GLuint CreateShader(GLenum eShaderType, const std::string &strShaderFile)
{
    GLuint shader = glCreateShader(eShaderType);
    const char *strFileData = strShaderFile.c_str();
    glShaderSource(shader, 1, &strFileData, NULL);

    glCompileShader(shader);

    GLint status;
    glGetShaderiv(shader, GL_COMPILE_STATUS, &status);
    if (status == GL_FALSE)
    {
        GLint infoLogLength;
        glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &infoLogLength);

        GLchar *strInfoLog = new GLchar[infoLogLength + 1];
        glGetShaderInfoLog(shader, infoLogLength, NULL, strInfoLog);

        const char *strShaderType = NULL;
        switch(eShaderType)
        {
        case GL_VERTEX_SHADER: strShaderType = "vertex"; break;
        case GL_GEOMETRY_SHADER: strShaderType = "geometry"; break;
        case GL_FRAGMENT_SHADER: strShaderType = "fragment"; break;
        }

        std::cout << "Compile failure in " << strShaderType << "shader:\n" << strInfoLog << "\n";

        delete[] strInfoLog;
    }

 return shader;
}


GLuint CreateProgram(const std::vector<GLuint> &shaderList)
{
    GLuint program = glCreateProgram();

    for(size_t iLoop = 0; iLoop < shaderList.size(); iLoop++)
     glAttachShader(program, shaderList[iLoop]);

    glLinkProgram(program);

    GLint status;
    glGetProgramiv (program, GL_LINK_STATUS, &status);
    if (status == GL_FALSE)
    {
        GLint infoLogLength;
        glGetProgramiv(program, GL_INFO_LOG_LENGTH, &infoLogLength);

        GLchar *strInfoLog = new GLchar[infoLogLength + 1];
        glGetProgramInfoLog(program, infoLogLength, NULL, strInfoLog);
        std::cout << "Linker failure: " << strInfoLog << "\n";
        delete[] strInfoLog;
    }

    for(size_t iLoop = 0; iLoop < shaderList.size(); iLoop++)
        glDetachShader(program, shaderList[iLoop]);

    return program;
}


int main()

{

...

shaderList.push_back(CreateShader(GL_VERTEX_SHADER, "VertexShader.vert"));
shaderList.push_back(CreateShader(GL_FRAGMENT_SHADER, "FragmentShader.frag"));

GLuint shaderProgram = CreateProgram(shaderList);

std::for_each(shaderList.begin(), shaderList.end(), glDeleteShader);

...

}


 

Thank you smile.png

thecheeselover


#3thecheeselover

Posted 13 April 2013 - 06:39 PM

Hello,

 

I had been following this tutorial on how to create/compile/link shader http://arcsynthesis.org/gltut/Basics/Tut01%20Making%20Shaders.html until I tested the code. I tried to compile the same vertex and fragment shaders as the author but I got some errors which I naturally didn't understand. I have uploaded the errors I got from OpenGL as an attached image to my post. I don't think the mistakes come from the shaders themselves but more likely from the C++ code. Do you know what are my mistakes?

 

VertexShader.vert

#version 330

layout(location = 0) in vec4 position;
void main()
{
    gl_Position = position;
}

 

FragmentShader.frag


#version 330

 

void main()
{
    gl_FragColor = vec4(0.7, 0.7, 0.6, 1.0);
}

 

My code:

 


GLuint CreateShader(GLenum eShaderType, const std::string &strShaderFile)
{
    GLuint shader = glCreateShader(eShaderType);
    const char *strFileData = strShaderFile.c_str();
    glShaderSource(shader, 1, &strFileData, NULL);

    glCompileShader(shader);

    GLint status;
    glGetShaderiv(shader, GL_COMPILE_STATUS, &status);
    if (status == GL_FALSE)
    {
        GLint infoLogLength;
        glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &infoLogLength);

        GLchar *strInfoLog = new GLchar[infoLogLength + 1];
        glGetShaderInfoLog(shader, infoLogLength, NULL, strInfoLog);

        const char *strShaderType = NULL;
        switch(eShaderType)
        {
        case GL_VERTEX_SHADER: strShaderType = "vertex"; break;
        case GL_GEOMETRY_SHADER: strShaderType = "geometry"; break;
        case GL_FRAGMENT_SHADER: strShaderType = "fragment"; break;
        }

        std::cout << "Compile failure in " << strShaderType << "shader:\n" << strInfoLog << "\n";

        delete[] strInfoLog;
    }

 return shader;
}

 

GLuint CreateProgram(const std::vector<GLuint> &shaderList)
{
    GLuint program = glCreateProgram();

    for(size_t iLoop = 0; iLoop < shaderList.size(); iLoop++)
     glAttachShader(program, shaderList[iLoop]);

    glLinkProgram(program);

    GLint status;
    glGetProgramiv (program, GL_LINK_STATUS, &status);
    if (status == GL_FALSE)
    {
        GLint infoLogLength;
        glGetProgramiv(program, GL_INFO_LOG_LENGTH, &infoLogLength);

        GLchar *strInfoLog = new GLchar[infoLogLength + 1];
        glGetProgramInfoLog(program, infoLogLength, NULL, strInfoLog);
        std::cout << "Linker failure: " << strInfoLog << "\n";
        delete[] strInfoLog;
    }

    for(size_t iLoop = 0; iLoop < shaderList.size(); iLoop++)
        glDetachShader(program, shaderList[iLoop]);

    return program;
}

 

int main()

{

...

shaderList.push_back(CreateShader(GL_VERTEX_SHADER, "VertexShader.vert"));
shaderList.push_back(CreateShader(GL_FRAGMENT_SHADER, "FragmentShader.frag"));

GLuint shaderProgram = CreateProgram(shaderList);

std::for_each(shaderList.begin(), shaderList.end(), glDeleteShader);

...

}

Thank you smile.png

thecheeselover


#2thecheeselover

Posted 13 April 2013 - 06:39 PM

Hello,

 

I had been following this tutorial on how to create/compile/link shader http://arcsynthesis.org/gltut/Basics/Tut01%20Making%20Shaders.html until I tested the code. I tried to compile the same vertex and fragment shaders as the author but I got some errors which I naturally didn't understand. I have uploaded the errors I got from OpenGL as an attached image to my post. I don't think the mistakes come from the shaders themselves but more likely from the C++ code. Do you know what are my mistakes?

 

VertexShader.vert

#version 330

layout(location = 0) in vec4 position;
void main()
{
    gl_Position = position;
}

 

FragmentShader.frag


#version 330

 

void main()
{
    gl_FragColor = vec4(0.7, 0.7, 0.6, 1.0);
}

 

My code:

 


GLuint CreateShader(GLenum eShaderType, const std::string &strShaderFile)
{
    GLuint shader = glCreateShader(eShaderType);
    const char *strFileData = strShaderFile.c_str();
    glShaderSource(shader, 1, &strFileData, NULL);

    glCompileShader(shader);

    GLint status;
    glGetShaderiv(shader, GL_COMPILE_STATUS, &status);
    if (status == GL_FALSE)
    {
        GLint infoLogLength;
        glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &infoLogLength);

        GLchar *strInfoLog = new GLchar[infoLogLength + 1];
        glGetShaderInfoLog(shader, infoLogLength, NULL, strInfoLog);

        const char *strShaderType = NULL;
        switch(eShaderType)
        {
        case GL_VERTEX_SHADER: strShaderType = "vertex"; break;
        case GL_GEOMETRY_SHADER: strShaderType = "geometry"; break;
        case GL_FRAGMENT_SHADER: strShaderType = "fragment"; break;
        }

        std::cout << "Compile failure in " << strShaderType << "shader:\n" << strInfoLog << "\n";

        delete[] strInfoLog;
    }

 return shader;
}

 

GLuint CreateProgram(const std::vector<GLuint> &shaderList)
{
    GLuint program = glCreateProgram();

    for(size_t iLoop = 0; iLoop < shaderList.size(); iLoop++)
     glAttachShader(program, shaderList[iLoop]);

    glLinkProgram(program);

    GLint status;
    glGetProgramiv (program, GL_LINK_STATUS, &status);
    if (status == GL_FALSE)
    {
        GLint infoLogLength;
        glGetProgramiv(program, GL_INFO_LOG_LENGTH, &infoLogLength);

        GLchar *strInfoLog = new GLchar[infoLogLength + 1];
        glGetProgramInfoLog(program, infoLogLength, NULL, strInfoLog);
        std::cout << "Linker failure: " << strInfoLog << "\n";
        delete[] strInfoLog;
    }

    for(size_t iLoop = 0; iLoop < shaderList.size(); iLoop++)
        glDetachShader(program, shaderList[iLoop]);

    return program;
}

 

int main()

{

...

shaderList.push_back(CreateShader(GL_VERTEX_SHADER, "VertexShader.vert"));
shaderList.push_back(CreateShader(GL_FRAGMENT_SHADER, "FragmentShader.frag"));

GLuint shaderProgram = CreateProgram(shaderList);

std::for_each(shaderList.begin(), shaderList.end(), glDeleteShader);

...

}

Thank you smile.png

thecheeselover


#1thecheeselover

Posted 13 April 2013 - 06:38 PM

Hello,

 

I had been following this tutorial on how to create/compile/link shader http://arcsynthesis.org/gltut/Basics/Tut01%20Making%20Shaders.html until I tested the code. I tried to compile the same vertex and fragment shaders as the author but I got some errors which I naturally didn't understand. I have uploaded the errors I got from OpenGL as an attached image to my post. I don't think the mistakes come from the shaders themselves but more likely from the C++ code. Do you know what are my mistakes?

 

VertexShader.vert

#version 330

layout(location = 0) in vec4 position;
void main()
{
    gl_Position = position;
}

 

FragmentShader.frag


#version 330

 

void main()
{
    gl_FragColor = vec4(0.7, 0.7, 0.6, 1.0);
}

 

My code:

 


GLuint CreateShader(GLenum eShaderType, const std::string &strShaderFile)
{
    GLuint shader = glCreateShader(eShaderType);
    const char *strFileData = strShaderFile.c_str();
    glShaderSource(shader, 1, &strFileData, NULL);

    glCompileShader(shader);

    GLint status;
    glGetShaderiv(shader, GL_COMPILE_STATUS, &status);
    if (status == GL_FALSE)
    {
        GLint infoLogLength;
        glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &infoLogLength);

        GLchar *strInfoLog = new GLchar[infoLogLength + 1];
        glGetShaderInfoLog(shader, infoLogLength, NULL, strInfoLog);

        const char *strShaderType = NULL;
        switch(eShaderType)
        {
        case GL_VERTEX_SHADER: strShaderType = "vertex"; break;
        case GL_GEOMETRY_SHADER: strShaderType = "geometry"; break;
        case GL_FRAGMENT_SHADER: strShaderType = "fragment"; break;
        }

        std::cout << "Compile failure in " << strShaderType << "shader:\n" << strInfoLog << "\n";

        delete[] strInfoLog;
    }

 return shader;
}

 

GLuint CreateProgram(const std::vector<GLuint> &shaderList)
{
    GLuint program = glCreateProgram();

    for(size_t iLoop = 0; iLoop < shaderList.size(); iLoop++)
     glAttachShader(program, shaderList[iLoop]);

    glLinkProgram(program);

    GLint status;
    glGetProgramiv (program, GL_LINK_STATUS, &status);
    if (status == GL_FALSE)
    {
        GLint infoLogLength;
        glGetProgramiv(program, GL_INFO_LOG_LENGTH, &infoLogLength);

        GLchar *strInfoLog = new GLchar[infoLogLength + 1];
        glGetProgramInfoLog(program, infoLogLength, NULL, strInfoLog);
        std::cout << "Linker failure: " << strInfoLog << "\n";
        delete[] strInfoLog;
    }

    for(size_t iLoop = 0; iLoop < shaderList.size(); iLoop++)
        glDetachShader(program, shaderList[iLoop]);

    return program;
}

 

int main()

{

...

shaderList.push_back(CreateShader(GL_VERTEX_SHADER, "VertexShader.vert"));
shaderList.push_back(CreateShader(GL_FRAGMENT_SHADER, "FragmentShader.frag"));

GLuint shaderProgram = CreateProgram(shaderList);

std::for_each(shaderList.begin(), shaderList.end(), glDeleteShader);

...

}

Thank you :)

thecheeselover


PARTNERS