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

Similar documents
Lecture 2 2D transformations Introduction to OpenGL

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

Exercise 1 Introduction to OpenGL

Computer Graphics. Bing-Yu Chen National Taiwan University

CS 543 Lecture 1 (Part 3) Prof Emmanuel Agu. Computer Science Dept. Worcester Polytechnic Institute (WPI)

ERKELEY DAVIS IRVINE LOS ANGELES RIVERSIDE SAN DIEGO SAN FRANCISCO EECS 104. Fundamentals of Computer Graphics. OpenGL

Lecture 4 of 41. Lab 1a: OpenGL Basics

Computer Graphics 1 Computer Graphics 1

CS Computer Graphics: OpenGL, Continued

CS Computer Graphics: OpenGL, Continued

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

CS 4731 Lecture 3: Introduction to OpenGL and GLUT: Part II. Emmanuel Agu

Introduction to OpenGL. CSCI 4229/5229 Computer Graphics Fall 2012

Rendering. Part 1 An introduction to OpenGL

CS 432 Interactive Computer Graphics

CS559: Computer Graphics. Lecture 12: OpenGL Li Zhang Spring 2008

Introduction to Computer Graphics with OpenGL/GLUT

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

CS 4204 Computer Graphics

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

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

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

OpenGL refresher. Advanced Computer Graphics 2012

OpenGL and GLUT. COMP413 Computer Graphics. School of Computer Sci. & Eng. Kyungpook National University, Korea. Spring Semester, 2016

Computer Graphics. Making Pictures. Computer Graphics CSC470 1

RECITATION - 1. Ceng477 Fall

Programming using OpenGL: A first Introduction

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

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

An Overview GLUT GLSL GLEW

2/3/16. Interaction. Triangles (Clarification) Choice of Programming Language. Buffer Objects. The CPU-GPU bus. CSCI 420 Computer Graphics Lecture 3

Interaction. CSCI 420 Computer Graphics Lecture 3

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

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

Computer Graphics. OpenGL

2. OpenGL -I. 2.1 What is OpenGL? Things OpenGL can do: -23-

COMP371 COMPUTER GRAPHICS

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

Teacher Assistant : Tamir Grossinger Reception hours: by - Building 37 / office -102 Assignments: 4 programing using

cs123 Lab 3 OpenGL Part One 1 Introduction 2 OpenGL Basics 2.2 The Rendering Pipeline 2.1 The CPU and the GPU 2.3 Basic Syntax of OpenGL commands

LECTURE 02 OPENGL API

GLUT. What is OpenGL? Introduction to OpenGL and GLUT

Geometry Shaders. And how to use them

Computer Graphics Course 2005

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

OpenGL. Jimmy Johansson Norrköping Visualization and Interaction Studio Linköping University

API for creating a display window and using keyboard/mouse interations. See RayWindow.cpp to see how these are used for Assignment3

Introduction to OpenGL

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

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

Drawing Primitives. OpenGL basics

COMP 371/4 Computer Graphics Week 1

Lecture 3 Advanced Computer Graphics (CS & SE )

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

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

to OpenGL Introduction Pipeline Graphics pipeline OpenGL pipeline OpenGL syntax Modeling Arrays Conclusion 1 Introduction Introduction to OpenGL

Lectures OpenGL Introduction

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

CS 432 Interactive Computer Graphics

Image Processing. Geometry Processing. Reading: (Not really covered in our text. See Sects 18.1, 18.2.) Overview: Display

OPENGL AND GLSL. Computer Graphics

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

Computer Graphics, Chapt 08

Lecture 2 CISC440/640 Spring Department of Computer and Information Science

CSC Graphics Programming. Budditha Hettige Department of Statistics and Computer Science

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

CS 548: COMPUTER GRAPHICS INTRODUCTION TO OPENGL AND GLUT SPRING 2015 DR. MICHAEL J. REALE

GL_COLOR_BUFFER_BIT, GL_PROJECTION, GL_MODELVIEW

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

This Lecture. Introduction to OpenGL. Outline. Why OpenGL? Programmer s View. Foundations of Computer Graphics

