Ch 2 Graphics Programming page 1 CSC 367 Coordinate Systems (2.1.2) Device coordinates, or screen coordinates (pixels) put limitations on programmers and.

Slides:



Advertisements
Similar presentations
Computer Graphics - Graphics Programming -
Advertisements

Chapter 2: Graphics Programming
Computer Graphics CSCE 441
Graphics Pipeline.
Pemrograman OpenGL Dasar
CS 4731 Lecture 2: Intro to 2D, 3D, OpenGL and GLUT (Part I) Emmanuel Agu.
What is OpenGL? Low level 2D and 3D Graphics Library Competitor to Direct3D (the rendering part of DirectX) Used in: CAD, virtual reality, scientific.
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.
IAT 3551 Computer Graphics Overview Color Displays Drawing Pipeline.
Graphics Systems I-Chen Lin’s CG slides, Doug James’s CG slides Angel, Interactive Computer Graphics, Chap 1 Introduction to Graphics Pipeline.
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Models and Architectures Ed Angel Professor of Computer Science, Electrical and Computer.
3D Rendering with JOGL Introduction to Java OpenGL Graphic Library By Ricardo Veguilla
CAP 4703 Computer Graphic Methods Prof. Roy Levow Lecture 2.
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.
Graphics Architectures & OpenGL API Introduction Angel Angel: Interactive Computer Graphics5E © Addison-Wesley
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.
CSC 461: Lecture 3 1 CSC461 Lecture 3: Models and Architectures  Objectives –Learn the basic design of a graphics system –Introduce pipeline architecture.
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.
CSE Real Time Rendering Week 2. Graphics Processing 2.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
1Computer Graphics Lecture 4 - Models and Architectures John Shearer Culture Lab – space 2
Computer Graphics Chapter 6 Andreas Savva. 2 Interactive Graphics Graphics provides one of the most natural means of communicating with a computer. Interactive.
Introduction to OpenGL  OpenGL is a graphics API  Software library  Layer between programmer and graphics hardware (and software)  OpenGL can fit in.
1 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 Programming with OpenGL Review.
Introduction to OpenGL and GLUT. What’s OpenGL? An Application Programming Interface (API) A low-level graphics programming API – Contains over 250 functions.
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.
Image Synthesis Rabie A. Ramadan, PhD 4. 2 Review Questions Q1: What are the two principal tasks required to create an image of a three-dimensional scene?
NoufNaief.net TA: Nouf Al-harbi.
1 Angel: Interactive Computer Graphics5E © Addison- Wesley 2009 Image Formation Fundamental imaging notions Fundamental imaging notions Physical basis.
Graphics: Conceptual Model
1 Programming with OpenGL Part 2: Complete Programs.
OpenGL API 2D Graphic Primitives Angel Angel: Interactive Computer Graphics5E © Addison-Wesley
Chapter 4 -- Color1 Color Open GL Chapter 4. Chapter 4 -- Color2 n The goal of almost all OpenGL applications is to draw color pictures in a window on.
1 Perception, Illusion and VR HNRS 299, Spring 2008 Lecture 15 Creating 3D Models.
Lecture 13: Raster Graphics and Scan Conversion
31/1/2006Based on: Angel (4th Edition) & Akeine-Möller & Haines (2nd Edition)1 CSC345: Advanced Graphics & Virtual Environments Lecture 2: Introduction.
CIS 681 Review: OpenGL. CIS 681 Command Syntax OpenGL commands start with a gl. This is followed by the base command such as Color. Followed by the number.
Chapter 1 Graphics Systems and Models Models and Architectures.
1 E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012 Models and Architectures 靜宜大學 資訊工程系 蔡奇偉 副教授 2012.
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.
OpenGL CS418 Computer Graphics John C. Hart. OpenGL Based on GL (graphics library) by Silicon Graphics Inc. (SGI) Advantages: Runs on everything, including.
OpenGL CS418 Computer Graphics John C. Hart. OpenGL: Event-driven How in OpenGL? Programmer registers callback functions Callback function called when.
INTRODUCTION TO OPENGL
Computer Graphics (Fall 2003) COMS 4160, Lecture 5: OpenGL 1 Ravi Ramamoorthi Many slides courtesy Greg Humphreys.
Program Studi S-1 Teknik Informatika FMIPA Universitas Padjadjaran
The Human Visual System vs The Pinhole camera
Programming with OpenGL Part 2: Complete Programs
Materi Anatomi OpenGL Fungsi GLUT Posisi Kamera Proyeksi
OpenGL API 2D Graphic Primitives
Models and Architectures
Programming with OpenGL Part 2: Complete Programs
OpenGL (Open Graphics Library) Mr. B.A.Swamy Assistant Professor Dept of CSE.
Models and Architectures
Models and Architectures
Introduction to Computer Graphics with WebGL
Drawing in the plane 455.
Introduction to OpenGL
Models and Architectures
Models and Architectures
Programming with OpenGL Part 2: Complete Programs
Programming with OpenGL Part 2: Complete Programs
Programming with OpenGL Part 2: Complete Programs
Presentation transcript:

Ch 2 Graphics Programming page 1 CSC 367 Coordinate Systems (2.1.2) Device coordinates, or screen coordinates (pixels) put limitations on programmers and the code is not portable generally expressed in integers World coordinates an effort was made to hide the actual device coordinates from the programmer and allow ANY coordinate to be used generally expressed in floats programmer defines world space Mapping the mathematical transformation from one coordinate system to another involves relatively simple algebra Example Device coordinates of 640 x 480 World coordinates of 5000 x 4000 Map (2500, 2000) to ___________ Map (1000, 1000) to ___________

