CSE 494/598 Intro to Applied Computer Graphics Anshuman Razdan DCST AR's Web Page AR's Web Page

Slides:



Advertisements
Similar presentations
Programming with OpenGL - Getting started - Hanyang University Han Jae-Hyek.
Advertisements

Chapter 2: Graphics Programming
Computer Graphics CSCE 441
Pemrograman OpenGL Dasar
CS 4731 Lecture 2: Intro to 2D, 3D, OpenGL and GLUT (Part I) Emmanuel Agu.
OpenGL (Graphics Library) Software Interface to graphics software Allows to create interactive programs that produce color images of moving 3D 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,
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Programming with OpenGL Part 1: Background Ed Angel Professor of Computer Science, Electrical.
OpenGL and Projections
30/1/2006Based on: Angel (4th Edition) & Akeine-Möller & Haines (2nd Edition)1 CSC345: Advanced Graphics & Virtual Environments Lecture 1: Introduction.
Programming with OpenGL Part 0: 3D API March 1, 2007.
Interactive 3D Graphics and Virtual Reality Introduction to OpenGL concepts Session 2.
Programming with OpenGL Part 1: Background Mohan Sridharan Based on slides created by Edward Angel CS4395: Computer Graphics 1.
Development of Interactive 3D Virtual World Applications
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.
Chapter 03: Graphics Primitives Course web page: Chapter #3.
OpenGL A Brief Overview. What is OpenGL?  It is NOT a programming language.  It is a Graphics Rendering API consisting of a set of function with a well.
Reference1. [OpenGL course slides by Rasmus Stenholt]
Computer Graphics Bing-Yu Chen National Taiwan University.
Using OpenGL. 2 What is OpenGL? A software interface to graphics hardware It is a Graphics Rendering API (Application Programmer’s Interface) that is.
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.
CSC 461: Lecture 41 CSC461: Lecture 4 Introduction to OpenGL Objectives: Development of the OpenGL API OpenGL Architecture -- OpenGL as a state machine.
Graphics Architectures & OpenGL API Introduction Angel Angel: Interactive Computer Graphics5E © Addison-Wesley
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.
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Programming with OpenGL Part 1: Background Ed Angel Professor of Computer Science, Electrical.
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Programming with OpenGL Part 1: Background Ed Angel Professor of Computer Science, Electrical.
Introduction to OpenGL 1. 2 OpenGL A Graphics rendering API introduced in 1992 by Silicon Graphics Inc Provide the low-level functions to access graphics.
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.
Computing & Information Sciences Kansas State University CIS 536/636 Introduction to Computer Graphics Lecture 4 of 41 William H. Hsu Department of Computing.
OpenGL: Introduction Yanci Zhang Game Programming Practice.
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.
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.
Viewing and Transformation. Pixel pipeline Vertex pipeline Course Map Transformation & Lighting Primitive assembly Viewport culling & clipping Texture.
Chun-Yuan Lin Introduction to OpenGL 2015/12/19 1 CG.
NoufNaief.net TA: Nouf Al-harbi.
Chap 3 Viewing and Transformation
CSCE 441: Computer Graphics
Introduction to OpenGL Programming
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 Graphics Programming. Graphics API.
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: 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
Introduction to OpenGL (IDE: Eclipse)
The Human Visual System vs The Pinhole camera
Programming with OpenGL Part 1: Background
Programming with OpenGL Part 1: Background
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
OpenGL (Open Graphics Library) Mr. B.A.Swamy Assistant Professor Dept of CSE.
גרפיקה ממוחשבת: מבוא ל-OpenGL
Programming with OpenGL Part 1: Background
Introduction to OpenGL
Programming with OpenGL Part 2: Complete Programs
Programming with OpenGL Part 2: Complete Programs
Programming with OpenGL Part 1: Background
Programming with OpenGL Part 2: Complete Programs
Presentation transcript:

CSE 494/598 Intro to Applied Computer Graphics Anshuman Razdan DCST AR's Web Page AR's Web Page

Anshuman Razdan based on Peter Wonka's Slides 2 Disclaimer These slides can only be used as study material for the at ASU The slides cannot be distributed or used for another purpose The slides may contain errors

OpenGL Part 1 Introduction to OpenGL and GLUT: Part I

Anshuman Razdan based on Peter Wonka's Slides 4 What Is OpenGL? high-quality color images composed of geometric and image primitives window system independent operating system independent No high-level commands for describing models of three-dimensional objects The OpenGL Utility Library (GLU) provides many of the modeling features, such as quadric surfaces and NURBS curves and surfaces Graphics rendering API

