Introduction to OpenGL & HW1 Announcement 劉軒銘, 網媒所 碩二 ICG 2012 Fall.

Slides:



Advertisements
Similar presentations
School of Computer Science University of Seoul. How can we create a window? How can we handle the events? What kind of objects can we render? How can.
Advertisements

Chapter 2: Graphics Programming
Hwk1- A Tutorial of OPENGL ver2.0. We will introduce… Draw a window by OpenGL Draw one/many polygons by OpenGL Rotate/Translate Matrix Push/PopMatrix.
What is OpenGL? Low level 2D and 3D Graphics Library Competitor to Direct3D (the rendering part of DirectX) Used in: CAD, virtual reality, scientific.
Computer Graphics (Fall 2008) COMS 4160, Lecture 9: OpenGL 1
Draw a Simple Object. Example 1/4 #include “ glut.h ” void display(); void reshape(GLsizei w, GLsizei h); void main(int argc, char** argv){ glutInit(&argc,
OpenGL and Projections
Objectives Learn to build arbitrary transformation matrices from simple transformations Learn to build arbitrary transformation matrices from simple transformations.
Computer Graphics (Fall 2005) COMS 4160, Lecture 10: OpenGL 1
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2008 Tamara Munzner OpenGL, GLUT, Transformations.
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 OpenGL Transformations Ed Angel Professor of Computer Science, Electrical and Computer.
Introduction to OpenGL M. Ramanathan STTP CAD 2011Introduction to OpenGL.
Introduction to OpenGL Keng Shih-Ling 2003 Spring.
Write a Simple Program with OpenGL & GLUT. Books and Web Books OpenGL Programming Guide (Red-book) OpenGL Reference Manual (Blue-book) OpenGL Super Bible.
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. [
Using Graphics Libraries Lecture 3 Mon, Sep 1, 2003.
CAP4730: Computational Structures in Computer Graphics Introduction to OpenGL.
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.
Write a Simple Program with OpenGL & GLUT. Books OpenGL Programming Guide (Red-book) OpenGL Reference Manual (Blue-book) OpenGL Super Bible
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 Figures are extracted from Angel's book (ISBN x) The Human Visual System vs The Pinhole camera Human Visual System Visible Spectrum Pinhole.
CD2012 Principles of Interactive Graphics Lecture 01 Introduction Abir Hussain (Rome: 6.33,Tel , Web:
Introduction to GL Geb Thomas. Example Code int main(int argc, char **argv) { glutInit(&argc, argv); glutInitDisplayMode ( GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH);
Modeling with OpenGL Practice with OpenGL transformations.
Introduction to OpenGL and GLUT. What’s OpenGL? An Application Programming Interface (API) A low-level graphics programming API – Contains over 250 functions.
Draw a Simple Object. Pixel pipeline Vertex pipeline Course Map Transformation & Lighting Primitive assembly Viewport culling & clipping Texture blending.
Computer Graphics I, Fall 2010 OpenGL Transformations.
1 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 OpenGL Transformations.
Viewing and Transformation. Pixel pipeline Vertex pipeline Course Map Transformation & Lighting Primitive assembly Viewport culling & clipping Texture.
CGGM Lab. Tan-Chi Ho 2001 Viewing and Transformation.
NoufNaief.net TA: Nouf Al-harbi.
Transformations Angel Angel: Interactive Computer Graphics5E © Addison-Wesley
CGGM Lab. Tan-Chi Ho Introduction to OpenGL.
Doç. Dr. Cemil Öz SAÜ Bilgisayar Mühendisliği Dr. Cemil Öz.
Chap 3 Viewing and Transformation
OpenGL Basic Drawing 2003 Spring Keng Shih-Ling
Chap 2 Write a Simple OpenGL Program. Preparing 1/2 environment : Microsoft Visual C 、 Microsoft Visual C++.Net Also need : GLUT
1 OpenGL Transformations. 2 Objectives Learn how to carry out transformations in OpenGL ­Rotation ­Translation ­Scaling Introduce OpenGL matrix modes.
CS559: Computer Graphics Lecture 12: OpenGL - Transformation Li Zhang Spring 2008.
CS559: Computer Graphics Lecture 12: OpenGL: ModelView Li Zhang Spring 2010.
OpenGL Basic Drawing Jian-Liang Lin A Smidgen of OpenGL Code #include main() { InitializeAWindowPlease(); glClearColor (0.0, 0.0, 0.0, 0.0); glClear.
Introduction to OpenGL Muhammad Aamir Khan Lecturer, DCS, UOP.
Introduction to Graphics Programming. Graphics API.
Implement of transformation,projection, viewing Hanyang University Jungsik Park.
CS380 LAB II OpenGL Donghyuk Kim Reference1. [OpenGL course slides by Rasmus Stenholt] Reference2. [
INTRODUCTION TO OPENGL
Computer Graphics (Fall 2003) COMS 4160, Lecture 5: OpenGL 1 Ravi Ramamoorthi Many slides courtesy Greg Humphreys.
Computer Graphics -practical- Lecture 6. (visual c++) open gl library To use open GL with VC++ we add these files:- 1)Glut.h C:\program files\ Microsoft.
OpenGL Matrices and Transformations Angel, Chapter 3 slides from AW, Red Book, etc. CSCI 6360/4360.
CSC Graphics Programming
OpenGL Transformations
Jason Lawrence COS426 Precept Notes 2/16/04
OpenGL Transformations
Computer Graphics OpenGL Transformations
Reference1. [OpenGL course slides by Rasmus Stenholt]
Advanced Graphics Algorithms Ying Zhu Georgia State University
OpenGL (Open Graphics Library) Mr. B.A.Swamy Assistant Professor Dept of CSE.
גרפיקה ממוחשבת: מבוא ל-OpenGL
Computer Graphics, KKU. Lecture 13
Chapter 4/5 glMatrixMode Modeling Transformations glTranslate glScale
Introduction to OpenGL
Lecture 6 and 7 Transformations
OpenGL program.
Advanced Graphics Algorithms Ying Zhu Georgia State University
OpenGL Transformations
OpenGL Transformations
Presentation transcript:

Introduction to OpenGL & HW1 Announcement 劉軒銘, 網媒所 碩二 ICG 2012 Fall

Introduction to OpenGL & HW1 Announcement 劉軒銘, 網媒所 碩二 ICG 2012 Fall Introduction to openGL Coordinate system and transformations in openGL A simple sample Requirements of HW1 Others

Introduction to openGL A Graphics rendering API introduced in 1992 by Silicon Graphics Inc Now managed by Khronos Group Provide the API functions to access graphics hardware directly Cross-platform

Introduction to openGL 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())

World coordinates object coordinates Coordinate system

World coordinates Camera coordinates Coordinate system

World coordinates Camera coordinates Clip coordinates Coordinate system

Model-view transformati on Projection transformatio n Vertices World coordinates Camera coordinates Clip coordinates Vertices There are two matrix stacks. ◦ ModelView matrix (GL_MODELVIEW) ◦ Projection matrix (GL_PROJECTION) CTM

Coordinate system Model-view transformati on Projection transformatio n Vertices World coordinates Camera coordinates Clip coordinates Vertices 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…. When we call functions of transformation, we should change to the appropriate matrix stack first.

openGL as 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)

openGL as state machine glBegin(GL_LINES); R G B 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(); (1,1,0) (-1,-1,0) (-1,1,0) (1,-1,0)

openGL as state machine glLoadIdentity(); glTranslatef( distance,0, 0); glRotatef(angleX, 1.0, 0.0, 0.0); glRotatef(angleY, 0.0, 1.0, 0.0); glBegin(GL_QUADS); glVertex3f(-7, 7, 7); … glEnd(); (1,1,0) (-1,-1,0) (-1,1,0) (1,-1,0) Current Transformation matrix (CTM)

Matrix in OpenGL Mantain matrix stack ◦ glPushMatrix() : used to save current stack ◦ glPopMatrix() : used to restore previous stack glPushMatirx() x glRotatef glPopMatrix() 13

World coordinates glBegin(TYPE) glVertex3f(x,y,z) ……. glEnd() Coordinate system

Primitives

Transformations : Model-View glMatrixMode(GL_MODELVIEW) //Affine Transformation glRotatef(angle,direction) glTranslatef(displacement) glScalef(scale coefficients) glBegin(TYPE) glVertex3f(x,y,z) …………………. glEnd() World coordinates Camera coordinates V ’ <- [R][T][S] V

glMatrixMode(GL_MODELVIEW) gluLookAt({eye},{look at},{{up}) //Affine Transformation glBegin(TYPE) glVertex3f(v0) glEnd() World coordinates Camera coordinates Transformations : Model-View

glMatrixMode(GL_PROJECTION) //projection Transformation glOrtho(clipping volume) gluPerspective(fov,ciipping Volume) glFrustrum(clipping volume) glMatrixMode(GL_MODELVIEW) gluLookAt //Affine Transformation glBegin(TYPE) glVertex3f(v0) ……….. glEnd() World coordinates Camera coordinates Image coordinates Transformations : Projection

Notice!! Each affine and projective transformation is implemented as a matrix, the order of function calls plays an important role. glRotatef glTranslatef glScalef Code: glBegin glVertex3f …… glEnd Matrix multiplication gluLookAt glMatrixMode(GL_MODELVIEW) glMatrixMode(GL_PROJECTION) gluperspective = V gluLookAt glRotatef glTranslatef glScalef glVertex3f gluperspective

A Simple Example

#include int main(int argc, char** argv) { glutInit(&argc, argv); glutInitWindowSize(600, 800); glutInitWindowPosition(500, 500); glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE); glutCreateWindow("ICG simple"); glutReshapeFunc(GL_reshape); glutDisplayFunc(GL_display); glutMainLoop(); return 0; }

A Simple Example void GL_display() { glClearColor(0.0f, 0.0f, 0.0f, 0.0f); glClear(GL_COLOR_BUFFER_BIT); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); 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(); glutSwapBuffers(); }

A Simple Example void GL_display() { glClearColor(0.0f, 0.0f, 0.0f, 0.0f); glClear(GL_COLOR_BUFFER_BIT); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); 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(); glutSwapBuffers(); }

