Lecture 2 2D transformations Introduction to OpenGL

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

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

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

Computer Graphics. Bing-Yu Chen National Taiwan University

Computer Graphics 1 Computer Graphics 1

Exercise 1 Introduction to OpenGL

Introduction to Computer Graphics with OpenGL/GLUT

CS Computer Graphics: OpenGL, Continued

CS Computer Graphics: OpenGL, Continued

OpenGL refresher. Advanced Computer Graphics 2012

RECITATION - 1. Ceng477 Fall

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

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

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

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

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

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

An Interactive Introduction to OpenGL Programming

CS 4204 Computer Graphics

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

Computer Graphics. OpenGL

Computer Graphics Course 2005

GL_COLOR_BUFFER_BIT, GL_PROJECTION, GL_MODELVIEW

COMP 371/4 Computer Graphics Week 1

Image Rendering. Rendering can be divided into three sub-problems. Image Formation The hidden surface problem visibility determination steps

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

Lectures OpenGL Introduction

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

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

Rendering. Part 1 An introduction to OpenGL

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

5HDOLVP7KURXJK6\QWKHVLV

Basic Graphics Programming

Computer graphics MN1

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

Introduction to OpenGL

Books, OpenGL, GLUT, GLUI, CUDA, OpenCL, OpenCV, PointClouds, and G3D

Programming using OpenGL: A first Introduction

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

An Interactive Introduction to OpenGL and OpenGL ES Programming. Ed Angel Dave Shreiner

Lecture 3 Advanced Computer Graphics (CS & SE )

Computer Graphics Introduction to OpenGL

Drawing Primitives. OpenGL basics

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

OpenGL: A Practical Introduction. (thanks, Mark Livingston!)

Computer Graphics, Chapt 08

Books, OpenGL, GLUT, CUDA, OpenCL, OpenCV, PointClouds, G3D, and Qt

Chapter 7 Display Lists

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

Computer Graphics Primitive Attributes

OpenGL/GLUT Intro. Week 1, Fri Jan 12

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

Computer Graphics. Making Pictures. Computer Graphics CSC470 1

Precept 2 Aleksey Boyko February 18, 2011

Basic Graphics Programming

Display Lists in OpenGL

Computer Graphics (Basic OpenGL)

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

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

Introduction to OpenGL

Lectures Display List

OpenGL Programming Guide Chapter 1, Introduction to OpenGL 1

Lecture 2. Determinants. Ax = 0. a 11 x 1 + a 12 x a 1n x n = 0 a 21 x 1 + a 22 x a 2n x n = 0

GLUT. What is OpenGL? Introduction to OpenGL and GLUT

Introduction to OpenGL

C++ is Fun Part 13 at Turbine/Warner Bros.! Russell Hanson

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

Overview of Graphics Systems Hearn & Baker Chapter 2. Some slides are taken from Robert Thomsons notes.

C OMPUTER G RAPHICS Thursday

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

Introduction to OpenGL and 3D Graphics

OpenGL. Toolkits.

Computer graphics MN1

Lecture 3. Understanding of OPenGL programming

A display list is a group of OpenGL commands that have been stored for later execution.

CS Computer Graphics: Intro to OpenGL

CS Computer Graphics: Intro to OpenGL

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

CSE528 Computer Graphics: Theory, Algorithms, and Applications

Class of Algorithms. Visible Surface Determination. Back Face Culling Test. Back Face Culling: Object Space v. Back Face Culling: Object Space.

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

Computer Graphics Programming

LECTURE 02 OPENGL API

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

UNIT 7 LIGHTING AND SHADING. 1. Explain phong lighting model. Indicate the advantages and disadvantages. (Jun2012) 10M

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

COMPUTER GRAPHICS LAB # 3

Programming with OpenGL Part 1: Background

Introduction to OpenGL: Part 2

Using OpenGL with CUDA

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

CS 543 Lecture 1 (Part II): Intro to OpenGL and GLUT (Part I) Emmanuel Agu

Computer Graphics. Chapter 3 Computer Graphics Software

Interaction. CSCI 420 Computer Graphics Lecture 3

3D Graphics and API with OpenGL

Computer Graphics Introduction to OpenGL

Introduction to OpenGL Week 1

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

SOURCES AND URLS BIBLIOGRAPHY AND REFERENCES