Anshuman Razdan based on Peter Wonka's Slides 5 Some History Web site: OpenGL is a registered trademark, owned by Silicon Graphics (SGI) OpenGL is controlled by the “ARB: Architecture Review Board”. Members include SGI, Microsoft, HP, IBM, ATI, apple, Intel … 1977, Jim Clark writes –LDS for E&S Multi Picture System 1990, OpenGL development begins 1992, OpenGL 1.0 completed, OpenGL course at SIGGRAPH’92 OpenGL 1.1(1995); OpenGL 1.2 (1998) … Today: OpenGL 2.0

Anshuman Razdan based on Peter Wonka's Slides 6 OpenGL Libraries OpenGL core library (GL) OpenGL32 on Windows GL on most UNIX / LINUX systems (libGL.a) OpenGL Utility Library (GLU) #include Provides functionality in OpenGL core but avoids having to rewrite code OpenGL Utility Toolkit (GLUT) #include Provides functionality common to all window systems Open a window Get input from mouse and keyboard Menus Event-driven Code is portable but GLUT lacks the functionality of a good toolkit for a specific platform

Anshuman Razdan based on Peter Wonka's Slides 7 OpenGL and Related APIs GLUT GLU GL GLX, AGL or WGL X, Win32, Mac O/S software and/or hardware application program OpenGL Motif widget or similar

Anshuman Razdan based on Peter Wonka's Slides 8 OpenGL as a Render Geometric primitives points, lines and polygons Image Primitives images and bitmaps separate pipeline for images and geometry linked through texture mapping Rendering depends on state colors, materials, light sources, etc.

Anshuman Razdan based on Peter Wonka's Slides 9 OpenGL Syntax functions have prefix gl and initial capital letters for each word glClearColor(), glEnable(), glPushMatrix() … glu for GLU functions gluLookAt(), gluPerspective() … constants begin with GL_, use all capital letters GL_COLOR_BUFFER_BIT, GL_PROJECTION, GL_MODELVIEW … Extra letters in some commands indicate the number and type of variables glColor3f(), glVertex3f() … OpenGL data types GLfloat, GLdouble, GLint, GLenum, …

Anshuman Razdan based on Peter Wonka's Slides 10 OpenGL Geometric Primitives All geometric primitives are specified by vertices, and put between the construct glBegin(mode) and glEnd(). GL_QUAD_STRIP GL_POLYGON GL_TRIANGLE_STRIP GL_TRIANGLE_FAN GL_POINTS GL_LINES GL_LINE_LOOP GL_LINE_STRIP GL_TRIANGLES GL_QUADS

Anshuman Razdan based on Peter Wonka's Slides 11 OpenGL Function Format 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 )

Anshuman Razdan based on Peter Wonka's Slides 12 OpenGL Drawing Attributes Besides glVertex() commands, other attributes commands can also be used between glBegin() and glEnd(), e.g. glColor3f(). There are more drawing attributes than color Point size: glPointSize() Line width: glLinewidth() Dash or dotted line: glLineStipple() Polygon pattern: glPolygonStipple() …

Anshuman Razdan based on Peter Wonka's Slides 13 Simple Example

GLUT: OpenGL Utility Toolkit

Anshuman Razdan based on Peter Wonka's Slides 15 GLUT: OpenGL Utility Toolkit GLUT provide a portable API for creating window and interacting with I/O devices Application Structure Configure and open window Initialize OpenGL state Register input callback functions render resize input: keyboard, mouse, etc. Enter event processing loop

Anshuman Razdan based on Peter Wonka's Slides 16 Prequisites for GLUT Glut.h – in your include path Glut32.lib (for windows) in your library path Glut32.dll in system path For OpenGL calls Gl.h and glu.h (included by glut.h) Opengl32.lib and glu32.lib Opengl32.dll and glu32.dll

Anshuman Razdan based on Peter Wonka's Slides 17 GLUT Window Setup glutInit (&argc, argv) Glut initialization glutCreateWindow (“OpenGL Example”) Create a display window with a title glutDisplayFunc ( myDisplay ) Specify what the display window is to contain glutMainLoop () Activate the display window and its graphic content glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB | …) Set other initial options for the display window glutInitWindowPosition (int x, int y) & glutInitWindowSize (int width, int height ) An Initial display window location (top-left corner) and size

Anshuman Razdan based on Peter Wonka's Slides 18 Example I 500 (0.5,0.5) (-0.5,-0.5)

Anshuman Razdan based on Peter Wonka's Slides 19 main() Function int main(int argc, char** argv) { // glut init glutInit(&argc, argv); glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB); // actual window size glutInitWindowSize(500,500); // initial window location, top-left corner glutInitWindowPosition(0,0); // create window with title “simple” glutCreateWindow("simple"); // call mydisplay() function glutDisplayFunc(mydisplay); // call init() function init(); // main event loop, do not use exit() glutMainLoop(); }