Ch 2 Graphics Programming page 2 CSC 367 OpenGL Originally SGIs GL modified to be more portable Collection of functions that interface to graphics hardware Works well on a network Protocol (format of instructions) is the same regardless of the computer. This makes the code portable or system independent It does NOT do windows input modeling It does do sophisticated rendering of 3D scenes

Ch 2 Graphics Programming page 3 CSC 367 uisGL (3D object library) The book explains that OpenGL is not OO This API helps to hide some ugly details #include Vertex uisVertex P1, P2, P3(10,10,0); P1.set(20,20,0); P2.set(40,40,0); P3 = P1 + P2; P3 = P1 / 2; P3 = P2 * 2.0; cout << P3;

Ch 2 Graphics Programming page 4 CSC 367 Typical API Functions (2.2.1) Primitives draw points, lines, polygons (maybe curves) Attributes colors, fill patterns, fonts Viewing position, orientation and lens for the virtual camera Input handle events from keyboard and mouse Control initialize programs, create windows Transformation rotate, translate, and scale objects

Ch 2 Graphics Programming page 5 CSC 367 Drawing Primitives (2.1.1) We will consider 2D to be a special case (x,y,0) Point or Vertex define geometric objects glVertex2f (x, y); glVertex3f (x,y,z); Array or Vector format float vertex[3]; glVertex3fv(vertex); Drawing individual points glBegin(GL_POINTS); glVertex3f (x,y,z); glEnd( ); <--- warning! Drawing a line glBegin(GL_LINES); glVertex3f(x,y,z); glEnd( );

Ch 2 Graphics Programming page 6 CSC 367 Polygons (2.3.1) a series of connected lines simple polygon edges do not cross the interior can be filled with a color convex polygons can be tested by connecting all vertices with each other. If all of the lines remain inside the polygon then it is covex. concave polygons are not convex Drawing a polygon float P1[3] = {10, 10, 0}; glBegin(GL_POLYGON); glVertex3fv (P1); glVertex3fv (P2); glVertex3fv (P3); glVertex3fv (P4); glEnd(); Interior can be filled with a color Edges can be turned on or off

Ch 2 Graphics Programming page 7 CSC 367 Attributes (2.3.5) the name for any property that determines how an object appears a solid red line is different that a dashed green line color, line thickness, fill pattern The general approach is to set current attributes and then display the object. Each geometric type has a set of attributes. A line has color, width and style. glPointSize (2.0) // 2 pixels wide

Ch 2 Graphics Programming page 8 CSC 367 Color (2.4) Ignore color theory and mathematics Three colored spot lights analogy Different than mixing paints RGB color or true color C = T 1 R + T 2 G + T 3 B T is the intensity that ranges from glColor3f (0, 0, 0); // balck glColor3f (1, 0, 0); // red glClearColor (1, 1, 1, 0); // white background glClear (); // clear the screen The number of colors that can be displayed are determined by the number of bits available for each pixel true color requires 24 bits - 8 bits for each

Ch 2 Graphics Programming page 9 CSC 367 Indexed Color not often needed any longer when the number of bits per pixel is limited rather than limit the possible range of colors we limit the possible number of colors painter example that can mix an unlimited number of paints but can only fit so many on the cardboard plate Color-lookup Table the 8-bit representation is used as an index into the color lookup table contains a limited number of entries but each entry can represent any color set current color by specifying an index common configuration is 256 indices

Ch 2 Graphics Programming page 10 CSC 367 Viewing 2.5 Viewing rectangle or window items within the window will be seen and others will be clipped 3D Viewing Volume glOrtho(left,right,bottom,top,near,far) Be aware of right handed coordinate system positive Z comes out from screen Viewport a rectangular region within the window glViewport(x,y,width,height) Aspect Ratio the ratio of the viewing rectangle should be the same as the viewport

Ch 2 Graphics Programming page 11 CSC 367 Matrix Mode (2.5.3) Primitives are multiplied by matrices before being displayed. OpenGL has two important matrices MODELVIEW - for viewing parameters PROJECTION - for display parameters obj’ = obj x MV obj’’ = obj’ x P Typical initialization glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0,10,0,10,0,10); glMatrixMode(GL_MODELVIEW); Leave in MODELVIEW mode

Ch 2 Graphics Programming page 12 CSC 367 GLUT (GL Untility Toolkit) 2.6 Windowing system independent API for OpenGL applications Allows one to window management simple menus event processing loop input We will use an X11 implementation of GLUT. There could be a Windows version or Macintosh version. X11 is a protocal that allows device independent display of graphics over a network. Using real X11 commands would be a pain. Somewhat equivalent to programming in assembler. Client Server model. The client is the application and the computer that does the display is the server.

Ch 2 Graphics Programming page 13 CSC 367 Event Processing 2.6 What stops the image from disappearing after it has been drawn? Event Processing Loop glutMainLoop() this causes an infinite loop until closing the window by hand Callback Mechanism a programmer defined function that glutMainLoop will call when GLUT determines an event has occurred. this is called “registering a call back” Display function glutDisplayFunc(*func(void)) Additional Events mouse button presses keyboard window movement

Ch 2 Graphics Programming page 14 CSC 367 Sample Code look a source discuss Makefile

Ch 2 Graphics Programming page 15 CSC 367 Sierpinski Gasket interesting example from the book Choose a random point within the triangle Loop Find midpoint between current point and a random vertex Make a mark Update current point Extended to 3D requires a tetrahedron