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.

Slides:



Advertisements
Similar presentations
Computer Graphics - Viewing -
Advertisements

02/17/05CISC640/440 OpenGL Tutorial1 OpenGL Tutorial CISC 640/440 Computer Graphics TA: Qi Li/Mani Thomas
Based on slides created by Edward Angel
Viewing and Transformation
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Computer Viewing Ed Angel Professor of Computer Science, Electrical and Computer Engineering,
OpenGL and Projections
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?
Introduction to OpenGL Pipeline From Programmer View Tong-Yee Lee.
Noggin (BYU Students, SIGGRAPH 2006). Introduction to OpenGL Programming Rick Skarbez, Instructor COMP 575 September 11, 2007.
3D Rendering with JOGL Introduction to Java OpenGL Graphic Library By Ricardo Veguilla
Introduction to OpenGL M. Ramanathan STTP CAD 2011Introduction to OpenGL.
Introduction to OpenGL Keng Shih-Ling 2003 Spring.
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.
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
Computer Graphics, KKU. Lecture 131 Transformation and Viewing in OpenGL.
OpenGL Matrices and Transformations Angel, Chapter 3 slides from AW, Red Book, etc. CSCI 6360.
The Viewing Pipeline (Chapter 4) 5/26/ Overview OpenGL viewing pipeline: OpenGL viewing pipeline: – Modelview matrix – Projection matrix Parallel.
Geometric transformations The Pipeline
Stages of Vertex Transformation To specify viewing, modeling, and projection transformations, you construct a 4 × 4 matrix M, which is then multiplied.
Computer Graphics Bing-Yu Chen National Taiwan University.
Computer Graphics I, Fall 2010 Computer Viewing.
Modeling with OpenGL Practice with OpenGL transformations.
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.
Intro to OpenGL Transformations CS 445/645 Introduction to Computer Graphics David Luebke, Spring 2003.
OpenGL Viewing and Modeling Transformation Geb Thomas Adapted from the OpenGL Programming Guidethe OpenGL Programming Guide.
Graphics Graphics Korea University kucg.korea.ac.kr Viewing 고려대학교 컴퓨터 그래픽스 연구실.
Viewing and Transformation. Pixel pipeline Vertex pipeline Course Map Transformation & Lighting Primitive assembly Viewport culling & clipping Texture.
CA 302 Computer Graphics and Visual Programming Lecture 2: Introduction to OpenGL Aydın Öztürk
The Camera Analogy ► Set up your tripod and point the camera at the scene (viewing transformation) ► Arrange the scene to be photographed into the desired.
Chapters 5 2 March Classical & Computer Viewing Same elements –objects –viewer –projectors –projection plane.
CGGM Lab. Tan-Chi Ho 2001 Viewing and Transformation.
Projections. Viewports Windows can have separate viewports void glViewport(GLint x, GLint y, GLsizei width, GLsizei height ) x, y - Specify the lower.
CGGM Lab. Tan-Chi Ho Introduction to OpenGL.
OpenGL: The Open Graphics Language Introduction By Ricardo Veguilla.
Introduction to OpenGL & HW1 Announcement 劉軒銘, 網媒所 碩二 ICG 2012 Fall.
Viewing Korea Univ. Computer Graphics Lab. Hong, Jin Kyung.
Lecture 2: Introduction to OpenGL
Chap 3 Viewing and Transformation
CS559: Computer Graphics Lecture 11: Antialiasing & Visibility, Intro to OpenGL Li Zhang Spring 2010.
Chap 2 Write a Simple OpenGL Program. Preparing 1/2 environment : Microsoft Visual C 、 Microsoft Visual C++.Net Also need : GLUT
CS559: Computer Graphics Lecture 12: OpenGL - Transformation Li Zhang Spring 2008.
CS559: Computer Graphics Lecture 12: OpenGL: ModelView Li Zhang Spring 2010.
1 Geometric Transformations-II Modelling Transforms By Dr.Ureerat Suksawatchon.
Introduction to OpenGL Muhammad Aamir Khan Lecturer, DCS, UOP.
Introduction to Graphics Programming. Graphics API.
Implement of transformation,projection, viewing Hanyang University Jungsik Park.
CSC Graphics Programming Budditha Hettige Department of Statistics and Computer Science.
OpenGL LAB III.
CS380 LAB II OpenGL Donghyuk Kim Reference1. [OpenGL course slides by Rasmus Stenholt] Reference2. [
OpenGL: The Open Graphics Language Technology and Historical Overview By Ricardo Veguilla.
CSC Graphic Programming Lecture 2 OpenGL Lightning.
CSC Graphics Programming
Viewing 고려대학교 컴퓨터 그래픽스 연구실 kucg.korea.ac.kr.
Viewing.
Transformations Introduction to Computer Graphics and Animation
Computer Viewing.
Isaac Gang University of Mary Hardin-Baylor
Reference1. [OpenGL course slides by Rasmus Stenholt]
Advanced Graphics Algorithms Ying Zhu Georgia State University
Lecture 08 and 09 View & Projection
Computer Graphics, KKU. Lecture 13
Chapter 4/5 glMatrixMode Modeling Transformations glTranslate glScale
Type of View Perspective View COP(Center of Plane) Diminution of size
University of New Mexico
Computer Graphics 3Practical Lesson
Chapter 3 Viewing.
Presentation transcript:

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 hardware directly Cross-platform 3

Related API GLU (OpenGL Utility Library) –Part of OpenGL –Use the prefix of glu (ex: gluLookAt()) GLUT (OpenGL Utility Toolkit) –Not officially part of OpenGL –hide the complexities of differing window system APIs. –Use the prefix of glut (ex: glutDisplayFunc()) 4

OpenGL Utility Toolkit (GLUT) Visual C++ – –glut32.dll to %WinDir%\System, –glut32.lib to $(MSDevDir)\..\..\VC\lib –glut.h to $(MSDevDir)\..\..\VC\include\GL. 5

A Simple Example #include void GL_display(); void GL_reshape(GLsizei w, GLsizei h); void main(void) { glutCreateWindow("Sample"); glutDisplayFunc(GL_display); glutReshapeFunc(GL_reshape); glutMainLoop(); } 6

A Simple Example void GL_display() { glClearColor(0.0f, 0.0f, 0.0f, 0.0f); glClear(GL_COLOR_BUFFER_BIT); glBegin( GL_LINES ); glColor3f(0.0f, 1.0f, 0.0f); glVertex3f(1.0, 1.0, 0.0); glVertex3f(-1.0, -1.0, 0.0); glColor3f(1.0f, 0.0f, 0.0f); glVertex3f(-1.0, 1.0, 0.0); glVertex3f(1.0, -1.0, 0.0); glEnd(); glFlush(); } 7

A Simple Example void GL_display() { glClearColor(0.0f, 0.0f, 0.0f, 0.0f); glClear(GL_COLOR_BUFFER_BIT); glBegin( GL_LINES ); glColor3f(0.0f, 1.0f, 0.0f); glVertex3f(1.0, 1.0, 0.0); glVertex3f(-1.0, -1.0, 0.0); glColor3f(1.0f, 0.0f, 0.0f); glVertex3f(-1.0, 1.0, 0.0); glVertex3f(1.0, -1.0, 0.0); glEnd(); glFlush(); } Color BufferDepth Buffer 8

A Simple Example void GL_display() { glClearColor(0.0f, 0.0f, 0.0f, 0.0f); glClear(GL_COLOR_BUFFER_BIT); glBegin( GL_LINES ); glColor3f(0.0f, 1.0f, 0.0f); glVertex3f(1.0, 1.0, 0.0); glVertex3f(-1.0, -1.0, 0.0); glColor3f(1.0f, 0.0f, 0.0f); glVertex3f(-1.0, 1.0, 0.0); glVertex3f(1.0, -1.0, 0.0); glEnd(); glFlush(); } 9

Primitives 10

A Simple Example void GL_display() { glClearColor(0.0f, 0.0f, 0.0f, 0.0f); glClear(GL_COLOR_BUFFER_BIT); glBegin( GL_LINES ); glColor3f(0.0f, 1.0f, 0.0f); glVertex3f(1.0, 1.0, 0.0); glVertex3f(-1.0, -1.0, 0.0); glColor3f(1.0f, 0.0f, 0.0f); glVertex3f(-1.0, 1.0, 0.0); glVertex3f(1.0, -1.0, 0.0); glEnd(); glFlush(); } 11

OpenGL as a State Machine Put a value into various states, then it will remain in effect until being changed. –e.g. glColor*() Many state variables are enabled or disabled with glEnable(), glDisable() –e.g. glEnable(GL_LIGHT0) 12

A Simple Example void GL_display() { glClearColor(0.0f, 0.0f, 0.0f, 0.0f); glClear(GL_COLOR_BUFFER_BIT); glBegin( GL_LINES ); glColor3f(0.0f, 1.0f, 0.0f); glVertex3f(1.0, 1.0, 0.0); glVertex3f(-1.0, -1.0, 0.0); glColor3f(1.0f, 0.0f, 0.0f); glVertex3f(-1.0, 1.0, 0.0); glVertex3f(1.0, -1.0, 0.0); glEnd(); glFlush(); } 13

Command Syntax glVertex3f( 1.0, 1.0, 0.0 ); OpenGL API Name The number and types of arguments Data TypeC-Language TypeOpenGL Type Definition b8-bit integersigned charGLbyte s16-bit integershortGLshort i32-bit integerlongGLint, GLsizei f32-bit floating-pointfloatGLfloat, GLclampf d64-bit floating-pointdoubleGLdouble, GLclampd ub8-bit unsigned integerunsigned charGLubyte, GLboolean us16-bit unsigned integerunsigned shortGLushort ui32-bit unsigned integerunsigned longGLuint, GLenum, GLbitfield 14

A Simple Example void GL_display() { glClearColor(0.0f, 0.0f, 0.0f, 0.0f); glClear(GL_COLOR_BUFFER_BIT); glBegin( GL_LINES ); glColor3f(0.0f, 1.0f, 0.0f); glVertex3f(1.0, 1.0, 0.0); glVertex3f(-1.0, -1.0, 0.0); glColor3f(1.0f, 0.0f, 0.0f); glVertex3f(-1.0, 1.0, 0.0); glVertex3f(1.0, -1.0, 0.0); glEnd(); glFlush(); } 15

A Simple Example void GL_reshape(GLsizei w, GLsizei h) { glViewport(0, 0, w, h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(-2.0f, 2.0f, -2.0f, 2.0f, -2.0f, 2.0f); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); } 16

A Simple Example void GL_reshape(GLsizei w, GLsizei h) { glViewport(0, 0, w, h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(-2.0f, 2.0f, -2.0f, 2.0f, -2.0f, 2.0f); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); } 17

A Simple Example void GL_reshape(GLsizei w, GLsizei h) { glViewport(0, 0, w, h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(-2.0f, 2.0f, -2.0f, 2.0f, -2.0f, 2.0f); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); } 18

Matrix in OpenGL There are two matrix stacks. –ModelView matrix (GL_MODELVIEW) –Projection matrix (GL_PROJECTION) When we call functions of transformation, we should change to the appropriate matrix stack first. glMatrixMode(GL_MODELVIEW); //now we are in modelview matrix stack! //do modelview transformation here….. glMatrixMode(GL_PROJECTION); //now we are in projection matrix stack! //do projection transformation here…. 19

ModelView Matrix Modeling Transformation Perform rotate, translate, scale and combinations of these transformations to the object. Viewing Transformation To positioning and aiming the camera 20

Modeling Transformations glTranslate{fd}(x, y, z) –Multiplies current matrix by a matrix that moves an object by x,y,z glTranslatef( 0, 0, -1 ) 21

Modeling Transformations glRotate{fd}(angle, x, y, z ) –Multiplies current matrix by a matrix that rotates an object in a counterclockwise direction about the ray from origin to (x,y,z) with angle as the degrees glRotatef( 45.0, 0, 0, 1) 22

Modeling Transformations glScale{fd} (x, y, z) –Multiplies current matrix by a matrix that scales an object along axes. glScalef( 2.0, -0.5, 1.0 ) 23

Viewing Transformations gluLookAt (eyex, eyey, eyez, atx, aty, atz, upx, upy, upz ); 24

Matrix in OpenGL Matrix multiplications always apply to the top of matrix stack. Top matrix In the stack Translation matrix (glTranslatef) X 25

Matrix in OpenGL The order of transformations is critical. 26 glTranslatef( 1,0,0 ); glRotatef(45.0, 0,0,1 ); drawObject(); glRotatef(45.0, 0,0,1 ); glTranslatef( 1,0,0 ); drawObject();

Projection Transformations Orthographic Projection glOrtho( GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble near, GLdouble far ) gluOrtho2D( GLdouble left, GLdouble right, GLdouble bottom, GLdouble top) 27

Projection Transformations Perspective Projection –gluPerspective( GLdouble fovy, GLdouble aspect, GLdouble near, GLdouble far ); 28

Projection Transformations Perspective Projection –glFrustum( GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble near, GLdouble far ); 29

A Simple Example void GL_reshape(GLsizei w, GLsizei h) { glViewport(0, 0, w, h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(-2.0f, 2.0f, -2.0f, 2.0f, -2.0f, 2.0f); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); } 30

OpenGL Transformations 31 Modelview Matrix Modelview Matrix Viewport Transformation Viewport Transformation Projection Matrix Projection Matrix Perspective Division eye coordinates clip coordinates normalized device coordinates window coordinates XYZWXYZW Vertex XYXY glTranslatef glRotatef glScalf gluLookAt gluPerspective gluOrtho2D glFrustum glOrtho glViewport()

Matrix in OpenGL Mantain matrix stack –glPushMatrix() : used to save current stack –glPopMatrix() : used to restore previous stack glPushMatirx() x glScalef glPopMatrix() 32

Matrix in OpenGL glPushMatrix(); glTranslatef (-1.0, 0.0, 0.0); glRotatef ((GLfloat) shoulder, 0.0, 0.0, 1.0); glTranslatef (1.0, 0.0, 0.0); glPushMatrix(); glScalef (2.0, 0.4, 1.0); glutWireCube (1.0); glPopMatrix(); glPushMatrix(); glTranslatef (1.0, 0.0, 0.0); glRotatef ((GLfloat) elbow, 0.0, 0.0, 1.0); glTranslatef (1.0, 0.0, 0.0); glPushMatrix(); glScalef (2.0, 0.4, 1.0); glutWireCube (1.0); glPopMatrix(); 33

Matrix in OpenGL Reference: Object Hierarchy – e1267.asphttp:// e1267.asp 34

References OpenGL officially website: – NeHe (useful installation guides included) – Nate Robins (for demonstration) – The Red Book (OpenGL Programming Guide) 35