Anshuman Razdan based on Peter Wonka's Slides 20 Init() Function void init() { glClearColor (0.0, 0.0, 0.0, 1.0); // black clear color, opaque window glColor3f(1.0, 1.0, 1.0); // white glMatrixMode (GL_PROJECTION); glLoadIdentity (); glOrtho2D(-1.0, 1.0, -1.0, 1.0); // screen size (-1.0,-1.0) to (1.0,1.0) }

Anshuman Razdan based on Peter Wonka's Slides 21 display() Function void mydisplay() { glClear(GL_COLOR_BUFFER_BIT); // clear the window glBegin(GL_POLYGON); // fill connected polygon glVertex2f(-0.5, -0.5); // vertices of the square glVertex2f(-0.5, 0.5); glVertex2f(0.5, 0.5); glVertex2f(0.5, -0.5); glEnd(); }

Anshuman Razdan based on Peter Wonka's Slides 22 Callbacks Virtually all interactive graphics programs are event driven Glut uses callbacks to handle events Windows system invokes a particular procedure when an event of particular type occurs. MOST IMPORTANT: display event Signaled when window first displays and whenever portions of the window reveals from blocking window glutDisplayFunc(void (*func)(void)) registers the display callback function

Anshuman Razdan based on Peter Wonka's Slides 23 More Callbacks glutReshapeFunc(void (*func)(int w, int h)) indicates what action should be taken when the window is resized. glutKeyboardFunc(void (*func)(unsigned char key, int x, int y)) glutMouseFunc(void (*func)(int button, int state, int x, int y)) allow you to link a keyboard key or a mouse button with a routine that's invoked when the key or mouse button is pressed or released. glutMotionFunc(void (*func)(int x, int y)) registers a routine to call back when the mouse is moved while a mouse button is also pressed. glutIdleFunc(void (*func)(void)) registers a function that's to be executed if no other events are pending – use for animation or continuous update

Projection and Viewport

Anshuman Razdan based on Peter Wonka's Slides 25 Projection and Clipping Window

Anshuman Razdan based on Peter Wonka's Slides 26 Viewing – The Camera Analogy Position the camera ( Viewing transformation) Arrange the scene to a desired composition (Modeling transformation) Choose the lens and zoom ( Projection transformation) Determine the size of the photograph (Viewport transformation)

Anshuman Razdan based on Peter Wonka's Slides 27 Stages of Vertex Transformation

Anshuman Razdan based on Peter Wonka's Slides 28 Viewing/Modeling Transformation Projection transformations adjust the lens of the camera Viewing transformations tripod–define position and orientation of the viewing volume in the world Modeling transformations moving the model Viewport transformations enlarge or reduce the physical photograph

Anshuman Razdan based on Peter Wonka's Slides 29 Matrix Stack Specify Current Matrix Stack glMatrixMode( GL_MODELVIEW or GL_PROJECTION ) Other Matrix or Stack OperationsglLoadIdentity()glPushMatrix()glPopMatrix() Viewport usually same as window size viewport aspect ratio should be same as projection transformation or resulting image may be distorted glViewport( x, y, width, height )

Anshuman Razdan based on Peter Wonka's Slides 30 Viewing/Modeling Transformation Viewing transformation can be specified using the command gluLookAt ( eyex, eyey, eyez, atx, aty, atz, upx, upy, upz ) gluLookAt ( ) encapsulates a series of rotation and translation commands and is used. Modeling transformation can be specified using the commands glTranslate{f,d} (x, y, z) glRotate{f,d} (angle, x, y, z) glScale{f,d} (x, y, z)

Anshuman Razdan based on Peter Wonka's Slides 31 Thinking about Transformations Translation then rotationRotation then translation transformations should be specified in the reverse order.

Anshuman Razdan based on Peter Wonka's Slides 32 Projection Transformations Perspective projection Viewing volume is a truncated pyramid. Farther objects appear small and closer objects appear big. glFrustum (left, right, bottom, top, near, far) gluPerspective (fov, aspectratio, near, far) These commands calculates the projection matrix and multiplies the current projection matrix by it. glFrustum ( ) gluPerspective( )

Anshuman Razdan based on Peter Wonka's Slides 33 Projection Transformations Orthographic Projection Viewing volume is a box. Objects appear same size irrespective of their distance from the camera. glOrtho (left, right, bottom, top, near, far) gluOrtho2D (left, right, bottom, top)