Computer Graphics Course 2005

Similar documents
GL_COLOR_BUFFER_BIT, GL_PROJECTION, GL_MODELVIEW

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

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

Lectures OpenGL Introduction

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

Drawing Primitives. OpenGL basics

CS Computer Graphics: OpenGL, Continued

CS Computer Graphics: OpenGL, Continued

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

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

Exercise 1 Introduction to OpenGL

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

Lecture 2 2D transformations Introduction to OpenGL

Introduction to Computer Graphics with OpenGL/GLUT

CS 4204 Computer Graphics

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

Computer Graphics. OpenGL

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

Computer Graphics. Making Pictures. Computer Graphics CSC470 1

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

Computer Graphics. Bing-Yu Chen National Taiwan University

RECITATION - 1. Ceng477 Fall

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

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

CS 432 Interactive Computer Graphics

Basic Graphics Programming

Lecture 3. Understanding of OPenGL programming

Computer Graphics 1 Computer Graphics 1

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

Computer graphic -- Programming with OpenGL 2

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

Introduction to OpenGL

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

OpenGL Programming Guide Chapter 1, Introduction to OpenGL 1

Lecture 4 of 41. Lab 1a: OpenGL Basics

Computer Graphics, Chapt 08

Announcements OpenGL. Computer Graphics. Autumn 2009 CS4815

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

Graphics Programming

OpenGL Tutorial. Ceng 477 Introduction to Computer Graphics

Announcements OpenGL. Computer Graphics. Spring CS4815

COMPUTER GRAPHICS LAB # 3

OpenGL/GLUT Intro. Week 1, Fri Jan 12

1 (Practice 1) Introduction to OpenGL

Computer Graphics (Basic OpenGL)

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

C OMPUTER G RAPHICS Thursday

Introduction to OpenGL

Rendering. Part 1 An introduction to OpenGL

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

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

Duc Nguyen CSE 420 Computer Graphics 10/10/2018 Homework 1

Introduction to OpenGL: Part 2

Precept 2 Aleksey Boyko February 18, 2011

Project Sketchpad. Ivan Sutherland (MIT 1963) established the basic interactive paradigm that characterizes interactive computer graphics:

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

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

Programming with OpenGL Part 3: Three Dimensions

Lecture 3 Advanced Computer Graphics (CS & SE )

3D computer graphics: geometric modeling of objects in the computer and rendering them

Basic Graphics Programming

Using OpenGL with CUDA

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

VTU EDUSAT PROGRAMME. Computer Graphics & Visualization

1.2 Basic Graphics Programming

CS418 OpenGL & GLUT Programming Tutorial (I) Presented by : Wei-Wen Feng 1/30/2008

Interaction. CSCI 480 Computer Graphics Lecture 3

OpenGL Introduction Computer Graphics and Visualization

CS380: Computer Graphics Basic OpenGL Structure. Sung-Eui Yoon ( 윤성의 ) Course URL:

Programming using OpenGL: A first Introduction

COMP 371/4 Computer Graphics Week 1

Introduction to OpenGL

Computer graphics MN1

OpenGL refresher. Advanced Computer Graphics 2012

Assignment 1. Simple Graphics program using OpenGL

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

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

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

Interaction Computer Graphics I Lecture 3

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

CSE4030 Introduction to Computer Graphics

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

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

Computer Graphics Introduction to OpenGL

Interaction. CSCI 420 Computer Graphics Lecture 3

Lectures Display List

CS621 Lab 1 Name: Ihab Zbib


SOURCES AND URLS BIBLIOGRAPHY AND REFERENCES

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

20 GLuint objects; 36 Scale += 0.1; 37 break; 38 case GLUT_KEY_DOWN:

GLUT. What is OpenGL? Introduction to OpenGL and GLUT

Lecture 11: Callbacks. CITS 3003 Graphics & Animation

Bob s Concise Introduction to Doxygen

Computer Graphics Primitive Attributes

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

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

GLUT Tutorial. Keyboard

COS340A Assignment 1 I Pillemer Student# March 25 th 2007 p1/15

3D Graphics and API with OpenGL

Transcription:

