CS475/CS675 - Computer Graphics. OpenGL Drawing

Similar documents
CSE 167: Introduction to Computer Graphics Lecture #7: GLSL. Jürgen P. Schulze, Ph.D. University of California, San Diego Spring Quarter 2016

Computação Gráfica. Computer Graphics Engenharia Informática (11569) 3º ano, 2º semestre. Chap. 4 Windows and Viewports

OpenGL pipeline Evolution and OpenGL Shading Language (GLSL) Part 2/3 Vertex and Fragment Shaders

Copyright Khronos Group 2012 Page 1. Teaching GL. Dave Shreiner Director, Graphics and GPU Computing, ARM 1 December 2012

COMP371 COMPUTER GRAPHICS

Computer Graphics CS 543 Lecture 4 (Part 2) Building 3D Models (Part 2)

Graphics Programming. Computer Graphics, VT 2016 Lecture 2, Chapter 2. Fredrik Nysjö Centre for Image analysis Uppsala University

Programming shaders & GPUs Christian Miller CS Fall 2011

Tutorial 04. Harshavardhan Kode. September 14, 2015

Building Models. CS 537 Interactive Computer Graphics Prof. David E. Breen Department of Computer Science

Rendering Objects. Need to transform all geometry then

Building Models. Prof. George Wolberg Dept. of Computer Science City College of New York

CS 432 Interactive Computer Graphics

Comp 410/510 Computer Graphics Spring Programming with OpenGL Part 2: First Program

An Introduction to OpenGL Programming

Tutorial 1: Your First Triangle!

CS452/552; EE465/505. Image Processing Frame Buffer Objects

Shaders. Slide credit to Prof. Zwicker

Comp 410/510 Computer Graphics Spring Programming with OpenGL Part 3: Shaders

3d Programming I. Dr Anton Gerdelan

The Graphics Pipeline

CSE 167: Introduction to Computer Graphics Lecture #5: Visibility, OpenGL

The Graphics Pipeline

Lecture 09: Shaders (Part 1)

Starting out with OpenGL ES 3.0. Jon Kirkham, Senior Software Engineer, ARM

We assume that you are familiar with the following:

Computer Graphics (CS 543) Lecture 4a: Linear Algebra for Graphics (Points, Scalars, Vectors)

INTRODUCTION TO OPENGL PIPELINE

CS452/552; EE465/505. Review & Examples

WebGL A quick introduction. J. Madeira V. 0.2 September 2017

GLSL Overview: Creating a Program

We will use WebGL 1.0. WebGL 2.0 is now being supported by most browsers but requires a better GPU so may not run on older computers or on most cell

Information Coding / Computer Graphics, ISY, LiTH. OpenGL! ! where it fits!! what it contains!! how you work with it 11(40)

CS 450: COMPUTER GRAPHICS REVIEW: STATE, ATTRIBUTES, AND OBJECTS SPRING 2015 DR. MICHAEL J. REALE

EECS 487: Interactive Computer Graphics

3D Modeling. 3D Modeling 1

API Background. Prof. George Wolberg Dept. of Computer Science City College of New York

CSE 167. Discussion 03 ft. Glynn 10/16/2017

Modern OpenGL Guide. Alexander Overvoorde. May Introduction 3 Credits... 3 Prerequisites... 4

Programming with OpenGL Shaders I. Adapted From: Ed Angel Professor of Emeritus of Computer Science University of New Mexico

CS452/552; EE465/505. Image Formation

Introduction to Computer Graphics with WebGL

CS 548: COMPUTER GRAPHICS PORTRAIT OF AN OPENGL PROGRAM SPRING 2015 DR. MICHAEL J. REALE

Computer Graphics Seminar

CSE 4431/ M Advanced Topics in 3D Computer Graphics. TA: Margarita Vinnikov

Shaders. Introduction. OpenGL Grows via Extensions. OpenGL Extensions. OpenGL 2.0 Added Shaders. Shaders Enable Many New Effects

last time put back pipeline figure today will be very codey OpenGL API library of routines to control graphics calls to compile and load shaders

