You are on page 1of 7

OpenGL with Visual Studio 2010

1. Download GLUT 2. Unzip the file. 3. Put the file "glut32.dll" into the system path. This can be in the same directory as your executable file. On Windows XP or earlier, this can be in "C:\WINDOWS\system32" Or you can create a directory like "C:\DLLs", put the file in this directory and change your system path to include this new directory.
o

Do this by opening Control Panel -> System, clicking on "Advanced System Settings", followed by "Environment Variables", and editing the "Path" variable.

4. Put the file "glut.h" into the standard Visual C++ include directoy (For Visual Studio 2010, this should be: "C:\Program Files\Microsoft SDKs\Windows\v7.0A\include\gl") (For Visual Studio 2008, this should be: "C:\Program Files\Microsoft SDKs\Windows\v6.0A\Include\gl") 5. Put the file "glut32.lib" into the standard Visual C++ library directory (For Visual Studio 2010, this should be: "C:\Program Files\Microsoft SDKs\Windows\v7.0A\Lib") (For Visual Studio 2008, this should be: "C:\Program Files\Microsoft SDKs\Windows\v6.0A\Lib") There should be lots of .lib files here, including "opengl32.lib" and "glu32.lib".

6. Create New Project

main.c
#include <windows.h> #include <GL/gl.h> #include <GL/glut.h> int a[3]={10,10,10}, b[3]={10,-10,10}, c[3]={-10,-10,10}, d[3]={-10,10,10}, e[3]={10,10,-10}, f[3]={10,-10,-10}, g[3]={-10,-10,-10}, h[3]={-10,10,-10}; float angle=1.0; void drawcube(void) { glClear(GL_COLOR_BUFFER_BIT); glColor3f(1.0, 1.0, 1.0); glMatrixMode(GL_MODELVIEW); glRotatef(angle, 0.0, 1.0, 0.0); glBegin(GL_LINE_LOOP); glVertex3iv(a); glVertex3iv(b); glVertex3iv(c); glVertex3iv(d); glEnd(); glBegin(GL_LINE_LOOP); glVertex3iv(a); glVertex3iv(e); glVertex3iv(f); glVertex3iv(b); glEnd(); glBegin(GL_LINE_LOOP); glVertex3iv(d); glVertex3iv(h); glVertex3iv(g); glVertex3iv(c); glEnd(); glBegin(GL_LINE_LOOP); glVertex3iv(e); glVertex3iv(f); glVertex3iv(g); glVertex3iv(h); glEnd(); glFlush(); glutSwapBuffers(); } void keyboard(unsigned char key, int x, int y) { switch (key) { case 0x1B: case 'q': case 'Q': exit(0); break; } } void mouse(int btn, int state, int x, int y) { if (state == GLUT_DOWN) {

if (btn angle else if angle else angle } }

== GLUT_LEFT_BUTTON) = angle + 0.05f; (btn == GLUT_RIGHT_BUTTON) = angle - 1.0f; = 0.0f;

int main(int argc, char **argv) { glutInit(&argc, argv); glutInitWindowSize(500, 500); glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE); glutCreateWindow("Glut rotate"); glutMouseFunc(mouse); glutKeyboardFunc(keyboard); glutDisplayFunc(drawcube); glutIdleFunc(drawcube); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(-30.0, 30.0, -30.0, 30.0, -30.0, 30.0); glRotatef(30.0, 1.0, 0.0, 0.0); glMatrixMode(GL_MODELVIEW); glClearColor(0.0, 0.0, 0.0, 0.0); glutMainLoop(); return(0); }

Make sure your Visual C++ project links in the GLUT/gl/glu libraries. This is located in:

Righ Click (your-project-name) ->Properties" Configuration: All Configurations Tab: "Configuration Properties -> Linker -> Input" Under "Additional Dependancies", add "glut32.lib glu32.lib opengl32.lib"

Run (F5)

Copy file glut32.dll to Debug ( to location .exe)