Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8487647
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T21:18:24+00:00 2026-06-10T21:18:24+00:00

For OpenGL learning, I am referring to openglbook . Currently in chapter 2 ,

  • 0

For OpenGL learning, I am referring to openglbook. Currently in chapter 2, I am trying to run its code which is pasted here for reference.

The problem I am facing is with below function:

void CreateShaders(void)
{
    GLenum ErrorCheckValue = glGetError();

    VertexShaderId = glCreateShader(GL_VERTEX_SHADER);
    glShaderSource(VertexShaderId, 1, &VertexShader, NULL);
    glCompileShader(VertexShaderId);

    FragmentShaderId = glCreateShader(GL_FRAGMENT_SHADER);
    glShaderSource(FragmentShaderId, 1, &FragmentShader, NULL);
    glCompileShader(FragmentShaderId);

    ProgramId = glCreateProgram();
        glAttachShader(ProgramId, VertexShaderId);
        glAttachShader(ProgramId, FragmentShaderId);
    glLinkProgram(ProgramId);
    glUseProgram(ProgramId);

    ErrorCheckValue = glGetError(); // =====> returns GL_INVALID_OPERATION
    if (ErrorCheckValue != GL_NO_ERROR)
    {
        fprintf(
            stderr,
            "ERROR: Could not create the shaders: %s \n",
            gluErrorString(ErrorCheckValue)
        );

        exit(-1);
    }
}

As shown in above function(glew.h), why does it return "GL_INVALID_OPERATION" ?
If I comment those line, then it works but just prints a blank window.

Here is my glxinfo. Since my version is 2.2 and this code is meant for 3.3+, I have removed below code to avoid failure:

  glutInitContextVersion(4, 0); 
  glutInitContextFlags(GLUT_FORWARD_COMPATIBLE);
  glutInitContextProfile(GLUT_CORE_PROFILE);

Update: After following suggestions from @Tim’s answer, I was able to run the program successfully; it seems that these lines were creation problem:

“#version 400\n” (replaced with “#version 130”)

and

layout(location=0) (removed).
layout(location=1) (removed).

However due to this the expected triangle is not printed exactly same. Probably the tutorial teaches with latest opengl version in mind, which I don’t have and that creates the problem.

Is there any way to modify the code from latest OpenGL (4.0+) compatible code to lesser versions (e.g. < 3.0) without altering the output ? I won’t be able to upgrade the graphics hardware.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T21:18:26+00:00Added an answer on June 10, 2026 at 9:18 pm

    You’re not doing proper error checking for shader compiling and linking. It’s likely you have some kind of syntax error in your shader which is preventing it from compiling, and therefore your useProgram call attempts to use an invalid program.

    For each shader, after calling glCompileShader you’ll want to call glGetShaderiv(shader, GL_COMPILE_STATUS, compile_status) which returns a true or false in compile_status to tell you if the compilation was a success. If it is not, you can call glGetShaderiv(shader, GL_INFO_LOG_LENGTH, length) to get the size of the infoLog, and then call glGetShaderInfoLog() to get a string which tells you any errors that occured during compilation.

    In summary the compiler/linker error checking should be something like this:

    void CheckError (GLuint shaderId, uint LINE)
    {
      GLint bCompiled;
      glGetShaderiv(shaderId, GL_COMPILE_STATUS, &bCompiled);
      if(bCompiled == false)
      {
        GLint length;
        glGetShaderiv(shaderId, GL_INFO_LOG_LENGTH, &length);
        GLchar *pInfo = new GLchar[length + 1];
        glGetShaderInfoLog(shaderId, length, &length, pInfo);
        fprintf(stderr, "called at line-%u: Compiler/Linker error: %s", LINE, pInfo);
        delete[] pInfo;
      }
    }
    

    If both shaders compile successfully, then after linking the program, you want to test the same thing on the program object with glGetProgramiv/GL_LINK_STATUS and glGetProgramInfoLog

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am learning OpenGL and having a problem with gluPerspective. Here is the code
I'm learning OpenGL from this tutorial: http://openglbook.com/the-book/ . I have problem with shaders. I'm
Total noob here learning openGL and I don't have any code to post because
The problem is that, shaders (pretty simple ones, as I'm learning OpenGL) fail to
I'm currently learning OpenGL and got my first bunch of geometry and textures displayed.
I'm currently learning OpenGL ES programming on Android (2.1). I started with the obligatory
I am in a class in which we will be learning OpenGL. The professor
I'm learning OpenGL ES. When I'm using texture for triangle, I meet error. Here
I am learning OpenGL these days, and I tried to compile the example code
I am learning OpenGL NeHe Production.When I read lesson22 Bump-Mapping、Multi-texture,I got a problem. When

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.