Exercise 1 Introduction to OpenGL

Similar documents
Computer Graphics. Bing-Yu Chen National Taiwan University

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 1 Computer Graphics 1

Lecture 2 2D transformations Introduction to OpenGL

Introduction to Computer Graphics with OpenGL/GLUT

OpenGL refresher. Advanced Computer Graphics 2012

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

CS 4204 Computer Graphics

RECITATION - 1. Ceng477 Fall

GLUT. What is OpenGL? Introduction to OpenGL and GLUT

Basic Graphics Programming

CS Computer Graphics: OpenGL, Continued

CS Computer Graphics: OpenGL, Continued

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

Computer Graphics Course 2005

OpenGL/GLUT Intro. Week 1, Fri Jan 12

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

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

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

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

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

Computer Graphics (Basic OpenGL)

Basic Graphics Programming

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

An Overview GLUT GLSL GLEW

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

1.2 Basic Graphics Programming

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

COMP 371/4 Computer Graphics Week 1

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

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

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

Rendering. Part 1 An introduction to OpenGL

Computer graphics MN1

Computer Graphics. OpenGL

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

Drawing Primitives. OpenGL basics

Programming with OpenGL Part 1: Background

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

Computer Graphics, Chapt 08

Introduction to OpenGL

Interaction. CSCI 420 Computer Graphics Lecture 3

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

An Interactive Introduction to OpenGL Programming

Interaction. CSCI 480 Computer Graphics Lecture 3

Lectures OpenGL Introduction

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

Abel J. P. Gomes LAB. 1. INTRODUCTION TO OpenGL

Introduction to OpenGL: Part 2

Lecture 2 Sections 3.6, 3.7. Fri, Aug 28, 2009

Interaction Computer Graphics I Lecture 3

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

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

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

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

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

Computer Graphics. Chapter 3 Computer Graphics Software

Cameras (and eye) Ideal Pinhole. Real Pinhole. Real + lens. Depth of field

OpenGL. Toolkits.

Precept 2 Aleksey Boyko February 18, 2011

Using OpenGL with CUDA

SOURCES AND URLS BIBLIOGRAPHY AND REFERENCES

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

Lecture 3 Advanced Computer Graphics (CS & SE )

Lecture 3. Understanding of OPenGL programming

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

Rendering Pipeline/ OpenGL

GL_COLOR_BUFFER_BIT, GL_PROJECTION, GL_MODELVIEW

Programming using OpenGL: A first Introduction

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

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

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

1/12/11. Basic Graphics Programming. What is OpenGL. OpenGL is cross-platform. How does OpenGL work. How does OpenGL work (continued) The result

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

Announcements OpenGL. Computer Graphics. Autumn 2009 CS4815

Computer graphic -- Programming with OpenGL I

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

Input and Interaction. 1. Interaction. Chapter 3. Introduction: - We now turn to the development of interactive graphics programs.

LECTURE 02 OPENGL API

CS450/550. Pipeline Architecture. Adapted From: Angel and Shreiner: Interactive Computer Graphics6E Addison-Wesley 2012

Computer Graphics. Making Pictures. Computer Graphics CSC470 1

Lectures Display List

Graphics and Visualization

Erik Anchondo cse 520 lab 4

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

Announcements OpenGL. Computer Graphics. Spring CS4815

COMPUTER GRAPHICS LAB # 3

CS193E Lecture 17. Multiple Document Windows OpenGL & Cocoa

CSC 8470 Computer Graphics. What is Computer Graphics?

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

CS Computer Graphics: Intro to OpenGL

CS Computer Graphics: Intro to OpenGL

Graphics Programming. 1. The Sierpinski Gasket. Chapter 2. Introduction:

Computer Graphics Introduction to OpenGL


Graphics Programming

Programming of Graphics

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

Transcription:

