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

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

- Surface Rendering -

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

EECS 487: Interactive Computer Graphics

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

Pointers. Lecture 2 Sections Robb T. Koether. Hampden-Sydney College. Mon, Jan 20, 2014

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

Lecture 09: Shaders (Part 1)

The Graphics Pipeline

The Graphics Pipeline

Scope and Parameter Passing

Pointers. Lecture 2 Sections Robb T. Koether. Hampden-Sydney College. Fri, Jan 18, 2013

Pointer Arithmetic. Lecture 4 Chapter 10. Robb T. Koether. Hampden-Sydney College. Wed, Jan 25, 2017

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

Pointers. Lecture 1 Sections Robb T. Koether. Hampden-Sydney College. Wed, Jan 14, 2015

CS475/CS675 - Computer Graphics. OpenGL Drawing

Introduction to Computer Graphics. Hardware Acceleration Review

An Overview GLUT GLSL GLEW

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

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

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

Dynamic Allocation of Memory

Supplement to Lecture 22

Shading Triangles. Lecture 37. Robb T. Koether. Hampden-Sydney College. Mon, Nov 30, 2015

GLSL: Creating GLSL Programs - Overview

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

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

List Iterator Implementation

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

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

Fundamental Data Types

Scope and Parameter Passing

GLSL Overview: Creating a Program

Recursive Linked Lists

The Critical-Path Algorithm

Implementing Linked Lists

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

INTRODUCTION TO OPENGL PIPELINE

Dynamic Allocation of Memory

Shaders CSCI 4239/5239 Advanced Computer Graphics Spring 2014

Shaders CSCI 4229/5229 Computer Graphics Fall 2017

Recognition of Tokens

Programmable shader. Hanyang University

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

Programming Languages

Lecture 29 Section Wed, Apr 1, 2009

Introduction to the OpenGL Shading Language (GLSL)

Computer Graphics (CS 4731) & 2D Graphics Systems

CS380: Computer Graphics Screen Space & World Space. Sung-Eui Yoon ( 윤성의 ) Course URL:

Array Elements as Function Parameters

12.2 Programmable Graphics Hardware

The Basic Computer Graphics Pipeline, OpenGL-style. Introduction to the OpenGL Shading Language (GLSL)

Introduction to Shaders.

Ambient and Diffuse Light

Lecture 37 Section 9.4. Wed, Apr 22, 2009

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

Programmable Graphics Hardware

Array Lists. Lecture 15. Robb T. Koether. Hampden-Sydney College. Mon, Feb 22, 2016

The Projection Matrix

Converts geometric primitives into images Is split into several independent stages Those are usually executed concurrently

Philip Calderon CSE 520 Lab 3 Color Shader

The Projection Matrix

Sign up for crits! Announcments

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

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

GLSL II. Objectives. Coupling GLSL to Applications Example applications

Objectives. Coupling GLSL to Applications Example applications

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

WebGL and GLSL Basics. CS559 Fall 2016 Lecture 14 October

Binary Tree Applications

OpenSceneGraph 3.0 Beginners Guide. WGM # 52 Gustavo Rovelo

Array Lists. Lecture 15. Robb T. Koether. Hampden-Sydney College. Fri, Feb 16, 2018

Scheduling and Digraphs

Programming Languages

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

The string Class. Lecture 21 Sections 2.9, 3.9, Robb T. Koether. Wed, Oct 17, Hampden-Sydney College

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

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

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

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

Linked Lists. Lecture 16 Sections Robb T. Koether. Hampden-Sydney College. Wed, Feb 22, 2017

GLSL 1: Basics. J.Tumblin-Modified SLIDES from:

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

a data type is Types

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

Lecture 22 Sections 8.8, 8.9, Wed, Oct 28, 2009

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

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

Objectives. Open GL Shading Language (GLSL)

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

The Constructors. Lecture 7 Sections Robb T. Koether. Hampden-Sydney College. Wed, Feb 1, 2017

The Traveling Salesman Problem Brute Force Method

while Loops Lecture 13 Sections Robb T. Koether Wed, Sep 26, 2018 Hampden-Sydney College

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

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

CS 432 Interactive Computer Graphics

School of Information Technology and Computer Science CSCI192 - Spring Session Revision

Recursive Sequences. Lecture 24 Section 5.6. Robb T. Koether. Hampden-Sydney College. Wed, Feb 27, 2013

OPENGL RENDERING PIPELINE

Transcription:

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 OpenGL library. The vertex and fragment shaders were built-in (not extensions) in OpenGL 2.0 and higher. For earlier versions, the extension wrangler is needed to Check whether vertex and fragment shader extensions are available. Provide an interface for the function calls. All function names in the extension end with ARB.

Initialize the Extension Initialize the Extension GLenum err = glewinit(); First, initialize glew.

Check the Initialization Check the Initialization if (GLEW_OK!= err) cout << ": " << glewgetstring(err) << endl; else cout << "Status: Using GLEW " << glewgetstring(glew_version) << endl; Check whether the initialization was successful.

Check for Extensions Check for Extensions if (GLEW_ARB_vertex_shader GLEW_ARB_fragment_shader) cout << "Ready for GLSL" << endl; else cout << "Not ready for GLSL" << endl; Check whether the initialization was successful.

