Using OpenGL in Visual C++ Opengl32.dll and glu32.dll should be in the system folder Opengl32.dll...

23
Using OpenGL in Visual C++ Using OpenGL in Visual C++ Opengl32.dll and glu32.dll should be Opengl32.dll and glu32.dll should be in the system folder in the system folder Opengl32.lib and glu32.lib should be Opengl32.lib and glu32.lib should be in the lib folder for VC++ in the lib folder for VC++ gl.h and glu.h should be in a gl.h and glu.h should be in a folder called GL under the include folder called GL under the include folder for VC++ folder for VC++ Get glut32.lib, glut32.dll and Get glut32.lib, glut32.dll and glut.h from the course homepage and glut.h from the course homepage and put them in the same places as the put them in the same places as the other files other files

Transcript of Using OpenGL in Visual C++ Opengl32.dll and glu32.dll should be in the system folder Opengl32.dll...

Page 1: Using OpenGL in Visual C++ Opengl32.dll and glu32.dll should be in the system folder Opengl32.dll and glu32.dll should be in the system folder Opengl32.lib.

Using OpenGL in Visual C++ Using OpenGL in Visual C++

Opengl32.dll and glu32.dll should be in the Opengl32.dll and glu32.dll should be in the system foldersystem folder

Opengl32.lib and glu32.lib should be in the Opengl32.lib and glu32.lib should be in the lib folder for VC++lib folder for VC++

gl.h and glu.h should be in a folder called gl.h and glu.h should be in a folder called GL under the include folder for VC++GL under the include folder for VC++

Get glut32.lib, glut32.dll and glut.h from Get glut32.lib, glut32.dll and glut.h from the course homepage and put them in the the course homepage and put them in the same places as the other filessame places as the other files

Page 2: Using OpenGL in Visual C++ Opengl32.dll and glu32.dll should be in the system folder Opengl32.dll and glu32.dll should be in the system folder Opengl32.lib.

Using OpenGL in Visual C++ Using OpenGL in Visual C++

Fire up visual studioFire up visual studio Create a new project as the following:Create a new project as the following:

File File New New Project (input your project Project (input your project name, then a directory (workspace) with the name, then a directory (workspace) with the same name will be built) same name will be built) Win32 Console Application Win32 Console Application An Empty Application An Empty Application

Page 3: Using OpenGL in Visual C++ Opengl32.dll and glu32.dll should be in the system folder Opengl32.dll and glu32.dll should be in the system folder Opengl32.lib.

Using OpenGL in Visual C++ Using OpenGL in Visual C++

In the workspace click on “File View” to In the workspace click on “File View” to access (expand) the source code treeaccess (expand) the source code tree

In “Source Files”, add in the source code (*.c In “Source Files”, add in the source code (*.c files)files)

Select Project Select Project Settings Settings Link and Link andin “Object/library modules” add “Opengl32.lib in “Object/library modules” add “Opengl32.lib glu32.lib glut32.lib”glu32.lib glut32.lib”

Press “F7” to build “your_project.exe”Press “F7” to build “your_project.exe”

Page 4: Using OpenGL in Visual C++ Opengl32.dll and glu32.dll should be in the system folder Opengl32.dll and glu32.dll should be in the system folder Opengl32.lib.

Objects are usually defined by a set of verticesObjects are usually defined by a set of vertices

The following code fragment defines a triangular The following code fragment defines a triangular polygon in OpenGLpolygon in OpenGL

glBegin(GL_POLYGON);glBegin(GL_POLYGON); glVertex3f(0.0,0.0,0.0);glVertex3f(0.0,0.0,0.0); glVertex3f(0.0,1.0,0.0);glVertex3f(0.0,1.0,0.0); glVertex3f(0.0,0.0,1.0);glVertex3f(0.0,0.0,1.0); glEND();glEND();

Page 5: Using OpenGL in Visual C++ Opengl32.dll and glu32.dll should be in the system folder Opengl32.dll and glu32.dll should be in the system folder Opengl32.lib.

