Graphics: Conceptual Model

Slides:



Advertisements
Similar presentations
Computer Graphics - Graphics Programming -
Advertisements

OpenGL CMSC340 3D Character Design & Animation. What is OpenGL? A low-level graphics library specification designed for use with the C and C++ provides…
OPEN GL. Install GLUT Download package di sini Dari devcpp, buka Tools->PackageManager-
Chapter 2: Graphics Programming
Pemrograman OpenGL Dasar
© 2004, Tom Duff and George Ledin Jr1 Lectures OpenGL Introduction By Tom Duff Pixar Animation Studios Emeryville, California and George Ledin Jr Sonoma.
Informationsteknologi Monday, October 29, 2007Computer Graphics - Class 21 Today’s class Graphics programming Color.
What is OpenGL? Low level 2D and 3D Graphics Library Competitor to Direct3D (the rendering part of DirectX) Used in: CAD, virtual reality, scientific.
OpenGL (Graphics Library) Software Interface to graphics software Allows to create interactive programs that produce color images of moving 3D objects.
OpenGL (I). What is OpenGL (OGL)? OGL is a 3D graphics & modeling library Can also use it to draw 2D objects.
CSC 461: Lecture 51 CSC461 Lecture 5: Simple OpenGL Program Objectives: Discuss a simple program Discuss a simple program Introduce the OpenGL program.
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Programming with OpenGL Part 2: Complete Programs Ed Angel Professor of Computer Science,
30/1/2006Based on: Angel (4th Edition) & Akeine-Möller & Haines (2nd Edition)1 CSC345: Advanced Graphics & Virtual Environments Lecture 1: Introduction.
ITEPC 06 - Workshop on Fractal Creation Chiew-Lan Tai and Oscar Au.
Programming with OpenGL Part 1: Background Mohan Sridharan Based on slides created by Edward Angel CS4395: Computer Graphics 1.
Computer Graphics CS 385 February 7, Fundamentals of OpenGl and Glut Today we will go through the basics of a minimal OpenGl Glut project, explaining.
Today … The rendering pipeline in detail What is OpenGL
Introduction to OpenGL M. Ramanathan STTP CAD 2011Introduction to OpenGL.
Introduction to OpenGL Jian Huang This set of slides are extracted from the Interactive OpenGL Programming course given by Dave Shreine, Ed Angel and Vicki.
Reference1. [OpenGL course slides by Rasmus Stenholt]
CAP 4703 Computer Graphic Methods Prof. Roy Levow Lecture 2.
Using Graphics Libraries Lecture 3 Mon, Sep 1, 2003.
Introduction to OpenGL and GLUT GLUT. What is OpenGL? An application programming interface (API) A (low-level) Graphics rendering API Generate high-quality.
Using OpenGL in Visual C++ Opengl32.dll and glu32.dll should be in the system folder Opengl32.dll and glu32.dll should be in the system folder Opengl32.lib.
Programming with OpenGL Part 1: Background
CSE 470: Computer Graphics. 10/15/ Defining a Vertex A 2D vertex: glVertex2f(GLfloat x, GLfloat y); 2D vertexfloating pointopenGL parameter type.
Graphics Systems and OpenGL. Business of Generating Images Images are made up of pixels.
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Programming with OpenGL Part 1: Background Ed Angel Professor of Computer Science, Electrical.
Ch 2 Graphics Programming page 1 CSC 367 Coordinate Systems (2.1.2) Device coordinates, or screen coordinates (pixels) put limitations on programmers and.
1. OpenGL/GLU/GLUT  OpenGL v4.0 (latest) is the “core” library that is platform independent  GLUT v3.7 is an auxiliary library that handles window creation,
1 Figures are extracted from Angel's book (ISBN x) The Human Visual System vs The Pinhole camera Human Visual System Visible Spectrum Pinhole.
16/5/ :47 UML Computer Graphics Conceptual Model Application Model Application Program Graphics System Output Devices Input Devices API Function.
Computing & Information Sciences Kansas State University CIS 536/636 Introduction to Computer Graphics Lecture 4 of 41 William H. Hsu Department of Computing.
1 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 Programming with OpenGL Review.
C O M P U T E R G R A P H I C S Guoying Zhao 1 / 43 C O M P U T E R G R A P H I C S Guoying Zhao 1 / 43 Computer Graphics Programming with OpenGL I.
Program 2 due 02/01  Be sure to document your program  program level doc  your name  what the program does  each function  describe the arguments.
Chun-Yuan Lin Introduction to OpenGL 2015/12/19 1 CG.
NoufNaief.net TA: Nouf Al-harbi.
1 E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012 Programming with OpenGL Part 2: Complete Programs Ed Angel Professor.
NoufNaief.net 1 TA: Nouf Al-Harbi.
1 Angel: Interactive Computer Graphics5E © Addison- Wesley 2009 Image Formation Fundamental imaging notions Fundamental imaging notions Physical basis.
Introduction to OpenGL Programming
Lecture 2 Review OpenGL Libraries Graphics Overview Rendering Pipeline OpenGL command structure.
CS552: Computer Graphics Lecture 6: Viewing in 2D.
1 Programming with OpenGL Part 2: Complete Programs.
OpenGL API 2D Graphic Primitives Angel Angel: Interactive Computer Graphics5E © Addison-Wesley
Introduction to OpenGL Muhammad Aamir Khan Lecturer, DCS, UOP.
Introduction to Graphics Programming. Graphics API.
Graphics Graphics Korea University kucg.korea.ac.kr Graphics Programming 고려대학교 컴퓨터 그래픽스 연구실.
Introduction to Graphics Programming. Graphics: Conceptual Model Real Object Human Eye Display Device Graphics System Synthetic Model Synthetic Camera.
Computer Graphics I, Fall Programming with OpenGL Part 2: Complete Programs.
INTRODUCTION TO OPENGL
Computer Graphics (Fall 2003) COMS 4160, Lecture 5: OpenGL 1 Ravi Ramamoorthi Many slides courtesy Greg Humphreys.
CS 480/680 Computer Graphics Programming with Open GL Part 2: Complete Programs Dr. Frederick C Harris, Jr. Fall 2011.
Program Studi S-1 Teknik Informatika FMIPA Universitas Padjadjaran
The Human Visual System vs The Pinhole camera
“Computer Science is no more about computers than astronomy is about telescopes.” Professor Edsger Dijkstra.
Programming with OpenGL Part 2: Complete Programs
Materi Anatomi OpenGL Fungsi GLUT Posisi Kamera Proyeksi
OpenGL API 2D Graphic Primitives
Programming with OpenGL Part 2: Complete Programs
Graphics Programming (I)
OpenGL (Open Graphics Library) Mr. B.A.Swamy Assistant Professor Dept of CSE.
Introduction to OpenGL
Interactive Computer Graphics Graphics Programming
Programming with OpenGL Part 2: Complete Programs
Programming with OpenGL Part 2: Complete Programs
Programming with OpenGL Part 2: Complete Programs
Programming with OpenGL Part 2: Complete Programs
Programming with OpenGL Part 2: Complete Programs
Presentation transcript:

