| OpenGL GLUT Tutorial
home: http://www.geocities.com/SiliconValley/Code/1219/ e-mail: craterz@hotmail.com Why GLUT? I can think of three great reasons to use GLUT. First, it's OpenGL, you can't beat that. Second, it's amazingly simple to use compared to other windowing APIs. Third, it's portable to likely anything under the sun: Win32, Linux, UNIX, and maybe even Macintosh. Use GLUT, OpenGL, stick to ANSI C/C++ and other multi-platform libraries and you'll have great portability. For my own example, in using MIDAS on The Fuzz with GLUT, I have the potential to be able to mearly recompile and have the program run with minimal hassle on either Win32 or Linux. GLUT provides the obvious window interface. But it also provides input. In the latest version (GLUT 3.7), you have the ability to use keyboard (and indirectly determine if a key is down at any point in time), mouse, and joystick under Win32. glutGameModeString glutGameModeString is a useful function for setting the screen resolution, refresh rate, and bit depth for fullscreen applications (like games). The sole parameter is a pointer to a string which specifies the screen properties desired.
In the above example, this selects a resolution of 640x480, 16 bits per pixel (bit depth), and 60Hz refresh rate. You can create your own game mode string using the following sprintf statement or your own method.
Think of this as a request to the GLUT system. You aren't necessarily guarenteed the mode you requested. glutGameModeGet To see what you are working with, simply use the glutGameModeGet function. The single arguement specifies what you are trying to get. Here's a list of possible arguements.
To determine what mode we are dealing with, the following code snippet should suffice for most cases.
glutEnterGameMode Instead of worrying about a bunch of calls to the Operating System to initialize a fullscreen window and create the OpenGL interface, you can do it in one single call to glutEnterGameMode. It's that simple. Think of it as a replacement to your usual call of glutCreateWindow. Then you must setup your callbacks (display, keyboard, etc) after the call to glutEnterGameMode just like an ordinary GLUT program.
glutLeaveGameMode After you are finished with the fullscreen window, you can get rid of it with a call to glutLeaveGameMode somewhere where you are shutting down. HOWTO: Check if a Key is Down One thing I liked in both Allegro and DirectInput, is that you could determine if any key on the keyboard was down at any time by simply looking up an entry in an array. You can do the exact same thing with GLUT by setting up two callback functions. This is shown below. You will need GLUT 3.7 for this to work, as glutKeyboardUpFunc is required to set the necessary callback.
[ powered by Latte and Python | last updated Sat Aug 25 00:55:02 2001 PST ] |