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 8689951
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T23:47:20+00:00 2026-06-12T23:47:20+00:00

Trying to get a very simple opengl/glut/glew program up and running. Currently the display()

  • 0

Trying to get a very simple opengl/glut/glew program up and running. Currently the display() function passed to glutDisplayFunc() is not being called. When executed, init() sets everything up and gives me a blank white window, but display never fills it with the generated points. Here is the init() function which is called just before entering the glutMainLoop():

void init()
{

    //generate points
    const int NumPoints = 5000;
    point3 points[NumPoints];

    point3 vertices[3] = {point3(-1.0, -1.0, 0.0),
                          point3(0.0, 1.0, 0.0),
                          point3(1.0, -1.0, 0.0)};


    points[0] = point3(0.25, 0.5, 0.0);

    for(int k = 1; k < NumPoints; k++)
    {
        int j = rand() % 3;
        points[k] = (points[k-1]+vertices[j])/2.0;
    }

    //load shaders and use the resulting shader program
    GLuint program = InitShader("shaders/vshader.glsl", "shaders/fshader.glsl");

    GLint linked;
    glGetProgramiv( program, GL_LINK_STATUS, &linked );
    if( !linked ){
        std::cerr << "Shader program failed to link" << std::endl;
        GLint logSize;
        glGetProgramiv( program, GL_INFO_LOG_LENGTH, &logSize);
        char *logMsg = new char[logSize];
        glGetProgramInfoLog( program, logSize, NULL, logMsg);
        std::cerr << logMsg << std::endl;
        delete [] logMsg;

        exit( EXIT_FAILURE );
    }

    glUseProgram( program );

    //create Vertex-Array object
    GLuint aBuffer;

    glGenVertexArrays(1, &aBuffer);
    glBindVertexArray((GLuint)&aBuffer);

    //create Buffer object
    GLuint buffer;

    //glGenBuffers(1, &buffer);
    glGenBuffers(1, &buffer);
    glBindBuffer(GL_ARRAY_BUFFER, buffer);
    glBufferData(GL_ARRAY_BUFFER, sizeof(points),
                 points, GL_STATIC_DRAW);

    //initialize the vertex position attribute from the vertex shader
    GLuint loc = glGetAttribLocation( program, "vPosition");
    glEnableVertexAttribArray( loc );
    glVertexAttribPointer( loc, 3, GL_FLOAT, GL_FALSE, 0, 0);

    glClearColor( 1.0, 1.0, 1.0, 1.0);  // white background


}

and here are the main() and display() functions:

void display()
{
    fprintf(stderr, "display called!\n");
    glClear(GL_COLOR_BUFFER_BIT);
    glDrawArrays(GL_POINTS, 0, 5000);
    glFlush();
}

int main(int argc, char **argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_SINGLE | GLUT_RGBA);
    glutInitWindowSize(500, 500);
    glutInitWindowPosition(100, 100);
    glutDisplayFunc(display);
    glutCreateWindow("Program 1");
    glewInit();

    init();

    glutMainLoop();
    return 0;
}

using eclipse CDT C/C++ with MinGW. Debugging shows that glutMainLoop is indeed being called but I can’t follow it past that. Could it be a shader issue? They are reportedly compiling and linking fine, but here they are

vshader.glsl

#version 150

in vec4 vPosition;

void main() {
    gl_Position = vPosition;
}

.

fshader.glsl

#version 150

out vec4 fColor;

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

edit: the shaders definitely work. By inserting glutIdleFunc(display); into the main(), the program executes properly and draws all the expected points. So like I originally thought, for some reason glutMainLoop() just doesnt want to call the function passed to glutDisplayFunc()? Or am I doing something terribly wrong?

  • 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-12T23:47:22+00:00Added an answer on June 12, 2026 at 11:47 pm

    GLUT can create multiple windows. glutDisplayFunc operates on the currently active window, so you must call glutCreateWindow before the glut…Func functions.

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

Sidebar

Related Questions

I'm trying to get a very simple Javascript function to work that will change
I'm trying to get client-side validation running. I've put together a very simple test
I am trying to get my very simple shader working with my current OpenGL
I'm trying to get a very simple test of Amazon SimpleDB running with Node.js/Express.
I am trying to get a very simple program to compile while using functions
I'm trying to get a very simple Spring @mvc app to work and I'm
I'm trying to compile a very simple c++ code and get a linking error
I'm trying to make a very simple OSGi test but I can't get it
I'm trying to build a very simple OpenGL-app under Ubuntu 10.04 (I have a
SOLVED, ERROR IN THE JAVASCRIPT-FILE I'm trying to get a very simple autocomplete test

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.