Exercise 1 Introduction to OpenGL What we are going to do OpenGL Glut Small Example using OpenGl and Glut Alexandra Junghans 2 What is OpenGL? OpenGL Two Parts most widely used and supported graphics API for portable and interactive 2D and 3D Broad set of rendering, texture mapping and other powerful visualization functions Can render high-quality color images composed of geometric and image primitives Advantages: window system and OS independent, stable, scalable, evolving, supported by many manufacturers it s easy to use and well documented 3 State Machine: Certain states control how OpenGL renders a scene Colors, materials, light sources, etc. Specification of objects to be rendered: Geometric primitives: Points, lines and polygons Image primitives: Images and bitmaps Separate pipeline for images & geometry...linked through texture mapping 4

Data Flow OpenGL initialization Image Unpack pixels Pixel operations Image rasterization Set up whatever state you are going to use Display lists Texture memory Fragment operations to framebuffer void init(void) glclearcolor( 0.0, 0.0, 0.0, 1.0 ); glcleardepth( 1.0 ); Geometry Unpack vertices [ fragment = pixel ] Vertex operations Geometric rasterization 5 OpenGL glenable( GL_LIGHT0 ); glenable( GL_LIGHTING ); glenable( GL_DEPTH_TEST ); 6 OpenGL geometric primitives All geometric primitives are specified by vertices Specifying geometric primitives Primitives are specified using: glbegin(type);... glend(); 7 Code example GLfloat red, green, blue; Glfloat coords[3]; glbegin( GL_POINTS ); for (i =0; i<nverts; ++i) glcolor3f( red, green, blue ); glvertex3fv( coords ); glend(); 8

OpenGL command formats OpenGL Types Number of components 2 - (x,y) 3 - (x,y,z) 4 - (x,y,z,w) glvertex3fv(v) Data type b - byte ub - unsigned byte s - short us - unsigned short i - int ui - unsigned int f - float d - double Vector Omit v for scalar form glvertex2f(x,y) OpenGL provides an own type system Glfloat : 32-bit floating-point Glint: a 32 bit integer Glboolean: 8-bit unsigned integer And some more Why? To ensure portability, therefore try to use them, although it s a bit more typing work 9 10 OpenGl man pages! More Information http://www.opengl.org/documentation/sp ecs/man_pages/hardcopy/gl/html/ Related APIs GLU (OpenGL Utility Library) Part of OpenGL NURBS, tessellators, quadric shapes, etc. GLUT (OpenGL Utility Toolkit) Portable windowing API Many additional feature, e.g. glutwiredsphere() not officially part of OpenGL AGL, GLX, WGL Glue between OpenGL and windowing system 11 12

OpenGL and related APIs GLUT callback functions 13 Routine to call when something happens ( event handler ) Window resize or redraw User input Animation Must register callbacks with GLUT glutdisplayfunc(display); glutidlefunc(idle); glutkeyboardfunc(keyboard); 14 GLUT basics Sample program Application structure Configure and open window Initialize OpenGL state Register input callback functions render resize input: keyboard, mouse, etc. Enter event processing loop 15 void main( int argc, char** argv ) glutcreatewindow(argv[0]); glutinitdisplaymode(glut_rgb GLUT_DOUBLE); init(); glutdisplayfunc(display); glutreshapefunc(resize); glutkeyboardfunc(key); glutidlefunc(idle); glutmainloop(); 16

Rendering callback Idle callback Do all of your drawing here glutdisplayfunc(render); Code Example void render(void) glclear( GL_COLOR_BUFFER_BIT ); glbegin( GL_TRIANGLE_STRIP ); glvertex3fv( v[0] ); glvertex3fv( v[1] ); glvertex3fv( v[2] ); glvertex3fv( v[3] ); glend(); glutswapbuffers(); Use for animation and continuous update glutidlefunc(idle); Code example void idle(void) t +=dt; glutpostredisplay(); 17 18 User input callback Double Buffering Process user input glutkeyboardfunc(keyboard); Code example void keyboard(char key, int x, int y) switch(key) case q: case Q: exit(); break; case r: case R: rotate = GL_TRUE; break; 19 The drawing process is visible when using only one buffer Nasty for animation where we want a certain frame rate without flickering Therefore most graphic cards have two or more frame buffers display the front buffer until the back buffer is drawn completely, then swap the buffers 20

Useful links www.opengl.org nehe.gamedev.net www.naturewizard.com http://en.wikipedia.org/wiki/opengl 21