Programming with OpenGL Shaders I. Adapted From: Ed Angel Professor of Emeritus of Computer Science University of New Mexico

Programming with OpenGL Complete Programs Objectives Build a complete first program

Today s Agenda. Basic design of a graphics system. Introduction to OpenGL

Advanced Graphics. OpenGL and Shaders I. Alex Benton, University of Cambridge Supported in part by Google UK, Ltd

Models and Architectures. Angel and Shreiner: Interactive Computer Graphics 7E Addison-Wesley 2015

The Graphics Pipeline

Mali & OpenGL ES 3.0. Dave Shreiner Jon Kirkham ARM. Game Developers Conference 27 March 2013

Fog example. Fog is atmospheric effect. Better realism, helps determine distances

Introductory Seminar

CSE 167: Introduction to Computer Graphics Lecture #5: Illumination Model

6.S096 Lecture 9 Visualization

8 Three-Dimensional Object Representations. Chapter 8. Three-Dimensional Object Representations. Department of Computer Science and Engineering 8-1

Programming with OpenGL Part 3: Shaders. Ed Angel Professor of Emeritus of Computer Science University of New Mexico

Practical 1: OpenTK Tutorial

Comp 410/510 Computer Graphics Spring Programming with OpenGL Part 4: Three Dimensions

CS770/870 Spring 2017 Open GL Shader Language GLSL

CS770/870 Spring 2017 Open GL Shader Language GLSL

Advanced Graphics. OpenGL and Shaders I. Alex Benton, University of Cambridge Supported in part by Google UK, Ltd

Ciril Bohak. - INTRODUCTION TO WEBGL

CPSC 436D Video Game Programming

CS 432 Interactive Computer Graphics

Lecture 19: OpenGL Texture Mapping. CITS3003 Graphics & Animation

Announcement. Homework 1 has been posted in dropbox and course website. Due: 1:15 pm, Monday, September 12

The GLSL API. Mike Bailey. Oregon State University. Geometry Shader. Program. The GLSL Shader-creation Process. create. compile. Vertex.

Programming with WebGL Part 1: Background. CS 432 Interactive Computer Graphics Prof. David E. Breen Department of Computer Science

CS452/552; EE465/505. Overview of Computer Graphics

Programmable GPUs. Real Time Graphics 11/13/2013. Nalu 2004 (NVIDIA Corporation) GeForce 6. Virtua Fighter 1995 (SEGA Corporation) NV1

Computer Graphics (CS 543) Lecture 1 (Part 2): Introduction to OpenGL/GLUT (Part 1)

Z-buffer Pipeline and OpenGL. University of Texas at Austin CS384G - Computer Graphics

OUTLINE. Learn the basic design of a graphics system Introduce pipeline architecture Examine software components for a graphics system

Best practices for effective OpenGL programming. Dan Omachi OpenGL Development Engineer

C P S C 314 S H A D E R S, O P E N G L, & J S RENDERING PIPELINE. Mikhail Bessmeltsev

Shader Programs. Lecture 30 Subsections 2.8.2, Robb T. Koether. Hampden-Sydney College. Wed, Nov 16, 2011

GLSL: Creating GLSL Programs - Overview

How OpenGL Works. Retained Mode. Immediate Mode. Introduction To OpenGL

Objectives. Programming with WebGL Part 1: Background. Retained vs. Immediate Mode Graphics. Early History of APIs. PHIGS and X.

OpenGL refresher. Advanced Computer Graphics 2012

OPEN GL BACKGROUND. Objectives. Early History of APIs. SGI and GL. PHIGS and X. Modified from Angel 6e book slides

Introduction to OpenGL/GLSL and WebGL GLSL

Draw the basic Geometry Objects. Hanyang University

BCA611 Video Oyunları için 3B Grafik

CS230 : Computer Graphics Lecture 4. Tamar Shinar Computer Science & Engineering UC Riverside

Introduction to Computer Graphics. Hardware Acceleration Review

Texture Mapping. CS 537 Interactive Computer Graphics Prof. David E. Breen Department of Computer Science

Lecture 5 Vertex and Fragment Shaders-1. CITS3003 Graphics & Animation

