Introductory Seminar

Similar documents
CPSC 436D Video Game Programming

COMP371 COMPUTER GRAPHICS

EDAF80 Introduction to Computer Graphics. Seminar 1. Hierarchical Transformation. Michael Doggett. Some slides by Carl Johan Gribel,

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

WebGL. Creating Interactive Content with WebGL. Media #WWDC14. Session 509 Dean Jackson and Brady Eidson WebKit Engineers

Shaders. Slide credit to Prof. Zwicker

Lecture 11 Shaders and WebGL. October 8, 2015

CS475/CS675 - Computer Graphics. OpenGL Drawing

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

COSC342: Computer Graphics

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

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

EDAF80 Introduction to Computer Graphics. Seminar 3. Shaders. Michael Doggett. Slides by Carl Johan Gribel,

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

CS 376b Computer Vision

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

3d Programming I. Dr Anton Gerdelan

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

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

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

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

Tutorial 1: Your First Triangle!

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

CS 432 Interactive Computer Graphics

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

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

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

Announcements. CSCI 334: Principles of Programming Languages. Lecture 18: C/C++ Announcements. Announcements. Instructor: Dan Barowy

Seminar: Assignment 1. Magnus Andersson

Introduction to C++ Introduction to C++ 1

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 Part 3: Shaders. Ed Angel Professor of Emeritus of Computer Science University of New Mexico

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

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

Introduction to OpenGL/GLSL and WebGL GLSL

CE221 Programming in C++ Part 1 Introduction

Rendering Objects. Need to transform all geometry then

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

CS 432 Interactive Computer Graphics

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

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

Introduction to C++ Professor Hugh C. Lauer CS-2303, System Programming Concepts

CS452/552; EE465/505. Review & Examples

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

Short Notes of CS201

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

An Overview GLUT GLSL GLEW

CS201 - Introduction to Programming Glossary By

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

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

Supplement to Lecture 22

The Graphics Pipeline

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

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

Programming shaders & GPUs Christian Miller CS Fall 2011

CENG 477 Introduction to Computer Graphics. Graphics Hardware and OpenGL

Lecture 9(B): GPUs & GPGPU

Multimedia-Programmierung Übung 3

The Graphics Pipeline

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

Motivation was to facilitate development of systems software, especially OS development.

2D graphics with WebGL

Seminar on Simulation of Telecommunication Sistems. Introduction to object-oriented programming: C++

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

Lecture 13: OpenGL Shading Language (GLSL)

CMSC427 OpenGL and JOGL

GLSL Overview: Creating a Program

Geometry Shaders. And how to use them

Outline. 1 About the course

Partha Sarathi Mandal

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

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

CS 261 Fall C Introduction. Variables, Memory Model, Pointers, and Debugging. Mike Lam, Professor

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

Common Misunderstandings from Exam 1 Material

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

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

C Introduction. Comparison w/ Java, Memory Model, and Pointers

CS 11 C++ track: lecture 1

CS

An Introduction to C++

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

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

CSE 374 Programming Concepts & Tools. Hal Perkins Fall 2015 Lecture 19 Introduction to C++

Introduction to C++ Introduction. Structure of a C++ Program. Structure of a C++ Program. C++ widely-used general-purpose programming language

Computer Graphics Seminar

Motivation was to facilitate development of systems software, especially OS development.

AN OVERVIEW OF C++ 1

CSE 374 Programming Concepts & Tools. Hal Perkins Spring 2010

Introduction to C++ with content from

Introduction to Shaders.

Properties of an identifier (and the object it represents) may be set at

CSE 303: Concepts and Tools for Software Development

Shader Programming 1. Examples. Vertex displacement mapping. Daniel Wesslén 1. Post-processing, animated procedural textures

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

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

Android NDK. Federico Menozzi & Srihari Pratapa

Pointers, Dynamic Data, and Reference Types

CGT520 Lighting. Lighting. T-vertices. Normal vector. Color of an object can be specified 1) Explicitly as a color buffer

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

Transcription:

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 assignments week 3-7 book sessions on course homepage Work in pairs If looking for a partner, post on forum E:Uranus Located in the E-huset basement Windows 10, 64 bit, Core i5, 8 GB RAM Visual Studio 2015 Geforce GTX 560

OpenGL 4

OpenGL Application Programming Interface (API) Set of functions that create a 2D image of a 3D scene 3D scene is made of : Primitives - Triangles Textures - 2D images and much, much more Controls a graphics pipeline (graphics hardware) Graphics Processing Unit (GPU) MD16 5

OpenGL We will focus on the core profile no fixed function/immediate mode OpenGL is a state machine Current state is the OpenGL context There are many functions that change the current state OpenGL uses objects that are a part of the state Drawing uses the most recently bound buffers MD16 6

Application setup First, make a window, use GLFW library Second, Create a while loop : grab inputs, render the screen, swap the buffers Third, do some rendering in the render loop MD16 7

OpenGL Pipeline Vertex Shader PA Rasteriser Fragment Shader Test and blend Shaders are programmable, other parts are not There are no default Vertex and Fragment Shaders, you must provide them Primitive Assembly (PA) puts the vertices into the primitive that is currently specified MD16 8

Vertices 3 vertices in (x,y,z) Range from [-1,+1] Output from VS is in Normalized Device Coordinates (NDC) also [-1,+1] origin is in the middle of the screen Put vertices into Vertex Buffer Object (VBO) GLfloat vertices[] = -0.5f, -0.5f, 0.0f, 0.5f, -0.5f, 0.0f, 0.0f, 0.5f, 0.0f }; GLuint VBO; glgenbuffers(1, &VBO); glbindbuffer(gl_array_buffer, VBO); glbufferdata(gl_array_buffer, sizeof(vertices), vertices, GL_STATIC_DRAW); MD16 9

