red book

Started by
5 comments, last by Emmanuel Deloget 17 years, 6 months ago
i heard about this "OpenGL red book". i downloaded it. it had this sample program in it. looks utterly meaningless if you ask me. tell me if it has effective coding..

#include <iostream.h>

main() {

   OpenAWindowPlease();

   glClearColor(0.0, 0.0, 0.0, 0.0);
   glClear(GL_COLOR_BUFFER_BIT);
   glColor3f(1.0, 1.0, 1.0);
   glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0); 
   glBegin(GL_POLYGON);
      glVertex2f(-0.5, -0.5);
      glVertex2f(-0.5, 0.5);
      glVertex2f(0.5, 0.5);
      glVertex2f(0.5, -0.5);
   glEnd();
   glFlush();

   KeepTheWindowOnTheScreenForAWhile();
}
[Edited by - Fruny on September 27, 2006 10:10:59 AM]
Advertisement
Of course it is effective code. I'm not quite sure what you are asking. The top and bottom functions are of course not defined here and need to be implemented but the OpenGL stuff just clears the render target and draws a polygon.

Only problem with it I see is that it includes <iostream.h> which implies C++ but main has an assumed int return type which implies C.
What do you mean by meaningless? It's a simple illustrative example, with the platform-specific elements represented by some 'imaginary' user-supplied functions.

Anyway, the Red Book is a solid reference and a good starting point for learning OpenGL, so if that's your aim you should definitely spend some time with it.
Quote:Original post by Felon_pro
i heard about this "OpenGL red book". i downloaded it.


The editions of the Red Book that are available for download are seriously out of date. I highly suggest you eventually head to your nearest bookstore and order the most recent edition.

Quote:it had this sample program in it. looks utterly meaningless if you ask me. tell me if it has effective coding..


Aside from the fact that it uses <iostream.h> and omits main()'s int return type, which are bad form, but not surprising considering how old that edition is, the code is perfectly clear to me.

#include <iostream.h>#include <iostream>int main() {   \\ Obviously a placeholder for platform-specific functions   \\ dealing with window management. The GLUT library was written   \\ to abstract platform differences in that book's examples.   OpenAWindowPlease();                                       \\ All function names beginning with 'gl' are OpenGL calls   \\ 'glu' indicates a convenience function that wraps GL calls.   \\ e.g. computing the perspective projection matrix for you.   \\ Sets the color used when clearing the screen to black   \\ red = 0, green = 0, blue = 0, alpha = 0   glClearColor(0.0, 0.0, 0.0, 0.0);     \\ This actually clears the screen, the "color buffer"   \\ There are other buffers, but they aren't used in this   \\ example.   glClear(GL_COLOR_BUFFER_BIT);   \\ This sets the color used for drawing. '3f' indicates that   \\ this is the version that takes 3 floats parameters.   glColor3f(1.0, 1.0, 1.0);   \\ Sets up an orthographic projection so that the boundaries of   \\ the viewport are at coordinates X=-1, X=1, Y=-1, Y=1, Z=-1, Z=1.   \\ In an orthographic projection, the Z coordinate has no visible   \\ effect (except for clipping), and so makes things essentially 2D.   glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0);    \\ Tells OpenGL that we are starting to draw something, a polygon.   glBegin(GL_POLYGON);      \\ The coordinates of the polygon's vertices (points).      \\ This call is the '2 floats' version, which only specifies      \\ the X and Y coordinates, leaving Z=0.      glVertex2f(-0.5, -0.5);      glVertex2f(-0.5, 0.5);      glVertex2f(0.5, 0.5);      glVertex2f(0.5, -0.5);   \\ We're done listing the set of points used to draw this polygon.   \\ When we want to draw another one, we'll issue another glBegin() call.   glEnd();   \\ OpenGL uses a client-server architecture. The computer   \\ on which your program is running is not necessarily the one   \\ that actually performs the rendering. This flushes the pipe   \\ and tells GL to start running the commands.   glFlush();   \\ Another obvious placeholder.   KeepTheWindowOnTheScreenForAWhile();}
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
My Dev c++ compiler (version 4.0) is signalling 31 errors!

OpenAWindowPlease();

also doesn't really sound as any existing function. it sounds like we're almost begging the computer to do something...

anyway, thanx for your help!
Quote:Original post by Felon_pro
OpenAWindowPlease();

also doesn't really sound as any existing function.
It's not (as has been mentioned a couple of times). It's a placeholder for platform-specific window management code or for a cross-platform solution such as GLUT or SDL.
Quote:Original post by jyk
Quote:Original post by Felon_pro
OpenAWindowPlease();

also doesn't really sound as any existing function.
It's not (as has been mentioned a couple of times). It's a placeholder for platform-specific window management code or for a cross-platform solution such as GLUT or SDL.


It actually means that you have to write this function by yourself. Give a look to NeHe tutorial, as they provide system specific initialization code that will suit your needs.

And buy a more recent version of the red book too [smile]

This topic is closed to new replies.

Advertisement