Open GL Programming Speaker: 彭任右 Date: 2005/10/3.

Slides:



Advertisements
Similar presentations
02/17/05CISC640/440 OpenGL Tutorial1 OpenGL Tutorial CISC 640/440 Computer Graphics TA: Qi Li/Mani Thomas
Advertisements

When click!! (void) glRenderMode (GL_SELECT); glInitNames(); glPushName(0); glMatrixMode (GL_PROJECTION); glPushMatrix (); glLoadIdentity (); gluPickMatrix.
Chapter 12 Interactive Graphics Chih-Kuo Yeh. Direct Manipulation Demo.
OpenGL (Graphics Library) Software Interface to graphics software Allows to create interactive programs that produce color images of moving 3D objects.
What is OpenGL The OpenGL graphics system is a software interface to graphics hardware. (The GL stands for Graphics Library.) It allows you to create interactive.
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Programming with OpenGL Part 2: Complete Programs Ed Angel Professor of Computer Science,
Computer Graphics (Fall 2003) COMS 4160, Lecture 6: OpenGL 2 Ravi Ramamoorthi Many slides courtesy Greg Humphreys.
Interactive 3D Graphics and Virtual Reality Introduction to OpenGL concepts Session 2.
CSE 494/598 Intro to Applied Computer Graphics Anshuman Razdan DCST AR's Web Page AR's Web Page
OpenGL (II). How to Draw a 3-D object on Screen?
CS 4731: Computer Graphics Lecture 11: 3D Viewing Emmanuel Agu.
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.
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]
CS380 LAB I OpenGL Donghyuk Kim Reference1. [OpenGL course slides by Rasmus Stenholt] Reference2. [
19/4/ :32 Graphics II Syllabus Selection and Picking Session 1.
3D coordinate systems X Y Z Right-Hand Coordinate System X Y Z Left-Hand Coordinate System OpenGL uses this! Direct3D uses this!
1 OpenGL Basics A Graphics Standard ©Mel Slater, Anthony Steed
Using OpenGL. 2 What is OpenGL? A software interface to graphics hardware It is a Graphics Rendering API (Application Programmer’s Interface) that is.
Korea University Korea University Computer Graphics Laboratory Computer Graphics Laboratory Jung Lee, Chapter 13.
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,
Computer Graphics Bing-Yu Chen National Taiwan University.
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.
OpenGL Selection. Three Selection Methods Color coding (OpenGL) Selection mode (OpenGL) Selection ray (generic)
OpenGL Color and Lighting 2003 Spring Keng Shih-Ling.
Computer Graphics Bing-Yu Chen National Taiwan University.
OpenGL Viewing and Modeling Transformation Geb Thomas Adapted from the OpenGL Programming Guidethe OpenGL Programming Guide.
Viewing and Transformation. Pixel pipeline Vertex pipeline Course Map Transformation & Lighting Primitive assembly Viewport culling & clipping Texture.
Chapters 5 2 March Classical & Computer Viewing Same elements –objects –viewer –projectors –projection plane.
CGGM Lab. Tan-Chi Ho 2001 Viewing and Transformation.
Computing & Information Sciences Kansas State University CG Basics 3 of 8: OpenGL Primer 1 CIS 636/736: (Introduction to) Computer Graphics CIS 636 Introduction.
Chap 3 Viewing and Transformation
1 Programming with OpenGL Part 2: Complete Programs.
OpenGL API 2D Graphic Primitives Angel Angel: Interactive Computer Graphics5E © Addison-Wesley
CS559: Computer Graphics Lecture 12: OpenGL - Transformation Li Zhang Spring 2008.
CS559: Computer Graphics Lecture 12: OpenGL: ModelView Li Zhang Spring 2010.
OpenGL: Introduction #include main() { OpenWindow() ; glClearColor(0.0, 0.0, 0.0, 0.0); glClear(GL_COLOR_BUFFER_BIT); glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0,
OpenGL Basic Drawing Jian-Liang Lin A Smidgen of OpenGL Code #include main() { InitializeAWindowPlease(); glClearColor (0.0, 0.0, 0.0, 0.0); glClear.
2002 by Jim X. Chen: Drawing Geometric Models.1. Objectives –OpenGL drawing primitives and attributes –OpenGL polygon face.
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.
Introduction to Graphics Programming. Graphics API.
Introduction to OpenGL (INF 250) Veronika Solteszova et al., UiB Dept. of Informatics,
Computer Graphics I, Fall Programming with OpenGL Part 2: Complete Programs.
OpenGL LAB III.
CS380 LAB II OpenGL Donghyuk Kim Reference1. [OpenGL course slides by Rasmus Stenholt] Reference2. [
Computer Graphics Lecture 34. OpenGL Programming II Taqdees A. Siddiqi
OpenGL Programming Guide Chapter 2 Korea Univ. Graphics Labs. Ji Jun Yong Korea Univ. Graphics Labs. Ji Jun Yong.
Program Studi S-1 Teknik Informatika FMIPA Universitas Padjadjaran
CSC Graphics Programming
The Human Visual System vs The Pinhole camera
Reference1. [OpenGL course slides by Rasmus Stenholt]
“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
OpenGL (Open Graphics Library) Mr. B.A.Swamy Assistant Professor Dept of CSE.
Lab 3 Geometric Drawing Lab 3 Geometric Drawing.
Objectives OpenGL drawing primitives and attributes
Lecture 08 and 09 View & Projection
OpenGL program.
Programming with OpenGL Part 2: Complete Programs
Programming with OpenGL Part 2: Complete Programs
Computer Graphics 3Practical Lesson
Chapter 3 Viewing.
Picking in OpenGL Yingcai Xiao.
Programming with OpenGL Part 2: Complete Programs
Presentation transcript:

Open GL Programming Speaker: 彭任右 Date: 2005/10/3

Coordinate System World Window (0,0) (w,h) x x y y z+ left handedright handed (0,0) (w,h) View Port

OpenGL Color Models RGBA or Color Index color index mode Display  RedGreenBlue  RGBA mode

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 )

Buffers Color Buffer Depth Buffer Stencil Buffer Accumulation Buffer Selection Buffer

State Machine Set State –glPointSize(size); –glLineWidth(width); –glLineStipple(repeat, pattern); –glShadeModel(GL_SMOOTH); Get State –glGet*(); Enable Features –glEnable(GL_LIGHTING); –glDisable(GL_TEXTURE_2D); –glIsEnable(GL_DEPTH_TEST);

Framework Clear the window Set the Viewing, Projection, and Viewport transformation Loop for each primitive –Modeling Transformation –Specify the primitive type, attributes, and rendering states Flush or Swap buffer

Clearing the Window glClearColor(red, green, blue, alpha);glClearColor(red, green, blue, alpha); –From 0.0f to 1.0f glClearDepth(1.0f);glClearDepth(1.0f); glClear();glClear(); –glClear(GL_COLOR_BUFFER_BIT); –glClear(GL_DEPTH_BUFFER_BIT); –Use the logical or ( | ) to combine

Specifying a Color glColor3f() –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, 0.0, 0.0) – magenta –glColor3f(0.0, 1.0, 1.0) – cyan –glColor3f(1.0, 1.0, 1.0) – White