Computer Graphics (CS 543) Lecture 3b: Shader Setup & GLSL Introduction

Vertex Buffer Objects

Vertex Buffer Objects. Vertex Buffer Objects: The Big Idea

I think this assignment should have 8 objectives but we should still mark it out of 10. The Mean TA.

Lecture 13: OpenGL Shading Language (GLSL)

The Graphics Pipeline and OpenGL III: OpenGL Shading Language (GLSL 1.10)!

Learn OpenGL. An offline transcript of learnopengl.com. Joey de Vries

SHADER PROGRAMMING. Based on Jian Huang s lecture on Shader Programming

Transcription:

CS475/CS675 - Computer Graphics OpenGL Drawing

What is OpenGL? Open Graphics Library API to specify geometric objects in 2D/3D and to control how they are rendered into the framebuffer. A software interface to graphics hardware. Cross language, cross platform, open source Alternatives Direct3D (Microsoft) CS475/CS675 - Lecture 3 2

OpenGL Vertices A vertex is a point coordinate for OpenGL it is internally represented as a four vector (more on why later). Vertices are assembled into primitives Points, Lines, Triangles CS475/CS675 - Lecture 3 3

OpenGL Fragments A fragment is a pixel with a lot of other information: Location Color Normal Depth Opacity OpenGL rasterizes primitive shapes and outputs fragments. CS475/CS675 - Lecture 3 4

OpenGL 1 (1991) Entirely fixed-function Vertex Data Pixel Data Vertex Transform and Lighting Texture Store Primitive Setup and Rasterization Fragment Coloring and Texturing Blending An Introduction to OpenGL Programming, Edward Angel and Dave Schreiner, SIGGRAPH 2013 Course. The pipeline evolved but remained based on fixed-function operation through OpenGL versions 1.1 through 2.0. CS475/CS675 - Lecture 3 5

OpenGL 2 (1994) Introduced programmable shaders Vertex Data Pixel Data Vertex Transform and Lighting Texture Store Primitive Setup and Rasterization Fragment Coloring and Texturing Blending An Introduction to OpenGL Programming, Edward Angel and Dave Schreiner, SIGGRAPH 2013 Course. Vertex shading, Fragment shading CS475/CS675 - Lecture 3 6

OpenGL 3, 3.1, 3.2 (~2008) Introduced the deprecation model Removed the fixed function pipeline. Large chunks of data fed to the pipeline instead of small chunks. OpenGL catching up with GPU architecture Vertex Data Pixel Data Vertex Shader Texture Store Primitive Setup and Rasterization Fragment Shader Blending An Introduction to OpenGL Programming, Edward Angel and Dave Schreiner, SIGGRAPH 2013 Course. CS475/CS675 - Lecture 3 7

OpenGL 4.0 4.5 (current day) Geometry & Tesselation Shader Geometry generated on the GPU Vertex Data Vertex Shader Tessellation Control Shader Tessellation Evaluation Shader Geometry Shader Primitive Setup and Rasterization Fragment Shader Blending Pixel Data Texture Store An Introduction to OpenGL Programming, Edward Angel and Dave Schreiner, SIGGRAPH 2013 Course. CS475/CS675 - Lecture 3 8

OpenGL Variants OpenGL ES For hand-held devices and embedded environments WebGL Javascript implementation of ES Runs on most recent browsers CS475/CS675 - Lecture 3 9

Simplified Pipeline Application GPU Data Flow Framebuffer Vertices Vertices Fragments Pixels Vertex Processing Rasterizer Fragment Processing Vertex Shader Fragment Shader An Introduction to OpenGL Programming, Edward Angel and Dave Schreiner, SIGGRAPH 2013 Course. CS475/CS675 - Lecture 3 10

Simplified Pipeline 1 Application GPU Data Flow Framebuffer Vertices Vertices Fragments Pixels Vertex Processing Rasterizer Fragment Processing 2 3 Vertex Shader Fragment Shader An Introduction to OpenGL Programming, Edward Angel and Dave Schreiner, SIGGRAPH 2013 Course. CS475/CS675 - Lecture 3 11

