Stewart Taylor writes:
On Saturday 13 July 2002 21:57, Jesse Marlin wrote:
Hi Jesse
Thanks for your reply. I tried what your little demo and my own trial program using the nvidia header files and both produced a parse error in glu.h. When I ran them with the glut supplied files they both compiled and
What kinds of errors? Show me the output.
ran OK. Do you have any ideas on what caused this to happen. Out of interest when I started my move over to Linux I bought both the OpenGL Programming Guide and the OpenGL Reference Manualas I 've told that these are just about the best books to get me started.
Is that the red book? That is the one I have heard is good. The one I own is "OpenGL Programming for the X Window System", and it has a green cover. Depending on what you are planning to do, using the GLUT toolkit should be adequate. So any book that discusses GLUT and OpenGL should be good enough to get you going. The book I have shows how to use the GLX interface and also GLUT.
Stewart
No you don't want to use that I'm sure. NVIDIA ships with the NVIDIA_GLX-1.0-xxxx package some header files. These should not differ too much from a standard GL.h file except that they probably have definitions for NVIDIA specific extensions.
NVIDIA_GLX-1.0-2960/usr/include/GL/gl/gl.h glx.h glxtokens.h
Copy these into /usr/include/GL or wherever you prefer. Then refer to them with:
#include <GL/glu.h>
This should get you started. If you don't know anything about OpenGL then I suggest you look into the GLUT toolkit. If you write an OpenGL program in Linux it will use the GLX interface whereas in windows it uses the WGL interface. The GLUT hides this from you, and lets you just programm OpenGL.
To get you started with glut here is an example I did a while back that uses OpenGL to plot a koch snowflake. Compile like so:
gcc -c -g koch.c gcc -o koch koch.o -lGL -lGLU -lglut
Don't pay too much attention to the logic. Look in main for how the window is setup, and then look at the different glXXXXX calls. This is a 2d example, but it should help you get started.
Save to file koch.c -------------------------------------------
#include <stdio.h> #include <time.h> #include <math.h> #include <GL/gl.h> #include <GL/glu.h> #include <GL/glut.h>
#define WIN_HEIGHT 400 #define WIN_WIDTH 400 #define LEVEL 9
static void koch ( int level, float r, float *xleft, float *yleft, float *xright, float *yright );
static void draw_koch ( int level, int x1, int y1, int x0, int y0 );
static void draw_koch ( int level, int x1, int y1, int x0, int y0 ) { float xleft[30], yleft[30], xright[30], yright[30];
xleft[level-1] = (float)x0; yleft[level-1] = (float)y0; xright[level-1] = (float)x1; yright[level-1] = (float)y1;
koch (level-1, (float)0.29, xleft, yleft, xright, yright); }
static void koch ( int level, float r, float *xleft, float *yleft, float *xright, float *yright ) { if (level > 0) { level--;
/* Left Branch */ xleft[level] = xleft[level+1]; yleft[level] = yleft[level+1]; xright[level] = (0.3333f * xright[level+1]) + (0.6667f * xleft[level+1]); yright[level] = (0.3333f * yright[level+1]) + (0.6667f * yleft[level+1]); koch (level, r, xleft, yleft, xright, yright);
/* Middle Left Branch */ xleft[level] = xright[level]; yleft[level] = yright[level]; xright[level] = (0.5f * xright[level+1]) + (0.5f * xleft[level+1]) - (r * (yleft[level+1] - yright[level+1])); yright[level] = (0.5f * yright[level+1]) + (0.5f * yleft[level+1]) + (r * (xleft[level+1] - xright[level+1])); koch (level, r, xleft, yleft, xright, yright);
/* Middle Right Branch */ xleft[level] = xright[level]; yleft[level] = yright[level]; xright[level] = (0.6667f * xright[level+1]) + (0.3333f * xleft[level+1]); yright[level] = (0.6667f * yright[level+1]) + (0.3333f * yleft[level+1]); koch (level, r, xleft, yleft, xright, yright);
/* Right Branch */ xleft[level] = xright[level]; yleft[level] = yright[level]; xright[level] = xright[level+1]; yright[level] = yright[level+1]; koch (level, r, xleft, yleft, xright, yright); level++; } else { glBegin (GL_LINES); glVertex2i ((int)xleft[0], (int)yleft[0]); glVertex2i ((int)xright[0], (int)yright[0]); glEnd (); } }
static int win_width = WIN_WIDTH; static int win_height = WIN_HEIGHT; static int the_level = LEVEL;
static void redraw (void) { time_t start_time, end_time;
printf ("Enter - redraw ()\n"); start_time = time (0);
glClearColor (0.0, 0.0, 0.0, 0.0); glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glFlush ();
draw_koch (the_level, 0.0, win_height/2, win_width-1, win_height/2);
end_time = time (0); printf ("Exit - redraw () %d secs\n", end_time - start_time); }
static void reshape (int width, int height) { printf ("Enter - reshape ()\n"); win_width = width; win_height = height; glViewport (0, 0, width, height);
glMatrixMode (GL_PROJECTION); glLoadIdentity (); gluOrtho2D (-0.5, (width + 0.5), -0.5, (height + 0.5));
printf ("Exit - reshape ()\n"); }
static void keyboard (int key, int x, int y) { int changed = 0;
switch (key) { case GLUT_KEY_UP: if (++the_level > 10) the_level = 10; changed = 1; break;
case GLUT_KEY_DOWN: if (--the_level < 1) the_level = 1; changed = 1; break; }
if (changed) glutPostRedisplay (); }
int main (int argc, char **argv) { /* init window parameters. */ glutInitWindowSize (WIN_WIDTH, WIN_HEIGHT); glutInitWindowPosition (100, 100); glutInitDisplayMode (GLUT_RGBA | GLUT_SINGLE | GLUT_DEPTH);
/* create window. */ if (glutCreateWindow ("koch curve") <= 0) exit (0);
/* set display and reshape functions. */ glutDisplayFunc (redraw); glutReshapeFunc (reshape); glutSpecialFunc (keyboard);
/* start GLUT processing loop. */ glutMainLoop (); return 0; }