MVPV

Matrix Operation glMatrixMode() –GL_PROJECTION –GL_MODELVIEW –GL_TEXTURE glLoadIdentity() glLoadMatrix() glMultMatrix() glPushMatrix() glPopMatrix()

Matrix Multiplication glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glMultMatrix(N); glMultMatrix(M); glMultMatrix(L); glBegin(GL_POINTS); glVertex3f(v); glEnd(); The vertex transformation is N(M(Lv))

Modeling Transformation Move object glTranslate{234}{fd}( x, y, z ) Rotate object around arbitrary axis glRotate{234}{fd}( angle, x, y, z ) –angle is in degrees Stretch, shrink, or mirror object glScale{234}{fd}( x, y, z )

Transformation Tutorial

Viewing Transformation Position the camera/eye in the scene –gluLookAt( posx, posy, posz, viewx, viewy, viewz, upx, upy, upz);

Projection Transformation Orthogonal Projection Perspective Projection

Orthogonal Projection glOrtho(left, right, bottom, top, near far); gluOrtho2D( left, right, bottom, top )

Perspective Projection glFrustum(left, right, bottom, top, zNear, zFar); gluPerspective (fovy, aspect, zNear, zFar);

Projection Tutorial

Viewport Transformation View Port –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); (0,0) (x,y) width height

OpenGL Geometric Primitives All geometric primitives are specified by vertices 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

Shapes Tutorial

Drawing Primitives glBegin(GLenum mode);glBegin(GLenum mode); glColor*();glColor*(); glVertex*();glVertex*(); glEnd();glEnd();

glShadeModel() glShadeModel(GLenum mode);glShadeModel(GLenum mode); –Flat Shading GL_FLAT –Smooth Shading GL_SMOOTH

glPolygonMode() glPolygonMode(face, mode);glPolygonMode(face, mode); –GLenum face GL_FRONT GL_BACK –GLenum mode GL_POINT GL_LINE (hint: wireframe) GL_FILL

Depth –think as distance from view point Depthe Test –glEnable(GL_DEPTH_TEST); –If we draw rectangle first, the ellipse will cove the rectangle when the depth test is closed. Z = 1.0 Z = 2.0 Without Depth Test Z = 1.0 Z = 2.0 With Depth Test x y z+ left handed

Culling glFrontFace(GLenum mode);glFrontFace(GLenum mode); –GL_CW –GL_CCW glCullFace(GLenum mode);glCullFace(GLenum mode); –GL_FRONT –GL_BACK –GL_FRONT_AND_BACK glEnable(GL_CULL_FACE);glEnable(GL_CULL_FACE); Counterclockwise winding (Front facing)

Force Completion of Drawing Win32Win32 –SwapBuffers(hDC); GLUTGLUT –glutSwapBuffer();

glRenderMode() GLint glRenderMode(GLenum mode);GLint glRenderMode(GLenum mode); –GL_RENDER –GL_SELECTION –GL_FEEDBACK

Selection Mode Method to determine which primitives are inside the viewing volume Select selection mode for rendering –glRenderMode(GL_SELECT);

Selection Buffer glSelectBuffer(GLsizei size, GLuint *buffer);glSelectBuffer(GLsizei size, GLuint *buffer); 4 elements per hit –# of names on names stack –Z Min –Z Max –Bottom of names stack

Names Stack To identify a primitive, give it a name –“ names ” are just integer values, not strings Names are stack based –allows for hierarchies of primitives –glInitNames(); –glPushName(); –glPopName(); –glLoadName();

Sample void RenderScene() { // “ set the rendering states glInitNames(); glLoadName(1); “ draw something ” glLoadName(2); // draw something else … continue }

Picking gluPickMatrix(x, y, width, height, viewport); –x, y should be set as x Mouse and y Mouse glGetIntegerv(GL_VIEWPORT, viewport);

Sample void pick(xPos, yPos) { glSelectBuffer(LENGTH, selectBuff); glMatrixMode(GL_PROJECTION); glRenderMode(GL_SELECTION); glLoadIdentity(); gluPickMatrix(x, y, 2, 2, viewport); gluPerspective(fovy, aspect, near, far); RenderScene(); hits = glRenderMode(GL_RENDER); Cout << we pick << selectBuff[3] << object; }