home

OpenGL Game Programming (book) Errata


OpenGL Game Programming

Ok, just so there's no confusion, this is most definitely NOT an official page for this textbook! See here for an explanation.

Chapter 2: Using Windows with OpenGL

The code for the "openglwindow" example was missing from the CD-ROM I got with the book, so I had to download the source code from http://glbook.gamedev.net

This example showed how to create an OpenGL-enabled window and was supposed to also show how to go into fullscreen mode, but when I started the application I noticed that it simply ran in window mode! This problem exists in some other examples I believe, but I don't know whether the authors intentionly did this or not. Seemed kind of weird to me to purposely write the code so that it could not possibly make it to fullscreen mode. At the beginning of the code, the fullScreen boolean variable is set to false and no where else in the code has the possiblity of changing to true. This means that the code where the DEVMODE structure is initialized and the ChangeDisplaySettings() function is called never executes, when in reality it should always execute so that you can programmatically determine whether the system is capable of doing fullscreen mode! Basically what I did first was change the fullScreen boolean to true, so that the default mode would be fullscreen, and I also took out this if statement:

if (fullScreen)	
Oh yeah, there's also a statement in WinMain() that I removed that for some odd reason sets fullScreen to false yet again! No chance in hell getting into fullscreen mode with that there... Making these changes causes the code to always attempt to get into fullscreen mode.

This didn't entirely fix the problem... The call to CreateWindowEx() has NULL for the first parameter in the original code, which instead should be the extended styles variable dwExStyle.

There was something else that bothered me about this example, namely that the resolution was hardcoded at 800x600, and so the "fullscreen" mode wasn't exactly FULLSCREEN on my screen running at 1024x768! To get around this, I made calls to the Win32 functions GetSystemMetrics() to get the width and height of the screen, and GetDeviceCaps() for the bits per pixel. Another way around this problem would be to query the system for available display modes and then change to the resolution you want to use, rather than adapting the window to the currently-enabled resolution.

Chapter 8: Texture Mapping

The problem I found in this chapter was in the flag-waving example. Man, I don't know about you, but when I see a cool demo and then start it up to just have it crash (see Chapter 15: Special Effects), or appear screwed up is kind of irritating. So when I started this example up, the flag was waving alright, but the lower right corner of the flag (i.e. the last vertex in the last quad) would sometimes show up way out to the right, putting a really ugly jagged line out, or sometimes way out to the left, and it would change with each start of the program. To make things worse, sometimes the flag would appear perfectly normal! Most of the time when I see random errors such as these, I think, "garbage!" In other words, a pointer being used that wasn't intitalized. As it turned out, the for loop that draws the grid for the flag was going one step further in the x-direction than it should have. This was the line:

for (xIdx = 0; xIdx < 36; xIdx++) // x-direction
I changed the 36 to 35 and the problem vanished! Each start of the program now produces a decent-looking, waving flag.

There was something that bothered me about this example also... the flag was waving, sure, but it looked like it was just floating out in space. Most flags, you know, are attached to flag poles. This one wasn't. I didn't go so far as to create a flag pole persay, but I did clamp the z-values for the verticies along the y=0 line to z=0. I did this with the following lines of code in the IntializeFlag() function's double for loop where the sin wave z-values are being pre-calcuated and stored:

if (xIdx < 1)
    flagPoints[xIdx][yIdx][2]= 0;
This creates a slightly more realistic waving flag (i.e. the flag looks like it's attached to something!).

Chapter 15: Special Effects

There was a problem with the first example in this chapter, which is a 3D world containing sand and cacti! Turned out to be a pretty cool demo, but when I launched it the first time it promptly crashed. I narrowed the problem down to this line of code in the DrawSand() function:

glLockArraysEXT(0, MAP_X * MAP_Z * 6);
The first parameter to the glLockArraysEXT function tells where to start locking the array and the second parameter specifies how many elements to lock. The problem is that the array being operated upon has this declaration:
GLuint  g_indexArray[MAP_X * MAP_Z * 2];
As you can see, the second parameter of the call to glLockArraysEXT() is out of bounds and throwing an exception upon intitialization. I tweaked this line to:
glLockArraysEXT(0, MAP_X * MAP_Z * 2);
...and voila! Starts up and runs beautifully now! I liked this example program a lot, in spite of its tiny flaw.

This is where I'm currently at in the book. Look for more updates as I find problems.

Hosted by www.Geocities.ws

1