A Simple Example void GL_display() { glClearColor(0.0f, 0.0f, 0.0f, 0.0f); glClear(GL_COLOR_BUFFER_BIT); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); 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(); glutSwapBuffers(); }

A Simple Example void GL_display() { glClearColor(0.0f, 0.0f, 0.0f, 0.0f); glClear(GL_COLOR_BUFFER_BIT); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); 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(); glutSwapBuffers(); }

A Simple Example void GL_display() { glClearColor(0.0f, 0.0f, 0.0f, 0.0f); glClear(GL_COLOR_BUFFER_BIT); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); 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(); glutSwapBuffers(); }

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); }

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); }

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); }

A Simple Example #include void GL_reshape(GLsizei w, GLsizei h); void GL_display(); int main(int argc, char** argv) { glutInit(&argc, argv); glutInitWindowSize(600, 800); glutInitWindowPosition(500, 500); glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE); glutCreateWindow("ICG simple"); glutReshapeFunc(GL_reshape); glutDisplayFunc(GL_display); glutMainLoop(); return 0; } 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); } void GL_display() { glClearColor(0.0f, 0.0f, 0.0f, 0.0f); glClear(GL_COLOR_BUFFER_BIT); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); 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(); glutSwapBuffers(); }

Requirements of HW1 Due : 10/24 You are required to do the following in homework #1: (6 points ) 1. Load a 3D model file of TRI format. Draw it in wireframe mode and view it in perspective view.(2 pts) 2. Implement basic transformations such as rotation, translation, scaling and shearing.(3 pts) 3. Object rotation around x, y and z-axis.(4 pts) ** You have to make these transformation matrix by yourself in problem 2 and 3 ** glTranslate, glRotate, glScale are not allowed 4. Clipping implementation. Try to show the difference between clipping and non- clipping. (5 pts) ** glOrtho, gluPerspective and glFrustum are not allowed in problem 4 5. Bonus. Any kind of effort you made more than requirements above.(6 pts)