Angel: Interactive Computer Graphics 4E © Addison-

Wesley 2005

A Simple ProgramA Simple Program

Generate a square on a solid backgroundGenerate a square on a solid background

Page 6: Using OpenGL in Visual C++ Opengl32.dll and glu32.dll should be in the system folder Opengl32.dll and glu32.dll should be in the system folder Opengl32.lib.

Angel: Interactive Computer Graphics 4E © Addison-

Wesley 2005

simple.csimple.c#include <GL/glut.h>void mydisplay(){ glClear(GL_COLOR_BUFFER_BIT);

glBegin(GL_POLYGON); glVertex2f(-0.5, -0.5); glVertex2f(-0.5, 0.5); glVertex2f(0.5, 0.5); glVertex2f(0.5, -0.5);

glEnd();glFlush();

}int main(int argc, char** argv){

glutCreateWindow("simple"); glutDisplayFunc(mydisplay); glutMainLoop();

}

Page 7: Using OpenGL in Visual C++ Opengl32.dll and glu32.dll should be in the system folder Opengl32.dll and glu32.dll should be in the system folder Opengl32.lib.

7Angel: Interactive Computer

Graphics 4E © Addison-Wesley 2005

simple.c revisitedsimple.c revisited

In this version, we shall see the same output In this version, we shall see the same output but we have defined all the relevant state but we have defined all the relevant state values through function calls using the default values through function calls using the default valuesvalues

In particular, we setIn particular, we set ColorsColors Viewing conditionsViewing conditions Window propertiesWindow properties

Page 8: Using OpenGL in Visual C++ Opengl32.dll and glu32.dll should be in the system folder Opengl32.dll and glu32.dll should be in the system folder Opengl32.lib.

8Angel: Interactive Computer

Graphics 4E © Addison-Wesley 2005

main.cmain.c

#include <GL/glut.h>#include <GL/glut.h>

int main(int argc, char** argv)int main(int argc, char** argv){{

glutInit(&argc,argv); glutInit(&argc,argv); glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB); glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB); glutInitWindowSize(500,500); glutInitWindowSize(500,500); glutInitWindowPosition(0,0); glutInitWindowPosition(0,0); glutCreateWindow("simple"); glutCreateWindow("simple"); glutDisplayFunc(mydisplay); glutDisplayFunc(mydisplay);

init(); init();

glutMainLoop();glutMainLoop();

}}

includes gl.h

define window properties

set OpenGL state

enter event loop

display callback

Page 9: Using OpenGL in Visual C++ Opengl32.dll and glu32.dll should be in the system folder Opengl32.dll and glu32.dll should be in the system folder Opengl32.lib.

9Angel: Interactive Computer

Graphics 4E © Addison-Wesley 2005

GLUT functionsGLUT functions

glutInit glutInit allows application to get command line arguments allows application to get command line arguments and initializes systemand initializes system

gluInitDisplayMode gluInitDisplayMode requests properties for the window requests properties for the window (the (the rendering contextrendering context)) RGB colorRGB color Single bufferingSingle buffering Properties logically ORed togetherProperties logically ORed together

glutWindowSize glutWindowSize in pixelsin pixels glutWindowPosition glutWindowPosition from top-left corner of displayfrom top-left corner of display glutCreateWindow glutCreateWindow create window with title “simple”create window with title “simple” glutDisplayFunc glutDisplayFunc display callbackdisplay callback glutMainLoop glutMainLoop enter infinite event loopenter infinite event loop

Page 10: Using OpenGL in Visual C++ Opengl32.dll and glu32.dll should be in the system folder Opengl32.dll and glu32.dll should be in the system folder Opengl32.lib.

10Angel: Interactive Computer

Graphics 4E © Addison-Wesley 2005

init.cinit.c

