Keep the gluInit Window Open

Sid Kraft 96 Reputation points
2026-08-05T01:33:18.3466667+00:00

//OpenGL functions, open a window and initialize

void display(void)

{

glClearColor(0.0f, 1.0f, 0.0f, 1.0f);

glClear(GL_COLOR_BUFFER_BIT);

glLoadIdentity();

glBegin(GL_LINES);

I = 0.;

do

{

	glVertex3d(PLOTX[I], PLOTY[I], PLOTZ[I]);

	glVertex3d(PLOTX[I + 1], PLOTY[I + 1], PLOTZ[I + 1]);

	++I;

	//output the values to the plot routines in OpenGL

	cout << "Output of values to OpenGL Plot routines, I" << " " << PLOTX[I] << " " << PLOTY[I] << " " << PLOTZ[I] << " " << I << "\n";

	cout << "Output of values to OpenGL Plot routines, I+1" << " " << PLOTX[I] << " " << PLOTY[I] << " " << PLOTZ[I] << " " << I + 1 << "\n";

} while (I <= INOW);

glEnd;

//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("This is a window title");

glutDisplayFunc(display);

glutIdleFunc(display);

//glutMainLoop();

glFlush();

}

int main(int argcp, char** argv)

.

.

.

{

Running the above OpenGL sequence with graphics output to a window that was created with glutInit. Before I can view the output to the window, it immediately closes. How can I keep it open until finished in OpenGL and glutInit? 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.

0 comments No comments

2 answers

Sort by: Most helpful
  1. Tom Tran (WICLOUD CORPORATION) 5,625 Reputation points Microsoft External Staff Moderator
    2026-08-05T02:49:17.7266667+00:00

    Hi @Sid Kraft ,

    The window closes because glutMainLoop() is commented out. That function keeps GLUT processing window events and calls the display function you registered.

    I would call it from main after initializing the window:

    int main(int argc, char** argv)
    {
        initWindow(&argc, argv);
        glutMainLoop();
        return 0;
    }
    

    Also change:

    glEnd;
    

    to:

    glEnd();
    

    The parentheses are required to call the function, as explained in Microsoft’s documentation for compiler warning C4551.

    With those changes, the window should remain open and GLUT can call display(). If it stays open but only shows the green background, that would be a separate drawing or coordinate issue.

    If this helps resolve your issue, I would appreciate it if you could follow this guidance. It may also help others who encounter the same problem. 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-05T01:36:39.66+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.