Still No Graphic Output

Sid Kraft 96 Reputation points
2026-08-05T20:21:59.1066667+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();
	//issue the GL commands
	glTranslatef(-.3, 0., 0.);
	glRotated(ROT, XX, YY, ZZ);
	glScalef(.001, .001, .001);
	glBegin(GL_LINES);
	I = 0.;
	do
	{
		glVertex3d(PLOTX[I], PLOTY[I], PLOTZ[I]);
		glVertex3d(PLOTX[I + 1], PLOTY[I + 1], PLOTZ[I + 1]);
		++I;
	} 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)
.
.
.
initWindow(&argcp, argv);
glutMainLoop();
return 0;
}

Have the above sequence of events in C++, Visual Studio, though that I had placed all instructions in the functions necessary to output the curve data to my window:
-OpenGL instructions within the "display" function
-call to the initWindow function with argument input from the int main(...) function
-call to the glutMainLoop(); function to produce the graphics output
-return 0; to terminate

The program executes all, displays the window but no graphics output???
Does this mean that: the window has a black display, does the output also have black so would be invisible, do I have to change the color of the graphic curve data or? Please advise, Sid Kraft
Developer technologies | Visual Studio | Other
Developer technologies | Visual Studio | Other

A family of Microsoft suites of integrated development tools for building applications for Windows, the web, mobile devices and many other platforms. Miscellaneous topics that do not fit into specific categories.

0 comments No comments

1 answer

Sort by: Most helpful
  1. Rakesh Agrawal 5 Reputation points
    2026-08-11T15:15:47.7833333+00:00

    The missing graphics output is caused by three separate issues in the code:

    No Active Color Set for Vertices: glColor3f(...) (or similar) is never called before drawing lines. By default, OpenGL uses black (0.0, 0.0, 0.0) for geometry, which makes the drawn lines completely invisible against a dark background or obscured if the default state matches the clear color.

    Missing Double-Buffering Swap: GLUT defaults to single-buffered display unless GLUT_DOUBLE is specified. However, single-buffered rendering requires glFlush() or glutSwapBuffers() inside the display() function. Since glFlush() is commented out inside display() and instead called prematurely in initWindow(), the rendered commands are never flushed/flushed to the frame buffer.

    Array Bounds Overflow in Drawing Loop: The loop evaluates PLOTX[I + 1] up to I == INOW. If INOW is the final valid index of the array, I + 1 reads out of bounds, leading to undefined behavior or silent loop termination before execution finishes.

    Resolution & Fixed Code

    Set the Geometry Color: Add glColor3f(1.0f, 0.0f, 0.0f); (or another bright color) inside display() prior to glBegin(GL_LINES).

    Flush the Render Queue: Uncomment glFlush() inside display(), or switch to double buffering by adding GLUT_DOUBLE to glutInitDisplayMode and replacing glFlush() with glutSwapBuffers().

    Fix Array Bounds: Adjust the loop condition to stop at I < INOW so PLOTX[I + 1] stays within valid array limits.

    #include <GL/glut.h>
    

    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.