3. Motivation
• WebGL is based on OpenGL ES 2.0 and provides an API for 3D
graphics
• WebGL uses the HTML5 canvas element
• Moreover, OpenGL ES is a subset of OpenGL
4. What is OpenGL ?
• Open Graphics Library
• A library designed for cross platform 3D graphics
• Is the only competitor to Direct3D in the Direct library
• Hardware accelerated
• Main focus for graphics card performance
5. Why We Learn OpenGL ?
• Good support of hardware
• Microsoft DX 10 and DX11 can only run on the platform upon Windows
Vista
• The same function can be implemented by OpenGL on Windows XP
• OpenGL provides extensions for the latest function of GPU vendors
• Cross-platform
• OpenGL works on Windows/ Linux/ Mac
• OpenGL ES
• WebGL
6. OpenGL Libraries
• OpenGL core library
• OpenGL32 on Windows
• GL on most unix/linux system
• 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
7. What is GLUT ?
• OpenGL Utility Toolkit library
• A tool which allows the creation of windows and handling of
input on multiple systems
• Making OpenGL cross-platform and extremely simple to set up
• Original GLUT is no longer being developed
• There is a remake of GLUT called FreeGLUT
8. What is GLEW
• OpenGL Extension Wrangler
• A cross-platform open-source C/C++ extension loading library
• Provides efficient run-time mechanisms for determining which
OpenGL extensions are supported on the target platform
9. API Hierarchy
UNIX APPLICATION
Xlib GLX OpenGL
GLU
WINDOWS APPLICATION
GDU WGL OpenGL
GLU
OpenGL applications use the window system’s window, input, and event mechanism
12. Draw Processing
• Vertex Specification, Vertex Puller
• The process of setting up the necessary objects for rendering
with a particular shader program
• Vertex Array Object (VAO)
• An object which contains one or more VBOs
• Designed to store information for a complete renderded object
• Vertex Buffer Object (VBO)
• A memory buffer in the high speed memory of your video card
• Designed to hold information about vertices
14. Vertex Processing
• Vertex Shader
• Handles the processing of individual vertices
• Vertex shaders are fed vertex attribute, and generates vertexes
to the output vertex stream
• Must be a 1:1 mapping
16. Tessellation
• Patches of vertex data are subdivided into smaller Primitives
• Note : Primitives are ways that OpenGL interprets vertex streams,
converting them from vertices into triangles, lines, points and so forth
19. Primitive Processing
• Geometry Shader
• Governs the processing of primitives
• Take a single primitive as input and may output zero or more
primitives
22. Transform Feedback
• So far, we've used VBOs (Vertex Buffer Objects) to store
vertices to be used for drawing operations.
• The transform feedback extension allows shaders to write
vertices back to VBOs as well.
• You could for example build a vertex shader that simulates
gravity and writes updated vertex positions back to the buffer.
• This way you don't have to transfer this data back and forth
from graphics memory to main memory.
24. Rasterization
• Converts vector information (composed of shapes or primitives)
into a raster image (composed of pixels) for the purpose of
displaying real-time 3D graphics
26. Fragment Processing
• Fragment Shader, Pixel Shader
• Process a fragment into a set of colors and a single depth value
• Common fragment shader operations include texture mapping
and lighting
• Since the fragment shader runs independently for every pixel
drawn, it can perform the most sophisticated special effects
29. Pixel Processing
• Fragments output from a fragment shader are processed, and
their resulting data are written to various buffers
• A framebuffer can have a depth buffer and stencil buffer, both
of which optionally filter fragments before they are drawn to the
framebuffer
31. Environment
• Visual Studio 2012
• FreeGLUT
• http://freeglut.sourceforge.net/
• 2.8.1 version
• GLEW
• http://glew.sourceforge.net/
• 1.10.0 version
32. Installation
1. Download a stable release of FreeGLUT
2. Unzip. Go to VisualStudio2012 directory and open the
freeglut.sln Visual Studio solution file
3. Solution Configuration as Release. In Solution Explorer, right-
click on the freeglut project and choose Build.
33. Installation
4. Copy all the header files in includeGL of FreeGLUT to
C:Program Files (x86)Microsoft Visual Studio
11.0VCincludeGL
5. Copy freeglut.lib from libx86 to C:Program Files
(x86)Microsoft Visual Studio 11.0VClib
6. Copy freeglut.dll from libx86 to System32 or SysWOW64
folder
34. Visual Studio Project
1. Start a “Win32 Console Application” new project
2. Go to your “project properties” -> “Configuration Properties” -
> “Linker”, click on “input” and add two additional dependencies,
“glew32.lib” and “freeglut.lib”
35. OpenGL API
• void glutInit (int *argcp, char **argv);
• Initialized GLUT
• void glutInitDisplayMode (unsigned int mode);
• Sets the display mode
• void glutInitWindowSize (int width, int height);
• void glutInitWindowPosition (int x, int y);
• Set the size and the position on the screen for GLUT window
• int glutCreateWindow (char *name);
• Create window and give it a title/caption
36. OpenGL API
• void glutDisplayFunc (void (*func) (void));
• Sets the display callback for the current window
• void glutMainLoop (void);
• Enters the GLUT event processing loop
• void glClearColor (GLfloat red, GLfloat green, GLfloat blue,
GLfloat alpha);
• Specify clear values for the color buffers
• void glClear (GLbitfield mask);
• Clear buffers to preset values
38. Conclusion
• OpenGL pipeline is the process, from vertex buffers to
framebuffer, that your data goes through when you make a
single "draw" call in OpenGL.
• Rendering a scene usually involves multiple draw jobs,
switching out textures, other uniform state, or shaders between
passes and using the framebuffer's depth and stencil buffers to
combine the results of each pass.
• Now that we've covered the general dataflow of 3d rendering,
we can write a simple program to see how OpenGL makes it all
happen.