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

Similar documents
CS 380 Introduction to Computer Graphics. LAB (1) : OpenGL Tutorial Reference : Foundations of 3D Computer Graphics, Steven J.

CS4621/5621 Fall Computer Graphics Practicum Intro to OpenGL/GLSL

INTRODUCTION TO OPENGL PIPELINE

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

Shaders. Slide credit to Prof. Zwicker

CS475/CS675 - Computer Graphics. OpenGL Drawing

Dave Shreiner, ARM March 2009

COMP371 COMPUTER GRAPHICS

CPSC 436D Video Game Programming

CS 432 Interactive Computer Graphics

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

Rendering Objects. Need to transform all geometry then

Lecture 13: OpenGL Shading Language (GLSL)

Lighting and Texturing

OpenGL refresher. Advanced Computer Graphics 2012

We assume that you are familiar with the following:

Computer Graphics (CS 4731) OpenGL/GLUT(Part 1)

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

Ciril Bohak. - INTRODUCTION TO WEBGL

CS179: GPU Programming

CS 432 Interactive Computer Graphics

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

OPENGL RENDERING PIPELINE

HW2d Project Addenda

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

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

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

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

WebGL and GLSL Basics. CS559 Fall 2015 Lecture 10 October 6, 2015

OpenGL. Toolkits.

To Do. Computer Graphics (Fall 2008) Course Outline. Course Outline. Methodology for Lecture. Demo: Surreal (HW 3)

The Graphics Pipeline

CS 432 Interactive Computer Graphics

Lecture 2. Shaders, GLSL and GPGPU

An Overview GLUT GLSL GLEW

The Application Stage. The Game Loop, Resource Management and Renderer Design

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

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

object (say a cube) will be made up of triangles, each with three vertices, each with known object coordinates.

WebGL and GLSL Basics. CS559 Fall 2016 Lecture 14 October

Real-Time Rendering (Echtzeitgraphik) Michael Wimmer

OUTLINE. Implementing Texturing What Can Go Wrong and How to Fix It Mipmapping Filtering Perspective Correction

Introduction. What s New in This Edition

CS451Real-time Rendering Pipeline

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

Homework 3: Programmable Shaders

2: Introducing image synthesis. Some orientation how did we get here? Graphics system architecture Overview of OpenGL / GLU / GLUT

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

Blis: Better Language for Image Stuff Project Proposal Programming Languages and Translators, Spring 2017

Real - Time Rendering. Graphics pipeline. Michal Červeňanský Juraj Starinský

Sign up for crits! Announcments

General Purpose computation on GPUs. Liangjun Zhang 2/23/2005

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

Applying Textures. Lecture 27. Robb T. Koether. Hampden-Sydney College. Fri, Nov 3, 2017

Practical Texturing (WebGL) CS559 Fall 2016 Lecture 20 November 7th 2016

CS 432 Interactive Computer Graphics

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

Introductory Seminar

CS770/870 Spring 2017 Open GL Shader Language GLSL

CS770/870 Spring 2017 Open GL Shader Language GLSL

CS4621/5621 Fall Basics of OpenGL/GLSL Textures Basics

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

From system point of view, a graphics application handles the user input, changes the internal state, called the virtual world by modeling or

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

CENG 477 Introduction to Computer Graphics. Graphics Hardware and OpenGL

CS450/550. Pipeline Architecture. Adapted From: Angel and Shreiner: Interactive Computer Graphics6E Addison-Wesley 2012

OpenGL Performances and Flexibility

Computer Graphics. Bing-Yu Chen National Taiwan University

OpenGL Performances and Flexibility. Visual Computing Laboratory ISTI CNR, Italy

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

BCA611 Video Oyunları için 3B Grafik

Optimisation. CS7GV3 Real-time Rendering

Computer Science 175. Introduction to Computer Graphics lib175 time: m/w 2:30-4:00 pm place:md g125 section times: tba

PROFESSIONAL. WebGL Programming DEVELOPING 3D GRAPHICS FOR THE WEB. Andreas Anyuru WILEY. John Wiley & Sons, Ltd.

X. GPU Programming. Jacobs University Visualization and Computer Graphics Lab : Advanced Graphics - Chapter X 1

Shaders CSCI 4239/5239 Advanced Computer Graphics Spring 2014