Programming with OpenGL Part 2: Complete Programs Computer Graphics I, Fall

CS475/CS675 - Computer Graphics. OpenGL Drawing

OpenGL. 1 OpenGL OpenGL 1.2 3D. (euske) 1. Client-Server Model OpenGL

Basic Graphics Programming

11/1/13. Basic Graphics Programming. Teaching Assistant. What is OpenGL. Course Producer. Where is OpenGL used. Graphics library (API)

// double buffering and RGB glutinitdisplaymode(glut_double GLUT_RGBA); // your own initializations

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

Precept 2 Aleksey Boyko February 18, 2011

Early History of APIs. PHIGS and X. SGI and GL. Programming with OpenGL Part 1: Background. Objectives

CMSC 425: Lecture 4 More about OpenGL and GLUT Tuesday, Feb 5, 2013

Introduction to OpenGL Week 1

Objectives. Image Formation Revisited. Physical Approaches. The Programmer s Interface. Practical Approach. Introduction to OpenGL Week 1

Lecture 3. Programming with OpenGL GLUT + GLEW. CS 354 Computer Graphics Sunday, January 20, 13

Computer Graphics (Basic OpenGL)

Draw the basic Geometry Objects. Hanyang University

Programming with OpenGL Part 1: Background

Computer Graphics Introduction to OpenGL

Assignment 1. Simple Graphics program using OpenGL

Using OpenGL with CUDA

Computer Graphics. Chapter 3 Computer Graphics Software

CSC 8470 Computer Graphics. What is Computer Graphics?

Graphics Programming. August 31, Programming of the Sierpinski gasket. Programming with OpenGL and C/C++

Programming with OpenGL Part 1: Background

Computer Graphics Seminar

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

Graphics and Visualization

To Do. Demo: Surreal (now 15+ years ago) This Lecture. Outline. Computer Graphics. CSE 167 [Win 19], Lecture 6: OpenGL 1 Ravi Ramamoorthi

COMPUTER GRAPHICS LAB # 3

Basic Graphics Programming

Lectures Display List

Transcription:

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 - Linux, Mac, Windows... Any language Three branches: OpenGL - ordinary computers OpenGL ES - phones and tablets WebGL - web browsers 12(40)12(40)

OpenGL and Related APIs application program X, OSX, Win32 etc GLX, WGL, CGL, NSOpenGL GLUT SDL GLFW GL GLU drivers, hardware 13(40)13(40)

OpenGL parts: GL = Graphics Library (core lib) GLU = GL Utilities (no longer supported) GLX, WGL, CGL, NSOpenGL = System dependent libraries GLUT = GL Utility Toolkit (optional) FreeGLUT, MicroGlut Also note: SDL (Simple Directmedia Layer) GLFW (similar to GLUT) 14(40)14(40)

OpenGL versions OpenGL 1-2: Old OpenGL. Avoid Big leap here OpenGL 3.2 and up: Modern OpenGL Latest version 4.5. Even hotter (but harder): Vulkan (released 2016) 15(40)15(40)

Simple OpenGL example A single triangle upload to the GPU once draw any time you want but also upload shader to specify transformations and colors 16(40)16(40)

Vital concepts VAO, VBO Vertex shader Fragment shader 17(40)17(40)

VAO and VBO VBO = Vertex Buffer Object A reference to an array of vertices on the GPU VAO = Vertex Array Object A reference to a set of buffers 18(40)18(40)

What is a shader? Small program kernel that runs on the GPU Gives you great freedom to specify certain operations. Run in parallel on multiple kernels (hundreds) in the GPU Extremely efficient 19(40)19(40)

Vertex shader Specifies transformations on each vertex Translations, rotations... Short program with data sent from the main program In the example: Pass-through 20(40)20(40)

Fragment shader Specifies color of each pixel Short program with data sent from the main program or vertex shader. In the example: Set-to-white 21(40)21(40)

Sample main program (in C) void main( int argc, char** argv ) { glutinit(argc, argv)); glutcreatewindow( GL3 white triangle example ); glutdisplayfunc( display ); init(); glutmainloop(); } Looks different for different wrapper libraries 22(40)22(40)

