CS 4204 Computer Graphics

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

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

Computer Graphics. Bing-Yu Chen National Taiwan University

Lecture 4 of 41. Lab 1a: OpenGL Basics

Introduction to Computer Graphics with OpenGL/GLUT

Computer Graphics 1 Computer Graphics 1

Exercise 1 Introduction to OpenGL

RECITATION - 1. Ceng477 Fall

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

CS Computer Graphics: OpenGL, Continued

CS Computer Graphics: OpenGL, Continued

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

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

Computer Graphics. OpenGL

Drawing Primitives. OpenGL basics

Programming using OpenGL: A first Introduction

Programming with OpenGL Part 1: Background

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

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

Computer Graphics. Making Pictures. Computer Graphics CSC470 1

Precept 2 Aleksey Boyko February 18, 2011

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

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

Programming with OpenGL Part 1: Background

Computer Graphics (Basic OpenGL)

Lecture 2 2D transformations Introduction to OpenGL

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

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

Assignment 1. Simple Graphics program using OpenGL

Lecture 3. Understanding of OPenGL programming

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

Introduction to OpenGL Week 1

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

Lectures OpenGL Introduction

COMP 371/4 Computer Graphics Week 1

Rendering. Part 1 An introduction to OpenGL

CSE4030 Introduction to Computer Graphics

Computer Graphics Introduction to OpenGL

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

Computer Graphics Course 2005

Lecture 3 Advanced Computer Graphics (CS & SE )

OpenGL refresher. Advanced Computer Graphics 2012

GL_COLOR_BUFFER_BIT, GL_PROJECTION, GL_MODELVIEW

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

Using OpenGL with CUDA

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

Introduction to OpenGL

Computer graphics MN1

Computer Graphics Primitive Attributes

GLUT. What is OpenGL? Introduction to OpenGL and GLUT

Graphics Programming

Basic Graphics Programming

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

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

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

Basic Graphics Programming

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

An Interactive Introduction to OpenGL Programming

Announcements OpenGL. Computer Graphics. Autumn 2009 CS4815

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

CS Computer Graphics: Intro to OpenGL

CS Computer Graphics: Intro to OpenGL

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

Announcements OpenGL. Computer Graphics. Spring CS4815

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

COMPUTER GRAPHICS LAB # 3

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


Computer Graphics, Chapt 08

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

Computer Graphics. Chapter 3 Computer Graphics Software

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

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

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

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

1.2 Basic Graphics Programming

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

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

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

OpenGL Tutorial. Ceng 477 Introduction to Computer Graphics

C OMPUTER G RAPHICS Thursday

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

Programming of Graphics

Introduction to MS Visual C/C++

OpenGL/GLUT Intro. Week 1, Fri Jan 12

Computer Graphics Introduction to OpenGL

LECTURE 02 OPENGL API

OpenGL Introduction Computer Graphics and Visualization

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

Programming with OpenGL Part 3: Three Dimensions

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

OpenGL. Toolkits.

Graphics Pipeline & APIs

CSC 8470 Computer Graphics. What is Computer Graphics?

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

Interaction. CSCI 480 Computer Graphics Lecture 3

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

SOURCES AND URLS BIBLIOGRAPHY AND REFERENCES

OpenGL Basics I. Seoul National University Graphics & Media Lab

An Overview GLUT GLSL GLEW

Transcription:

CS 4204 Computer Graphics OpenGL Basics Yong Cao Virginia Tech References: 2001 Siggraph, An Interactive Introduction to OpenGL Programming, Dave Shreiner,Ed Angel, Vicki Shreiner Official Presentation from Text book Computer Graphics using OpenGL,, chapter 2

OpenGL and GLUT Overview What is OpenGL & what can it do for me? OpenGL in windowing systems Why GLUT A GLUT program template

What Is OpenGL? Open Graphics Standard Specification for INTERACTIVE 3D Graphics Graphics rendering API high-quality color images composed of geometric and image primitives window system independent operating system independent

What is it for us? Open Graphics Standard API Library State Machine Pipeline GL: Core GLU: Higher level utilities GLUT: Windowing and interaction

OpenGL and Related APIs application program OpenGL Motif widget or similar GLX, AGL or WGL X, Win32, Mac O/S GLUT GLU GL software and/or hardware

OpenGL Architecture (Pipeline) Polynomial Evaluator Per Vertex Operations & Primitive Assembly CPU Display List Rasterization Per Fragment Operations Frame Buffer Pixel Operations Texture Memory

Preliminaries Headers: #include <GL/gl.h gl.h> #include <GL/glu.h glu.h> #include "GL/glut.h glut.h Libraries: glut32.lib, opengl32.lib, glu32.lib Dynamic libraries glut32.dll Let s setup a OpenGL project in Visual Studio 2003.