OpenGL Application Program OpenGL Programming Create Shader Program Create Buffer Objects and load data into them. Connect data locations with shader variables Render Windowing System Interface: GLFW Opening windows, handling input Version, Context and profiles: GLEW CS475/CS675 - Lecture 3 12 OpenGL Math Library (only headers): GLM

Geometric Objects in OpenGL A vertex is a location in space. Attributes: Position Coordinates Colors, Texture Coordinates, Other Data Vertex data must be stored in vertex buffer objects (VBOs) Vertex attribute information must be stored in vertex array objects (VAOs) CS475/CS675 - Lecture 3 13

OpenGL Primitives Deprecated CS475/CS675 - Lecture 3 14

Example: ColorCube A cube with different colors at each vertex //6 faces, 2 triangles/face, 3 vertices/triangles const int num_vertices = 36; //Eight vertices in homogenous coordinates glm::vec4 positions[8] = { glm::vec4(-0.5, -0.5, 0.5, 1.0), glm::vec4(-0.5, 0.5, 0.5, 1.0),...}; //RGBA colors glm::vec4 colors[8] = { glm::vec4(0.0, 0.0, 0.0, 1.0), glm::vec4(1.0, 0.0, 0.0, 1.0), glm::vec4(1.0, 1.0, 0.0, 1.0),...}; CS475/CS675 - Lecture 3 15

Example: ColorCube A cube with different colors at each vertex // quad defines two triangles for each face and assigns colors to the vertices void quad(int a, int b, int c, int d) { v_colors[tri_idx] = colors[a]; v_positions[tri_idx] = positions[a]; tri_idx++; v_colors[tri_idx] = colors[b]; v_positions[tri_idx] = positions[b]; tri_idx++; v_colors[tri_idx] = colors[c]; v_positions[tri_idx] = positions[c]; tri_idx++; v_colors[tri_idx] = colors[a]; v_positions[tri_idx] = positions[a]; tri_idx++; v_colors[tri_idx] = colors[c]; v_positions[tri_idx] = positions[c]; tri_idx++; v_colors[tri_idx] = colors[d]; v_positions[tri_idx] = positions[d]; tri_idx++; } // define 12 triangles: 36 vertices and 36 colors void colorcube(void) { quad( 1, 0, 3, 2 ); quad( 2, 3, 7, 6 ); quad( 3, 0, 4, 7 ); quad( 6, 5, 1, 2 ); quad( 4, 5, 6, 7 ); quad( 5, 4, 0, 1 ); } CS475/CS675 - Lecture 3 16

Example: ColorCube A cube with different colors at each vertex VertexArrayObjects (VAOs) VertexBufferObjects(VBOs) Generate and Bind CS475/CS675 - Lecture 3 17

Example: ColorCube Vertex Array Object Stores attribute data corresponding to the VBOs GLuint vao; glgenvertexarrays( 1, &vao ); glbindvertexarray( vao ); CS475/CS675 - Lecture 3 18

Example: ColorCube Vertex Buffer Object Vertex data must be stored in a VBO, and associated with a VAO The code-flow is similar to configuring a VAO generate VBO names by calling glgenbuffers() Bind a specific VBO for initialization by calling glbindbuffer( GL_ARRAY_BUFFER, ) Load data into VBO using glbufferdata( GL_ARRAY_BUFFER,...) glbuffersubdata( GL_ARRAY_BUFFER, ) CS475/CS675 - Lecture 3 19

Example: ColorCube Create a Shader Program Create Program Create Shader Load Shader Source Compile Shader Attach Shader to Program Link Program glcreateprogram() glcreateshader() glshadersource() glcompileshader() glattachshader() gllinkprogram() These steps need to be repeated for each type of shader in the shader program Use Program gluseprogram() CS475/CS675 - Lecture 3 20

Example: ColorCube GLSL Vertex Shader #version 430 in vec4 vposition; in vec4 vcolor; out vec4 color; void main () { gl_position = vposition; color = vcolor; } CS475/CS675 - Lecture 3 21