Graphics: Conceptual Model Real Light Human Eye Real Object Synthetic Light Source Synthetic Camera Human Eye Synthetic Model Real Object Display Device Graphics System

RGB Color Space G R B Green (1,0,0) Yellow (1,1,0) White (1,1,1) Cyan Image: Pixel maps to color Green (1,0,0) Yellow (1,1,0) White (1,1,1) Cyan (0,1,1) Red (1,0,0) R Blk Blue (0,0,1) Magenta (1,0,1) B

Color Frame Buffer CRT Red D/A Green D/A Blue D/A 1 1 1 1 1 1 1 Bit n 1 1 1 1 1 1 Bit 3 Bit 2 Bit 1

RGB Color Space 12 Bit Encoding Example [111111110000] Green (0, 1, 0) Yellow (1,1,0) White (1,1,1) Cyan (0,1,1) Red (1,0,0) R Blk Blue (0,0,1) [111100000000] [000000001111] Magenta (1,0,1) [111100001111] B

Video Look-up Table CRT Look Up Table 1 = 179 Red D/A Green D/A Blue Bit 1 Bit 2 Bit 3 Bit 4 Bit n 1 = 179 CRT Look Up Table Red D/A Green D/A Blue D/A 177 178 179 1 1 1 1 1 1 1 1 1 1 1 1 1 1 180

