Programming with OpenGLProgramming with OpenGL- - Getting started -Getting started -
Hanyang University
Han Jae-Hyek
Division of Electrical and Computer Engineering, Hanyang University2
ObjectiveObjective
Development of the OpenGL API OpenGL Architecture
OpenGL as a state machine Functions
Types Formats
Programming Environment Setting Simple program
Division of Electrical and Computer Engineering, Hanyang University
OpenGLOpenGL
The success of GL lead to OpenGL (1992), a platform-independent API that was Easy to use Close enough to the hardware to get excellent
performance Focus on rendering Omitted windowing and input to avoid window system
dependencies
Division of Electrical and Computer Engineering, Hanyang University
OpenGL EvolutionOpenGL Evolution
Originally controlled by an Architectural Review Board (ARB) Members included SGI, Microsoft, Nvidia, HP, 3DLabs,
IBM,……. Relatively stable (present version 2.1)
Evolution reflects new hardware capabilities• 3D texture mapping and texture objects• Vertex programs
Allows for platform specific features through extensions ARB replaced by Khronos
Division of Electrical and Computer Engineering, Hanyang University
OpenGL LibrariesOpenGL Libraries OpenGL core library
OpenGL32 on Windows GL on most unix/linux systems (libGL.a)
OpenGL Utility Library (GLU) Provides functionality in OpenGL core but avoids
having to rewrite code Links with window system
GLX for X window systems WGL for Windows AGL for Macintosh
OpenGL Utility Toolkit (GLUT) Provides functionality common to all window systems
OpenGL Extension Wrangler library Helps in querying and loading OpenGL extensions
Division of Electrical and Computer Engineering, Hanyang University
GLUTGLUT
OpenGL Utility Toolkit (GLUT) Provides functionality common to all window systems
Open a window Get input from mouse and keyboard Menus Event-driven
Code is portable but GLUT lacks the functionality of a good toolkit for a specific platform
No slide bars
Division of Electrical and Computer Engineering, Hanyang University
Software OrganizationSoftware Organization
GLUT
GLU
GL
GLX, AGLor WGL
X, Win32, Mac O/S
software and/or hardware
application program
OpenGL Motifwidget or similar
Division of Electrical and Computer Engineering, Hanyang University
OpenGL ArchitectureOpenGL Architecture
Immediate Mode
DisplayList
PolynomialEvaluator
Per VertexOperations &
PrimitiveAssembly
RasterizationPer Fragment
Operations
TextureMemory
CPU
PixelOperations
FrameBuffer
geometry pipeline
Division of Electrical and Computer Engineering, Hanyang University
OpenGL FunctionsOpenGL Functions
Primitives Points Line Segments Polygons
Attributes Transformations
Viewing Modeling
Control (GLUT) Input (GLUT) Query
Division of Electrical and Computer Engineering, Hanyang University
OpenGL StateOpenGL State
OpenGL is a state machine OpenGL functions are of two types
Primitive generating Can cause output if primitive is visible How vertices are processed and appearance of
primitive are controlled by the state State changing
Transformation functions Attribute functions
Division of Electrical and Computer Engineering, Hanyang University
Lack of Object OrientationLack of Object Orientation
OpenGL is not object oriented so that there are multiple functions for a given logical function glVertex3f glVertex2i glVertex3dv
Underlying storage mode is the same Easy to create overloaded functions in C++ but issue
is efficiency
Division of Electrical and Computer Engineering, Hanyang University
OpenGL function formatOpenGL function format
glVertex3f(x,y,z)
belongs to GL library
function name
x,y,z are floats
glVertex3fv(p)
p is a pointer to an array
dimensions
Division of Electrical and Computer Engineering, Hanyang University
OpenGL #definesOpenGL #defines
Most constants are defined in the include files gl.h, glu.h and glut.h Note #include <GL/glut.h> should automatically
include the others Examples glBegin(GL_POLYGON) glClear(GL_COLOR_BUFFER_BIT)
include files also define OpenGL data types: GLfloat, GLdouble,….
Division of Electrical and Computer Engineering, Hanyang University
ProgrammingProgramming Environment SettingEnvironment Setting
http://www.microsoft.com/express/download/
Division of Electrical and Computer Engineering, Hanyang University
http://www.opengl.org http://nehe.gamedev.net
Division of Electrical and Computer Engineering, Hanyang University
Division of Electrical and Computer Engineering, Hanyang University
Platform SDK Platform SDK 경로에 설치할 경우경로에 설치할 경우 glut.h
Division of Electrical and Computer Engineering, Hanyang University
Platform SDK Platform SDK 경로에 설치할 경우경로에 설치할 경우 glut.lib, glut32.lib
dll 파일을 “ Window/System32/” 으로 이동
Division of Electrical and Computer Engineering, Hanyang University
다른 경로에 설치할 경우다른 경로에 설치할 경우 ex) d:\library\opengl\
Division of Electrical and Computer Engineering, Hanyang University
다른 경로에 설치할 경우다른 경로에 설치할 경우 visual studio 에서 tools->options->projects and
solutions->VC++ directories
Division of Electrical and Computer Engineering, Hanyang University
다른 경로에 설치할 경우다른 경로에 설치할 경우 visual studio 에서 tools->options->projects and
solutions->VC++ directories
Division of Electrical and Computer Engineering, Hanyang University
Division of Electrical and Computer Engineering, Hanyang University
Division of Electrical and Computer Engineering, Hanyang University
Division of Electrical and Computer Engineering, Hanyang University
Project->properties->configuration properties->linker->input->additional dependencies
OpenGL32.lib glu32.lib glut32.lib
Division of Electrical and Computer Engineering, Hanyang University
A Simple ProgramA Simple Program
Generate a square on a solid background
Division of Electrical and Computer Engineering, Hanyang University
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();
}