glutInit Placement

Sid Kraft 96 Reputation points
2026-08-04T15:03:58.9933333+00:00
//OpenGL functions, open a window and initialize
void display(void)
{
	glClearColor(1.0f, 0.0f, 0.0f, 1.0f);
	glClear(GL_COLOR_BUFFER_BIT);
	glLoadIdentity();
	glFlush();
}
//rename glutInit as one already in library, to eliminate "already has a body"
void initWindow(int* argcp, char** argv)
{
	glutInit(argcp, argv);
	glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH);
	glutInitWindowPosition(100, 200);
	glutInitWindowSize(800, 700);
	glutCreateWindow("Output Curve From Input Definition Data");
	glutDisplayFunc(display);
	glutIdleFunc(display);
}
Have the above definitions to call the OpenGL routines and plot graphics to an output "window". Wondering where to place the different elements of the plot. Have the following plot statements, INOW = 47, PLOTX,Y,Z array of values:

 int I =0.;
 do
 {
  glVertex3d(PLOTX[I], PLOTY[I], PLOTZ[I]);
  glVertex3d(PLOTX[I + 1], PLOTY[I + 1], PLOTZ[I + 1]);
 } while (I <= INOW);
 glutMainLoop();

So far, I get no output in the "window" but do get the point values PLOYX, PLOTY, PLOTZ generated.

Final guess is that the loop that generates the "window" output should be placed within the "display" function, but not sure, please advise, Sid Kraft
Developer technologies | C++
Developer technologies | C++

A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.


2 answers

Sort by: Most helpful
  1. Taki Ly (WICLOUD CORPORATION) 3,460 Reputation points Microsoft External Staff Moderator
    2026-08-05T07:16:59.2166667+00:00

    Hello @Sid Kraft ,

    Thank you for providing the details and the code snippets.

    In a typical GLUT application, drawing commands are generally executed within the designated display callback function whenever the window requires repainting. It might be beneficial to place your rendering loop inside the display function.

    Additionally, it is possible that the points are not displaying because the glVertex3d calls are not enclosed within a glBegin() and glEnd() block. OpenGL requires this block to define what types of primitives you are trying to draw (such as GL_LINES or GL_LINE_STRIP).

    I also noticed that the do-while loop does not seem to increment the index I. Adding I++ within the loop could help prevent the application from hanging indefinitely.

    This suggests that updating your display function to include the state block, the loop, and the index increment might resolve the issue. Below is an example of what that could look like:

    void display(void)
    {
        glClearColor(1.0f, 0.0f, 0.0f, 1.0f);
        glClear(GL_COLOR_BUFFER_BIT);
        glLoadIdentity();
    
        // It might be helpful to specify the drawing mode, such as GL_LINES or GL_LINE_STRIP
        glBegin(GL_LINES);
    
        int I = 0;
        // Assuming INOW, PLOTX, PLOTY, and PLOTZ are accessible within this scope
        do
        {
            glVertex3d(PLOTX[I], PLOTY[I], PLOTZ[I]);
            glVertex3d(PLOTX[I + 1], PLOTY[I + 1], PLOTZ[I + 1]);
            I++; // Increment I to avoid an infinite loop
        } while (I <= INOW);
    
        glEnd();
    
        glFlush();
    }
    

    Then, you can retain glutMainLoop(); at the very end of your main function (or the function where you initialize the window) to keep the window open and listening for events.

    I hope this information is helpful. Please let me know if you see the output graphics after making these adjustments, or if I can assist you further. If you found my response helpful or informative, I would greatly appreciate it if you could follow this guide for your confirmation.

    Thank you.

    Was this answer helpful?

    0 comments No comments

  2. Jay Pham (WICLOUD CORPORATION) 3,825 Reputation points Microsoft External Staff Moderator
    2026-08-05T00:07:27.5833333+00:00

    We are currently working the issue and will provide an update soon. Thank you for your patience.

    Was this answer helpful?

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.