Computer Graphics Conceptual Model User Written Provided by System Output Devices Application Program Application Model Graphics System Input Devices

Computer Graphics Conceptual Model API Output Devices Application Program Application Model Graphics System Input Devices Function Calls or Protocol Data

Shared Namespace Model Application Function Calls } Run in same process Graphics Lib. OS O I

Client-Server Model: Model Application O Function Graphics Calls Graphics Lib. I OS OS Network Protocol

How does application program communicate with graphics system? ??? 2D Output Image (3D) Model Application Program Graphics System Input Devices

Two Fundamental Ways to Approach Graphics: 1. Image-Oriented 2. Object-Oriented 1. For each pixel in the image, compute the color based upon the model of the object(s). 2. For each object, compute the color of all of the pixels in the image resulting from that object.

Object-Oriented Approach For each object model, we must compute: Which pixels are affected in the resulting image? What color should they be? How is this computation divided between the user’s program and the graphics system? How are the objects represented in the computer? How is this information communicated to the graphics system (API)?

Components of a Graphics API Primitive functions What to draw Primitive attributes How to draw it Transformation functions Rotate, scale, translate objects (where, how big?) Synthetic camera Viewing functions (how to look at it?) Input functions Handle interactivity Control functions Communicate with underlying window system/OS Initialization, error handling, etc.

API Design Considerations Low Level High Level Simple Primitives Complex Primitives Complex State Stateless (Functional)

High vs. Low Level API High level API API hides detail of actual drawing API defines objects and relationships among objects Example: scene-graph API such as JAVA3D Low level API API exposes detail of actual drawing API defines primitives from which objects are built Example: OpenGL, Direct3D

Simple vs. Complex Primitives: 2D Graphics Simple (linear) Point (pixel?} Line Polygon Complex Glyph (bitmap, subimage) Curve Conic section (e.g circle, ellipse) Arbitrary analytic function Complex primitives may be built over simple ones. Linear primitives have advantage in pipeline architecture.

Purely Functional Approach (no retained state) Application Graphics Subsystem Primitives Attributes Function Calls Graphics Context (State)

Retained State Approach Graphics Subsystem Application Function Calls Primitives Graphics Context (State) Attribute Functions

OpenGL Command Syntax Function calls: glXxxxx[type] ( [args] ) Example: glVertex2f (1.0, 2.0); Defined constants: GL_XXXXXXXXXX Example: GL_COLOR_BUFFER_BIT Type definition: GLxxxxxxx Example: GLfloat

OpenGL Primitive Syntax glBegin ( type ); glVertex* ( . . . ); . glEnd ( );

Point and Line Segment Primitives GL_POINTS GL_LINES P0 P1 P2 P3 P4 P5 P6 P7 P0 P1 P2 P3 P4 P5 P6 P7 GL_LINE_STRIP GL_LINE_LOOP P0 P1 P2 P3 P4 P5 P6 P7 P0 P1 P2 P3 P4 P5 P6 P7

Polygons 1. Closed sequence of line segments 2. Has an defined interior 3. Planar Simple: Well defined interior Complex:

Polygons: Defining the Interior Simple: Well defined interior Complex: Odd crossings: inside Even crossings: outside

Polygons: Convexity P1 P2 Definition extensible to 3D. Convex Non-Convex P1 P2 Definition extensible to 3D.

Polygon Primitives GL_POINTS GL_POLYGON P0 P1 P2 P3 P4 P5 P6 P7 P2 P1 GL_TRIANGLES GL_QUADS P0 P1 P2 P3 P4 P5 P6 P7 P0 P1 P2 P3 P4 P5 P6 P7 P0 P1 P2 P3 P4 P5 P6 P7

Immediate vs. Retained Mode Display Lists Creating the Display List: glNewList(Name, GL_COMPILE); Attribute 1; Primitive 1; Primitive 2; . . . Primitive n; glEndList; Executing the list: glCallList(Name);

