opengl introduction and hw1 guide
DESCRIPTION
OpenGL Introduction and HW1 Guide. Speaker:Ming Ouhyoung , TA 汪心威 2012 TA: Yu Tu CSIE M2. Virtual Reality 2013. This guide is talking about…. 1.Part of computer graphics. 2.OpenGL introduction. 3.Sample codes discussion : line.cpp, robot.c , dance.c. VR Hw #1 Requirements. - PowerPoint PPT PresentationTRANSCRIPT
![Page 1: OpenGL Introduction and HW1 Guide](https://reader036.vdocuments.mx/reader036/viewer/2022081419/5681692b550346895de06bfa/html5/thumbnails/1.jpg)
Virtual Reality 2013
OpenGL Introductionand HW1 Guide
Speaker:Ming Ouhyoung,TA 汪心威
2012 TA: Yu Tu CSIE M2
![Page 2: OpenGL Introduction and HW1 Guide](https://reader036.vdocuments.mx/reader036/viewer/2022081419/5681692b550346895de06bfa/html5/thumbnails/2.jpg)
This guide is talking about…
![Page 3: OpenGL Introduction and HW1 Guide](https://reader036.vdocuments.mx/reader036/viewer/2022081419/5681692b550346895de06bfa/html5/thumbnails/3.jpg)
1.Part of computer graphics
2.OpenGL introduction
3.Sample codes discussion : line.cpp, robot.c, dance.c
![Page 4: OpenGL Introduction and HW1 Guide](https://reader036.vdocuments.mx/reader036/viewer/2022081419/5681692b550346895de06bfa/html5/thumbnails/4.jpg)
VR Hw #1 Requirements
• Homework # 1 : Articulated Animal (and Human) Animation
• Simulation(real time) of articulated animals (including men)
• 1 ~ 3 minutes of animation (Demo final results at class)
• With short real-time manipulation of a few actions
• C,C++, Java ,with OpenGL,MS SDK...etc are OK
• due date: 2013/04/22
![Page 5: OpenGL Introduction and HW1 Guide](https://reader036.vdocuments.mx/reader036/viewer/2022081419/5681692b550346895de06bfa/html5/thumbnails/5.jpg)
Key frame animation• key frame in animation and filmmaking is a
drawing that defines the starting and ending points of any smooth transition.
• One frame at a time, the most popular and yet oldest animation generation method (Disney animation, Snow White)
• See the demo at http://en.wikipedia.org/wiki/Key_frame
![Page 6: OpenGL Introduction and HW1 Guide](https://reader036.vdocuments.mx/reader036/viewer/2022081419/5681692b550346895de06bfa/html5/thumbnails/6.jpg)
Snow White and the Seven Dwarfs (1937)
![Page 7: OpenGL Introduction and HW1 Guide](https://reader036.vdocuments.mx/reader036/viewer/2022081419/5681692b550346895de06bfa/html5/thumbnails/7.jpg)
Part of computer graphics
![Page 8: OpenGL Introduction and HW1 Guide](https://reader036.vdocuments.mx/reader036/viewer/2022081419/5681692b550346895de06bfa/html5/thumbnails/8.jpg)
Computer Graphics Pipeline
![Page 9: OpenGL Introduction and HW1 Guide](https://reader036.vdocuments.mx/reader036/viewer/2022081419/5681692b550346895de06bfa/html5/thumbnails/9.jpg)
- object observationModel in Graphics
![Page 10: OpenGL Introduction and HW1 Guide](https://reader036.vdocuments.mx/reader036/viewer/2022081419/5681692b550346895de06bfa/html5/thumbnails/10.jpg)
- coordinate system
World coordinate
Model in Graphics
Camera coordinateImage
coordinate
![Page 11: OpenGL Introduction and HW1 Guide](https://reader036.vdocuments.mx/reader036/viewer/2022081419/5681692b550346895de06bfa/html5/thumbnails/11.jpg)
OpenGL Introduction
![Page 12: OpenGL Introduction and HW1 Guide](https://reader036.vdocuments.mx/reader036/viewer/2022081419/5681692b550346895de06bfa/html5/thumbnails/12.jpg)
What is OpenGL• A Graphics rendering API introduced in
1992 by Silicon Graphics Inc• Produces high-quality color images
composed of geometric and image primitives
• Cross-platform
![Page 13: OpenGL Introduction and HW1 Guide](https://reader036.vdocuments.mx/reader036/viewer/2022081419/5681692b550346895de06bfa/html5/thumbnails/13.jpg)
Related APIsApplication program
X Window, Windows, Mac OSX GL
GLUAGL,WGL,GLX
GLUT
Software and/or hardware
![Page 14: OpenGL Introduction and HW1 Guide](https://reader036.vdocuments.mx/reader036/viewer/2022081419/5681692b550346895de06bfa/html5/thumbnails/14.jpg)
OpenGL Utility Toolkit (GLUT)
• Visual Studio 2010/2008, Visual C++ 2010/2008• http://www.xmission.com/~nate/glut.html• Add glut32.dll to
C:\Windows\SysWOW64
• Add glut32.lib toC:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\lib
• Add glut.h toC:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\GL
(9.0)
(9.0)
(System32)
![Page 15: OpenGL Introduction and HW1 Guide](https://reader036.vdocuments.mx/reader036/viewer/2022081419/5681692b550346895de06bfa/html5/thumbnails/15.jpg)
HelloWorld#include <GL/glut.h>
void GL_display();void GL_reshape(GLsizei w, GLsizei h);void main(void){
glutCreateWindow(“HelloWorld");glutDisplayFunc(GL_display);glutReshapeFunc(GL_reshape);glutMainLoop();
}
![Page 16: OpenGL Introduction and HW1 Guide](https://reader036.vdocuments.mx/reader036/viewer/2022081419/5681692b550346895de06bfa/html5/thumbnails/16.jpg)
HelloWorldvoid 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.0f, 1.0f, 0.0f);glVertex3f(-1.0f, -1.0f, 0.0f);glColor3f(1.0f, 0.0f, 0.0f);glVertex3f(-1.0, 1.0f, 0.0f);glVertex3f(1.0f, -1.0f, 0.0f);
glEnd();glFlush();
}
![Page 17: OpenGL Introduction and HW1 Guide](https://reader036.vdocuments.mx/reader036/viewer/2022081419/5681692b550346895de06bfa/html5/thumbnails/17.jpg)
Primitives
![Page 18: OpenGL Introduction and HW1 Guide](https://reader036.vdocuments.mx/reader036/viewer/2022081419/5681692b550346895de06bfa/html5/thumbnails/18.jpg)
HelloWorldvoid 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.0f, 1.0f, 0.0f);glVertex3f(-1.0f, -1.0f, 0.0f);glColor3f(1.0f, 0.0f, 0.0f);glVertex3f(-1.0, 1.0f, 0.0f);glVertex3f(1.0f, -1.0f, 0.0f);
glEnd();glFlush();
}
![Page 19: OpenGL Introduction and HW1 Guide](https://reader036.vdocuments.mx/reader036/viewer/2022081419/5681692b550346895de06bfa/html5/thumbnails/19.jpg)
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();
}
HelloWorld
![Page 20: OpenGL Introduction and HW1 Guide](https://reader036.vdocuments.mx/reader036/viewer/2022081419/5681692b550346895de06bfa/html5/thumbnails/20.jpg)
Now that you have done your first OpenGL Program,
let’s talk about something advanced.
![Page 21: OpenGL Introduction and HW1 Guide](https://reader036.vdocuments.mx/reader036/viewer/2022081419/5681692b550346895de06bfa/html5/thumbnails/21.jpg)
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….
ProjectionModelView
Vertex
![Page 22: OpenGL Introduction and HW1 Guide](https://reader036.vdocuments.mx/reader036/viewer/2022081419/5681692b550346895de06bfa/html5/thumbnails/22.jpg)
Projection Matrix
• Orthographic ProjectionglOrtho( GLdouble left, GLdouble right, GLdouble bottom, GLdouble top,
GLdouble near, GLdouble far )gluOrtho2D( GLdouble left, GLdouble right, GLdouble bottom, GLdouble
top)
![Page 23: OpenGL Introduction and HW1 Guide](https://reader036.vdocuments.mx/reader036/viewer/2022081419/5681692b550346895de06bfa/html5/thumbnails/23.jpg)
Projection Matrix
Perspective ProjectiongluPerspective( GLdouble fovy, GLdouble aspect, GLdouble near, GLdouble far );glFrustum( GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble near, GLdouble far );
![Page 24: OpenGL Introduction and HW1 Guide](https://reader036.vdocuments.mx/reader036/viewer/2022081419/5681692b550346895de06bfa/html5/thumbnails/24.jpg)
ModelView Matrix• Modeling Transformation
• Perform rotate, translate, scale and combinations of these transformations to the object.
• Viewing Transformation• To positioning and aiming the camera
![Page 25: OpenGL Introduction and HW1 Guide](https://reader036.vdocuments.mx/reader036/viewer/2022081419/5681692b550346895de06bfa/html5/thumbnails/25.jpg)
Modeling Transformations
glTranslatef(x, y, z)Multiplies current matrix by a matrix that moves an object by x,y,z
glTranslatef( 0, 0, -1)
![Page 26: OpenGL Introduction and HW1 Guide](https://reader036.vdocuments.mx/reader036/viewer/2022081419/5681692b550346895de06bfa/html5/thumbnails/26.jpg)
Modeling Transformations
glRotatef(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)
![Page 27: OpenGL Introduction and HW1 Guide](https://reader036.vdocuments.mx/reader036/viewer/2022081419/5681692b550346895de06bfa/html5/thumbnails/27.jpg)
Modeling Transformations
glScalef (x, y, z)Multiplies current matrix by a matrix that scales an object along axes.
glScalef( 2.0, -0.5, 1)
![Page 28: OpenGL Introduction and HW1 Guide](https://reader036.vdocuments.mx/reader036/viewer/2022081419/5681692b550346895de06bfa/html5/thumbnails/28.jpg)
Viewing Transformations
gluLookAt (eyex, eyey, eyez, atx, aty, atz, upx, upy, upz );
![Page 29: OpenGL Introduction and HW1 Guide](https://reader036.vdocuments.mx/reader036/viewer/2022081419/5681692b550346895de06bfa/html5/thumbnails/29.jpg)
Matrix OrderCode:glMatrixMode(GL_PROJECTION)gluPerspectiveglMatrixMode(GL_MODELVIEW)gluLookAtglRotatefglTranslatefglScalefglBeginglVertex3fglEnd
Matrix Stack: Matrix Multiplication
= Vi
gluLookAt glRotatef
glTranslatef glScalef glVertex3f
gluPerspective
gluPerspective
gluLookAt
glRotatef
glTranslatef
glScalef
glVertex3f
![Page 30: OpenGL Introduction and HW1 Guide](https://reader036.vdocuments.mx/reader036/viewer/2022081419/5681692b550346895de06bfa/html5/thumbnails/30.jpg)
Matrix OrderThe order of transformations is critical.
glTranslatef( 1,0,0 );glRotatef(45.0, 0,0,1 );drawObject();
glRotatef(45.0, 0,0,1 );glTranslatef( 1,0,0 );drawObject();
![Page 31: OpenGL Introduction and HW1 Guide](https://reader036.vdocuments.mx/reader036/viewer/2022081419/5681692b550346895de06bfa/html5/thumbnails/31.jpg)
Interactive Setting and Display
Glut Window functions:glutInit(&argc, argv);glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);glutInitWindowSize(800, 600);glutInitWindowPosition(100, 100);glutCreateWindow(“Name");glutDisplayFunc(display);glutReshapeFunc(reshape);
Interactive setting functions:glutKeyboardFunc(keyboard);glutMouseFunc(mouse);glutMotionFunc(motion);
![Page 32: OpenGL Introduction and HW1 Guide](https://reader036.vdocuments.mx/reader036/viewer/2022081419/5681692b550346895de06bfa/html5/thumbnails/32.jpg)
The most important topic.
Wake up for
![Page 33: OpenGL Introduction and HW1 Guide](https://reader036.vdocuments.mx/reader036/viewer/2022081419/5681692b550346895de06bfa/html5/thumbnails/33.jpg)
Mantain matrix stack• glPushMatrix() : save the current matrix• glPopMatrix() : restore the saved matrix
glPushMatirx()
xglScalef
glPopMatrix()
![Page 34: OpenGL Introduction and HW1 Guide](https://reader036.vdocuments.mx/reader036/viewer/2022081419/5681692b550346895de06bfa/html5/thumbnails/34.jpg)
Heirarchy Modeling
Body
head
Left hand
Right
handLeft leg
Right leg
Finger 1 Finger 2
![Page 35: OpenGL Introduction and HW1 Guide](https://reader036.vdocuments.mx/reader036/viewer/2022081419/5681692b550346895de06bfa/html5/thumbnails/35.jpg)
Heirarchy ModelingMatrix Stack:
Stack
Current Matrix
![Page 36: OpenGL Introduction and HW1 Guide](https://reader036.vdocuments.mx/reader036/viewer/2022081419/5681692b550346895de06bfa/html5/thumbnails/36.jpg)
Heirarchy ModelingMatrix Stack:
Stack
Current Matrix
glPushMatrix();
Push
![Page 37: OpenGL Introduction and HW1 Guide](https://reader036.vdocuments.mx/reader036/viewer/2022081419/5681692b550346895de06bfa/html5/thumbnails/37.jpg)
Heirarchy ModelingMatrix Stack:
Stack
Current Matrix
glTranslatef();
x
Push
![Page 38: OpenGL Introduction and HW1 Guide](https://reader036.vdocuments.mx/reader036/viewer/2022081419/5681692b550346895de06bfa/html5/thumbnails/38.jpg)
Heirarchy ModelingMatrix Stack:
Stack
Current Matrix
DrawBody();Push
![Page 39: OpenGL Introduction and HW1 Guide](https://reader036.vdocuments.mx/reader036/viewer/2022081419/5681692b550346895de06bfa/html5/thumbnails/39.jpg)
Heirarchy ModelingMatrix Stack:
Stack
Current Matrix
glPushMatrix();
Push
Push
![Page 40: OpenGL Introduction and HW1 Guide](https://reader036.vdocuments.mx/reader036/viewer/2022081419/5681692b550346895de06bfa/html5/thumbnails/40.jpg)
Heirarchy ModelingMatrix Stack:
Stack
Current Matrix
glRotatef();
x
Push
Push
![Page 41: OpenGL Introduction and HW1 Guide](https://reader036.vdocuments.mx/reader036/viewer/2022081419/5681692b550346895de06bfa/html5/thumbnails/41.jpg)
Heirarchy ModelingMatrix Stack:
Stack
Current Matrix
glTranslatef();
x
Push
Push
![Page 42: OpenGL Introduction and HW1 Guide](https://reader036.vdocuments.mx/reader036/viewer/2022081419/5681692b550346895de06bfa/html5/thumbnails/42.jpg)
Heirarchy ModelingMatrix Stack:
Stack
Current Matrix
DrawHead();Push
Push
![Page 43: OpenGL Introduction and HW1 Guide](https://reader036.vdocuments.mx/reader036/viewer/2022081419/5681692b550346895de06bfa/html5/thumbnails/43.jpg)
Current Matrix
Heirarchy ModelingMatrix Stack:
Stack
glPopMatrix();
Push
Push
Pop
Current Matrix
![Page 44: OpenGL Introduction and HW1 Guide](https://reader036.vdocuments.mx/reader036/viewer/2022081419/5681692b550346895de06bfa/html5/thumbnails/44.jpg)
Heirarchy ModelingMatrix Stack:
Stack
Current Matrix
glPushMatrix();
Push
Push
Pop
Push
![Page 45: OpenGL Introduction and HW1 Guide](https://reader036.vdocuments.mx/reader036/viewer/2022081419/5681692b550346895de06bfa/html5/thumbnails/45.jpg)
Heirarchy ModelingMatrix Stack:
Stack
Current Matrix
Push
Push
Pop
Push
glRotatef();
x
![Page 46: OpenGL Introduction and HW1 Guide](https://reader036.vdocuments.mx/reader036/viewer/2022081419/5681692b550346895de06bfa/html5/thumbnails/46.jpg)
Heirarchy ModelingMatrix Stack:
Stack
Current Matrix
Push
Push
Pop
Push
DrawHand();
![Page 47: OpenGL Introduction and HW1 Guide](https://reader036.vdocuments.mx/reader036/viewer/2022081419/5681692b550346895de06bfa/html5/thumbnails/47.jpg)
Heirarchy ModelingMatrix Stack:
Stack
Current Matrix
glPushMatrix();
Push
Push
Pop
Push
Push
![Page 48: OpenGL Introduction and HW1 Guide](https://reader036.vdocuments.mx/reader036/viewer/2022081419/5681692b550346895de06bfa/html5/thumbnails/48.jpg)
Heirarchy ModelingMatrix Stack:
Stack
Current Matrix
Push
Push
Pop
Push
Push
glTranslatef();
x
![Page 49: OpenGL Introduction and HW1 Guide](https://reader036.vdocuments.mx/reader036/viewer/2022081419/5681692b550346895de06bfa/html5/thumbnails/49.jpg)
Heirarchy ModelingMatrix Stack:
Stack
Current Matrix
Push
Push
Pop
Push
glPopMatrix();
Push
Pop
Current Matrix
![Page 50: OpenGL Introduction and HW1 Guide](https://reader036.vdocuments.mx/reader036/viewer/2022081419/5681692b550346895de06bfa/html5/thumbnails/50.jpg)
Heirarchy ModelingMatrix Stack:
Stack
Current Matrix
DrawFinger();
Push
Push
Pop
Push
Push
![Page 51: OpenGL Introduction and HW1 Guide](https://reader036.vdocuments.mx/reader036/viewer/2022081419/5681692b550346895de06bfa/html5/thumbnails/51.jpg)
Heirarchy Modeling
Body
head
Left hand
Right
handLeft leg
Right leg
Finger 1 Finger 2
Push
Push Push
Push
Pop
Pop
Push Push Push
Push
Pop
Pop Pop Pop Pop
Pop
![Page 52: OpenGL Introduction and HW1 Guide](https://reader036.vdocuments.mx/reader036/viewer/2022081419/5681692b550346895de06bfa/html5/thumbnails/52.jpg)
Contratulations !
![Page 53: OpenGL Introduction and HW1 Guide](https://reader036.vdocuments.mx/reader036/viewer/2022081419/5681692b550346895de06bfa/html5/thumbnails/53.jpg)
You are well prepared for our homework now!
![Page 54: OpenGL Introduction and HW1 Guide](https://reader036.vdocuments.mx/reader036/viewer/2022081419/5681692b550346895de06bfa/html5/thumbnails/54.jpg)
Time for Sample Codes
![Page 55: OpenGL Introduction and HW1 Guide](https://reader036.vdocuments.mx/reader036/viewer/2022081419/5681692b550346895de06bfa/html5/thumbnails/55.jpg)
Robot.cglPushMatrix();
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(); glPopMatrix();
glPopMatrix();
![Page 56: OpenGL Introduction and HW1 Guide](https://reader036.vdocuments.mx/reader036/viewer/2022081419/5681692b550346895de06bfa/html5/thumbnails/56.jpg)
Dance.c • BOOL Open_CD(void)• BOOL Stop_CD(void) • BOOL Close_CD(void)• BOOL Play_CD(int bTrack)• int GetUnit(FILE* input)• void GetMovie(void)• void PutIntoFile(FILE* input,
int item)• void SetNull(FILE* input)• void SetRecord()• void ZoomChange()• void ColorChange(int mode)
• void init(void)• void reshape (int w, int h)• void baseroom(void)• void ManSet()• void WomanSet()• void display(void)• void keyboard (unsigned char
key, int x, int y)• int OnTimer(int value)• int main(int argc, char** argv)
![Page 57: OpenGL Introduction and HW1 Guide](https://reader036.vdocuments.mx/reader036/viewer/2022081419/5681692b550346895de06bfa/html5/thumbnails/57.jpg)
Dance.c • BOOL Open_CD(void)• BOOL Stop_CD(void) • BOOL Close_CD(void)• BOOL Play_CD(int bTrack)
• int GetUnit(FILE* input)• void GetMovie(void)• void PutIntoFile(FILE* input,
int item)• void SetNull(FILE* input)• void SetRecord()
• void ZoomChange()• void ColorChange(int mode)
• void ManSet()• void WomanSet()
• void init(void)• void reshape (int w, int h)• void baseroom(void)• void display(void)• void keyboard (unsigned char
key, int x, int y)• int OnTimer(int value)• int main(int argc, char** argv)
Class Music{…
}; .
Class Script{…
}; .Class Animation{
… };
Class Component{ … };Class Actor{ … };
![Page 58: OpenGL Introduction and HW1 Guide](https://reader036.vdocuments.mx/reader036/viewer/2022081419/5681692b550346895de06bfa/html5/thumbnails/58.jpg)
Compile OpenGL GLUT
![Page 59: OpenGL Introduction and HW1 Guide](https://reader036.vdocuments.mx/reader036/viewer/2022081419/5681692b550346895de06bfa/html5/thumbnails/59.jpg)
Compile Dance Code
• Just use visual studio to open Dance.sln or Dance.vcproj, it will deal with it.
![Page 60: OpenGL Introduction and HW1 Guide](https://reader036.vdocuments.mx/reader036/viewer/2022081419/5681692b550346895de06bfa/html5/thumbnails/60.jpg)
Download
Into
Target Folder
Put
![Page 61: OpenGL Introduction and HW1 Guide](https://reader036.vdocuments.mx/reader036/viewer/2022081419/5681692b550346895de06bfa/html5/thumbnails/61.jpg)
![Page 62: OpenGL Introduction and HW1 Guide](https://reader036.vdocuments.mx/reader036/viewer/2022081419/5681692b550346895de06bfa/html5/thumbnails/62.jpg)
Q&A