Computer Graphics Course 2005 Introduction to GLUT, GLU and OpenGL Administrative Stuff Teaching Assistant: Rony Goldenthal Reception Hour: Wed. 18:00 19:00 Room 31 (Ross 1) Questions: E-mail: cg@cs Newsgroups: local.course.cg

Exercises ~6 exercises, can be submitted in pairs (except ex0) Programming Language: C/C++ Programming Guidelines see homepage Exercises planned to be: Fun Creative Educational What is OpenGL OpenGL is a software interface to graphics hardware. Mainly used for interactive 3D graphics Consists about 250 commands Available both in software and hardware over different environments Specifications set by leading industry companies

GLU - OpenGL Utility Library Higher level library - wraps some of OpenGL s functions. Provides modelling features such as: basic geometric primitives, polygons tessellation, quadric surfaces and NURBS Helps setting view and projection matrices. GLUT - OpenGL Utility Toolkit OS independent windowing toolkit for graphics purposes Used mainly for educational purposes - to learn OpenGL Simple event-driven kit! Easy to write small applications based on OpenGL

Recognizing Command s Source OpenGL commands use gl prefix GLU commands use glu previx GLUT commands use glut previx GLUT Basics: Initialization glutinit(int *argc, char *argv[]) Initializes GLUT and processes command line arguments. Should be called before any other GLUT routine. glutinitdisplaymode(unsigned int mode) Specifies the window display mode, for example: GLUT_RGB - sets RGB color mode instead of indexed-color GLUT_DOUBLE - sets double buffered window instead of single GLUT_DEPTH - enables depth buffered window.

GLUT Basics: Initialization glutinitwindowposition(int x, int y) specifies the initial screen location for the upper-left corner of the GLUT window. glutinitwindowsize(int width, int height) specifies the initial window dimensions. int glutcreatewindow(char *string) Creates a window for OpenGL purposes. Returns the window s id. Warning: window will not appear before glutmainloop is called. GLUT Basics: Running GLUT glutmainloop() Starting point of GLUT Windows are displayed Event processing started After calling it, no direct control over program flow Do not start rendering to a window before calling it

GLUT Basics: Event Handling Once GLUT detects an event it calls the appropriate callback function (CBF) glut***func() is used to connect an event to a user defined CBF (by passing a pointer to the CBF) Event types: window, mouse, keyboard, timer GLUT Basics: Window Events glutdisplayfunc(void (*func)(void)) handles window display (rendering) glutreshapefunc(void (*func)(int w, int h)) handles changes in window size.

GLUT Basics: Keyboard and Mouse Events glutkeyboardfunc(void (*func)(unsigned char key, int x, int y)) handles keyboard strokes glutmousefunc(void (*func)(int button, int state, int x, int y)) handles mouse buttons events press/release button = GLUT_LEFT_BUTTON, GLUT_MIDDLE_BUTTON, GLUT_RIGHT_BUTTON state = GLUT_DOWN, GLUT_UP glutmotionfunc(void (*func)(int x, int y)) handles mouse movement events (while one of the buttons is pressed - dragging) GLUT Basics: Timer Event gluttimerfunc(int millis, void (*func)(int value), int value) Called once in millis time (from now) and will send value as the argument. glutidlefunc(void (*func)(void)) Called whenever the event loop is idle Used to manage background tasks

GLUT Basics: Other Commands glutswapbuffers( ) used in double buffer mode, in the display function glutpostredisplay() Notifies GLUT that the window needs to be redrawn Never call the display function directly OpenGL Command Syntax All OpenGL commands start with gl. Defined constants begin with GL_ and are all capital Example: GL_COLOR_BUFFER_BIT Suffix tells us which data type the function accepts: b signed char: GLbyte ub unsigned char: GLubyte i 32 bit integer: Glint f 32 bit floating point: GLfloat d 64 bit floating point GLdouble glvertex2f(glfloat x, GLfloat y) vs. glvertex2i(glint x, GLint y)

