180 likes | 318 Views
Introduction to OpenGL. What is OpenGL 1/2. A software interface to graphics hardware. Hardware-independent interface. No commands for performing windowing tasks or obtaining user input are included. What is OpenGL 2/2.
E N D
Introduction to OpenGL CGGM Lab. Tan-Chi Ho 2001
What is OpenGL1/2 • A software interface to graphics hardware. • Hardware-independent interface. • No commands for performing windowing tasks or obtaining user input are included. CGGM Lab. Tan-Chi Ho 2001
What is OpenGL2/2 • Does not provide high-level commands for describing models of three-dimensional objects. CGGM Lab. Tan-Chi Ho 2001
What OpenGL can do • Draw with points, lines, and polygons. • Matrix(View) Transformation • Depth test (Z-Buffer) • Light calculation • Texture mapping • Pixels operation CGGM Lab. Tan-Chi Ho 2001
The Framebuffer1/2 • An OpenGL system can manipulate the following buffers: • Color buffers: • front-left, front-right, back-left, back-right, and any number of auxiliary color buffers. • Depth buffer (Z-Buffer) • Performing Depth test in hidden surface removal. CGGM Lab. Tan-Chi Ho 2001
The Framebuffer2/2 • Stencil buffer • To restrict drawing to certain potions of the screen. • Accumulation buffer • Accumulating a serious of RGBA color data in the color buffers into a final, composite image. CGGM Lab. Tan-Chi Ho 2001
OpenGL Rendering Pipeline1/2 OpenGL Command Buffer OpenGL API Calls Transformation and Lighting Frame Buffer Rasterization CGGM Lab. Tan-Chi Ho 2001
API Hierarchy Application GDI OpenGL Hardware Driver Display Device CGGM Lab. Tan-Chi Ho 2001
OpenGL Rendering Pipeline2/2 Per-Vertex Operations and Primitive Assembly Vertex Data Evaluators Per-Fragment Operations Display List Frame Buffer Rasterization Texture Assembly Pixel Data Pixel Operations CGGM Lab. Tan-Chi Ho 2001
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 2001
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 2001
The Simplest Program3/3 CGGM Lab. Tan-Chi Ho 2001
OpenGL Utility Toolkit (GLUT) 1/2 • 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 2001
OpenGL Utility Toolkit (GLUT) 2/2 • Where can I get GLUT? • Win32: • http://www.xmission.com/~nate/glut.html • Linux: • http://www.mesa3d.org/ CGGM Lab. Tan-Chi Ho 2001
How to Compile1/2 • On Microsoft Visual C++: • 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. CGGM Lab. Tan-Chi Ho 2001
How to Compile2/2 • On UNIX: • Needed libraries: • libGL.so, libGLU.so, libglut.a, libX11.a, libX11.so… • Compile command: • gcc [source files] –o [output file] –lglut –lGLU –lGL –lX11 –lm CGGM Lab. Tan-Chi Ho 2001
Reference • Official site of OpenGL • http://www.opengl.org • Further Reading • OpenGL Programming Guide (Red Book) • OpenGL Reference Manual (Blue Book) CGGM Lab. Tan-Chi Ho 2001
Any Question? ? CGGM Lab. Tan-Chi Ho 2001