CS 4363/6353 OPENGL BACKGROUND
WHY IS THIS CLASS SO HARD TO TEACH? (I’LL STOP WHINING SOON) Hardware (GPUs) double in processing power ever 6 months! The “graphics pipeline” has been *drastically* changing Core profile Compatibility profile (for backwards compatibility) More of the pipeline is available: Good for developers (beautiful graphics) Hard for teachers (more difficult to get a “Hello, World!” going) Requires students to understand more simply to begin Need scaffolding
WHAT IS OPENGL? “Open” (source) Graphics Language Developed by Silicon Graphics, Inc. (SGI) Not a language, but an API (Application Programming Interface) Include the “new” GLSL (Shading Language) – a C-like language for rendering Intended to run on hardware Cross-platform (MacOS, Windows, Linux using Mesa3D) Was “owned” by an industry board (the ARB – Architecture Review Board) and now the Khronos group OpenGL != GPGPU Mesa is an open-source software implementation
VERSIONS V1 – Fixed function pipeline 1992 – – – – – 1.5 V2 – Programmable pipeline 2004 – V3* – Programmable buffers 2008 – – – – 3.3 V4 - ?? 2010 – (Aug) – 4.2 * No longer backwards compatible
STATE MACHINE OpenGL is a state machine that uses a client/server model Our (C/C++) program is the client The hardware (GPU driver) is the server Client sends commands to the server This is what GLEW does – asks the driver for pointers to all the gl functions!
HELPER LIBRARIES YOU MIGHT USE GL – The Graphics Library (opengl32.lib and DLL) GLUT – OpenGL “Utility Toolkit” for system-independent windows, which also accepts user input (mouse). Others are: SDL GLX WGL We’ll use “FreeGLUT” GLEW – The GL “Extension Wrangler” for determining which vendor extensions are available and loading them (later
GL CONVENTIONS Functions can begin with gl or glut Data types usually begin with GL GLboolean -1 bit GLbyte – 8 bits GLubyte – 8 bits (unsigned) GLchar – 8 bits GLshort - 16 bits GLushort – 16 bits unsigned GLint – 32 bits GLuint – 32 bits unsigned Enumerants start with GL_ GL_TRIANGLES GLsizei – 32 bits GLenum – 32 bits GLfloat – 32 bits GLdouble – 64 bits GLint64 – 64 bits GLintptr – native pointer
OPENGL ERRORS Hard to debug! Use the built-in method to determine which error occurred: GL_INVALID_ENUM GL_INVALID_VALUE GL_INVALID_OPERATION GL_OUT_OF_MEMORY GL_NO_ERROR if (glGetError() == GL_INVALID_OPERATION) {...} Note: invalid function calls are quietly disregarded!
IDENTIFYING THE VERSION Can query for the vendor and version number of the rendering engine: const GLubyte* glGetString(GLenum name);
HINTS… Sometimes, you need speed at the sacrifice of quality. glHint (GLenum target, GLenum mode) Sometimes, you need speed at the sacrifice of quality. glHint (GL_POLYGON_SMOOTH, GL_FASTEST);
ARE YOU AN ENABLER? (MORE OF THE STATE MACHINE) In OpenGL, we are always turning features on and off with glEnable and glDisable By default, everything is disabled! Example: glEnable (GL_DEPTH_TEST);. glDisable (GL_DEPTH_TEST); Note: you can always determine if something is on with GLboolean glIsEnabled(GLenum);
COLOR THEORY All colors in OpenGL are comprised of three primary colors Red Green Blue Have two separate ranges Examples: Red = {255, 0, 0} Green = {0, 255, 0} Blue = {0, 0, 255}
LIGHTING Lighting is complex! We have to make approximations to real-world lighting For now, understand OpenGL supports the idea of: Camera (View) – using a matrix Light sources – using an array Normals of a triangle We use math to calculate light
THE GRAPHICS PIPELINE (AKA - THE BIG PICTURE) Vertex Processing Clipping/Assembly Rasterization Fragment Processing 4 major phases, though several sub-phases
THE GRAPHICS PIPELINE (AKA - THE BIG PICTURE) Vertex Processing Clipping/Assembly Rasterization Fragment Processing Vertex Processing Transform vertices using math Light a vertex Determine the color of a vertex We write vertex shaders to do this!
THE GRAPHICS PIPELINE (AKA - THE BIG PICTURE) Vertex Processing Clipping/Assembly Rasterization Fragment Processing Clipping and Primitive Assembly Assemble vertices into triangles Clip triangles if they straddle viewport We have no (programmable) control over this
THE GRAPHICS PIPELINE (AKA - THE BIG PICTURE) Vertex Processing Clipping/Assembly Rasterization Fragment Processing Rasterization “Scanline” converting Output is a set of “uncolored” fragments Not programmable
THE GRAPHICS PIPELINE (AKA - THE BIG PICTURE) Vertex Processing Clipping/Assembly Rasterization Fragment Processing Works on a pixel/fragment basis Determining the color of each pixel We write pixel shaders for this Lighting Materials Color information