Example: ColorCube GLSL Fragment Shader #version 430 in vec4 color; out vec4 frag_color; void main () { frag_color = color; } CS475/CS675 - Lecture 3 22

Example: ColorCube Connect application program data to shader variable. OpenGL relates shader variables to indices for the application to set Have to find variable/index association Before linkage After linkage CS475/CS675 - Lecture 3 23

Example: ColorCube Connect application program data to shader variable. Assumes shader variable names are known GLint loc_idx = glgetattriblocation( program_id, variable_name ); GLint loc_idx = glgetuniformlocation( program_id, variable_name ); glenablevertexattribarray( loc_idx ); glvertexattribpointer( loc_idx, 4, GL_FLOAT, GL_FALSE, 0, pointer_to_data_in_buffer ); CS475/CS675 - Lecture 3 24

Example: ColorCube Draw gldrawarrays(gl_triangles, 0, num_vertices); Calls a vertex shader for each vertex. Assembled into triangles and rasterized to fragments. Calls a fragment shader for each fragment. CS475/CS675 - Lecture 3 25

Example: ColorCube GLFW GLFWwindow* window; glfwseterrorcallback(csx75::error_callback); if (!glfwinit()) return -1; //We want OpenGL 4.0 glfwwindowhint(glfw_context_version_major, 4); glfwwindowhint(glfw_context_version_minor, 1); //We don't want the old OpenGL glfwwindowhint(glfw_opengl_profile, GLFW_OPENGL_CORE_PROFILE); //! Create a windowed mode window and its OpenGL context window = glfwcreatewindow(512, 512, "CS475/CS675 Tutorial 2: Colorcube", NULL, NULL); if (!window) { glfwterminate(); return -1; } CS475/CS675 - Lecture 3 //! Make the window's context current 26 glfwmakecontextcurrent(window);

Example: ColorCube GLEW /Initialize GLEW //Turn this on to get Shader based OpenGL glewexperimental = GL_TRUE; GLenum err = glewinit(); if (GLEW_OK!= err) { //Problem: glewinit failed, something is seriously wrong. std::cerr<<"glew Init Failed : %s"<<std::endl; } CS475/CS675 - Lecture 3 27

Example: ColorCube GLFW glfwsetkeycallback(window, csx75::key_callback); glfwsetframebuffersizecallback(window, csx75::framebuffer_size_callback); glfwsetinputmode(window, GLFW_STICKY_KEYS, GL_TRUE); //Initialize GL state csx75::initgl(); initbuffersgl(); // Loop until the user closes the window while (glfwwindowshouldclose(window) == 0) { rendergl(); glfwswapbuffers(window); glfwpollevents(); } glfwterminate(); CS475/CS675 - Lecture 3 return 0; } 28

Example: ColorCube CS475/CS675 - Lecture 3 29

OpenGL Rasterization Y (0,1) (1,1) (0,0) (1,0) CS475/CS675 - Lecture 3 30 X

OpenGL Rasterization Y (0.5,1.5) (1.5,1.5) (0,1) (1,1) (0.5,0.5) (1.5,0.5) (0,0) (1,0) CS475/CS675 - Lecture 3 31 X

OpenGL Line Rasterization Y (0.5,1.5) (1.5,1.5) (0,1) (1,1) (0.5,0.5) (1.5,0.5) (0,0) (1,0) CS475/CS675 - Lecture 3 32 X

OpenGL Line Rasterization Y (0.5,1.5) (1.5,1.5) (0,1) (0.5,0.5) (1,1) (1.5,0.5) (0,0) (1,0) CS475/CS675 - Lecture 3 33 X

OpenGL Line Rasterization Y (0,1) (1,1) (0,0) (1,0) CS475/CS675 - Lecture 3 34 X

OpenGL Polygon Rasterization Y CS475/CS675 - Lecture 3 35 X

OpenGL Polygon Rasterization Y CS475/CS675 - Lecture 3 36 X

OpenGL Polygon Rasterization Y CS475/CS675 - Lecture 3 37 X

OpenGL Polygon Rasterization Y CS475/CS675 - Lecture 3 38 X