Setting up a GLUT Window int main(int argc,, char** argv) { glutinitdisplaymode (GLUT_DOUBLE GLUT_RGB GLUT_DEPTH); glutinitwindowposition (0, 0); glutinitwindowsize(640,640); glutcreatewindow(argv[0]); // register callbacks glutreshapefunc (myreshapecb); glutkeyboardfunc(mykeyboardcb ); glutmousefunc(mymousecb) ) ; glutmotionfunc(mymotioncb) ) ; glutdisplayfunc(display); myinit() ; // initialize glutmainloop(); // start the main loop return 0; } // never reached

Mouse callbacks void mymousecb(int button, int state, int x, int y) { // start or end interaction } if( button == GLUT_LEFT_BUTTON && state == GLUT_DOWN ) { } printf("left button down\n") n") ; if( button == GLUT_LEFT_BUTTON && state == GLUT_UP ) { } printf("left button up\n") ; glutpostredisplay() ; // Tell the system to redraw the window void mymotioncb(int x, int y) { // interaction (mouse motion) } printf("moving the mouse\n") ; glutpostredisplay() ;

Keyboard callback void mykeyboardcb(unsigned char key, int x, int y) { } switch (key) { } case 'q': case 27: exit(0); break;

Display function void display(void) ) { glmatrixmode(gl_projection) ) ; glloadidentity() ; glmatrixmode(gl_modelview) ) ; glloadidentity(); glclearcolor(0.0f,0.0f,0.0f,0.0f); // set the background colour // OK, now clear the screen with the background colour glclear(gl_color_buffer_bit GL_DEPTH_BUFFER_BIT); glcolor3f(0.5,0,0) ; // set the current color glutwiresphere( ( 1.0, 10, 10 ) ; // draw a sphere glutswapbuffers(); // swap the buffers (show the image) }

Elements of a scene in OpenGL Geometric Primitives Material properties Light sources Copyright Pixar

Primitives in OpenGL Points Lines Curves (piece-wise linear approximation) Polygons Surfaces ( polygonal approximation)

OpenGL Geometric Primitives All geometric primitives are specified by vertices GL_POINTS GL_LINES GL_LINE_STRIP GL_LINE_LOOP GL_POLYGON GL_TRIANGLES GL_TRIANGLE_STRIP GL_TRIANGLE_FAN GL_QUADS GL_QUAD_STRIP

OpenGL Geometric Primitives (Contiune)

Simple Example 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(); }

OpenGL Command Formats glvertex3fv( 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 us - unsigned short i - int ui - unsigned int f - float d - double Vector omit v for scalar form glvertex2f( x, y )

Specifying Geometric Primitives Primitives are specified using glbegin( primtype ); glend(); primtype determines how vertices are combined GLfloat red, green, blue; Glfloat coords[3]; glbegin( primtype ); for ( i = 0; i < nverts; ++i ) { glcolor3f( red, green, blue ); glvertex3fv( coords ); } glend();

Types GLint GLfloat GLdouble

Points glbegin(gl_points) glvertex3f(glfloat x, GLfloat y, GLfloat z) ; glvertex2i(glint x, GLint y) ; glvertex3dv(gldouble p[3] ) ; glend() ;

Point details glpointsize(float size) ; glcolor3f(glfloat r, GLfloat g, Glfloat b) ;

Lines glbegin(gl_lines) glvertex2i(x1,y1) ; glvertex2i(x2,y2) ; glvertex2i(x3,y3) ; glvertex2i(x4,y4) ; glend()

Line strip glbegin(gl_line_strip) glvertex2i(x1,y1) ; glvertex2i(x2,y2) ; glvertex2i(x3,y3) ; glvertex2i(x4,y4) ; glend()

Line loop glbegin(gl_line_loop) glvertex2i(x1,y1) ; glvertex2i(x2,y2) ; glvertex2i(x3,y3) ; glvertex2i(x4,y4) ; glend()

Line details gllinewidth(glfloat w) ; glcolor3f(glfloat r,glfloat g,glfloat b) ; gllinestipple(glint factor, GLushort pattern) ; glenable(gl_line_stipple) ) ;

Polygons in OpenGL glpolygonmode(gl_front,gl_fill) ) ; glpolygonmode(gl_back,gl_line) ) ; glcolor3f(red,green,blue) ; glbegin(gl_polygon) glnormal3f(v1,v2,v3) ; glvertex3f(x1,y1,z1) ; glnormal3f(v1n,v2n,v3n) ; glvertex3f(xn,yn,zn) ; glend() ;

Higher Primitives in GLUT glutsolidshere() ; glutsolidcube(); glutsolidcone() ; glutsolidteapot() ;

Shapes Tutorial

Reading Material and Homework Check Website. Quiz on reading materials next class. Homework due on next Monday midnight Send homework to TA via email