Minimalist's C++ OpenGL Programming Template for Windows, Mac OSX, and Linux | |
1. IntroductionYou can download pieces of code that allows you to open an OpenGL-enabled window, take key input, monitor key and mouse status etc. In the current trend, you need to create a big application framework and then fill the small amount of code. The file created by the framework gets megabytes when the amount you write is just a few hundred lines. It's like dispatching a fully loaded F-15E Strike Eagle to kill one rat. It is often laughable. On the other hand, the framework you can download here is small. This framework just opens up a window and let you write a polling-based main loop, just like an old-style programming. There is nothing wrong with a polling-based programming, which is good enough for simple purposes. I've been using this framework for verifying my algorithms. This framework has been derived from the code I wrote for YSFLIGHT, and also I used it in the C++ programming course. So, I think the code is well battle-tested. Well, none of my students used Linux framework. So, Linux framework may still be a little weak. This framework helps you if you faced, or you are facing, or will probably face one of the following problems.
I have also included my bitmap-font library in the download package so that you can draw ASCII characters without breaking code portability. To me, lack of ASCII-text drawing function is only one weakness of OpenGL. I'm not talking about fancy decorated stylish font. I just need to draw something readable on the screen, and I don't want to break portability just for that purpose. Although I have written a reference manual, I suppose it is easier to read some short examples to see how to use my functions. Here is one of the examples included in the package.
Easy enough, isn't it? Maybe, one thing I need to explain is FsPollDevice() function. This function internally checks events and stores key states, key strokes, mouse status, etc., in the template's buffer. Unless you call this function once in the loop, functions like FsInkey(), FsGetMouseState(), and other device-inquiry functions will not return correct value. The package also includes the same set of functions that works on Windows and Linux. If you stick with the template, your program can be compiled and run on Mac OS X, Windows and Linux. The condition for using the source codes and programs available on this page is as follows: you take responsibility for any consequence of using the source codes and/or the programs available on this page, and I will not take responsibility. If you agree with this condition, you can use the source codes available on this page in your program, modify them as necessary, and also bundle the joystick calibrator also available in this web site to your program, regardless of free or commercial, open source or proprietary. If you do not agree this condition, please do not use anything you download from this web site. Let me make clear one thing. Using source code available from this page will NOT obligate you to disclose your source code.
2. Download3. About ExamplesIf you learned programming in 1980s, these examples may remind you of good-old days of programming. Some of the examples use my OpenGL bitmap-font functions. See this page for more details. The first example is line art. It draws random lines with random colors. It was one of the first programming examples that I saw when I started learning programming. The next example is "Squash" The ball bounces on the top, left, and right edges of the window, and you need to move your racket by mouse to prevent the ball from falling below the bottom edge of the window. The third example is "Echo." This shows how you can get characters produced by key strokes. The template has two functions for getting key strokes, FsInkey() and FsInkeyChar(). FsInkey is for getting raw key strokes and FsInkeyChar is for getting characters. The fourth example has a diamond that follows the mouse cursor. It is for showing how to get mouse state. The fifth example is a typical OpenGL example, flipping cube. The cube rotates toward the direction of the mouse cursor relative to the center of the window. The sixth example demonstrates how to check key status. This program is a simple shooting game. FsGetKeyState function will return non-zero if the key specified by the parameter is depressed, or zero if not. You can see fskeycode.h for the keycode used in this template. 4. Function ReferenceYou can see the function reference from here. It is also included in the zip file after 2010/12/11 version.
[Update Information] 2010/12/12 2010/12/11 2010/01/04
[Download this version] 2009/12/25
[Download this version]
|
|