introduction to opengl
DESCRIPTION
Introduction to OpenGL. Graphics API. A software interface for graphics hardware. Provide the low-level functions to access graphics hardware directly. OpenGL / Direct3D. API Hierarchy. Application. GDI. OpenGL. Hardware Driver. …. Display Device. What is OpenGL 1/2. - PowerPoint PPT PresentationTRANSCRIPT
CGGM Lab. Tan-Chi Ho 2002 1
Introduction to OpenGL
CGGM Lab. Tan-Chi Ho 2002 2
Graphics API A software interface for graphics
hardware. Provide the low-level functions to
access graphics hardware directly. OpenGL / Direct3D
CGGM Lab. Tan-Chi Ho 2002 3
API Hierarchy
Application
GDI
Display Device
OpenGL
Hardware Driver
…
CGGM Lab. Tan-Chi Ho 2002 4
What is OpenGL1/2
Industry standard. Hardware independent. OS independent.
CGGM Lab. Tan-Chi Ho 2002 5
What is OpenGL2/2
No commands for performing windowing tasks or obtaining user input are included.
No high-level commands for describing models of 3D objects are provided.
CGGM Lab. Tan-Chi Ho 2002 6
What OpenGL provides Draw with points, lines, and polygons. Matrix(View) Transformation Hidden Surface Removal (Z-Buffer) Light effects Gouraud Shading Texture mapping Pixels operation
CGGM Lab. Tan-Chi Ho 2002 7
The Buffers A buffer is a memory area in the
graphics hardware for some special purposes.
An OpenGL system can manipulate the four buffers: Color buffers Depth buffer (Z-Buffer) Stencil buffer Accumulation buffer
CGGM Lab. Tan-Chi Ho 2002 8
OpenGL Rendering Pipeline1/2
OpenGL API Calls
OpenGL Command
Buffer
Transformation and Lighting
RasterizationFrame Buffer
CGGM Lab. Tan-Chi Ho 2002 9
OpenGL Rendering Pipeline2/2
Vertex Data
Pixel Data
Display List
Evaluators
Per-Vertex Operations and Primitive Assembly
Pixel Operations
Rasterization
Texture Assembly
Per-Fragment Operations
Frame Buffer
CGGM Lab. Tan-Chi Ho 2002 10
OpenGL Libraries OpenGL Library
The basic library to access the graphics hardware.
GLU Provide some useful utilities based on the
OpenGL library. GLX / WGL / AGL
OS dependent libraries to bind the OpenGL library with specific window system.
GLX for X-window, WGL for win32, AGL for Apple.
CGGM Lab. Tan-Chi Ho 2002 11
OpenGL Utility Toolkit (GLUT) 1/3
A window system-independent toolkit to hide the complexities of differing window system APIs.
Use the prefix of glut. (ex: glutDisplayFunc())
Provide following operations: Initializing and creating window Handling window and input events Drawing basic three-dimensional objects Running the program
CGGM Lab. Tan-Chi Ho 2002 12
OpenGL Utility Toolkit (GLUT) 2/3
Where can I get GLUT? Win32:
http://www.xmission.com/~nate/glut.html Linux:
http://www.mesa3d.org/
CGGM Lab. Tan-Chi Ho 2002 13
OpenGL Utility Toolkit (GLUT) 3/3
On Microsoft Visual C++ 6: Put glut.h into <MSVC>/include/GL/ Put glut.lib into <MSVC>/lib/ Put glut32.dll into <window>/System32/
On Microsoft Visual C++ .NET: Put glut.h into <MSVC>/platformSDK/include/G
L/ Put glut.lib into <MSVC>/platformSDK/lib/ Put glut32.dll into <window>/System32/
CGGM Lab. Tan-Chi Ho 2002 14
How to Compile1/4
On Microsoft Visual C++ 6: Create a new Project with Win32
Console Application Open Project Settings dialog and add
opengl32.lib glu32.lib glut32.lib into Link/Objects/library modules.
Writing your OpenGL code. Compile it.
CGGM Lab. Tan-Chi Ho 2002 15
How to Compile2/4
On Microsoft Visual C++ .NET: 建立 Win32 專案 在應用程式設定,選擇主控台應用程式 開啟專案屬性,在連結器 / 輸入 / 其他相依
性中輸入 opengl32.lib glu32.lib glut32.lib 。
Writing your OpenGL code. Compile it.
CGGM Lab. Tan-Chi Ho 2002 16
How to Compile3/4
CGGM Lab. Tan-Chi Ho 2002 17
How to Compile4/4
On UNIX: Needed libraries:
libGL.so, libGLU.so, libglut.a, libX11.a, libX11.so…
Compile command: gcc [OpenGL code files] –o [output file] –lglut
–lGLU –lGL –lX11 –lm
CGGM Lab. Tan-Chi Ho 2002 18
The Simplest Program1/3
#include <GL/glut.h>void GL_display(){
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);glClear(GL_COLOR_BUFFER_BIT);glColor3f(1.0f, 1.0f, 1.0f);glutSolidCube(1.0);glFlush();
}void GL_reshape(GLsizei w, GLsizei h){
glViewport(0, 0, w, h);glMatrixMode(GL_PROJECTION);glLoadIdentity();glOrtho(-2.0f, 2.0f, -2.0f, 2.0f, -2.0f, 2.0f);glMatrixMode(GL_MODELVIEW);glLoadIdentity();
}
CGGM Lab. Tan-Chi Ho 2002 19
The Simplest Program2/3
void main(void){
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);glutCreateWindow("Sample");glutDisplayFunc(GL_display);glutReshapeFunc(GL_reshape);glutMainLoop();
}
CGGM Lab. Tan-Chi Ho 2002 20
The Simplest Program3/3
CGGM Lab. Tan-Chi Ho 2002 21
Reference1/2
Official site of OpenGL http://www.opengl.org
Useful Sites NeHe’s OpenGL Tutorials The Developer’s Gallery
CGGM Lab. Tan-Chi Ho 2002 22
Reference2/2
Further Reading OpenGL Programming Guide (Red Book) OpenGL Reference Manual (Blue Book) OpenGL Super Bible ( 中文版 ?)
CGGM Lab. Tan-Chi Ho 2002 23
Any Question?
?