Open Graphics Library (OpenGL)

Slides:



Advertisements
Similar presentations
Programming with OpenGL - Getting started - Hanyang University Han Jae-Hyek.
Advertisements

Introduction to Modern OpenGL Programming
Chapter 2: Graphics Programming
EECS 700: Computer Modeling, Simulation, and Visualization Dr. Shontz Chapter 2: Shader Fundamentals (continued)
 The success of GL lead to OpenGL (1992), a platform-independent API that was  Easy to use  Close enough to the hardware to get excellent performance.
As well as colors, normals, and other vertex data PUSHIN’ GEO TO THE GPU JEFF CHASTINE 1.
OpenGL (Graphics Library) Software Interface to graphics software Allows to create interactive programs that produce color images of moving 3D objects.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
CS 480/680 Computer Graphics Course Overview Dr. Frederick C Harris, Jr. Fall 2012.
Programming with OpenGL Part 2: Complete Programs Ed Angel Professor of Emeritus of Computer Science University of New Mexico.
Programming with OpenGL Part 2: Complete Programs Ed Angel Professor of Emeritus of Computer Science University of New Mexico.
CS 480/680 Computer Graphics Programming with Open GL Part 1: Background Dr. Frederick C Harris, Jr. Fall 2011.
CS 450: COMPUTER GRAPHICS PORTRAIT OF AN OPENGL PROGRAM SPRING 2015 DR. MICHAEL J. REALE.
1 Angel and Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012 Introduction to Computer Graphics Ed Angel Professor Emeritus of Computer.
Introduction to GL Geb Thomas. Example Code int main(int argc, char **argv) { glutInit(&argc, argv); glutInitDisplayMode ( GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH);
1 Graphics CSCI 343, Fall 2015 Lecture 4 More on WebGL.
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!
CS 480/680 Intro Dr. Frederick C Harris, Jr. Fall 2014.
1 E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012 Programming with OpenGL Part 1: Background Ed Angel Professor Emeritus.
Introduction to OpenGL  OpenGL is a graphics API  Software library  Layer between programmer and graphics hardware (and software)  OpenGL can fit in.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
OpenGL Shader Language Vertex and Fragment Shading Programs.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
GLSL OpenGL Programming and Reference Guides, other sources
Chun-Yuan Lin Introduction to OpenGL 2015/12/19 1 CG.
1 Graphics CSCI 343, Fall 2015 Lecture 5 Color in WebGL.
NoufNaief.net TA: Nouf Al-harbi.
Vertex Buffer Objects and Shader Attributes. For Further Reading Angel 7 th Ed: –Most parts of Chapter 2. Beginning WebGL: –Chapter 1: vertex Buffer Objects,
Programming with OpenGL Part 0: 3D API. For Further Reading Angel 7 th Ed: –2.2: JavaScript –2.3: OpenGL & WebGL –2.8: fragment & vertex shaders Beginning.
1 E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012 Programming with OpenGL Part 2: Complete Programs Ed Angel Professor.
1 E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012 Programming with OpenGL Ed Angel Professor Emeritus of Computer Science.
CS 480/680 Computer Graphics Programming with Open GL Part 5: Putting it all together Dr. Frederick C Harris, Jr. Fall 2011.
Programming with OpenGL Part 5: More GLSL Isaac Gang University of Mary Hardin-Baylor E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley.
1 Graphics CSCI 343, Fall 2015 Lecture 25 Texture Mapping.
OpenGL API 2D Graphic Primitives Angel Angel: Interactive Computer Graphics5E © Addison-Wesley
Programming with OpenGL Part 3: Shaders Ed Angel Professor of Emeritus of Computer Science University of New Mexico 1 E. Angel and D. Shreiner: Interactive.
CSE Real Time Rendering Week 3. The Anatomy of *GL* Program TION/CODE/CHAPTER02/
Computer Graphics (Fall 2003) COMS 4160, Lecture 5: OpenGL 1 Ravi Ramamoorthi Many slides courtesy Greg Humphreys.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
CS 480/680 Computer Graphics Programming with Open GL Part 2: Complete Programs Dr. Frederick C Harris, Jr. Fall 2011.
Pushin’ Geo to the GPU As well as colors, normals, and other vertex data Made by Jeff Chastine, Modified by Chao Mei Jeff Chastine.
Introduction to OpenGL
OpenGL API 2D Graphic Primitives
Programming with OpenGL Part 2: Complete Programs
Introduction to Computer Graphics with WebGL
גרפיקה ממוחשבת: מבוא ל-OpenGL
Introduction to Computer Graphics with WebGL
Chapter VI OpenGL ES and Shader
Introduction to Computer Graphics with WebGL
Programming with OpenGL
Introduction to Computer Graphics with WebGL
Introduction to Computer Graphics with WebGL
Introduction to OpenGL
Building Models Ed Angel Professor Emeritus of Computer Science
Introduction to Computer Graphics with WebGL
Introduction to Computer Graphics with WebGL
Isaac Gang University of Mary Hardin-Baylor
Programming with OpenGL Part 2: Complete Programs
Programming with OpenGL Part 3: Shaders
Programming with OpenGL Part 5: More GLSL
Programming with OpenGL Part 2: Complete Programs
Mickaël Sereno Shaders Mickaël Sereno 25/04/2019 Mickaël Sereno -
Introduction to Computer Graphics with WebGL
Programming with OpenGL Part 5: More GLSL
Introduction to OpenGL
Introduction to Computer Graphics with WebGL
OpenGL Background CS 4722.
Introduction to Computer Graphics
OpenGL-Rendering Pipeline
CS 480/680 Fall 2011 Dr. Frederick C Harris, Jr. Computer Graphics
Presentation transcript:

Open Graphics Library (OpenGL) Images were taken from the book: “Interactive Computer Graphics” by Angel and Shreiner

OpenGL Application programming interface (API) for rendering 2D\3D graphics The API interacts with the graphics processing unit (GPU) Created in 1991 by Silicon Graphics. Now it is managed by the Khronos consortium

OpenGL – Design A library of functions (e.g., glDrawArrays) and constants (e.g., GL_TRIANGLES) Language-independent: has many bindings, e.g., WebGL. Platform-independent: works on Win/Linux/..

OpenGL – Documentation The manuals are known by their cover’s color: The Red Book: OpenGL Programming Guide The Orange Book: OpenGL Shading Language The Blue Book: OpenGL Reference manual The Green Book: OpenGL & X Window System The Alpha Book: OpenGL & Windows

OpenGL – Libraries OpenGL doesn’t support input or windowing GLUT (or freeglut) is used to create a context Platform-dependent extensions can be provided by vendors. Identified by ARB, EXT, .. GLEW wraps the extraction of functionality

OpenGL – History OpenGL 1 (1992): Fixed pipeline OpenGL 2 (2004): Programmable shaders OpenGL 3: Deprecated the fixed functionality OpenGL 3.1 (2009): Removed completely the fixed pipeline .. OpenGL 4.5 (2014):

OpenGL – History OpenGL 1 OpenGL 2 OpenGL 3 State Machine OpenGL 3.1 .. OpenGL 4.5 State Machine Data flow model

OpenGL – Suggested Readings The internet is full of tutorials.. Our course book has many examples Check chapters 2, 3 and appendices A, D. Also, see here: http://www.opengl-tutorial.org/

OpenGL – Coding The API is obtained by including freeglut: Extensions are accessed through GLEW: #include <GL/freeglut.h> #include <GL/glew.h> glewInit();

OpenGL – Coding Data flow model: send data to the GPU Many functions in the form of ∗=𝑛𝑡[𝑣], where 𝑛∈{2,3,4} and 𝑡∈{i,d,f}, and 𝑣 means we pass a pointer glSomeFunction*();

OpenGL – Coding Examples: Later, we will see how to transfer matrices glUniform1f(..); glUniform3iv(..);

OpenGL – Coding Send the array points to the GPU Name and create a vertex array object (VAO) GLuint abuffer; glGenVertexArrays(1, &abuffer); glBindVertexArray(abuffer);

OpenGL – Coding Next, we create a vertex buffer object (VBO) This is how data is actually stored GLuint buffer; glGenBuffers(1, &buffer); glBindBuffer(GL_ARRAY_BUFFER, buffer); glBufferData(GL_ARRAY_BUFFER,sizeof(points), points, GL_STATIC_DRAW);

OpenGL – Coding Rendering our data can be done simply by Thus, a simple display method is glDrawArrays(GL_TRIANGLES,0,sizeof(points)); void display(void) { glClear(GL_COLOR_BUFFER_BIT); glDrawArrays(GL_TRIANGLES,0,sizeof(points)); glFlush(); }

OpenGL – Graphics Pipeline Similar to our software renderer Your program will consist of shaders No default shaders You must at least supply vertex and fragment shaders

OpenGL – Shaders Vertex shader: Fragment shader: Send a vertex location to the rasterizer … Fragment shader: Its input is a fragment inside the clipping volume Output a color to the fragment

GL Shading Language (GLSL) C-like language Need to compile and link in runtime Create a program object with shader objects Connect shader’s entities to our program

OpenGL – Coding Create a program object with shader objects Connect shader’s entities to our program GLuint program; program = InitShader("vsource.glsl", "fsource.glsl"); GLuint loc; loc = glGetAttribLocation(program, "vPosition"); glEnableVertexAttribArray(loc); glVertexAttribPointer(loc, 2, GL_FLOAT, GL_FALSE, 0, 0);

OpenGL – Example static char* readShaderSource(const char* shaderFile) { … } Gluint InitShader(const char* vShaderFile, const char* fShaderFile) {

OpenGL – Example void init(void) { … points = …; GLuint program = InitShader( "vshader.glsl", "fshader.glsl" ); glUseProgram( program ); GLuint vao; glGenVertexArrays( 1, &vao ); glBindVertexArray( vao );

OpenGL – Example GLuint buffer; glGenBuffers( 1, &buffer ); glBindBuffer( GL_ARRAY_BUFFER, buffer ); glBufferData( GL_ARRAY_BUFFER, sizeof(points), points, GL_STATIC_DRAW ); GLuint loc = glGetAttribLocation( program, "vPosition" ); glEnableVertexAttribArray( loc ); glVertexAttribPointer(loc,2,GL_FLOAT,GL_FALSE,0,0) glClearColor( 1.0, 1.0, 1.0, 1.0 ); }

OpenGL – Example void display(void) { glClear( GL_COLOR_BUFFER_BIT ); glDrawArrays( GL_POINTS, 0, sizeof(points) ); glFlush( void ); }

OpenGL – Example int main( int argc, char **argv ) { glutInit( &argc, argv ); glutInitDisplayMode( GLUT_RGBA ); glutInitWindowSize( 512, 512 ); glutInitContextVersion( 3, 2 ); glutInitContextProfile( GLUT_CORE_PROFILE ); glutCreateWindow( “Example" ); glewInit( void ); init( void ); glutDisplayFunc( display ); glutMainLoop( void ); return 0; }

OpenGL – Example #version 150 in vec4 vPosition; void main() { gl_Position = vPosition; } out vec4 fColor; fColor = vec4( 1.0, 0.0, 0.0, 1.0 );