Sunteți pe pagina 1din 31

OpenGL

OpenGL Utility Toolkit (GLUT)


A window system-independent toolkit to hide
the complexity of differing window system
APIs.
Providing following operations:
Initializing and creating window
Handling window and input events
Drawing basic 3D objects
Running the program

Installation
Download GULT
http://www.xmission.com/~nate/glut/glut-3.7.6-bin.zip

Unzip contains.
glut.h
(Include it!)
glut32.lib
(Link it!)
glut32.dll
(Execute with it!)

Put the file "glut32.dll" into the system directory (Usually:


"C:\WINDOWS\system32")
Put the file "glut.h" into the standard Visual C++ include
directoy
(For Visual Studio 2008, this should be: "C:\Program Files\Microsoft
SDKs\Windows\v6.0A\Include\gl")
(For Visual Studio 2005, this should be: "C:\Program Files\Microsoft
Visual Studio.NET\Vc7\PlatformSDK\Include\gl")

Put the file "glut32.lib" into the standard Visual C++ library
directory Put the file "glut32.lib" into the standard Visual C++
library directory
(For Visual Studio 2008, this should be: "C:\Program Files\Microsoft
SDKs\Windows\v6.0A\Lib")
(For Visual Studio 2005, this should be: "C:\Program Files\Microsoft
Visual Studio.NET\Vc7\PlatformSDK\lib")

Step 1: Create a Visual Studio 2005 Project


To create an empty console project in Visual Studio, do
the following:
Create a new project (File ---> New ---> --->Project

In the Project Types: pane, select Visual C++, Win32. Then select Win 32 Console
Application in the Templates: pane. Name your project, select the location for the
project and click OK.

Click the Application Settings tab on the left, and check the Empty
Project box. Then click Finish button.

Step 2: Add Source Code


1. Select Project, Add New Item .

In the Categories pane, select Visual C++, Code. Then select C++ File( ,cpp) in
the Templates: pane. Name your file, and then click Add.

Copy and paste the code below into the file. Save your
time of typing.
#include glut.h
void display();
void reshape(GLsizei, GLsizei);
void main(int argc, char** argv){
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutCreateWindow("sample");
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutMainLoop();
}

A Simple OpenGL Program 2/4


void display(){
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0f, 1.0f, 1.0f);
glutSolidTeapot(1.0);
glFlush();
}

A Simple OpenGL Program 3/4


void reshape(GLsizei w, GLsizei h){
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glFrustum(-0.5, 0.5, -0.5, 0.5, 1.0, 20.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(0.0, 0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
}

Step 3: Modify the project properties


1. Use Visual Studio's menu Project options ( Project --> Draw Properties)

2. The Draw Property Page dialog will open. Once it appears, do the following:
a. Select the Configuration combo box, select All Configuration

In the left pane, select the linker subtree and then click the Input option. Add the
following code to the
Additional Dependencies text in the right pane.
Copy and Paste: opengl32.lib glu32.lib glut32.lib
Now Visual Studio knows where to find GLUT. Click OK button

Step 4: Compile and Run the project


a. Compile
From the Visual Studio's menu Build option (Build ---> Build Solution)

b. Execute the program


From the Visual Studio's menu Debug option (Debug ---> Start Without Debugging)

Microsoft 2008

Setup for a OpenGL Program(VC8.0) 1/8


Microsoft Visual C++ 8.0
New Blank Project

Setup for a OpenGL Program(VC8.0) 2/8


New Win32 Project

Setup for a OpenGL Program(VC8.0) 3/8


Next

Setup for a OpenGL Program(VC8.0) 4/8


Use Console application Empty , Finish

Setup for a OpenGL Program(VC8.0) 5/8


Set properties

Setup for a OpenGL Program(VC8.0) 6/8


Set include to the location of glut.h

Setup for a OpenGL Program(VC8.0) 7/8


Set link to the location of the lib file

Setup for a OpenGL Program(VC8.0) 8/8


Set link input ,add the glut32.lib

A Simple OpenGL Program 1/4


#include glut.h
void display();
void reshape(GLsizei, GLsizei);
void main(int argc, char** argv){
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutCreateWindow("sample");
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutMainLoop();
}

A Simple OpenGL Program 2/4


void display(){
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0f, 1.0f, 1.0f);
glutSolidTeapot(1.0);
glFlush();
}

A Simple OpenGL Program 3/4


void reshape(GLsizei w, GLsizei h){
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glFrustum(-0.5, 0.5, -0.5, 0.5, 1.0, 20.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(0.0, 0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
}

A Simple OpenGL Program 4/4

S-ar putea să vă placă și