SUMMARY. CS380: Introduction to Computer Graphics Texture Mapping Chapter 15. Min H. Kim KAIST School of Computing 18/05/03.

CS 428: Fall Introduction to. OpenGL primer. Andrew Nealen, Rutgers, /13/2010 1

OPENGL AND GLSL. Computer Graphics

Getting fancy with texture mapping (Part 2) CS559 Spring Apr 2017

I expect to interact in class with the students, so I expect students to be engaged. (no laptops, smartphones,...) (fig)

Cg 2.0. Mark Kilgard

Lecture 09: Shaders (Part 1)

CS 381 Computer Graphics, Fall 2008 Midterm Exam Solutions. The Midterm Exam was given in class on Thursday, October 23, 2008.

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

GLSL Overview: Creating a Program

Shaders CSCI 4229/5229 Computer Graphics Fall 2017

Shaders (some slides taken from David M. course)

Programming Graphics Hardware

Module 13C: Using The 3D Graphics APIs OpenGL ES

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

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

Introduction to OpenGL. CS 4620 Balazs Kovacs, 2014 Daniel Schroeder, 2013 Pramook Khungurn, 2012

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

OpenGL Essentials Training

Computer Graphics (CS 4731) OpenGL/GLUT (Part 2)

WebGL: Hands On. DevCon5 NYC Kenneth Russell Software Engineer, Google, Inc. Chair, WebGL Working Group

CSCI 4620/8626. The 2D Viewing Pipeline

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

Graphics Hardware, Graphics APIs, and Computation on GPUs. Mark Segal

Transcription:

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 calls to load vertex data to vertex buffers calls to load textures draw calls calls to set various options in the pipeline system issues cross platform the alternative would be DirectX graphics dominant for PC games not cross platform a related API is opengl ES, intended for mobile another related API is webgl. we will use opengl 3.2 on windows and linux, we use the glew library to help us access the API needs include and library files, and installed drivers glut library of functions to talk with the windowing system open up windows glut can inform you when some event occurs mousemove, buttonpress, windowresize, redraw needed you register callback functions with glut the callback function is called when the event occurs and passed relevant info (ex. the mouse location) we will need global variables, since we are not in control of the call sequence! cross platform for real applications, you would use a platform dependent library. glsl gl shading language you write small programs to be executed for each vertex. you write small programs to be executed for each fragment (pixel) you tell opengl to compile/link/load these shaders 1

code they operate in parallel on the vertices and fragments competitors microsoft s hlsl: we use c++ dominant for pc games only works with directx see our primer. main pattern for opengl resources note: this stuff is a bit annoying and confusing, and possibly not always consistent. opengl will provide us with storage for a few kinds of resources shader programs, vertex buffers, textures (images) we need to ask opengl for any such resource (AKA opengl object) glcreateshader, glgenbuffer, glgentexture, opengl will return us with a handle (AKA object name), which allows us later to refer to this object within opengl calls. the handle is of type GLuint when we are done, we need to tell opengl to free up the object with a gldelete* call opengl resources in C++ in C++ the clean way to do resource management is to always wrap each single resource request in its own class the constructor calls the glgen*, or glcreate* the destructor calls the gldelete* we use capital G for these types we store instances of these object in our own variables whenever one of these instanced objects goes out of scope (no longer accessible by our program), the destructor is automatically called, which guarantees the resource release we do not allow our objects to get copied, so there is no issues of knowing when the resource can get deleted. lets look at glsupport.h lookfor GlProgram, GlTexture, GlBuffer note that we cannot make any GL calls until our program has called glutcreatewindow. so we cannot have any of these objects as global variables. we can only have global pointers to such objects, and then construct new objects in the body of our code, and reset our pointers. asst1: look at squareshaderstate, tex0, square, manipulating the opengl resources we need to put our data in these resources. we may need to change certain special settings for how the resource will be used. for glprograms, this is done using special glcalls, with the appropriate handles. for buffers and textures we need to bind the particular resource to an opengl target 2

