1 / 39

Introduction to OpenGL & HW1 Announcement

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

Download Presentation

Introduction to OpenGL & HW1 Announcement

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

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

  3. 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

  4. 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())

  5. Coordinate system World coordinates object coordinates

  6. Coordinate system World coordinates Camera coordinates

  7. Coordinate system World coordinates Clip coordinates Camera coordinates

  8. Coordinate system Clip coordinates Camera coordinates World coordinates Model-view transformation Projection transformation Vertices Vertices • There are two matrix stacks. • ModelView matrix (GL_MODELVIEW) • Projection matrix (GL_PROJECTION) CTM

  9. Coordinate system Clip coordinates Camera coordinates World coordinates Model-view transformation Projection transformation Vertices Vertices • 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….

  10. 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)

  11. openGL as state machine glBegin(GL_LINES); RGB 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)

  12. openGL as state machine Current Transformation matrix (CTM) 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)

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

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

  15. Primitives

  16. 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

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

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

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

  20. A Simple Example

  21. A Simple Example #include <GL/glut.h> int main(intargc, 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; }

  22. 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(); }

  23. 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(); }

  24. 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(); }

  25. 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(); }

  26. 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(); }

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

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

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

  30. A Simple Example #include <GL\glut.h> void GL_reshape(GLsizei w, GLsizei h); void GL_display(); int main(intargc, 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(); }

  31. 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, gluPerspectiveand glFrustumare not allowed in problem 4 5. Bonus. Any kind of effort you made more than requirements above.(6 pts)

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

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

  34. 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.

  35. 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();

  36. 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; } }

  37. 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; ………………. } }

  38. Others Setting up openGL(visual C++): 1.download glut-3.7.6-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\GL4.Copy all *.lib files into C:\programme\microsoft visual studio\vc98\Lib 5.Copy all .dll files into C:\Windows\System326.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

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

More Related