GLUT program does nothing...?

May 12, 2009 at 2:11am
I'm trying to follow a GLUT tutorial that I found at the following site:

http://www.lighthouse3d.com/opengl/glut/index.php?1

I can get the first example program to compile and run, but when it runs, it doesn't do what it (presumably) is supposed to do, and that is to create a blank window with a title that you specify. It just pops up with a Command Prompt window that after a second or so displays the "pause" message ("Press any key to continue...").

Here's the code, just in case there might be a problem that I missed:

1
2
3
4
5
6
7
8
9
10
11
#include <stdlib.h>
#include <glut.h>

void main(int argc,char** argv)
{
	glutInit(&argc,argv);
	glutInitDisplayMode(GLUT_DEPTH | GLUT_SINGLE | GLUT_RGBA);
	glutInitWindowPosition(192,144);
	glutInitWindowSize(640,480);
	glutCreateWindow("GLUT says: Hello, World!");
}


I don't include a return statement at the end of main() on purpose, because the tutorial doesn't have one either.

I think I have everything in order...maybe. All I know is that the program compiles and runs, and that Visual C++ appears to be accepting my paths that I gave it for GLUT dependencies.

I just don't understand what's going wrong...
Last edited on May 12, 2009 at 2:14am
May 12, 2009 at 4:05am
Nothing persistent will happen unless you enter the event loop. Change your program to:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <stdlib.h>
#include <glut.h>

int main(int argc,char** argv)
{
	glutInit(&argc,argv);
	glutInitDisplayMode(GLUT_DEPTH | GLUT_SINGLE | GLUT_RGBA);
	glutInitWindowPosition(192,144);
	glutInitWindowSize(640,480);
	glutCreateWindow("GLUT says: Hello, World!");

	glutMainLoop();

	return 0;
}

Also, you should use standard C code even if the tutorial doesn't.

Hope this helps.
May 12, 2009 at 11:42am
Thanks for the help. I've changed the code in my main(), and added a rendering function that draws a triangle on screen, because (for whatever reason) it won't work without one. I get an error saying something about that there's no display callback, and I'm guessing that the rendering function is what it's talking about.

In any case, my problem appears to be solved (for now). Here's the revised code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include <stdlib.h>
#include <glut.h>

void RenderScene()
{
	glClear(GL_COLOR_BUFFER_BIT);
	glBegin(GL_TRIANGLES);
		glVertex3f(-0.5,-0.5,0.0);
		glVertex3f(0.5,0.0,0.0);
		glVertex3f(0.0,0.5,0.0);
	glEnd();
	glFlush();
}

int main(int argc,char** argv)
{
	glutInit(&argc,argv);
	glutInitDisplayMode(GLUT_DEPTH | GLUT_SINGLE | GLUT_RGBA);
	glutInitWindowPosition(192,144);
	glutInitWindowSize(640,480);
	glutCreateWindow("GLUT says: Hello, World!");
	glutDisplayFunc(RenderScene);
	glutMainLoop();

	return 0;
}


I think I'll leave this thread open, just in case something else goes wrong that I can't figure out on my own, but I'm hoping that won't happen.
May 12, 2009 at 12:38pm
It's been a while since I've played with GLUT, so I forgot -- yes, you must have at minimum a display callback. Sorry I missed that. Good job!
Topic archived. No new replies allowed.