z x y screen at z = 0 clipping box is enclosed by: x = 1,x=-1,y=1,y=-1,z=1,z=-1 Notice!! How does openGL set its clipping volume for window?? Using homogeneous coordinates clipping box nonhomogeneous coordinate: x y z w, w =/= 1

z x y screen at z = 0 clipping box is enclosed by: x = 1,x=-1,y=1,y=-1,z=1,z=-1 Notice!! How does openGL set its clipping volume for window?? Using homogeneous coordinates clipping box homogeneous coordinate: x/w y/w z/w 1

Notice!! How does openGL set its clipping volume for window?? Using homogeneous image coordinates clipping box You’d better set your own homogeneous image coordinates clipping box different from openGL’s. ※ Here the homogeneous image coordinates clipping volume is different from the One described in textbook, which is refer to camera coordinates clipping volume.

Others Glut window functions: glutInit(&argc, argv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB); glutInitWindowSize(800, 600); glutInitWindowPosition(100, 100); glutCreateWindow(“Name"); glutDisplayFunc(display); glutReshapeFunc(reshape); glutKeyboardFunc(keyboard); glutMouseFunc(mouse); glutMainLoop();

Others Interactive setting: void keyboard(unsigned char key, int x, int y){ switch(key){ ……… case 'a': glClearColor(1., 1., 1., 1.); startPosX -= 10; glutPostRedisplay(); break; }

Others Interactive setting: void mouse(int button, int state, int x, int y){ static float preX, preY; switch(state){ case GLUT_DOWN: preX = x; preY = y; glutPostRedisplay(); break; ………………. }

Others Setting up openGL(visual C++): 1.download glut bin.zip or similar - GLUT for Win32 dll, lib and header file - there. 2.Make a directory called "GL" under C:\Program Files\Microsoft Visual Studio 9.0\VC\include or similar 3.Copy the header files into C:\programme\microsoft visual studio\vc98\include\GL 4.Copy all *.lib files into C:\programme\microsoft visual studio\vc98\Lib 5.Copy all.dll files into C:\Windows\System32 6.In the Menu of VC++ go through to -> project -> settings -> Link and add (do not remove the others!) the following libraries to the Object/libary modules line: glut32.lib glu32.lib opengl32.lib glaux.lib

Reference 1.Introduction to OpenGL PPT, Presented by Chung-Lin Wen ICG 2006 Fall 2.Interactive Computer Graphics – A Top-Down Approach Using openGL