PDA

View Full Version : GLUT and Win32



yaro_dup1
02-01-2003, 05:18 AM
Hi,

Do I have to create in VC++ 6 Console application to use GLUT? I've created a Win 32 Application and I have a problems with glutInit because I can't pass arcp and argv parameters from WinMain, if I set glutInit(NULL, NULL) program crashes.

thanks

Dave Milici
02-01-2003, 04:55 PM
Here are a couple things I've found out when working with Win32 GLUT.

If you do a little digging in the GLUT source, you'd find that the Win32 implementation of glutInit() merely parses the command line for some pre-defined GLUT option switches and will adjust the command line accordingly if it finds any.

So you can simply create your own command line with an arg count = 1 and the arg string = app exe name, and pass that instead.

In porting some old public domain GLUT demos to Mac OS X Cocoa framework, I discovered that one of them never bothered to call glutInit() at all. This is *bad* practise for portability reasons since it did not work on Mac OS X, but happened to be acceptable on Win32 since there was so little that the function needed to do.

A final discovery by Kendall at SciTech is that compiling GLUT with Watcom C in Win32 GUI mode will work just like Win32 console mode, the only difference being whether or not a console window appears. The reason this works is that Watcom C's startup code automatically links main() and WinMain() functions interchangeably.

Stack Overflow
02-02-2003, 07:21 PM
Hello glYaro,

This is how you would initialize GLUT using a Win32 Application in Visual C++:

Here is a sample of using a Console App:




void main( int argc, char **argv ) {
glutInit( &argc, argv );
glutInitDisplayMode( GLUT_SINGLE | GLUT_RGB );
glutCreateWindow( "Win32 GLUT" );

glutReshapeFunc( reshape );
glutDisplayFunc( display );

glutMainLoop();
}


This is what it would look like if you revise it using a Win32 Application:




int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd ) {
glutInitDisplayMode( GLUT_SINGLE | GLUT_RGB );
glutCreateWindow( "Win32 GLUT" );

glutReshapeFunc( reshape );
glutDisplayFunc( display );

glutMainLoop();
return 0;
}


Please also remember to include the header file <windows.h>.

I hope this is what you are looking for. http://www.opengl.org/discussion_boards/ubb/smile.gif

- VC6-OGL

DavisPoon
09-19-2003, 01:48 AM
you solved my problem, thanks!
http://www.opengl.org/discussion_boards/ubb/smile.gif