You are on page 1of 8

TUTORIAL 1_SKM 3200_COMPUTER GRAPHIC

LAB 1
LAB 1: INTRODUCTION TO OPENGL

Notes :

OpenGL is a graphics application programming interface (API) which was originally developed
by Silicon Graphics.

The term Open is significant in that OpenGL is operating system independent while GL refers to
graphics language. It also contains a standard library referred to as the OpenGL Utilites (GLU).

GLU contains routine for setting up viewing projection matrices and describing.

OpenGL Utility Toolkit (GLUT) is a library that works in conjunction with OpenGL and provides
an interface to operating system services such as window management, menus and input
devices.

GLUT was originally developed by NVIDIA’s Mark Kilgard and ported to Win32 by Nate Robbins.

GLUT distribution includes source code, along with sample programs, which can be compiled
with C++. Precompiled Win32 DLL’s, along with library and header files, can also be downloaded.

Microsoft Visual Studio is an integrated development environment (IDE) from Microsoft. It can
be used to develop console and graphical user interface applications along with Windows
Forms applications, websites, web applications, and web services in both native code together
with managed code for all platforms supported by Microsoft Windows, Windows Mobile,
Windows CE, .NET Framework, .NET Compact Framework and Microsoft Silverlight.

Supports different programming languages by means of languages services, which allow the
code editor and debugger to support nearly any programming language, provided a language-
specific service exists. Built- in languages include C/C++ (via Visual C++), VB.NET (via Visual
Basic.NET), C# (via Visual C#), and F# (as of Visual Studio 2010).

1|
TUTORIAL 1_SKM 3200_COMPUTER GRAPHIC
LAB 1
Step 0 : GLUT INSTALLATION (only need to be done once)

Windows comes with OpenGL and Visual Studio comes with the OpenGL libraries, but neither of
them comes with GLUT.

Install GLUT into these files as follows :-

a) glu32.lib, glew32.lib, glui32.lib, glut32.lib


 C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\lib (VS 2010)
 C:\Program Files\Microsoft Visual Studio 12.0\VC\lib (VS 2013)

b) gl.h, glaux.h, glew.h, glu.h, glut.h


 C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\GL (VS 2010)
 C:\Program Files\Microsoft Visual Studio 12.0\VC\include\GL (VS 2013)

c) glu32.dll & glut32.dll


 C:\Windows\System32 (for 32-bit)
 C:\Windows\System32\SysWOW64 (for 64-bit)

Note :
If you plan on giving your program to friends to run using Windows, you must also include the
glut32.dll file or the program will not run.
Step 1 : Creating a Visual C++ project

 Click on File  New  Project

2|
TUTORIAL 1_SKM 3200_COMPUTER GRAPHIC
LAB 1

 Select Visual C++ and then, Win32. Select Win32 Console Application, type Project Name
and click OK

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

3|
TUTORIAL 1_SKM 3200_COMPUTER GRAPHIC
LAB 1

Step 2 : Adding a new file into the project

 Right-click on Source File  Add New Item.

 At the “Add New Item” dialogue box, choose Code option under Visual C++ on the left and
choose C++ File on the right. Then, click on Add.

4|
TUTORIAL 1_SKM 3200_COMPUTER GRAPHIC
LAB 1
Exercise #1 – Setting Up An OpenGL Window

Type in the following code into your source file.

Run the program.

SUPPOSED OUTPUT :

5|
TUTORIAL 1_SKM 3200_COMPUTER GRAPHIC
LAB 1
Exercise #2 – Preparing A Window For A Reshape

For this exercise, we need to go use back the main function that was defined in the previous
exercise and add a call to glutRehsapeFunc. The code for the main function with the call to
glutReshapeFunc added in is :

Next is to define the function that we’ll take care of the perspective. As seen by the syntax of
glutReshapeFunc, the myReshape function has two arguments, these are the new width and
height.

Run the program.

6|
TUTORIAL 1_SKM 3200_COMPUTER GRAPHIC
LAB 1
Exercise #3 – Drawing Aligned Rectangles

A special case of a polygon is the aligned rectangle, so called because its sides are aligned with
the coordinate axes. OpenGL provides the ready-made function for drawing aligned rectangle.

glRecti(GLint x1, GLint y1, GLint x2, Glint y2);

// draw a rectangle with opposite corners (x1,y1) and (x2,y2)


// fill the rectangle with the current color

In our display function, add in the following code right after glClear(GL_COLOR_BUFFER_BIT)
command:

Run the program.

7|
TUTORIAL 1_SKM 3200_COMPUTER GRAPHIC
LAB 1
Exercise #4 – Drawing Basic Graphics Primitives (2D)

OpenGL provides tools for drawing basic graphics primitives such as points, lines, polylines, and
polygons, defined by one or more vertices. To draw such objects in OpenGL, you pass it a list of
vertices. The list occurs between the two OpenGL function calls glBegin() and glEnd(). The
argument of glBegin() determines which object is drawn. For example :

glBegin(GL_POINTS);
glVertex2i(100,50);
glVertex2i(100,130);
glVertex2i(150,130);
glEnd();

Hence, add in the following code into the display function.

Run the program.

8|

You might also like