Sample shaders Minimal, doing pretty much nothing Vertex shader: Specifying positioning (pass-through) Fragment shader: Specifying pixel colors (set-to-white) #version 150 in vec3 in_position; void main(void) { gl_position = vec4(in_position, 1.0); } #version 150 out vec4 out_color; void main(void) { out_color = vec4(1.0); } 23(40)23(40)

Name conventions All calls prefixed by gl All constants prefixed by GL Some calls suffixed by number, f,d,v 24(40)24(40)

Example glvertexattrib2fv(index, v ) Number of components 2 - (x,y) 3 - (x,y,z) 4 - (x,y,z,w) Data type b - byte ub - unsigned byte s - short integer us - unsigned short i - int (integer) ui - unsigned int f - float d - double Vector If present: arguments are array If omitted: arguments as separate scalars: gluniform1f( loc, time ) 25(40)25(40)

OpenGL Initialization Set up whatever state you re going to use void init( void ) { glclearcolor( 0.0, 0.0, 0.0, 1.0 ); glcleardepth( 1.0 ); glenable( GL_DEPTH_TEST ); glenable( GL_CULL_FACE ); } 26(40)26(40)

OpenGL type names Standard types redefined prefixed GL (for compatibility reasons) From gl.h: typedef unsigned long GLenum; typedef unsigned char GLboolean; typedef unsigned long GLbitfield; typedef signed char GLbyte; typedef short GLshort; typedef long GLint; typedef long GLsizei; typedef unsigned char GLubyte; typedef unsigned short GLushort; typedef unsigned long GLuint; typedef float GLfloat; typedef float GLclampf; typedef double GLdouble; typedef double GLclampd; typedef void GLvoid; 27(40)27(40)

GLUT (FreeGLUT, MicroGLUT) Callback Functions Routines for GLUT to call when something happens window resize or redraw user input animation Register callbacks with GLUT glutdisplayfunc( display ); glutidlefunc( idle ); glutkeyboardfunc( keyboard ); 28(40)28(40)

Rendering Callback. Do all of our drawing here glutdisplayfunc( display ); void display( void ) { void display(void) { // clear the screen glclear(gl_color_buffer_bit GL_DEPTH_BUFFER_BIT); // Select VAO and draw glbindvertexarray(vertexarrayobjid); gldrawbuffer(gl_triangles, 36, GL_UNSIGNED_BYTE, NULL); glutswapbuffers(); } 29(40)29(40)

Timer Callbacks Use for animation and continuous update gluttimerfunc( time, idle ); void timerfunc( ignoredvalue ) { t +=dt; gluttimerfunc(20, timerfunc, 0); glutpostredisplay(); } 30(40)30(40)

Simple Example A shape can be hard-coded in an array GLfloat vertices[] = { -0.5f,-0.5f,0.0f, -0.5f,0.5f,0.0f, 0.5f,-0.5f,0.0f }; GLfloat colors[] = { 1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f }; But usually you read data from files. 31(40)31(40)

OpenGL Geometric Primitives All geometric primitives are specified by vertices: GL_POINTS GL_LINES GL_LINE_STRIP GL_LINE_LOOP Why not QUAD or POLYGON? GL_TRIANGLE_STRIP GL_TRIANGLE_FAN GL_TRIANGLES 32(40)32(40)

Uploading to the GPU is a bit hairy. // Allocate and activate Vertex Array Object glgenvertexarrays(1, &vertexarrayobjid); glbindvertexarray(vertexarrayobjid); // VBO for vertex data glgenbuffers(1, &vertexbufferobjid); glbindbuffer(gl_array_buffer, vertexbufferobjid); // Data to VBO glbufferdata(gl_array_buffer, 9*sizeof(GLfloat), vertices, GL_STATIC_DRAW); glvertexattribpointer(glgetattriblocation(program, "in_position"), 3, GL_FLOAT, GL_FALSE, 0, 0); glenablevertexattribarray(glgetattriblocation(program, "in_position")); 33(40)33(40)