Check for OpenGL 2.0 Support Check for OpenGL 2.0 Support if (glewissupported("gl_version_2_0")) cout << "Ready for OpenGL 2.0" << endl; else cout << "OpenGL 2.0 not supported" << endl; Check whether the initialization was successful.

Outline 1 2 3 4 5

GLSL Data Types Vertex glcreateobject() glattachobject() glattachobject() glcreateobject() readsource() glsource() glcompile() Fragment glcreateobject() void main() { gl_position =... } gllink() readsource() void main() { gl_fragcolor =... } gluse() glsource() glcompile()

Creating a The shader programs are written as text files. The application program will read and compile the shader programs. First, store the source code in a text file. Example ( ) int main() { gl_position = gl_modelviewprojectionmatrix*gl_vertex; }

Creating a Read the source code from the text file. Store it in an array of strings. Read the char* readsource(char* file_name); file_name Name of the text file that contains the source code. Return value A pointer the string of source code.

Creating a Example (Read the ) char* vsource = readsource(vfile);

Create a Then, create a shader object. glcreateobjectarb() unsigned int glcreateobjectarb(int shader_type); shader_type GL_VERTEX_SHADER or GL_FRAGMENT_SHADER. Return value A reference number of that shader object.

Create a Example (Create a ) char* vsource = readsource(vfile); unsigned int v = glcreateobjectarb(gl_vertex_shader);

Compiling a Next, pass the source code to the shader object. glsourcearb() glsourcearb(int shader, int num_strs, const char** source, int* len); shader Reference number of the shader object. num_strs Number of strings in the string array of source code. source Array of strings of source code. len Lengths of the string. If len is NULL, then the strings are null-terminated.

Create a Example (Create a ) char* vsource = readsource(vfile); unsigned int v = glcreateobjectarb(gl_vertex_shader); glsourcearb(v, 1, (const char**) &vsource, NULL);

Compiling a Then compile the source code. glcompilearb() glcompilearb(int shader); shader Reference number for the shader object.

Compiling a Example (Compiling a ) char* vsource = readsource(vfile); unsigned int v = glcreateobjectarb(gl_vertex_shader); glsourcearb(v, 1, (const char**) &vsource, NULL); glcompilearb(v);

Creating a Fragment Do all of these steps for both the vertex shader and the fragment shader.

Compiling a Example (Compiling a ) // Compile vertex shader char* vsource = readsource(vfile); unsigned int v = glcreateobjectarb(gl_vertex_shader); glsourcearb(v, 1, (const char**) &vsource, NULL); glcompilearb(v); // Compile fragment shader char* fsource = readsource(ffile); unsigned int f = glcreateobjectarb(gl_fragment_shader); glsourcearb(f, 1, (const char**) &fsource, NULL); glcompilearb(f);

Outline 1 2 3 4 5

Finally, create a program object. Attach the compiled shader program to the program object. Link the program object to the application program. Make the program object active.

Create a Object Create a Object unsigned int glcreateobjectarb(); Return value A reference number for the program object.

Attach a to a Object Attach a to a Object glattachobjectarb(int prog_obj, int shader_obj); prog_obj The reference number of the program object. shader_obj The reference number of the shader object.

Object Object gllinkarb(progobj); prog_obj The reference number of the program object.

Using a Object Using a Object gluseobjectarb(progobj); prog_obj The reference number of the program object.

Compiling a Example (Compiling a ) char* vsource = readsource(vfile); unsigned int v = glcreateobjectarb(gl_vertex_shader); glsourcearb(v, 1, (const char**) &vsource, NULL); glcompilearb(v); char* fsource = readsource(ffile); unsigned int f = glcreateobjectarb(gl_fragment_shader); glsourcearb(f, 1, (const char**) &fsource, NULL); glcompilearb(f); myprogobj = glcreateobjectarb(); glattachobjectarb(myprogobj, v); glattachobjectarb(myprogobj, f); gllinkarb(myprogobj); gluseobjectarb(myprogobj);

The vertex shader. The fragment shader. The application code. The executable.

Outline 1 2 3 4 5

If there are compilation errors, the application program will run, but OpenGL will revert to the fixed pipeline. If there are errors, it is extremely helpful to get error messages. To get the error messages, we must use the function glgetinfologarb.

glgetinfologarb(unsigned int shader, int buf_size, int* msg_size, char* buffer); shader The reference number of the shader object. buf_size The size of the message buffer. msg_size The size of the message (returned). buffer The message (returned).

Example (Compiling a ) char* vsource = readsource(vfile); unsigned int v = glcreateobjectarb(gl_vertex_shader); glsourcearb(v, 1, (const char**) &vsource, NULL); glcompilearb(v); const int size = 1000; char msgbuffer[size]; int msglen; glgetinfologarb(v, size - 1, &msglen, msgbuffer); msgbuffer[msglen] = 0; if (msglen > 0) { cout << "Vertex shader:" << endl; cout << msgbuffer << endl; }

The vertex shader. The fragment shader. The application code. The executable.

Outline 1 2 3 4 5

Homework Homework Read Section 9.1 programmable graphics cards. Read Section 9.2 shading languages. Read Section 9.3 extensions of OpenGL.