Transcription:

Lecture 2 2D transformations Introduction to OpenGL

OpenGL where it fits what it contains how you work with it

OpenGL parts: GL = Graphics Library (core lib) GLU = GL Utilities (always present) GLX, AGL, WGL = System dependent libraries GLUT = GL Utility Toolkit (optional) Also note: SDL (Simple Directmedia Layer)

Sample main program (in C) void main( int argc, char** argv ) { int mode = GLUT_RGB GLUT_DOUBLE; glutinitdisplaymode( mode ); glutcreatewindow( argv[0] ); init(); glutdisplayfunc( display ); glutreshapefunc( resize ); glutkeyboardfunc( key ); glutidlefunc( idle ); glutmainloop(); }

Name conventions All calls prefixed by gl, glu, glut All constants prefixed by GL, GLU, GLUT All calls suffixed by number, f,d,v

Example glvertex2fv( v ) umber of omponents - (x,y) - (x,y,z) - (x,y,z,w) ata type - byte b - unsigned byte - short integer s - unsigned short - int (integer) i - unsigned int - float - double ector f present: arguments re array f omitted: arguments as eparate scalars: lvertex2f( x, y )

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;

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_LIGHT0 ); glenable( GL_LIGHTING ); glenable( GL_DEPTH_TEST ); }

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

Rendering Callback Do all of our drawing here glutdisplayfunc( display ); void display( void ) { glclear( GL_COLOR_BUFFER_BIT ); glbegin( GL_TRIANGLE_STRIP ); glvertex3fv( v[0] ); glvertex3fv( v[1] ); glvertex3fv( v[2] ); glvertex3fv( v[3] ); glend(); glutswapbuffers(); }

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

Simple Example A shape can be hard-coded as a function void drawrhombus( GLfloat color[] ) { glbegin( GL_QUADS ); glcolor3fv( color ); glvertex2f( 0.0, 0.0 ); glvertex2f( 1.0, 0.0 ); glvertex2f( 1.5, 1.118 ); glvertex2f( 0.5, 1.118 ); glend(); }

Specifying geometric primitives primitive is described within a begin/end pair: glbegin( primtype ); glend(); etween them, put glvertex for specifying vertices, nd other call for changing the state (color, texture...) Immediate mode

GBA or indexed color We primarily use RGBA R = red = green = blue = alpha OpenGL color alues are specified from 0.0 to 1.0 Alpha = transparency!

OpenGL state he state is a set of internal values in OpenGL. Vertex attributes (color, texture...) Activation of features with glenable - Transformation matrix ny change you make lasts until you change it again! ou don t automatically get the default back, you get hat you used the last time.

Common OpenGL state manipulating calls Vertex attributes: lcolor*(), glnormal*(), gltexcoord*() Setting state variables: glpointsize(size) gllinestipple( repeat, pattern) glshademodel( GL_SMOOTH ) Enabling and disabling features: glenable( GL_LIGHTING ) gldisable( GL_TEXTURE_2D )

Affine transformations in OpenGL Rotation, translation, scaling and more Transformations are concatenated (multiplied) on the current atrix POST-multiplication: current := current * new gl LoadIdentity() sets the matrix to the identity matrix! gltranslate*() lrotate*() glscale*() glloadmatrix*( m ) sets the current matrix to m.

Manipulating the current matrix Very important: Saving and restoring glpushmatrix() saves a copy of the current matrix on a stack glpopmatrix() restores the matrix from the top of the stack. For completeness: You can use any matrix glloadmatrix*( m ) sets the current matrix to m. glmultmatrix*( m ) applies the matrix m

Transformation example oid display( void ) glclear( GL_COLOR_BUFFER_BIT ); glcolor3fv((const GLfloat *)&color); glloadidentity(); glrotatef(45, 0,0,1); gltranslatef(0, -1, 0); glbegin( GL_POLYGON); glvertex2f(0, 0); glvertex2f(1, 0); glvertex2f(0, 0.5); glend(); glflush(); eware that the order of transformations matter!

Specifying geometric primitives II lternative to Immediate mode : Specify geometry by passing arrays of vertices and onnectivity. gldrawelements(); ore efficient. Good for complex geometry.

Next lecture: Adding the third dimension! All this and more. Transformations. Camera placement and projection.