Embed presentation











![OpenGL Global State Machine●The OpenGL interface uses an architecture called a“global state machine”●Instead of doing this sort of thing:Mesh myMesh;myMesh.setData (some_array);opengl.drawMesh (myMesh);●in a G.S.M. we do this sort of thing [pseudo-code]:unsigned int mesh_handle;glGenMesh (&mesh_handle); // okay so far, just C styleglBindMesh (mesh_handle); // my mesh is now “the” mesh// affects most recently “bound” meshglMeshData (some_array);●How this might cause a problem later?](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2f013dproganton-170623132654%2f75%2fComputer-Graphics-Lecture-01-3D-Programming-I-12-2048.jpg&f=jpg&w=240)



























![File Naming Convention●Upgarde the template – load shader strings from text files●post-fix with– .vert - vetex shader– .frag - fragment shader– .geom - geometry shader– .comp - compute shader– .tesc - tessellation control shader– .tese - tessellation evaluation shader●allows you to use a tool like Glslang reference compiler tocheck for [obvious] errors](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2f013dproganton-170623132654%2f75%2fComputer-Graphics-Lecture-01-3D-Programming-I-40-2048.jpg&f=jpg&w=240)









![Second ArrayGLfloat points[] = {0.0f, 0.5f, 0.0f,0.5f, -0.5f, 0.0f,-0.5f, -0.5f, 0.0f};GLfloat colours[] = {1.0f, 0.0f, 0.0f,0.0f, 1.0f, 0.0f,0.0f, 0.0f, 1.0f};](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2f013dproganton-170623132654%2f75%2fComputer-Graphics-Lecture-01-3D-Programming-I-50-2048.jpg&f=jpg&w=240)







Here are a few key points about adding vertex colors to the example:- Storing the color data in a separate buffer is cleaner than concatenating or interleaving it with the position data. This keeps the data layout simple.- The vertex shader now has inputs for both the position (vp) and color (vc) attributes. - The color is passed through as an output (fcolour) to the fragment shader. - The position is still used to set gl_Position for transformation.- The color input has to start in the vertex shader because that is where per-vertex attributes like color are interpolated across the primitive before being sampled in the fragment shader. The vertex shader interpolates the color value











![OpenGL Global State Machine●The OpenGL interface uses an architecture called a“global state machine”●Instead of doing this sort of thing:Mesh myMesh;myMesh.setData (some_array);opengl.drawMesh (myMesh);●in a G.S.M. we do this sort of thing [pseudo-code]:unsigned int mesh_handle;glGenMesh (&mesh_handle); // okay so far, just C styleglBindMesh (mesh_handle); // my mesh is now “the” mesh// affects most recently “bound” meshglMeshData (some_array);●How this might cause a problem later?](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2f013dproganton-170623132654%2f75%2fComputer-Graphics-Lecture-01-3D-Programming-I-12-2048.jpg&f=jpg&w=240)



























![File Naming Convention●Upgarde the template – load shader strings from text files●post-fix with– .vert - vetex shader– .frag - fragment shader– .geom - geometry shader– .comp - compute shader– .tesc - tessellation control shader– .tese - tessellation evaluation shader●allows you to use a tool like Glslang reference compiler tocheck for [obvious] errors](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2f013dproganton-170623132654%2f75%2fComputer-Graphics-Lecture-01-3D-Programming-I-40-2048.jpg&f=jpg&w=240)









![Second ArrayGLfloat points[] = {0.0f, 0.5f, 0.0f,0.5f, -0.5f, 0.0f,-0.5f, -0.5f, 0.0f};GLfloat colours[] = {1.0f, 0.0f, 0.0f,0.0f, 1.0f, 0.0f,0.0f, 0.0f, 1.0f};](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2f013dproganton-170623132654%2f75%2fComputer-Graphics-Lecture-01-3D-Programming-I-50-2048.jpg&f=jpg&w=240)







Dr. Anton Gerdelan introduces 3D programming, emphasizing its difficulty and time requirements. Knowledge of graphics APIs and basic concepts is essential to prevent obsolescence.
Key practices include problem-solving before coding, understanding memory management, debugging, and knowing the hardware graphics pipeline.
Covers vertices in modern graphics hardware, detailing OpenGL's management, its C interface limitations, and the need for up-to-date practices.
Explains the global state machine architecture, cautioning on how binding and unbinding can complicate functions affecting drawn objects.
Discussion on CPU/GPU interactions, rendering loops, and OpenGL function naming conventions for programming.
Describes the use of GLFW and GLEW for creating OpenGL contexts, hinting at proper version usage for compatibility.
Steps for creating vertex points, vertex buffer objects (VBOs), and vertex array objects (VAOs), instrumental for drawing operations.
Introduces vertex and fragment shaders, their functions, and the importance of the drawing loop in OpenGL applications.
Discusses program termination protocols, how to start projects with templates, and the effort involved in basic shapes like triangles.
Explores main components of a 3D graphics program, including data storage and definition, crucial prior to utilizing drawing functions.
Encourages experimentation with colors, geometry, load methods, and reviews graphics system architecture and asynchronous processing.
Analyzes GPU parallelism, the difference between fragments and pixels, shader languages, and GLSL versions with operators.
Establishes file naming conventions for shaders and presents examples of vertex shaders with explanations about their components.
Presents a fragment shader example with discussions on uniforms, their importance, and error-checking functionality in shader programming.
Introduces Shadertoy for shader experimentation and various data layout options for managing vertex and color data.
Covers creating second VBOs for color data, establishing relationships in VAOs for multi-variable handling in shaders.
Details modifications in vertex and fragment shaders, interpolation in graphics rendering, and techniques for optimizing mesh drawing.