GLSL: Creating GLSL Programs - Overview

Size: px
Start display at page:

Download "GLSL: Creating GLSL Programs - Overview"

Transcription

1 GLSL: Creating GLSL Programs - Overview The steps used to incorporate shaders into an OpenGL program: 1. Create shader programs There must be at least a vertex and a fragment shader Each is a set of strings that represent lines of GLSL code 2. Create shader objects, one for each shader 3. Associate shader code with shader objects 4. Compile each shader 5. Cretae a program object 6. Attach shader objects to the program object 7. Link the program components 8. Install the shader executable in the current OpenGL state The actual coding of vertex and fragment shaders will be addressed later As the above sequence implies, the steps involved in creating shader programs is similar to that of creating any other compiled program The OpenGL environment must provide storage for 1. The source code, 2. compiled code, and 3. executable code These must be accessible to an OpenGL program from within its context 1

2 GLSL: Creating GLSL Programs - Versions Both OpenGL and GLSL have version numbers associated with them It is recommended that your program query these to promote compatibility with a given OpenGL environment Syntax: <version number> space [< vendor specific info>] Syntax for the version number: <major version number>.<minor version number>[.< release number>] This info is accessed using glgetstring with either GL V ERSION or GL SHADING LANGUAGE V ERSION 2

3 GLSL: Creating GLSL Programs - Versions (2) Sample code: // *** From p 202 void getglversion(int *major, int *minor) const char *verstr = (const char *) glgetstring(gl_version); if ((verstr == NULL) (sscanf(verstr,"%d.%d", major, minor)!= 2)) *major = *minor = 0; fprintf(stderr, "Invalid GL_VERSION format!!!\n"); void getglslversion(int *major, int *minor) int gl_major, gl_minor; getglversion(&gl_major, &gl_minor); *major = *minor = 0; if(gl_major == 1) /* GL v1.x can only provide GLSL v1.00 as an extension */ const char *extstr = (const char *) glgetstring(gl_extensions); if ((extstr!= NULL) && (strstr(extstr, "GL_ARB_shading_language_100")!= NULL)) *major = 1; *minor = 0; else if (gl_major >= 2) /* GL v2.0 and greater must parse the version string */ const char *verstr = (const char *) glgetstring(gl_shading_language_version); if((verstr == NULL) (sscanf(verstr, "%d.%d", major, minor)!= 2)) *major = *minor = 0; fprintf(stderr, "Invalid GL_SHADING_LANGUAGE_VERSION format!!!\n"); 3

4 GLSL: Creating GLSL Programs - Source Code Shader source code has the same syntax as C: Precompiler directives Variable declarations Main function The program is represented as an array of strings in an OpenGL program For examples, see C6 of Shading Language 3rd ed (Details will be addressed in subsequent discussion of vertex and fragment shaders) 4

5 GLSL: Creating GLSL Programs - Shader Objects These objects store the shader source code To create a shader object use: GLuint glcreateshader (GLenum shadertype) shadertype can be GL VERTEX SHADER, GL FRAGMENT SHADER (or similar values for geometric and tesselation shaders) A unique integer id is returned on successful creation of the object Source code is attached to the shader object using: void glshadersource (GLuint shader, GLsizei count, const GLchar **string, const GLint *length) where shader is the unique id of a shader object count is the number of strings in the array holding the source code string is the array holding the source code strings, and length is an array that holds the string lengths on a string-by-string basis (row-by-row) If length is NULL, it indicates all strings are null-terminated Otherwise, A positive integer indicates the number of characters in the string (excluding the null character) A negative integer indicates the string is null-terminated glshadersource simply copies the code into the object 5

6 GLSL: Creating GLSL Programs - Compiling The purpose of compiling shader source code is the same as for any language Syntax is checked Object code is generated The result of a successful compile is stored in the shader object Compile using: void glcompileshader(glint shader) The status of the compile (success or failure) is stored in the shader object s state The object code that results from a successful compile is stored in the object The status of a compile can be obtained by querying the object (see below) 6

7 GLSL: Creating GLSL Programs - Creating a Program To create a program, 1. A program object is created 2. Shader objects are attached to it,and 3. The programs are linked To create a program object: GLuint glcreateprogram (void) Returns a unique id for the object Zero is returned in failure To attach shader objects to a program: void glattachshader (GLuint program, GLuint shader) The shader objects attached to a program when linking occurs will be those that become part of the resulting executable There is no limit on the number that can be attached Shaders can be attached to more than one program Attachment can occur at any time once a shader object has been created 7

8 GLSL: Creating GLSL Programs - Creating a Program (2) To create an executable program: void gllinkprogram (GLuint program) The status of the linkage (success or failure) is stored in the shader object s state The executable that results from a successful linkage is stored in the object The status of a linkage can be obtained by querying the object (see below) Values of active user-defined uniform variables are initialized to zero and assigned storage (see later) Active user-defined atribute variables not not yet bound to an index are bound to one If a vertex shader is attached but not a fragment shader (or vice-versa), the program uses the fixed functionality pipeline Linkage failure may result from the following: 1. Number of active uniform or active variables exceeded 2. Main missing in vertex or fragment shader 3. Missing a corresponding in variable for an out variable (or vice-versa) 4. Shader being linked not successfully compiled 5. Issues with attribute matrices Successful linkage results in programs for the appropriate gfx processors Results of previous linkages are lost If the shader objects are modified after linkage it will have no effect on the current program object until another liknage operation occurs 8

9 GLSL: Creating GLSL Programs - Usage To use a program object in an OpenGL program: void gluseprogram (GLunint program) This installs the program in the current OpenGL rendering state If one or the other of the vertex or fragment shader objects are missing, the program uses fixed functionality for the missing component If program is zero, fixed functionality is used gfx processors are disabled 9