OpenGL Command Syntax A number in the suffix specifies number of parameters accepted: v specifies that this variant accepts an array or pointer as parameter: glvertex2i(glint x, GLint y) vs. glvertex3i(glint x, GLint y, GLint z) glvertex4dv(gldouble[4] vector) - one array of doubles of length of 4. OpenGL as a State Machine OpenGL is a state machine, therefore many of its commands change inner states such as color and other drawing modes. glclear(<buffer_const>) - clears the buffer indicated by the const argument: GL_COLOR_BUFFER_BIT - for color buffer(rgba) GL_DEPTH_BUFFER_BIT - for depth buffer GL_ACCUM_BUFFER_BIT - for accumulation buffer GL_STENCIL_BUFFER_BIT - for stencil buffer glclearcolor(double red, double green, double blue, double alpha) -sets the clear color (0.0-1.0). glcleardepth(double depth) - sets the depth value.

OpenGL as a State Machine OpenGL is a state machine You put it in a certain state Remains in effect until state is changed Example: glcolor() sets current drawing color. Once called all shapes will be drawn using this color Until next call of glcolor More states: current transformation, viewing and projection parameters, lighting parameters, line width Many states are either enabled or disabled. glenable() gldisable() OpenGL - Drawing Geometric Primitives glcolor{34}{b s i f d ub us ui}[v](...) sets drawing color (in RGBA mode). Colors are defined by a combination of Red, Green and Blue intensity components (and alpha channel). Examples: glcolor3f(1.0, 0.0, 0.0) ; defines Red color glcolor3f(0.5, 0.5, 0.5) ; defines Grey color glcolor3ub(0, 255, 0) ; defines Green color glcolor3dv(c) ; whereas c is - double c[3] ; Colors input range are type dependent (see OpenGL programming guide V1.2 page 168)

OpenGL - Drawing Geometric Primitives glbegin(glenum mode) Starts the vertex drawing mode glend() - Marks the end of vertex-data list. glflush() Forces previously issued OpenGL commands to begin execution. glfinish() Forces all previously issued OpenGL commands to complete. This command doesn t return until all previous commands are fully realized. OpenGL - Drawing Geometric Primitives glbegin(glenum mode) sets the type of primitive OpenGL will interpret the next vertices list:

OpenGL - Drawing Geometric Primitives glvertex{234}{sifd}[v](coords) this command specifies a vertex, example: glvertex2f(100.0,50.0) ; glvertex3iv(vector) ; whereas v is int v[3]. glvertex2xx sets the third coordinate to be 0 and the fourth to be 1.0, glvertex3xx sets the fourth coordinate to be 1.0 OpenGL - Drawing Geometric Primitives Example code: glclearcolor(0.0, 0.0, 0.0, 0.0) ; glclear(gl_color_buffer_bit) ; glcolor3f(1.0, 0.0, 0.0) ; /* red color */ glbegin(gl_triangles) ; glvertex2f(0.0, 0.0) ; glvertex2f(1.0, 0.0) ; glvertex2f(1.0, 1.0) ; glend() ; glcolor3f(0.0, 1.0, 0.0) ; /* green color */ glbegin(gl_lines) ; glvertex2f(0.0, 0.5) ; glvertex2f(1.0, 0.5) ; Result: glend() ; glflush() ;

OpenGL - 2D Viewing Transformation 2D Coordinate System specification: Where will a given vertex be mapped on the screen? Thinking the question over we should be able to specify which rectangle in vertices coords. sys. will be mapped to the screen OpenGL - 2D Viewing Transformation This is done by the next four commands: glviewport(u1, v1, u2, v2) ; glmatrixmode(gl_projection) ; glloadidentity() ; gluortho2d(x1, x2, y1, y2) ; The above four lines maps the rectangle(x1, y1, x2, y2) in the vertices coords. sys. to the (u1, v1, u2, v2) in the window.

OpenGL - 2D Viewing Transformation That is: (u2,v2) (x1,y1) (u1,v1) (x2,y2) gluortho2d performs parallel projection of a rectangle in the vertices coordinate system to a canonical square in the interval -1,1. The axis of projection is the Z-axis (the third coord in glvertex) glviewport maps this canonical square to the given windows coordinates. OpenGL - 2D Viewing Transformation y gluortho2d glviewport z x