Setting Color Attribute in OpenGL RGB Mode void glColor3{b s i d f d ub ud ui}(TYPE r, TYPE g, TYPE b); glColor3f(0.0, 0.0, 0.0); /*black*/ glColor3f(1.0, 0.0, 0.0); /*red*/ glColor3f(0.0, 1.0, 0.0); /*green*/ glColor3f(0.0, 0.0, 1.0); /*blue*/ glColor3f(1.0, 1.0, 0.0); /*yellow*/ glColor3f(0.0, 1.0, 1.0); /*cyan*/ glColor3f(1.0, 0.0, 1.0); /*magenta*/ glColor3f(1.0, 1.0, 1.0); /*white*/

Other Simple OpenGL Attributes glClearColor(1.0, 1.0, 1.0, 0.0); Sets background color to white Fourth argument is transparency; 0.0 is opaque Sets a state variable glPointSize(2.0); Sets point size to be 2 pixels wide Note that this is not a device-independent attribute glLinewidth (2.0); glLineStipple(Glint factor, Glushort pattern);

Synthetic Camera y (x,y,z) X Z d Xp, Yp, -d

Synthetic Camera Projection Geometry Projected Point (x’,y’,z’) X x,y,z d Z COP (0,0,0) Projection Plane x’ = x (d/z) y’ = y(d/z) z’ = d

Orthographic Projection x’ = x (d/z) y’ = y(d/z) z’ = d If d = z - D and d w x’ = x y’ = y z = d

Transformation Matrices in OpenGL Load Matrix Matrix Mode 3D Model Vertices Stack Current Stack Current 2D 3D Vertices Modelview Projection

Setting Viewing Matrix in GL: A Simple Case glMatrixMode(GL_PROJECTION); Sets the switch so that loaded matrix goes into the projection stack. glLoadIdentity(); Pushes an identity matrix onto the stack; glOrtho2D(GLdouble left, Gldouble right, Gldouble bottom, Gldouble top); Sets the current view to an orthographic projection with view volume bounded by x = left, x = right, y = bottom, y = top, z = -1.0 and z = 1.0.

Viewport Transformation Maps Clipped Projection Plane to Screen MyWindow w Clipping Window h x y void glViewport(Glint x, GLint y, GLsizei w, Glsizei h); Default viewport corresponds to entire window drawable area.

OpenGL Library Functions GL library contains all primitive and attribute functions associated with OpenGL GLU GLU library builds on the GL library to include more complex primitives (e.g. spheres) and convenience functions GLUT (GL Utility Toolkit) includes functions to interface with the native window system, including window creation, management of input devices GLUT

GL Library Organization Under Microsoft Windows GLU GL OpenGl application program Frame buffer GLUT Direct Draw

GL Library Organization (under X Windows) GLU GL OpenGL application program Frame buffer GLUT Xlib, Xtk GLX

Simple GLUT Window Management Functions glutInit(int *argc, char** argv); Initializes a window session. glutCreateWindow(char *name); Creates a window with title *name. glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB); Sets the display mode to single buffered and RGB color. glutInitWindowSize (GLsizei h, GLsizei w); Sets initial window size to h x w. glutInitWindowPosition(x,y); Sets initial window position to (x, y).

Form of Simplest glut/OpenGL program #include <glut.h> /* glut.h includes gl.h and glu.h */ void init (void) { /* Usually contains setting of the viewing transformation*/ } void display (void) /*This function contains all of the draw/redraw commands

Form of Simplest glut/OpenGL program (slide 2) void reshape (int w, int h) { /* What to do whenever the window is resized. Usually includes resetting the viewport */ } int main (int argc, char ** argv) glutInit(int *argc, char** argv); /* init glut */ glutCreate Window(char *name); /* create window */ glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB); glutInitWindowSize (GLsizei h, GLsizei w); glutInitWindowPosition(x,y); init ();

Form of Simplest glut/OpenGL program (slide 3) gllutDisplayFunc(display); /* register display */ glutReshapeFunc(reshape); /* register reshape */ glutMainLoop(); /* enter event loop */ return 0; }