10 GLSL: Creating GLSL Programs - Finishing Up As usual, you should deallocate storage for OpenGL objects when finished with them void gldeleteprogram (GLuint program) Opposite of glcreateprogram Frees memory used for program if not in use in current rendering state Flagged for deletion otherwise Any shaders attached to the program are automatically detached If the shaders have been previously flagged for deletion, they are deleted (see below) void gldeleteshader (GLuint shader) Opposite of glcreateshader Frees memory used for Shader if not attached to any program Flagged for deletion otherwise void gldetachshader (GLuint program, GLuint shader) Opposite of glatachshader Dissociates shader from program If flagged for deletion and not attached to any other program, is deleted Recommended that shader objects be deleted as soon as attached to a program When program object deleted in future, all shader objects will automatically be detached and if not attached to any other program objects, will be automatically deleted (since will have been flagged for deletion by the gldeleteshader call 10

11 GLSL: Creating GLSL Programs - Query Functions void glgetshaderiv (GLuint shader, GLenum pname, GLint *params) Retrieves info about a shader object Results returned in params Parameters: Parameter Values returned Indicates GL SHADER TYPE GL VERTEX SHADER, GL FRAGMENT SHADER,... GL DELETE STATUS GL TRUE/GL FALSE Is shader flagged for deletion? GL COMPILE STATUS GL TRUE/GL FALSE Was last compile successful? GL INFO LOG LENGTH Number of chars in log; zero if no log GL SHADER SOURCE LENGTH Number of chars in log (including null chars); zero if no log void glprogramiv (GLuint program, GLenum pname, GLint *params) Retrieves info about a program object Results returned in params Parameters: Parameter Values returned Indicates GL DELETE STATUS GL TRUE/GL FALSE Is program flagged for deletion? GL LINK STATUS GL TRUE/GL FALSE Was last linkage successful? GL VALIDATE STATUS GL TRUE/GL FALSE Was last validation operation successful? GL INFO LOG LENGTH Number of chars in log; zero if no log GL ATTACHED SHADERS Number of attached shaders GL ACTIVE ATTRIBUTES Number of active attributes GL ACTIVE ATTRIBUTE MAX LENGTH Length of longest active uniform (including null char); zero if none GL ACTIVE UNIFORMS GL ACTIVE UNIFORM MAX LENGTH Number of active attributes Length of longest active uniform (including null char); zero if none void glgetshadersource (GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *source) Retrieves the source code as a single null-terminated string Results returned in source bufsize imposes a limit to the number of chars returned (including the null char) length assigned to the number of chars actually returned If NULL passed to length, no value is returned 11

12 GLSL: Creating GLSL Programs - Query Functions (2) void glgetshaderinfolog (GLuint shader, GLsizei maxlength, GLsizei *length, GLchar *infolog) Retrieves info re shader s compilation Results returned in infolog maxlength imposes a limit to the number of chars returned (including the null char) length assigned to the number of chars actually returned If NULL passed to length, no value is returned void glgetprograminfolog (GLuint shader, GLsizei maxlength, GLsizei *length, GLchar *infolog) Retrieves info re shader s compilation Results returned in infolog maxlength imposes a limit to the number of chars returned (including the null char) length assigned to the number of chars actually returned If NULL passed to length, no value is returned Code for accessing a shader log (GLSL pp252-53); code for program log analogous void printshaderinfolog(gluint shader) int infologlen = 0; int charswritten = 0; GLchar *infolog; glgetshaderiv(shader, GL_INFO_LOG_LENGTH, &infologlen); printopenglerror(); // Check for OpenGL errors if (infologlen > 0) infolog = (GLchar*) malloc(infologlen); if (infolog == NULL) printf("error: Could not allocate InfoLog buffer\n"); exit(1); glgetshaderinfolog(shader, infologlen, &charswritten, infolog); printf("infolog:\n%s\n\n", infolog); free(infolog); printopenglerror(); // Check for OpenGL errors 12

13 GLSL: Creating GLSL Programs - Query Functions (3) void glgetattachedshaders (GLuint program, GLsizei maxcount, GLsizei *count, GLchar *shaders) Retrieves names of shaders attached to program Results returned in shaders maxcount imposes a limit to the number of shaders returned count assigned to the number of shaders actually returned If NULL passed to count, no value is returned GLboolean glisshader (GLuint shader) Returns GL TRUE/GL FALSE if shader names a shader object GLboolean glisprogram (GLuint program) Returns GL TRUE/GL FALSE if program names a program object 13

Lecture 09: Shaders (Part 1)

Lecture 09: Shaders (Part 1) Lecture 09: Shaders (Part 1) CSE 40166 Computer Graphics Peter Bui University of Notre Dame, IN, USA November 9, 2010 OpenGL Rendering Pipeline OpenGL Rendering Pipeline (Pseudo-Code) 1 f o r gl_vertex

More information

Programming shaders & GPUs Christian Miller CS Fall 2011

Programming shaders & GPUs Christian Miller CS Fall 2011 Programming shaders & GPUs Christian Miller CS 354 - Fall 2011 Fixed-function vs. programmable Up until 2001, graphics cards implemented the whole pipeline for you Fixed functionality but configurable

More information

An Introduction to 3D Computer Graphics, Stereoscopic Image, and Animation in OpenGL and C/C++ Fore June

An Introduction to 3D Computer Graphics, Stereoscopic Image, and Animation in OpenGL and C/C++ Fore June An Introduction to 3D Computer Graphics, Stereoscopic Image, and Animation in OpenGL and C/C++ Fore June Appendix D OpenGL Shading Language (GLSL) D.1 Extending OpenGL The OpenGL architecture we have presented

More information

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

The GLSL API. Mike Bailey. Oregon State University. Geometry Shader. Program. The GLSL Shader-creation Process. create. compile. Vertex. The GLSL API Mike Bailey Oregon State University Program The GLSL -creation Process create compile Source read Source read Program link Use create compile Source read create compile 1 Initializing the

More information

GLSL Overview: Creating a Program

GLSL Overview: Creating a Program 1. Create the OpenGL application GLSL Overview: Creating a Program Primarily concerned with drawing Preferred approach uses buffer objects All drawing done in terms of vertex arrays Programming style differs

More information

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

Copyright Khronos Group 2012 Page 1. Teaching GL. Dave Shreiner Director, Graphics and GPU Computing, ARM 1 December 2012 Copyright Khronos Group 2012 Page 1 Teaching GL Dave Shreiner Director, Graphics and GPU Computing, ARM 1 December 2012 Copyright Khronos Group 2012 Page 2 Agenda Overview of OpenGL family of APIs Comparison

More information

- Surface Rendering -

- Surface Rendering - Programmable Shaders II - Surface Rendering - 12 th Week, 2008 Sun-Jeong Kim Downloading 2 GLEW OpenGL Extension Wrangler Library http://glew.sourceforge.net/ Cross-platform open-source C/C++ extension

More information

CS475/CS675 - Computer Graphics. OpenGL Drawing

CS475/CS675 - Computer Graphics. OpenGL Drawing 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

More information

EECS 487: Interactive Computer Graphics

EECS 487: Interactive Computer Graphics Integrating GLSL with OpenGL EECS 487: Interactive Computer Graphics Lecture 19: Integrating shaders with OpenGL program Vertex-array objects with shaders Miscellaneous shader related stuff Integrating

More information

Tutorial 1: Your First Triangle!

Tutorial 1: Your First Triangle! Tutorial 1: Your First Triangle! Summary For your first dabble in OpenGL, you are going to create the graphics programming equivalent of Hello World - outputting a single coloured triangle. It doesn t

More information

Information Coding / Computer Graphics, ISY, LiTH GLSL. OpenGL Shading Language. Language with syntax similar to C

Information Coding / Computer Graphics, ISY, LiTH GLSL. OpenGL Shading Language. Language with syntax similar to C GLSL OpenGL Shading Language Language with syntax similar to C Syntax somewhere between C och C++ No classes. Straight ans simple code. Remarkably understandable and obvious! Avoids most of the bad things

More information

COURSE 17: STATE-OF-THE-ART IN SHADING HARDWARE1 CHAPTER 6: THE OPENGL SHADING LANGUAGE 2. Randi J. Rost 3Dlabs, Inc.

COURSE 17: STATE-OF-THE-ART IN SHADING HARDWARE1 CHAPTER 6: THE OPENGL SHADING LANGUAGE 2. Randi J. Rost 3Dlabs, Inc. COURSE 17: STATE-OF-THE-ART IN SHADING HARDWARE1 CHAPTER 6: THE OPENGL SHADING LANGUAGE 2 Randi J. Rost 3Dlabs, Inc. SIGGRAPH 2002 Course Notes 05-August-2002 SIGGRAPH 2002 6-1 State of the Art in Shading

More information

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

CSE 4431/ M Advanced Topics in 3D Computer Graphics. TA: Margarita Vinnikov CSE 4431/5331.03M Advanced Topics in 3D Computer Graphics TA: Margarita Vinnikov mvinni@cse.yorku.ca What do we need to do to use shaders in our program? Shaders Work flow For multiple shaders 1. Create

More information

Shading System Immediate-Mode API v2.2

Shading System Immediate-Mode API v2.2 Shading System Immediate-Mode API v2.2 William R. Mark and C. Philipp Schloter August 29, 2001 1 Introduction This document describes modifications to the OpenGL API to support the immediate-mode use of

More information

OpenGL SC. March Sean Harmer Managing Director UK

OpenGL SC. March Sean Harmer Managing Director UK March 2017 OpenGL SC Sean Harmer Managing Director UK The need for safety-critical systems with user-friendly interfaces is on the rise. To respond to this need, the Khronos Group (responsible for OpenGL,

More information

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

Computer Graphics (CS 543) Lecture 3b: Shader Setup & GLSL Introduction Computer Graphics (CS 543) Lecture 3b: Shader Setup & GLSL Introduction Prof Emmanuel Agu Computer Science Dept. Worcester Polytechnic Institute (WPI) OpenGL function format function name gluniform3f(x,y,z)

More information

Lighting and Texturing

Lighting and Texturing Lighting and Texturing Michael Tao Michael Tao Lighting and Texturing 1 / 1 Fixed Function OpenGL Lighting Need to enable lighting Need to configure lights Need to configure triangle material properties

More information

Philip Calderon CSE 520 Lab 3 Color Shader

Philip Calderon CSE 520 Lab 3 Color Shader Philip Calderon CSE 520 Lab 3 Color Shader Summary: The purpose of lab 4 is to produce a pyramid tetrahedron that we are able to rotate it when clicked. Part 1: Color Tetrahedron Part 2: Rotation to show

More information

Lecture 31 Sections 9.1, 9.2, 9.3. Mon, Nov 23, 2009

Lecture 31 Sections 9.1, 9.2, 9.3. Mon, Nov 23, 2009 Lecture 31 Sections 9.1, 9.2, 9.3 Hampden-Sydney College Mon, Nov 23, 2009 Outline 1 2 3 4 5 Outline 1 2 3 4 5 The extension wrangler (glew) will check to see which extensions are supported by the installed

More information

Some advantages come from the limited environment! No classes. Stranight ans simple code. Remarkably. Avoids most of the bad things with C/C++.

Some advantages come from the limited environment! No classes. Stranight ans simple code. Remarkably. Avoids most of the bad things with C/C++. GLSL OpenGL Shading Language Language with syntax similar to C Syntax somewhere between C och C++ No classes. Stranight ans simple code. Remarkably understandable and obvious! Avoids most of the bad things

More information

Advanced Graphics. The Shader knows. Alex Benton, University of Cambridge Supported in part by Google UK, Ltd

Advanced Graphics. The Shader knows. Alex Benton, University of Cambridge Supported in part by Google UK, Ltd Advanced Graphics The Shader knows Alex Benton, University of Cambridge A.Benton@damtp.cam.ac.uk Supported in part by Google UK, Ltd What is the shader? Local space World space Viewing space Local space

More information

Supplement to Lecture 22

Supplement to Lecture 22 Supplement to Lecture 22 Programmable GPUs Programmable Pipelines Introduce programmable pipelines - Vertex shaders - Fragment shaders Introduce shading languages - Needed to describe shaders - RenderMan

More information

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

Shaders. Introduction. OpenGL Grows via Extensions. OpenGL Extensions. OpenGL 2.0 Added Shaders. Shaders Enable Many New Effects CSCI 420 Computer Graphics Lecture 4 Shaders Jernej Barbic University of Southern California Shading Languages GLSL Vertex Array Objects Vertex Shader Fragment Shader [Angel Ch. 1, 2, A] Introduction The

More information

Today s Agenda. Shaders fundamentals. Programming with shader-based OpenGL

Today s Agenda. Shaders fundamentals. Programming with shader-based OpenGL Today s Agenda Shaders fundamentals Programming with shader-based OpenGL Shaders Like a function call data are passed in, processed, and passed back out -- Shreiner et al, OpenGL Programming Guide GLSL

More information

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

Comp 410/510 Computer Graphics Spring Programming with OpenGL Part 3: Shaders Comp 410/510 Computer Graphics Spring 2018 Programming with OpenGL Part 3: Shaders Objectives Basic shaders - Vertex shader - Fragment shader Programming shaders with GLSL Finish first program void init(void)

More information

OpenGL. Shading Language. Third Edition

OpenGL. Shading Language. Third Edition OpenGL Shading Language Third Edition OpenGL* Shading Language Third Edition Randi J. Rost Bill Licea-Kane With contributions by Dan Ginsburg, John M. Kessenich, Barthold Lichtenbelt, Hugh Malan, and Mike

More information

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

OpenGL pipeline Evolution and OpenGL Shading Language (GLSL) Part 2/3 Vertex and Fragment Shaders OpenGL pipeline Evolution and OpenGL Shading Language (GLSL) Part 2/3 Vertex and Fragment Shaders Prateek Shrivastava CS12S008 shrvstv@cse.iitm.ac.in 1 GLSL Data types Scalar types: float, int, bool Vector

More information

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

Programming with OpenGL Shaders I. Adapted From: Ed Angel Professor of Emeritus of Computer Science University of New Mexico Programming with OpenGL Shaders I Adapted From: Ed Angel Professor of Emeritus of Computer Science University of New Mexico 0 Objectives Shader Basics Simple Shaders Vertex shader Fragment shaders 1 Vertex

More information

An Introduction to 3D Computer Graphics, Stereoscopic Image, and Animation in OpenGL and C/C++ Fore June

An Introduction to 3D Computer Graphics, Stereoscopic Image, and Animation in OpenGL and C/C++ Fore June An Introduction to 3D Computer Graphics, Stereoscopic Image, and Animation in OpenGL and C/C++ Fore June Chapter 19 OpenGL Shading Language (GLSL) 19.1 Extending OpenGL The OpenGL architecture we have

More information

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

Starting out with OpenGL ES 3.0. Jon Kirkham, Senior Software Engineer, ARM Starting out with OpenGL ES 3.0 Jon Kirkham, Senior Software Engineer, ARM Agenda Some foundational work Instanced geometry rendering Uniform Buffers Transform feedback ETC2 Texture formats Occlusion Queries

More information

Vertex & Fragment shaders

Vertex & Fragment shaders Vertex & Fragment shaders The next big step in graphics hardware Adds programmability to the previously fixed rendering pipeline The OpenGL Shading Language (a.k.a. GLSL, glslang) Vertex shaders: programs

More information

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

Mali & OpenGL ES 3.0. Dave Shreiner Jon Kirkham ARM. Game Developers Conference 27 March 2013 Mali & OpenGL ES 3.0 Dave Shreiner Jon Kirkham ARM Game Developers Conference 27 March 2013 1 Agenda Some foundational work Instanced geometry rendering Transform feedback Occlusion Queries 2 What s New

More information

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

Programming with OpenGL Shaders I. Adapted From: Ed Angel Professor of Emeritus of Computer Science University of New Mexico Programming with OpenGL Shaders I Adapted From: Ed Angel Professor of Emeritus of Computer Science University of New Mexico Objectives Shader Programming Basics Simple Shaders Vertex shader Fragment shaders

More information

COMP371 COMPUTER GRAPHICS

COMP371 COMPUTER GRAPHICS COMP371 COMPUTER GRAPHICS SESSION 12 PROGRAMMABLE SHADERS Announcement Programming Assignment #2 deadline next week: Session #7 Review of project proposals 2 Lecture Overview GPU programming 3 GPU Pipeline

More information

OpenGL Über Buffers Extension

OpenGL Über Buffers Extension 1 of 70 OpenGL Über Buffers Extension Revision 0.29 Author Rob Mace Copyright 2002, 2003 ATI Technologies Inc. All rights reserved. This document is being distributed for the sole purpose of soliciting

More information

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

CSE 167: Introduction to Computer Graphics Lecture #7: GLSL. Jürgen P. Schulze, Ph.D. University of California, San Diego Spring Quarter 2016 CSE 167: Introduction to Computer Graphics Lecture #7: GLSL Jürgen P. Schulze, Ph.D. University of California, San Diego Spring Quarter 2016 Announcements Project 2 due Friday 4/22 at 2pm Midterm #1 on

More information

2a. The triangles scale increases (expands) when the 'e' key is pressed and decreases (contracts) when the 'c' key is pressed.

2a. The triangles scale increases (expands) when the 'e' key is pressed and decreases (contracts) when the 'c' key is pressed. Erik Anchondo 1-29-19 cse 520 lab 3 1. Wrote a shader program to display three colored triangles, with one of each triangle being red, green, and blue. The colors change which triangle they are applied

More information

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

I think this assignment should have 8 objectives but we should still mark it out of 10. The Mean TA. Chapter 1 CS488/688 F17 A1: Introduction I think this assignment should have 8 objectives but we should still mark it out of 10. The Mean TA. This assignment is due Thursday, September 28th [Week 3]. 1.1

More information

Computer Graphics (CS 4731) & 2D Graphics Systems

Computer Graphics (CS 4731) & 2D Graphics Systems Computer Graphics (CS 4731) Lecture 4: Shader Setup & 2D Graphics Systems Prof Emmanuel Agu Computer Science Dept. Worcester Polytechnic Institute (WPI) Recall: OpenGL Program: Shader Setup initshader(

More information

Erik Anchondo cse 520 lab 4

Erik Anchondo cse 520 lab 4 Erik Anchondo 2-6-19 cse 520 lab 4 1. Wrote a glsl program that displays a colored tetrahedron. The tetrahedron starts to rotate on the x axis when the mouse button is clicked once. If the mouse button

More information

Textures. Texture Mapping. Bitmap Textures. Basic Texture Techniques

Textures. Texture Mapping. Bitmap Textures. Basic Texture Techniques Texture Mapping Textures The realism of an image is greatly enhanced by adding surface textures to the various faces of a mesh object. In part a) images have been pasted onto each face of a box. Part b)

More information

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

Programming with OpenGL Part 3: Shaders. Ed Angel Professor of Emeritus of Computer Science University of New Mexico Programming with OpenGL Part 3: Shaders Ed Angel Professor of Emeritus of Computer Science University of New Mexico 1 Objectives Simple Shaders - Vertex shader - Fragment shaders Programming shaders with

More information

12.2 Programmable Graphics Hardware

12.2 Programmable Graphics Hardware Fall 2018 CSCI 420: Computer Graphics 12.2 Programmable Graphics Hardware Kyle Morgenroth http://cs420.hao-li.com 1 Introduction Recent major advance in real time graphics is the programmable pipeline:

More information

gvirtualxray Tutorial 01: Creating a Window and an OpenGL Context Using GLUT

gvirtualxray Tutorial 01: Creating a Window and an OpenGL Context Using GLUT gvirtualxray Tutorial 01: Creating a Window and an OpenGL Context Using GLUT Dr Franck P. Vidal 4 th September 2014 1 Contents Table of contents 2 List of figures 3 List of listings 3 1 Introduction 4

More information

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

CSE 167: Introduction to Computer Graphics Lecture #13: GLSL. Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2015 CSE 167: Introduction to Computer Graphics Lecture #13: GLSL Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2015 Announcements Project 6 due Friday Next Thursday: Midterm #2

More information

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

Applying Textures. Lecture 27. Robb T. Koether. Hampden-Sydney College. Fri, Nov 3, 2017 Applying Textures Lecture 27 Robb T. Koether Hampden-Sydney College Fri, Nov 3, 2017 Robb T. Koether (Hampden-Sydney College) Applying Textures Fri, Nov 3, 2017 1 / 24 Outline 1 Applying Textures 2 Photographs

More information

Programmable Graphics Hardware

Programmable Graphics Hardware CSCI 480 Computer Graphics Lecture 14 Programmable Graphics Hardware [Ch. 9] March 2, 2011 Jernej Barbic University of Southern California OpenGL Extensions Shading Languages Vertex Program Fragment Program

More information

Programming with OpenGL Part 5: More GLSL. Ed Angel Professor Emeritus of Computer Science University of New Mexico

Programming with OpenGL Part 5: More GLSL. Ed Angel Professor Emeritus of Computer Science University of New Mexico Programming with OpenGL Part 5: More GLSL Ed Angel Professor Emeritus of Computer Science University of New Mexico 1 Objectives Coupling shaders to applications - Reading - Compiling - Linking Vertex Attributes

More information

GLSL Programming. Nicolas Holzschuch

GLSL Programming. Nicolas Holzschuch GLSL Programming Nicolas Holzschuch GLSL programming C-like language structure: int i, j; i = 2; j = 0; j += i; Functions, loops, branches... Reading your first GSL shader is easy Differences with C New

More information

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

CS 380 Introduction to Computer Graphics. LAB (1) : OpenGL Tutorial Reference : Foundations of 3D Computer Graphics, Steven J. CS 380 Introduction to Computer Graphics LAB (1) : OpenGL Tutorial 2018. 03. 05 Reference : Foundations of 3D Computer Graphics, Steven J. Gortler Goals Understand OpenGL pipeline Practice basic OpenGL

More information

Shading Languages. Ari Silvennoinen Apri 12, 2004

Shading Languages. Ari Silvennoinen Apri 12, 2004 Shading Languages Ari Silvennoinen Apri 12, 2004 Introduction The recent trend in graphics hardware has been to replace fixed functionality in vertex and fragment processing with programmability [1], [2],

More information

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

Lecture 5 Vertex and Fragment Shaders-1. CITS3003 Graphics & Animation Lecture 5 Vertex and Fragment Shaders-1 CITS3003 Graphics & Animation E. Angel and D. Shreiner: Interactive Computer Graphics 6E Addison-Wesley 2012 Objectives The rendering pipeline and the shaders Data

More information

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

Comp 410/510 Computer Graphics Spring Programming with OpenGL Part 2: First Program Comp 410/510 Computer Graphics Spring 2017 Programming with OpenGL Part 2: First Program Objectives Refine the first program Introduce a standard program structure - Initialization Program Structure Most

More information

Introductory Seminar

Introductory Seminar EDAF80 Introduction to Computer Graphics Introductory Seminar OpenGL & C++ Michael Doggett 2017 C++ slides by Carl Johan Gribel, 2010-13 Today Lab info OpenGL C(++)rash course Labs overview 5 mandatory

More information

Shaders. Slide credit to Prof. Zwicker

Shaders. Slide credit to Prof. Zwicker Shaders Slide credit to Prof. Zwicker 2 Today Shader programming 3 Complete model Blinn model with several light sources i diffuse specular ambient How is this implemented on the graphics processor (GPU)?

More information

Getting Started with OpenGL ES 3+ Programming

Getting Started with OpenGL ES 3+ Programming Getting Started with OpenGL ES 3+ Programming Learn Modern OpenGL Basics Hans de Ruiter Getting Started with OpenGL ES 3+ Programming Hans de Ruiter Version 1.1 5 April 2017 Copyright 2017 by Kea Sigma

More information

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

Information Coding / Computer Graphics, ISY, LiTH. OpenGL! ! where it fits!! what it contains!! how you work with it 11(40) 11(40) Information Coding / Computer Graphics, ISY, LiTH OpenGL where it fits what it contains how you work with it 11(40) OpenGL The cross-platform graphics library Open = Open specification Runs everywhere

More information

Programmable shader. Hanyang University

Programmable shader. Hanyang University Programmable shader Hanyang University Objective API references (will be skipped) Examples Simple shader Phong shading shader INTRODUCTION GLSL(OPENGL SHADING LANGUAGE) Scalar Data types Structure Structures

More information

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

CS 450: COMPUTER GRAPHICS REVIEW: STATE, ATTRIBUTES, AND OBJECTS SPRING 2015 DR. MICHAEL J. REALE CS 450: COMPUTER GRAPHICS REVIEW: STATE, ATTRIBUTES, AND OBJECTS SPRING 2015 DR. MICHAEL J. REALE OPENGL STATE MACHINE OpenGL state system or state machine Has list of all current state values called state

More information

OpenGL Based Testing Tool Architecture for Exascale Computing

OpenGL Based Testing Tool Architecture for Exascale Computing OpenGL Based Testing Tool Architecture for Exascale Computing Muhammad Usman Ashraf Faculty of Information and Computer Technology Department of Computer Science King Abdulaziz University Jeddah, 21577,

More information

CPSC 436D Video Game Programming

CPSC 436D Video Game Programming CPSC 436D Video Game Programming OpenGL/Shaders Opengl RENDERING PIPELINE Copyright: Alla Sheffer 1 Opengl RENDERING PIPELINE C/C++ OpenGL GLSL (automatic) (automatic) GLSL (automatic) opengl Low-level

More information

C Language Part 1 Digital Computer Concept and Practice Copyright 2012 by Jaejin Lee

C Language Part 1 Digital Computer Concept and Practice Copyright 2012 by Jaejin Lee C Language Part 1 (Minor modifications by the instructor) References C for Python Programmers, by Carl Burch, 2011. http://www.toves.org/books/cpy/ The C Programming Language. 2nd ed., Kernighan, Brian,

More information

Pointers. 1 Background. 1.1 Variables and Memory. 1.2 Motivating Pointers Massachusetts Institute of Technology

Pointers. 1 Background. 1.1 Variables and Memory. 1.2 Motivating Pointers Massachusetts Institute of Technology Introduction to C++ Massachusetts Institute of Technology ocw.mit.edu 6.096 Pointers 1 Background 1.1 Variables and Memory When you declare a variable, the computer associates the variable name with a

More information

CGT520 Transformations

CGT520 Transformations CGT520 Transformations Bedrich Benes, Ph.D. Purdue University Department of Computer Graphics GLM A concise library for transforms and OpenGL mathematics All overloaded, predefined, optimized glm (OpenGL

More information

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

Shader Programs. Lecture 30 Subsections 2.8.2, Robb T. Koether. Hampden-Sydney College. Wed, Nov 16, 2011 Shader Programs Lecture 30 Subsections 2.8.2, 2.8.3 Robb T. Koether Hampden-Sydney College Wed, Nov 16, 2011 Robb T. Koether (Hampden-Sydney College) Shader Programs Wed, Nov 16, 2011 1 / 43 Outline 1

More information

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

Graphics Programming. Computer Graphics, VT 2016 Lecture 2, Chapter 2. Fredrik Nysjö Centre for Image analysis Uppsala University Graphics Programming Computer Graphics, VT 2016 Lecture 2, Chapter 2 Fredrik Nysjö Centre for Image analysis Uppsala University Graphics programming Typically deals with How to define a 3D scene with a

More information

Objectives. Open GL Shading Language (GLSL)

Objectives. Open GL Shading Language (GLSL) Open GL Shading Language (GLSL) Objectives Shader applications Vertex shaders Fragment shaders Programming shaders Cg GLSL Coupling GLSL to Applications Example applications 1 Vertex Shader Applications

More information

Curves: OpenGL Evaluators - Intro

Curves: OpenGL Evaluators - Intro Curves: OpenGL Evaluators - Intro Evaluators are used to describe polynomials, splines, curved surfaces of any degree Based on Bézier curves If want to use another curve form, programmer must provide code

More information

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

API Background. Prof. George Wolberg Dept. of Computer Science City College of New York API Background Prof. George Wolberg Dept. of Computer Science City College of New York Objectives Graphics API history OpenGL API OpenGL function format Immediate Mode vs Retained Mode Examples The Programmer

More information

1. Write a shader program that animates the morphing of Figure 'A' to Figure 'B' and back.

1. Write a shader program that animates the morphing of Figure 'A' to Figure 'B' and back. Karl Zachary Maier CSE 520 Homework 1 1. Write a shader program that animates the morphing of Figure 'A' to Figure 'B' and back. /* morph.cpp */ #include #include #include

More information

CMSC427 Fall 2017 OpenGL Notes A: Starting with JOGL and OpenGL Objectives of notes Readings Computer Graphics Programming in OpenGL with Java

CMSC427 Fall 2017 OpenGL Notes A: Starting with JOGL and OpenGL Objectives of notes Readings Computer Graphics Programming in OpenGL with Java CMSC427 Fall 2017 OpenGL Notes A: Starting with JOGL and OpenGL Objectives of notes Show how to program full OpenGL in JOGL Start on shader programing Readings Computer Graphics Programming in OpenGL with

More information

CS770/870 Spring 2017 Open GL Shader Language GLSL

CS770/870 Spring 2017 Open GL Shader Language GLSL Preview CS770/870 Spring 2017 Open GL Shader Language GLSL Review traditional graphics pipeline CPU/GPU mixed pipeline issues Shaders GLSL graphics pipeline Based on material from Angel and Shreiner, Interactive

More information

CS770/870 Spring 2017 Open GL Shader Language GLSL

CS770/870 Spring 2017 Open GL Shader Language GLSL CS770/870 Spring 2017 Open GL Shader Language GLSL Based on material from Angel and Shreiner, Interactive Computer Graphics, 6 th Edition, Addison-Wesley, 2011 Bailey and Cunningham, Graphics Shaders 2

More information

GLSL Introduction. Fu-Chung Huang. Thanks for materials from many other people

GLSL Introduction. Fu-Chung Huang. Thanks for materials from many other people GLSL Introduction Fu-Chung Huang Thanks for materials from many other people Shader Languages Currently 3 major shader languages Cg (Nvidia) HLSL (Microsoft) Derived from Cg GLSL (OpenGL) Main influences

More information

CS201- Introduction to Programming Current Quizzes

CS201- Introduction to Programming Current Quizzes CS201- Introduction to Programming Current Quizzes Q.1 char name [] = Hello World ; In the above statement, a memory of characters will be allocated 13 11 12 (Ans) Q.2 A function is a block of statements

More information

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

CS4621/5621 Fall Computer Graphics Practicum Intro to OpenGL/GLSL CS4621/5621 Fall 2015 Computer Graphics Practicum Intro to OpenGL/GLSL Professor: Kavita Bala Instructor: Nicolas Savva with slides from Balazs Kovacs, Eston Schweickart, Daniel Schroeder, Jiang Huang

More information

BCA611 Video Oyunları için 3B Grafik

BCA611 Video Oyunları için 3B Grafik BCA611 Video Oyunları için 3B Grafik WebGL - Shader Programming Zümra Kavafoğlu Canvas element The HTML element is used to draw graphics on a web page. Create canvas with id, width and height

More information

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

CSE 4431/ M Advanced Topics in 3D Computer Graphics. TA: Margarita Vinnikov CSE 4431/5331.03M Advanced Topics in 3D Computer Graphics TA: Margarita Vinnikov mvinni@cse.yorku.ca The OpenGL 4.x pipeline 2 new Programmable stages Tessellation Control Shader(GL_TESS_CONTROL_SHADER)

More information

GLSL Introduction. Fu-Chung Huang. Thanks for materials from many other people

GLSL Introduction. Fu-Chung Huang. Thanks for materials from many other people GLSL Introduction Fu-Chung Huang Thanks for materials from many other people Programmable Shaders //per vertex inputs from main attribute aposition; attribute anormal; //outputs to frag. program varying

More information

Objectives. Coupling GLSL to Applications Example applications

Objectives. Coupling GLSL to Applications Example applications GLSL II Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts Director, Arts Technology Center University of New Mexico Objectives Coupling GLSL to Applications Example

More information

OpenGL shaders and programming models that provide object persistence

OpenGL shaders and programming models that provide object persistence OpenGL shaders and programming models that provide object persistence COSC342 Lecture 22 19 May 2016 OpenGL shaders We discussed forms of local illumination in the ray tracing lectures. We also saw that

More information

This Lecture. Why OpenGL? Introduction to OpenGL. Programmer s View

This Lecture. Why OpenGL? Introduction to OpenGL. Programmer s View Foundations of Computer Graphics Overview and Motivation This Lecture Introduction to OpenGL and simple demo code mytest1.cpp ; you compiled mytest3.cpp for HW 0 I am going to show (and write) actual code

More information

VR-programming tools (procedural) More VRML later in this course! (declarative)

VR-programming tools (procedural) More VRML later in this course! (declarative) Realtime 3D Computer Graphics & Virtual Reality OpenGL Introduction VR-programming Input and display devices are the main hardware interface to users Immersion embeds users through the generation of live-like

More information

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

SHADER PROGRAMMING. Based on Jian Huang s lecture on Shader Programming SHADER PROGRAMMING Based on Jian Huang s lecture on Shader Programming What OpenGL 15 years ago could do http://www.neilturner.me.uk/shots/opengl-big.jpg What OpenGL can do now What s Changed? 15 years

More information

A Review of OpenGL Compute Shaders

A Review of OpenGL Compute Shaders 1 A Review of OpenGL Compute Shaders This work is licensed under a Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License Mike Bailey mjb@cs.oregonstate.edu OpenglComputeShaders.pptx

More information

Shaders CSCI 4229/5229 Computer Graphics Fall 2017

Shaders CSCI 4229/5229 Computer Graphics Fall 2017 Shaders CSCI 4229/5229 Computer Graphics Fall 2017 What is a Shader? A shader is a computer program that runs on the GPU to calculate the properties of vertexes, pixels and other graphical processing Examples:

More information

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

Announcement. Homework 1 has been posted in dropbox and course website. Due: 1:15 pm, Monday, September 12 Announcement Homework 1 has been posted in dropbox and course website Due: 1:15 pm, Monday, September 12 Today s Agenda Primitives Programming with OpenGL OpenGL Primitives Polylines GL_POINTS GL_LINES

More information

Programmable Shading. University of Texas at Austin CS354 - Computer Graphics

Programmable Shading. University of Texas at Austin CS354 - Computer Graphics Programmable Shading University of Texas at Austin CS354 - Computer Graphics Spring 2009 Don Fussell Lighting, Texturing, Shading Discussed Transformation, Texturing, and Lighting What if We could write

More information

INITIALISING POINTER VARIABLES; DYNAMIC VARIABLES; OPERATIONS ON POINTERS

INITIALISING POINTER VARIABLES; DYNAMIC VARIABLES; OPERATIONS ON POINTERS INITIALISING POINTER VARIABLES; DYNAMIC VARIABLES; OPERATIONS ON POINTERS Pages 792 to 800 Anna Rakitianskaia, University of Pretoria INITIALISING POINTER VARIABLES Pointer variables are declared by putting

More information

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

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 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

More information

To Do. Demo: Surreal (HW 3) This Lecture. Introduction to OpenGL. Outline. Foundations of Computer Graphics (Spring 2012)

To Do. Demo: Surreal (HW 3) This Lecture. Introduction to OpenGL. Outline. Foundations of Computer Graphics (Spring 2012) Foundations of Computer Graphics (Spring 2012) CS 184, Lecture 6: OpenGL 1 http://inst.eecs.berkeley.edu/~cs184 To Do HW 1 due on Thu Must find partners for HW 2 (if problems, speak to TAs during section).

More information

FORM 2 (Please put your name and form # on the scantron!!!!)

FORM 2 (Please put your name and form # on the scantron!!!!) CS 161 Exam 2: FORM 2 (Please put your name and form # on the scantron!!!!) True (A)/False(B) (2 pts each): 1. Recursive algorithms tend to be less efficient than iterative algorithms. 2. A recursive function

More information

GLSL II. Objectives. Coupling GLSL to Applications Example applications

GLSL II. Objectives. Coupling GLSL to Applications Example applications GLSL II Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts Director, Arts Technology Center University of New Mexico Objectives Coupling GLSL to Applications Example

More information

Introduction to SPIR-V Shaders

Introduction to SPIR-V Shaders Copyright Khronos Group 2016 - Page 38 Introduction to SPIR-V Shaders Neil Hickey Compiler Engineer, ARM SPIR History Copyright Khronos Group 2016 - Page 39 Copyright Khronos Group 2016 - Page 40 SPIR-V

More information

Research Placement Technical Report Cross-Platform OpenGL Shader Authoring

Research Placement Technical Report Cross-Platform OpenGL Shader Authoring Research Placement Technical Report Cross-Platform OpenGL Shader Authoring Matthew O'Loughlin 2 nd June, 2012 Supervisor: Dr. Christian Sandor Introduction During my time working with the Magic Vision

More information

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

Programmable GPUs. Real Time Graphics 11/13/2013. Nalu 2004 (NVIDIA Corporation) GeForce 6. Virtua Fighter 1995 (SEGA Corporation) NV1 Programmable GPUs Real Time Graphics Virtua Fighter 1995 (SEGA Corporation) NV1 Dead or Alive 3 2001 (Tecmo Corporation) Xbox (NV2A) Nalu 2004 (NVIDIA Corporation) GeForce 6 Human Head 2006 (NVIDIA Corporation)

More information

Shaders CSCI 4239/5239 Advanced Computer Graphics Spring 2014

Shaders CSCI 4239/5239 Advanced Computer Graphics Spring 2014 Shaders CSCI 4239/5239 Advanced Computer Graphics Spring 2014 What is a Shader? Wikipedia: A shader is a computer program used in 3D computer graphics to determine the final surface properties of an object

More information

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

The Graphics Pipeline and OpenGL III: OpenGL Shading Language (GLSL 1.10)! ! The Graphics Pipeline and OpenGL III: OpenGL Shading Language (GLSL 1.10)! Gordon Wetzstein! Stanford University! EE 267 Virtual Reality! Lecture 4! stanford.edu/class/ee267/! Lecture Overview! Review

More information

Information Coding / Computer Graphics, ISY, LiTH GLSL. OpenGL Shading Language. Language with syntax similar to C

Information Coding / Computer Graphics, ISY, LiTH GLSL. OpenGL Shading Language. Language with syntax similar to C GLSL OpenGL Shading Language Language with syntax similar to C Syntax somewhere between C och C++ No classes. Straight ans simple code. Remarkably understandable and obvious! Avoids most of the bad things

More information

Tutorial 04. Harshavardhan Kode. September 14, 2015

Tutorial 04. Harshavardhan Kode. September 14, 2015 Tutorial 04 Harshavardhan Kode September 14, 2015 1 About This tutorial an extension of the Tutorial 03. So you might see quite a lot similarities. The following things are new. A Plane is added underneath

More information