void init()void init(){{

glClearColor (0.0, 0.0, 0.0, 1.0);glClearColor (0.0, 0.0, 0.0, 1.0);

glColor3f(1.0, 1.0, 1.0); glColor3f(1.0, 1.0, 1.0);

glMatrixMode (GL_PROJECTION); glMatrixMode (GL_PROJECTION); glLoadIdentity (); glLoadIdentity (); glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0); glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0);

}}

black clear coloropaque window

fill/draw with white

viewing volume

Page 11: Using OpenGL in Visual C++ Opengl32.dll and glu32.dll should be in the system folder Opengl32.dll and glu32.dll should be in the system folder Opengl32.lib.

We can define a viewer or camera in a variety We can define a viewer or camera in a variety of waysof ways

We can identify four types of necessary We can identify four types of necessary specifications:specifications:

PositionPosition OrientationOrientation Focal lengthFocal length Film planeFilm plane

Page 12: Using OpenGL in Visual C++ Opengl32.dll and glu32.dll should be in the system folder Opengl32.dll and glu32.dll should be in the system folder Opengl32.lib.

Light sources can be defined by their location, Light sources can be defined by their location, strength, color, and directionality.strength, color, and directionality.

API’s provide a set of functions to specify these API’s provide a set of functions to specify these parameters for each source.parameters for each source.

Material properties are characteristics, or Material properties are characteristics, or attributes, of the objectsattributes, of the objects

such properties are usually defined through a series such properties are usually defined through a series of function calls at the time that each object is of function calls at the time that each object is defined.defined.

Page 13: Using OpenGL in Visual C++ Opengl32.dll and glu32.dll should be in the system folder Opengl32.dll and glu32.dll should be in the system folder Opengl32.lib.

8. Graphics Architectures8. Graphics Architectures

On one side of the API is the application program. On one side of the API is the application program. On the other is some combination of hardware and On the other is some combination of hardware and software that implements the functionality of the software that implements the functionality of the APIAPI

Researchers have taken various approaches to Researchers have taken various approaches to developing architectures to support graphics APIsdeveloping architectures to support graphics APIs

Page 14: Using OpenGL in Visual C++ Opengl32.dll and glu32.dll should be in the system folder Opengl32.dll and glu32.dll should be in the system folder Opengl32.lib.

Early systems used general purpose computersEarly systems used general purpose computers single processing unitsingle processing unit

In the early days of computer graphics, computers In the early days of computer graphics, computers were so slow that refreshing even simple images, were so slow that refreshing even simple images, containing a few hundred line segments, would containing a few hundred line segments, would burden an expensive computerburden an expensive computer

Page 15: Using OpenGL in Visual C++ Opengl32.dll and glu32.dll should be in the system folder Opengl32.dll and glu32.dll should be in the system folder Opengl32.lib.

8.1 Display Processors8.1 Display Processors The earliest attempts to build a special purpose The earliest attempts to build a special purpose

graphics system were concerned primarily with graphics system were concerned primarily with relieving the task of refreshing the displayrelieving the task of refreshing the display

Page 16: Using OpenGL in Visual C++ Opengl32.dll and glu32.dll should be in the system folder Opengl32.dll and glu32.dll should be in the system folder Opengl32.lib.

8.2 Pipeline Architectures8.2 Pipeline Architectures The major advances in graphics architectures The major advances in graphics architectures

parallel closely the advances in workstations.parallel closely the advances in workstations. For computer graphics applications, the most For computer graphics applications, the most

important use of custom VLSI circuits has been in important use of custom VLSI circuits has been in creating pipeline architecturescreating pipeline architectures

A simple arithmetic pipeline is shown here:A simple arithmetic pipeline is shown here:

Page 17: Using OpenGL in Visual C++ Opengl32.dll and glu32.dll should be in the system folder Opengl32.dll and glu32.dll should be in the system folder Opengl32.lib.

