Errors in demo files

54 views
Skip to first unread message

Gabriel N.

unread,
Dec 2, 2012, 8:32:35 PM12/2/12
to uoft_csc...@googlegroups.com
I found several errors in the demo files, some of which cause it to crash immediately when running.

In phong.c:

In line 347:
glGenProgramsARB(NProgs, VertShader);
Should be:
glGenProgramsARB(NProgs, &VertShader);

In line 353:
glGenProgramsARB(NProgs, FragShader);
Should be:
glGenProgramsARB(NProgs, &FragShader);

Both of the above cause the program to crash on my machine.

In line 341:
//if (FragSrc == NULL)
printf
("Invalid frag input file");
This will cause all programs to print out "Invalid frag input file" regardless if the file is invalid or not. It should be:
if (FragSrc == NULL)
  printf
("Invalid frag input file");


In shader.c:

In line 173:
glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, &FragShader);
Should be:
glGenProgramsARB(1, &FragShader);
glBindProgramARB
(GL_FRAGMENT_PROGRAM_ARB, FragShader);
The original wasn't crashing on my machine, (which struck me as odd considering that this function call is objectively wrong, passing in an integer's address instead of the integer itself) but was giving a warning on compilation about a pointer being automatically converted to an integer without an explicit cast. Based on my knowledge of OpenGL, I think this is comparable to accessing invalid/uninitialized memory: it won't always cause problems, but if/when it does it causes bad ones.

In line 29:
#define Near          -1
#define Far            1
This was giving an OpenGL error on my machine, because this gets (eventually) fed into glFrustum(...) (via gluPerspective(...)) as the near and far clipping planes, both of which have to be positive. Instead, these values should be something like:
#define Near          0.001
#define Far           1000
Near needs to be a small positive value to prevent the OpenGL error. Far, on the other hand, needs to be larger than 1, otherwise vertices further than 1 unit from the camera will not be drawn, resulting in a black screen. Setting it to a big value is good enough.

I am developing on a Mac (and thus had to change the includes and Makefiles appropriately), but I highly doubt any of these issues are due to platform differences, as these are all cross-platform APIs. Fixing all of these errors (and including a valid compiled or hand-written frag.txt ARB assembly file in the same directory) results in a working set of demos. Hopefully this helps everyone so they don't have to go through the debugging hell I went through.

Peter Goodman

unread,
Dec 5, 2012, 7:16:39 PM12/5/12
to uoft_csc...@googlegroups.com
Thank you.

Best Regards,

Peter Goodman,
http://www.petergoodman.me
65 High Park Ave.,
Toronto, Ontario
M6P 2R7


--
 
 

Reply all
Reply to author
Forward
0 new messages