First of all download the OpenGL files from http://www.xmission.com/~nate/glut.html
(download glut-3.7.6-bin.zip or similar - GLUT for Win32 dll, lib and
header file - there).
Make a directory called "GL" under
c:\programme\microsoft visual studio\vc98\include (or similar, dependent of
your environment)
Copy the OpenGL files into the new created directory
c:\programme\microsoft visual studio\vc98\include\GL
Copy all *.lib files into
c:\programme\microsoft visual studio\vc98\Lib
Doubleclick the .c file you want to build, now the Visual C++ environment
should come up with the file.
Try to compile or to build just to force that VC++ will ask you to make a workspace
for you, therefore you should accept with YES. You are not able to compile yet.
But very soon ;)
In the Menu of VC++ go through to -> project -> settings -> Link
and add (do not remove the others!) the following libraries to the Object/libary
modules line:
glut32.lib glu32.lib opengl32.lib glaux.lib
(in most cases you don't have to add glaux.lib really ;))
Now you should be able to run the file!
If you want to give your result to others they will need the glut32.dll
in the same directory as the executable.
template.c (sample code to test it, if needed copy and paste in your
favorite text editor)
-----------------------------------------------------------------------------------------------
#include <stdio.h> #include <string.h> #include <stdlib.h> #include <math.h> #include <GL/glut.h> /* * Window properties */ #define WINDOW_WIDTH 500 #define WINDOW_HEIGHT 500 #define WINDOW_X 100 #define WINDOW_Y 100 #define WINDOW_TITLE "RGB-ColorCube" /* * Perspective properties */ #define FOV_ANGLE 30 #define CENTER_X 0.0 #define CENTER_Y 0.0 #define CENTER_Z 0.0 #define VIEWER_X 0.0 #define VIEWER_Y 0.0 #define VIEWER_Z -2.1 #define UP_X 0.0 #define UP_Y 1.0 #define UP_Z 0.0 #define CLIPPLANE_NEAR 1.0 #define CLIPPLANE_FAR 20.0 #define ROTATION_SPEED 2.0 #ifndef M_PI #define M_PI 3.14159265358979323846 #endif GLfloat rot_x = 0.0, rot_y = 0.0; GLfloat saved_x, saved_y; /* * Material colors used for shading */ GLfloat red[4] = {.8, 0.0, 0.0, 1.0}; GLfloat white[4] = {.8, .8, .8, 1.0}; /* * Function prototypes */ void usage(void); void draw_scene(void); void draw_object(void); void init(int argc, char **argv, void (*draw)(void)); void save_position(int button, int state, int x, int y); struct point get_coords(double a, double b); void vertex(double a, double b); void rotate(int x, int y); void set_color(int angle); int main(int argc, char **argv) { /* * Init OpenGL and enter the event loop */ init(argc, argv, draw_scene); return 0; } /* * Handle rotations and buffer swapping and call the function draw_object * which does the actual drawing */ void draw_scene(void) { static GLfloat old_rot_matrix[16]; static int initialized = 0; GLfloat new_rot_matrix[16]; /* calculate new rotation matrix */ glPushMatrix(); glLoadIdentity(); glRotatef(rot_x, 1.0, 0.0, 0.0); glRotatef(rot_y, 0.0, 1.0, 0.0); glGetFloatv(GL_MODELVIEW_MATRIX, new_rot_matrix); glPopMatrix(); /* calculate total rotation */ glPushMatrix(); glLoadIdentity(); glMultMatrixf(new_rot_matrix); if (initialized) { glMultMatrixf(old_rot_matrix); } glGetFloatv(GL_MODELVIEW_MATRIX, old_rot_matrix); initialized = 1; glPopMatrix(); glPushMatrix(); glMultMatrixf(old_rot_matrix); draw_object(); glPopMatrix(); glFlush(); glutSwapBuffers(); } /* * Initialize the OpenGL machine */ void init(int argc, char **argv, void (*draw)(void)) { GLfloat light0_pos[] = {100.0, 100.0, 100.0, 1.0}; GLfloat light0_color[] = {1.0, 1.0, 1.0, 1.0}; GLfloat ambient_light[] = {0.8, 0.8, 0.8, 1.0}; glutInit(&argc, argv); /* Create a window */ glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE); glutInitWindowSize(WINDOW_WIDTH, WINDOW_HEIGHT); glutInitWindowPosition(WINDOW_X, WINDOW_Y); glutCreateWindow(WINDOW_TITLE); glClearColor(0.0, 0.0, 0.0, 0.0); /* Set up some light sources */ glLightfv(GL_LIGHT0, GL_POSITION, light0_pos); glLightfv(GL_LIGHT0, GL_DIFFUSE, light0_color); glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambient_light); glEnable(GL_LIGHT0); /* glEnable(GL_LIGHTING); */ glEnable(GL_DEPTH_TEST); glShadeModel(GL_SMOOTH); /* Create a viewing frustum */ glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(FOV_ANGLE, WINDOW_WIDTH/WINDOW_HEIGHT, CLIPPLANE_NEAR, CLIPPLANE_FAR); gluLookAt(VIEWER_X, VIEWER_Y, -VIEWER_Z, CENTER_X, CENTER_Y, CENTER_Z, UP_X, UP_Y, UP_Z); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glTranslatef(VIEWER_X, VIEWER_Y, VIEWER_Z); glutDisplayFunc(draw); glutMouseFunc(save_position); glutMotionFunc(rotate); glutMainLoop(); /* Not reached */ } /* * Save the position of the mouse pointer where the bottun press occured */ void save_position(int button, int state, int x, int y) { if (state == GLUT_DOWN) { saved_x = x; saved_y = y; } } /* * Calculate the angle the object has rotated by since the last update */ void rotate(int x, int y) { rot_y = (GLfloat)(x - saved_x) * ROTATION_SPEED; rot_x = (GLfloat)(y - saved_y) * ROTATION_SPEED; saved_x = x; saved_y = y; glutPostRedisplay(); } /* * Draw a object */ void draw_object(void) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glBegin(GL_QUAD_STRIP); glNormal3f(0,0,1); glColor3f(0,0,0); glVertex3f(-0.5,-0.5,-0.5); glColor3f(0,1,0); glVertex3f(-0.5,0.5,-0.5); glColor3f(1,0,0); glVertex3f(0.5,-0.5,-0.5); glColor3f(1,1,0); glVertex3f(0.5,0.5,-0.5); glNormal3f(1,0,0); glColor3f(1,0,1); glVertex3f(0.5,-0.5,0.5); glColor3f(1,1,1); glVertex3f(0.5,0.5,0.5); glNormal3f(0,0,1); glColor3f(0,0,1); glVertex3f(-0.5,-0.5,0.5); glColor3f(0,1,1); glVertex3f(-0.5,0.5,0.5); glNormal3f(-1,0,0); glColor3f(0,0,0); glVertex3f(-0.5,-0.5,-0.5); glColor3f(0,1,0); glVertex3f(-0.5,0.5,-0.5); glEnd(); glBegin(GL_QUADS); glNormal3f(0,1,0); glColor3f(0,1,0); glVertex3f(-0.5,0.5,-0.5); glColor3f(0,1,1); glVertex3f(-0.5,0.5,0.5); glColor3f(1,1,1); glVertex3f(0.5,0.5,0.5); glColor3f(1,1,0); glVertex3f(0.5,0.5,-0.5); glEnd(); glBegin(GL_QUADS); glNormal3f(0,-1,0); glColor3f(0,0,0); glVertex3f(-0.5,-0.5,-0.5); glColor3f(0,0,1); glVertex3f(-0.5,-0.5,0.5); glColor3f(1,0,1); glVertex3f(0.5,-0.5,0.5); glColor3f(1,0,0); glVertex3f(0.5,-0.5,-0.5); glEnd(); }