main (resp.) GL ARRAY BUFFER, and GL TEXTURE 2D then we make opengl calls if needed, these calls will use the target name (but not the object s handle) initializes lots of stuff (on windows) communicates with opengl API by loading glew. hands off all control to glut initsglutstate glut will call back our own functions when needed to do updating and drawing turns on glut requests a window with color, depth, and double buffering registers the names of our callback functions initglstate we will look at them soon sets some opengl control states initshaders background color 3 floats for rgb, (and 1 for α ) c++: note the decimal point in the divide plumbing for r/w of framebuffer modern color space note the use of some global pointers we need globals since glut controls the computational flow dive down: SquareShaderState struct has GlProgram (construction gets opengl resources). has handles to the variables in our program dive down: LoadSquareShader reads and complies the files (we will look at these shader files later) we have our own functions (defined in our own glsupport.h) to read the shader files and pass them to OpenGL gets gl handles to the input variables with the shown names in the shaders so we can pass info to them the inputs are attribute and uniform shader variables handles are really just integers identifiers safe calls (defined in our own glsupport.h) are our own wrappers around gl functions that won t cause an error if we try to set a variable that was optimized away for unuse simplifies the code during shader development tells gl to use the variable named fragcolor as the output of the fragment shader 3

initgeometry dive down: GeometrPX struct owns two GlBufferObjects. (construction gets opengl resources) one will be for position and one will be for texture coordinates. we also need to have a vertexarrayobject around during drawing dive down: loadsquaregeometry draw canonical square aposition will be used by us for positioning. draw this. atexcoord is auxiliary data we will use. so lets label this. the data is passed to the VBOs note the binding convention display called by glut when the screen needs updating clears screen (you can ignore depth for now) dive down drawsquare sets the program (from the SquareShaderState) sets some uniform variables in the shaders (more later) binds the vertexarrayobject hooks up the VBOs to the appropriate attribute variables makes a GL draw call. pop up to display swaps: sends to the screen checks for errors (which would be printed on the console) note: we could use many different GLprograms and draw lots of things before swapping. vertex shader attribute variables come in varying variables go out gl position goes out says where the vertex will go in the window assumes canonical -1..1 square for the display ignore the 3rd and 4th slots for now. fixed function each triangle is rasterized at each interior pixel, the varying variables are appropriately blended fragment shader is called with this data simple fragment shader 4

sets fragcolor. this is a vec4 in RGBA format. lets play a bit lets look at texvbo data which is passed to atexcoord it gets sent on as vtexcoord lets use that data for the r and g of the color. reshape called by glut when the window size changes. we tell opengl of the new size we store this info for our own use then we call glutpostredisplay so that glut will know to trigger a display callback. what do we think will happen when we change the size/aspect ratio of the window? lets add a texture auxiliary image data read from a file, loaded to opengl, used in fragment shader inittextures GlTexture is a wrapper around a texture handle dive: loadtexture reads from file, turns on any texture unit, turns on a texture, passes the data. binds texture to the GL TEXTURE 2D target of this unit. sets some more magical parameters for the texture. passing a texture to pass textures (see drawsquare) we bind each texture to the GL TEXTURE 2D target of its own texture unit. we send the texture unit info as a uniform in the fragment shader these are of type sampler2d texture coordinates we need texture coordinates at each vertex. uses 0-1 unit square we already have this data in a buffer! we will use same texture coords on two textures vertex shader just passes this on to a varying variable fragment shader makes texture() calls. returns vec4 in RGBA format. lets add some interaction 5

we will use mouse motion to change the global g objscale this will be sent to the uniform uvertexscale this will be used in the vertex shader to change the x coordinate of the vertices this will be used in the fragment shader to change the blendings between two texture colors. interaction mouse callback called (due to our registration) whenever the mouse is clicked down or up we store this information we need to flip the y coordinate from glut motion callback called whenever the mouse is moved here is where we update g objscale then we call glutpostredisplay so that glut will know to trigger a display callback. see drawsqaure for use of scale see vertex shader for use of scale keyboard s key will create screenshot. (ppm.c) for the mac the mac and glut and opengl 3 may not be supported ifso you will need to use opengl 2. no version numbers in shaders in vertex shader in > attribute, out > varying in fragment shader in > varying, out > gl FragColor also, no srgb color space. your assignment get the starter code to run improve resizing behavior do not alter the vertex buffer data, or the glviewport call. add a triangle to the scene use keyboard to move the triangle about 6