Jump to content

  • Log In with Google      Sign In   
  • Create Account

#ActualKametec

Posted 10 May 2013 - 03:20 AM

Hi,

I'm getting started with OpenGL. I'm trying to get my first program working, but I have no luck so far and I have no idea why. My test program is inspired by the first program in a book named "OpenGL Programming Guide, The Official Guide to Learning OpenGL, Version 4.3, Eight Edition".

 

I've written both vertex and fragment shaders, I've written code to initialize FreeGlut, GLEW, compile the shaders and link the shader program. But I have issues with the linking proccess. The output of glGetProgramInfoLog is this:

 

Vertex shader(s) failed to link, fragment shader(s) failed to link.
Vertex link error: INVALID_OPERATION.
ERROR: error(#97) No program main found
fragment link error: INVALID_OPERATION.
ERROR: error(#97) No program main found

 

I've written definition of my shaders into files, their contents are:

Vertex shader in triangles.vert:

 

#version 400 core

layout(location = 0) in vec4 vPosition;

void main()
{
    gl_Position = vPosition;
}

 

Fragment shader in triangles.frag:

 

#version 400 core

out vec4 fColor;

void main()
{
    fColor = vec4(0.0, 0.0, 1.0, 1.0);
}

 

I believe that the error suggests that there is something wrong with my shaders, but I don't know what. Both have void main() present.

 

For completeness' sake I include my C++ program which takes care about compiling and linking the shaders:

 

int main(int argc, char** argv)
{
    GLuint vShad,fShad,prg;
    GLchar **str = new GLchar*[1];
    GLubyte i;
    GLchar c;
    GLint err;

    str[0] = new GLchar[256];
    for (i=0; i<255;i++)
        str[0][i] = NULL;
    str[0][255] = NULL;
    i = 0;

    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_RGBA);
    glutInitWindowSize(512,512);
    glutInitContextVersion(4,0);
    glutInitContextProfile(GLUT_CORE_PROFILE);
    glutCreateWindow(argv[0]);
    if (glewInit())
        return -1;

    //Code omitted: vertices and buffers 

    //vertex shader
    std::ifstream ifs("F:\\dev\\project\\test\\test\\triangles.vert");
    while (ifs.get(c)) //Reading contents of the file into GLchar**
    {
        str[0][i] = c;
        i++;
    }
    vShad = glCreateShader(GL_VERTEX_SHADER);
    glShaderSource(vShad,1,(const char **)str,NULL);
    glCompileShader(vShad);
    glGetShaderiv(vShad,GL_COMPILE_STATUS,&err);
    if (err == GL_FALSE)
    {
        //Code omitted: Fetching compiler log
        return 1;
    }

    //fragment shader
    for (i=0; i<255;i++)
        str[0][i] = NULL;
    str[0][255] = NULL;
    i = 0;
    ifs.open("F:\\dev\\project\\test\\test\\triangles.frag");
    while (ifs.get(c)) //Reading contents of the file into GLchar**
    {
        str[0][i] = c;
        i++;
    }
    fShad = glCreateShader(GL_FRAGMENT_SHADER);
    glShaderSource(fShad,1,(const char **)str,NULL);
    glCompileShader(fShad);
    glGetShaderiv(fShad,GL_COMPILE_STATUS,&err);
    if (err == GL_FALSE)
    {
        //Code omitted: Fetching compiler log
        return 2;
    }

    //shader program
    prg = glCreateProgram();
    glAttachShader(prg,vShad);
    glAttachShader(prg,fShad);
    glLinkProgram(prg);
    glGetProgramiv(prg,GL_LINK_STATUS,&err);
    if (err == GL_FALSE)
    {
        //Code omitted: Fetching linker log
        return 3;
    }
    glUseProgram(prg);

    //Code omitted

    return 0;
}

 

A few notes:

I had to reduce #version 430 core to #version 400 core, because FreeGlut couldn't initialize OpenGL 4.3 context on my hardware.

I am sure that shaders are compiled successfully. My main() returns 3, indicating an error with linking.

I have omitted code which I believe to be irrelevant to my issue.

Both FreeGlut and GLEW are initialized.

I'm using MS Visual Studio 2010 Express, FreeGlut 2.8.1 and GLEW 1.9.0.

 

I would be really grateful for any advice on where should I check for error and what kind of error might that be.

Thanks in advance.

 

edit: Code omitted comments are now in right places.

edit2: Glut window, profile and context initialization code included, unnecessary empty lines in code removed

edit3: Code responsible for reading files updated


#4Kametec

Posted 10 May 2013 - 02:57 AM

Hi,

I'm getting started with OpenGL. I'm trying to get my first program working, but I have no luck so far and I have no idea why. My test program is inspired by the first program in a book named "OpenGL Programming Guide, The Official Guide to Learning OpenGL, Version 4.3, Eight Edition".

 

I've written both vertex and fragment shaders, I've written code to initialize FreeGlut, GLEW, compile the shaders and link the shader program. But I have issues with the linking proccess. The output of glGetProgramInfoLog is this:

 

Vertex shader(s) failed to link, fragment shader(s) failed to link.
Vertex link error: INVALID_OPERATION.
ERROR: error(#97) No program main found
fragment link error: INVALID_OPERATION.
ERROR: error(#97) No program main found

 

I've written definition of my shaders into files, their contents are:

Vertex shader in triangles.vert:

 

#version 400 core

layout(location = 0) in vec4 vPosition;

void main()
{
    gl_Position = vPosition;
}

 

Fragment shader in triangles.frag:

 

#version 400 core

out vec4 fColor;

void main()
{
    fColor = vec4(0.0, 0.0, 1.0, 1.0);
}

 

I believe that the error suggests that there is something wrong with my shaders, but I don't know what. Both have void main() present.

 

For completeness' sake I include my C++ program which takes care about compiling and linking the shaders:

 

int main(int argc, char** argv)
{
    GLuint vShad,fShad,prg;
    GLchar **str = new GLchar*[1];
    GLubyte i;
    GLchar c;
    GLint err;

    str[0] = new GLchar[256];
    for (i=0; i<255;i++)
        str[0][i] = NULL;
    str[0][255] = NULL;
    i = 0;

    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_RGBA);
    glutInitWindowSize(512,512);
    glutInitContextVersion(4,0);
    glutInitContextProfile(GLUT_CORE_PROFILE);
    glutCreateWindow(argv[0]);
    if (glewInit())
        return -1;

    //Code omitted: vertices and buffers 

    //vertex shader
    std::ifstream ifs("F:\\dev\\project\\test\\test\\triangles.vert");
    while (ifs.good()) //Reading contents of the file into GLchar**
    {
        c = ifs.get();
        str[0][i] = c;
        i++;
    }
    vShad = glCreateShader(GL_VERTEX_SHADER);
    glShaderSource(vShad,1,(const char **)str,NULL);
    glCompileShader(vShad);
    glGetShaderiv(vShad,GL_COMPILE_STATUS,&err);
    if (err == GL_FALSE)
    {
        //Code omitted: Fetching compiler log
        return 1;
    }

    //fragment shader
    for (i=0; i<255;i++)
        str[0][i] = NULL;
    str[0][255] = NULL;
    i = 0;
    ifs.open("F:\\dev\\project\\test\\test\\triangles.frag");
    while (ifs.good()) //Reading contents of the file into GLchar**
    {
        c = ifs.get();
        str[0][i] = c;
        i++;
    }
    fShad = glCreateShader(GL_FRAGMENT_SHADER);
    glShaderSource(fShad,1,(const char **)str,NULL);
    glCompileShader(fShad);
    glGetShaderiv(fShad,GL_COMPILE_STATUS,&err);
    if (err == GL_FALSE)
    {
        //Code omitted: Fetching compiler log
        return 2;
    }

    //shader program
    prg = glCreateProgram();
    glAttachShader(prg,vShad);
    glAttachShader(prg,fShad);
    glLinkProgram(prg);
    glGetProgramiv(prg,GL_LINK_STATUS,&err);
    if (err == GL_FALSE)
    {
        //Code omitted: Fetching linker log
        return 3;
    }
    glUseProgram(prg);

    //Code omitted

    return 0;
}

 

A few notes:

I had to reduce #version 430 core to #version 400 core, because FreeGlut couldn't initialize OpenGL 4.3 context on my hardware.

I am sure that shaders are compiled successfully. My main() returns 3, indicating an error with linking.

I have omitted code which I believe to be irrelevant to my issue.

Both FreeGlut and GLEW are initialized.

I'm using MS Visual Studio 2010 Express, FreeGlut 2.8.1 and GLEW 1.9.0.

 

I would be really grateful for any advice on where should I check for error and what kind of error might that be.

Thanks in advance.

 

edit: Code omitted comments are now in right places.

edit2: Glut window, profile and context initialization code included, unnecessary empty lines in code removed


#3Kametec

Posted 10 May 2013 - 02:33 AM

Hi,

I'm getting started with OpenGL. I'm trying to get my first program working, but I have no luck so far and I have no idea why. My test program is inspired by the first program in a book named "OpenGL Programming Guide, The Official Guide to Learning OpenGL, Version 4.3, Eight Edition".

 

I've written both vertex and fragment shaders, I've written code to initialize FreeGlut, GLEW, compile the shaders and link the shader program. But I have issues with the linking proccess. The output of glGetProgramInfoLog is this:

 

Vertex shader(s) failed to link, fragment shader(s) failed to link.

Vertex link error: INVALID_OPERATION.

ERROR: error(#97) No program main found

fragment link error: INVALID_OPERATION.

ERROR: error(#97) No program main found

 

I've written definition of my shaders into files, their contents are:

Vertex shader in triangles.vert:

 

#version 400 core

 

layout(location = 0) in vec4 vPosition;

 

void main()

{

    gl_Position = vPosition;

}

 

Fragment shader in triangles.frag:

 

#version 400 core

 

out vec4 fColor;

 

void main()

{

    fColor = vec4(0.0, 0.0, 1.0, 1.0);

}

 

I believe that the error suggests that there is something wrong with my shaders, but I don't know what. Both have void main() present.

 

For completeness' sake I include my C++ program which takes care about compiling and linking the shaders:

 

int main(int argc, char** argv)

{

    GLuint vShad,fShad,prg;

    GLchar **str = new GLchar*[1];

    GLubyte i;

    GLchar c;

    GLint err;

 

    str[0] = new GLchar[256];

    for (i=0; i<255;i++)

        str[0][i] = NULL;

    str[0][255] = NULL;

    i = 0;

    glutInit(&argc, argv);
    
    //Code omitted: Glut window, context

    if (glewInit())

        return -1;

 

    //Code omitted: vertices and buffers

 

    //vertex shader

    std::ifstream ifs("F:\\dev\\project\\test\\test\\triangles.vert");

    while (ifs.good()) //Reading contents of the file into GLchar**

    {

        c = ifs.get();

        str[0][i] = c;

        i++;

    }

    vShad = glCreateShader(GL_VERTEX_SHADER);

    glShaderSource(vShad,1,(const char **)str,NULL);

    glCompileShader(vShad);

    glGetShaderiv(vShad,GL_COMPILE_STATUS,&err);

    if (err == GL_FALSE)

    {

        //Code omitted: Fetching compiler log

        return 1;

    }

 

    //fragment shader

    for (i=0; i<255;i++)

        str[0][i] = NULL;

    str[0][255] = NULL;

    i = 0;

    ifs.open("F:\\dev\\project\\test\\test\\triangles.frag");

    while (ifs.good()) //Reading contents of the file into GLchar**

    {

        c = ifs.get();

        str[0][i] = c;

        i++;

    }

    fShad = glCreateShader(GL_FRAGMENT_SHADER);

    glShaderSource(fShad,1,(const char **)str,NULL);

    glCompileShader(fShad);

    glGetShaderiv(fShad,GL_COMPILE_STATUS,&err);

    if (err == GL_FALSE)

    {

        //Code omitted: Fetching compiler log

        return 2;

    }

 

    //shader program

    prg = glCreateProgram();

    glAttachShader(prg,vShad);

    glAttachShader(prg,fShad);

    glLinkProgram(prg);

    glGetProgramiv(prg,GL_LINK_STATUS,&err);

    if (err == GL_FALSE)

    {

        //Code omitted: Fetching linker log

        return 3;

    }

    glUseProgram(prg);

 

    //Code omitted

 

    return 0;

}

 

A few notes:

I had to reduce #version 430 core to #version 400 core, because FreeGlut couldn't initialize OpenGL 4.3 context on my hardware.

I am sure that shaders are compiled successfully. My main() returns 3, indicating an error with linking.

I have omitted code which I believe to be irrelevant to my issue.

Both FreeGlut and GLEW are initialized.

I'm using MS Visual Studio 2010 Express, FreeGlut 2.8.1 and GLEW 1.9.0.

 

I would be really grateful for any advice on where should I check for error and what kind of error might that be.

Thanks in advance.

 

edit: Code omitted comments are now in right places.


#2Kametec

Posted 10 May 2013 - 02:32 AM

Hi,

I'm getting started with OpenGL. I'm trying to get my first program working, but I have no luck so far and I have no idea why. My test program is inspired by the first program in a book named "OpenGL Programming Guide, The Official Guide to Learning OpenGL, Version 4.3, Eight Edition".

 

I've written both vertex and fragment shaders, I've written code to initialize FreeGlut, GLEW, compile the shaders and link the shader program. But I have issues with the linking proccess. The output of glGetProgramInfoLog is this:

 

Vertex shader(s) failed to link, fragment shader(s) failed to link.

Vertex link error: INVALID_OPERATION.

ERROR: error(#97) No program main found

fragment link error: INVALID_OPERATION.

ERROR: error(#97) No program main found

 

I've written definition of my shaders into files, their contents are:

Vertex shader in triangles.vert:

 

#version 400 core

 

layout(location = 0) in vec4 vPosition;

 

void main()

{

    gl_Position = vPosition;

}

 

Fragment shader in triangles.frag:

 

#version 400 core

 

out vec4 fColor;

 

void main()

{

    fColor = vec4(0.0, 0.0, 1.0, 1.0);

}

 

I believe that the error suggests that there is something wrong with my shaders, but I don't know what. Both have void main() present.

 

For completeness' sake I include my C++ program which takes care about compiling and linking the shaders:

 

int main(int argc, char** argv)

{

    GLuint vShad,fShad,prg;

    GLchar **str = new GLchar*[1];

    GLubyte i;

    GLchar c;

    GLint err;

 

    str[0] = new GLchar[256];

    for (i=0; i<255;i++)

        str[0][i] = NULL;

    str[0][255] = NULL;

    i = 0;

    glutInit(&argc, argv);
    
    //Code omitted: Glut window, context

    if (glewInit())

        return -1;

 

    //Code omitted: vertices and buffers

 

    //vertex shader

    std::ifstream ifs("F:\\dev\\project\\test\\test\\triangles.vert");

    while (ifs.good()) //Reading contents of the file into GLchar**

    {

        c = ifs.get();

        str[0][i] = c;

        i++;

    }

    vShad = glCreateShader(GL_VERTEX_SHADER);

    glShaderSource(vShad,1,(const char **)str,NULL);

    glCompileShader(vShad);

    glGetShaderiv(vShad,GL_COMPILE_STATUS,&err);

    if (err == GL_FALSE)

    {

        //Code omitted: Fetching compiler log

        return 1;

    }

 

    //fragment shader

    for (i=0; i<255;i++)

        str[0][i] = NULL;

    str[0][255] = NULL;

    i = 0;

    ifs.open("F:\\dev\\project\\test\\test\\triangles.frag");

    while (ifs.good()) //Reading contents of the file into GLchar**

    {

        c = ifs.get();

        str[0][i] = c;

        i++;

    }

    fShad = glCreateShader(GL_FRAGMENT_SHADER);

    glShaderSource(fShad,1,(const char **)str,NULL);

    glCompileShader(fShad);

    glGetShaderiv(fShad,GL_COMPILE_STATUS,&err);

    if (err == GL_FALSE)

    {

        //Code omitted: Fetching compiler log

        return 2;

    }

 

    //shader program

    prg = glCreateProgram();

    glAttachShader(prg,vShad);

    glAttachShader(prg,fShad);

    glLinkProgram(prg);

    glGetProgramiv(prg,GL_LINK_STATUS,&err);

    if (err == GL_FALSE)

    {

        //Code omitted: Fetching linker log

        return 3;

    }

    glUseProgram(prg);

 

    //Code omitted

 

    return 0;

}

 

A few notes:

I had to reduce #version 430 core to #version 400 core, because FreeGlut couldn't initialize OpenGL 4.3 context on my hardware.

I am sure that shaders are compiled successfully. My main() returns 3, indicating an error with linking.

I have omitted code which I believe to be irrelevant to my issue.

Both FreeGlut and GLEW are initialized.

I'm using MS Visual Studio 2010 Express, FreeGlut 2.8.1 and GLEW 1.9.0.

 

I would be really grateful for any advice on where should I check for error and what kind of error might that be.

Thanks in advance.


#1Kametec

Posted 09 May 2013 - 01:45 AM

Hi,

I'm getting started with OpenGL. I'm trying to get my first program working, but I have no luck so far and I have no idea why. My test program is inspired by the first program in a book named "OpenGL Programming Guide, The Official Guide to Learning OpenGL, Version 4.3, Eight Edition".

 

I've written both vertex and fragment shaders, I've written code to initialize FreeGlut, GLEW, compile the shaders and link the shader program. But I have issues with the linking proccess. The output of glGetProgramInfoLog is this:

Vertex shader(s) failed to link, fragment shader(s) failed to link.

Vertex link error: INVALID_OPERATION.

ERROR: error(#97) No program main found

fragment link error: INVALID_OPERATION.

ERROR: error(#97) No program main found

 

I've written definition of my shaders into files, their contents are:

Vertex shader in triangles.vert:

#version 400 core

 

layout(location = 0) in vec4 vPosition;

 

void main()

{

    gl_Position = vPosition;

}

 

Fragment shader in triangles.frag:

#version 400 core

 

out vec4 fColor;

 

void main()

{

    fColor = vec4(0.0, 0.0, 1.0, 1.0);

}

 

I believe that the error suggests that there is something wrong with my shaders, but I don't know what. Both have void main() present.

 

For completeness' sake I include my C++ program which takes care about compiling and linking the shaders:

int main(int argc, char** argv)

{

    GLuint vShad,fShad,prg;

    GLchar **str = new GLchar*[1];

    GLubyte i;

    GLchar c;

    GLint err;

 

    str[0] = new GLchar[256];

    for (i=0; i<255;i++)

        str[0][i] = NULL;

    str[0][255] = NULL;

    i = 0;

    glutInit(&argc, argv);

    if (glewInit())

        return -1;

 

    //Code omitted: Glut window, context, vertices and buffers

 

    //vertex shader

    std::ifstream ifs("F:\\dev\\project\\test\\test\\triangles.vert");

    while (ifs.good()) //Reading contents of the file into GLchar**

    {

        c = ifs.get();

        str[0][i] = c;

        i++;

    }

    vShad = glCreateShader(GL_VERTEX_SHADER);

    glShaderSource(vShad,1,(const char **)str,NULL);

    glCompileShader(vShad);

    glGetShaderiv(vShad,GL_COMPILE_STATUS,&err);

    if (err == GL_FALSE)

    {

        //Code omitted: Fetching compiler log

        return 1;

    }

 

    //fragment shader

    for (i=0; i<255;i++)

        str[0][i] = NULL;

    str[0][255] = NULL;

    i = 0;

    ifs.open("F:\\dev\\project\\test\\test\\triangles.frag");

    while (ifs.good()) //Reading contents of the file into GLchar**

    {

        c = ifs.get();

        str[0][i] = c;

        i++;

    }

    fShad = glCreateShader(GL_FRAGMENT_SHADER);

    glShaderSource(fShad,1,(const char **)str,NULL);

    glCompileShader(fShad);

    glGetShaderiv(fShad,GL_COMPILE_STATUS,&err);

    if (err == GL_FALSE)

    {

        //Code omitted: Fetching compiler log

        return 2;

    }

 

    //shader program

    prg = glCreateProgram();

    glAttachShader(prg,vShad);

    glAttachShader(prg,fShad);

    glLinkProgram(prg);

    glGetProgramiv(prg,GL_LINK_STATUS,&err);

    if (err == GL_FALSE)

    {

        //Code omitted: Fetching linker log

        return 3;

    }

    glUseProgram(prg);

 

    //Code omitted

 

    return 0;

}

 

A few notes:

I had to reduce #version 430 core to #version 400 core, because FreeGlut couldn't initialize OpenGL 4.3 context on my hardware.

I am sure that shaders are compiled successfully. My main() returns 3, indicating an error with linking.

I have omitted code which I believe to be irrelevant to my issue.

Both FreeGlut and GLEW are initialized.

I'm using MS Visual Studio 2010 Express, FreeGlut 2.8.1 and GLEW 1.9.0.

 

I would be really grateful for any advice on where should I check for error and what kind of error might that be.

Thanks in advance.


PARTNERS