Simple Vertex Shader Must set the predefined variable gl_position Need to link vertex data to the vertex shader A Vertex Array Object (VAO) is also required #version 400 in vec3 position; void main() gl_position = vec4(position, 1.0); } MD16 10

Simple Fragment Shader Requires one output variable of vec4, for the color #version 400 out vec4 color; void main() color = vec4(1.0f, 0.0f, 0.0f, 1.0f); // set color to red } MD16 11

Compiling Shaders glshadersource takes a pointer to a string as input Should check for errors after glcompileshader Need to link the shaders together to use as a shader program MD16 glshadersource(vertexshader, 1, &vertexshadersource, NULL); glcompileshader(vertexshader); glcompileshader(fragmentshader); glattachshader(shaderprogram, vertexshader); glattachshader(shaderprogram, fragmentshader); gllinkprogram(shaderprogram); gluseprogram(shaderprogram); 12

OpenGL - Drawing Tell OpenGL what to render gldrawarrays(gl_triangles, 0, 3); (what to draw, starting index, number of vertices); MD16 13

OpenGL - more info http://www.learnopengl.com/ Some first triangles : Easiest : Anton Gerdelan, http://antongerdelan.net/ opengl/hellotriangle.html Alexander Overvoorde, https://open.gl/drawing (GL focused) Joey de Vries, http://www.learnopengl.com/#!gettingstarted/hello-triangle (Part of a complete course) MD16 14

C++ 15

Hello C++ #include <iostream> int main() std::cout << "Hello world!\n"; return 0; }

About C++ Based on C Created by Bjarne Stroustrup in 80 s Object-oriented (classes and structs) Constructors & destructors Inheritance & virtual functions Operator overloading (+, -, *, / etc) Templates C++11 began a 3 year cycle of updates

Stack integer declaration int x; printf( %i, x);

Stack integer declaration & initialization int x; x = 35; printf( %i, x);

Pointer to an integer int *y; printf( %i, y);

Allocate heap memory int *y; y = new int(10); printf( %i, y);

Pointer dereferencing int *y; y = new int(10); printf( %i, y); printf( %i, *y); dereferenced pointer

Pointer to stack integer int x = 35; int *xp;

Pointer to stack integer int x = 35; int *xp = x; x is an int, not an *int (pointer to an int)

Pointer to stack integer int x = 35; int *xp = x; int *xp = &x; address of x printf( %i, *xp);

Heap deallocation int *y = new int(10); delete y;

C++ class class MyClass };

C++ class: scope class MyClass }; class scope

C++ class: member access class MyClass private: access within this class only (default) protected: public: access to this and inherited classes }; access to everyone

C++ class: constructor class MyClass float mx; }; MyClass(float x) mx = x; }

C++ class: constructor + initialization class MyClass float mx; MyClass(float x) : mx(x) }; }

C++ class: constructor & destructor class MyClass float mx; MyClass(float x) mx = x; } ~MyClass() }; } (mx on stack so automatically deallocated)

C++ class: constructor & destructor class MyClass float *mxp; MyClass(float x) mxp = new float(x); } }; ~MyClass() delete mxp; } mx on heap, deallocate manually

C++ class: member method class MyClass float mx; }; void setx(float x) mx = x; }

Class member access Stack MyClass myclass = MyClass(5); myclass.setx(2); Heap MyClass *myclassp = new MyClass(5); myclassp->setx(2);... delete myclassp;

C++ class: declaration + definition class MyClass float mx; MyClass.h }; void setx(float x); #include MyClass.h MyClass.cpp void MyClass::setX(float x) mx = x; }

Array stack & heap allocation Stack 1 float numbers[3]; numbers[0] = 1.0f;... Stack 2 (direct initilization) float numbers[3] = 1.0f, 2.0f, 3.0f }; Heap float *numbers = new float[3] numbers[0] = 1.0f;...... delete[] numbers;

Parameters: Value, Reference, Pointer MyClass mc0 = MyClass(1); MyClass mc1 = MyClass(1); MyClass *mc2 = new MyClass(1); foo(mc0, mc1, mc2); by copy by reference (Java-style) by pointer int foo(myclass mc0, MyClass &mc1, MyClass *mc2) mc0.setx(10); edits local copy only } mc1.setx(10); mc2->setx(10); edits original edits original

C++ Types int a = -1; (32 bit) unsigned int b = 1; (32 bit) long c = -2; (64 bit) unsigned long d = 2; (64 bit) float e = 1.0f; (32 bit) double f = 3.14; (64 bit) bool g = true; (8 bit) char h = x ; (8 bit) char i[] = abcd ; (5*8 bit)...

Inheritance class Transformable public: virtual void transform(void)... } }; class Point3d : public Transformable public: void transform(void)... } };

Operator overloading May customize +, -, *, / and many others Very useful for linear algebra, e.g.: glm::mat3 A, B; glm::vec3 u; glm::mat3 M = A * B; glm::vec3 v = M * u;

Output Print Rendering to standard output, followed by a new line: std::cout << Rendering...\n ; Or, with the same result: printf( Rendering...\n ); Inclusion of variables (many formatting options available): printf( an integer: %d, a float: %f\n, 1, 3.14f);

More info EDA031 - C++ Programming cplusplus.com http://www.cplusplus.com/doc/tutorial/ MD16 43

End Kursombud/course representative Check the forum often Next week : Assignment 1 Questions?