If we think in terms of processing the geometry of If we think in terms of processing the geometry of our objects to obtain an image, we can use the our objects to obtain an image, we can use the following block diagram:following block diagram:

Page 18: Using OpenGL in Visual C++ Opengl32.dll and glu32.dll should be in the system folder Opengl32.dll and glu32.dll should be in the system folder Opengl32.lib.

8.3 Transformations8.3 Transformations Many of the steps in the imaging process can be Many of the steps in the imaging process can be

viewed as transformations between viewed as transformations between representations of objects in different representations of objects in different coordinate systemscoordinate systems

for example: from the system in which the object for example: from the system in which the object was defined to the system of the camera was defined to the system of the camera

We can represent each change of coordinate We can represent each change of coordinate systems by a matrixsystems by a matrix

We can represent successive changes by multiplying We can represent successive changes by multiplying (or concatenating) the individual matrices into a (or concatenating) the individual matrices into a single matrix.single matrix.

Page 19: Using OpenGL in Visual C++ Opengl32.dll and glu32.dll should be in the system folder Opengl32.dll and glu32.dll should be in the system folder Opengl32.lib.

8.4 Clipping8.4 Clipping Why do we Clip?Why do we Clip?

Page 20: Using OpenGL in Visual C++ Opengl32.dll and glu32.dll should be in the system folder Opengl32.dll and glu32.dll should be in the system folder Opengl32.lib.

8.5. Projection8.5. Projection In general three-dimensional objects are kept in In general three-dimensional objects are kept in

three dimensions as long as possible, as they three dimensions as long as possible, as they pass through the pipeline. pass through the pipeline.

Eventually though, they must be projected into Eventually though, they must be projected into two-dimensional objects.two-dimensional objects.

There are various projections that we can There are various projections that we can implement.implement.

we can implement this step using 4 x 4 we can implement this step using 4 x 4 matrices, and, thus, also fit it into the pipeline.matrices, and, thus, also fit it into the pipeline.

Page 21: Using OpenGL in Visual C++ Opengl32.dll and glu32.dll should be in the system folder Opengl32.dll and glu32.dll should be in the system folder Opengl32.lib.

8.6 Rasterization8.6 Rasterization Finally, our projected objects must be Finally, our projected objects must be

represented as pixels in the frame buffer.represented as pixels in the frame buffer.

Page 22: Using OpenGL in Visual C++ Opengl32.dll and glu32.dll should be in the system folder Opengl32.dll and glu32.dll should be in the system folder Opengl32.lib.

8.7 Performance Characteristics8.7 Performance Characteristics There are two fundamentally different types of There are two fundamentally different types of

processing processing Front end -- geometric processing, based on the Front end -- geometric processing, based on the

processing of verticesprocessing of vertices ideally suited for pipelining, and usually involves floating-ideally suited for pipelining, and usually involves floating-

point calculations.point calculations. The geometry engine developed by SGI was a VLSI The geometry engine developed by SGI was a VLSI

implementation for many of these operations in a special implementation for many of these operations in a special purpose chip. These became the basis for a series of purpose chip. These became the basis for a series of graphics workstations.graphics workstations.

Back end -- involves direct manipulation of bits in Back end -- involves direct manipulation of bits in the frame buffer.the frame buffer.

Ideally suited for parallel bit processors.Ideally suited for parallel bit processors.

Page 23: Using OpenGL in Visual C++ Opengl32.dll and glu32.dll should be in the system folder Opengl32.dll and glu32.dll should be in the system folder Opengl32.lib.

9. Summary9. Summary

In this chapter we have set the stage for our top-In this chapter we have set the stage for our top-down development of computer graphics.down development of computer graphics.

Computer graphics is a method of image formation that Computer graphics is a method of image formation that should be related to classical methods -- in particular to should be related to classical methods -- in particular to camerascameras

Our next step is to explore the application side of Our next step is to explore the application side of Computer Graphics programmingComputer Graphics programming

We will use the OpenGL APIWe will use the OpenGL API