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.

Slides:



Advertisements
Similar presentations
Using GLU/GLUT Objects GLU/GLUT provides very simple object primitives glutWireCube glutWireCone gluCylinder glutWireTeapot.
Advertisements

#include int line_width = 1; void Display( void ) { glEnable( GL_LINE_STIPPLE ); glClearColor (0.0, 0.0, 0.0, 0.0); glClear(GL_COLOR_BUFFER_BIT);
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2007 Tamara Munzner Transformations I Week.
OpenGL (Graphics Library) Software Interface to graphics software Allows to create interactive programs that produce color images of moving 3D objects.
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 (I). What is OpenGL (OGL)? OGL is a 3D graphics & modeling library Can also use it to draw 2D objects.
#4: OpenGL Implementation & Project 2 CSE167: Computer Graphics TAs: Alex Kozlowski & Cameron Chrisman UCSD, Winter 2006.
OpenGL and Projections
Objectives Learn to build arbitrary transformation matrices from simple transformations Learn to build arbitrary transformation matrices from simple transformations.
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2008 Tamara Munzner OpenGL, GLUT, Transformations.
Hierarchical ModelingHofstra University1 Modeling Define volumetric objects in terms of surfaces patches that surround the volume Each surface patch is.
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 OpenGL Transformations Ed Angel Professor of Computer Science, Electrical and Computer.
Write a Simple Program with OpenGL & GLUT. Books and Web Books OpenGL Programming Guide (Red-book) OpenGL Reference Manual (Blue-book) OpenGL Super Bible.
Reference1. [OpenGL course slides by Rasmus Stenholt]
Using Graphics Libraries Lecture 3 Mon, Sep 1, 2003.
Introduction to OpenGL and GLUT GLUT. What is OpenGL? An application programming interface (API) A (low-level) Graphics rendering API Generate high-quality.
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.
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2010 Tamara Munzner GLUT, Transformations.
Lecture 3 OpenGL.
Write a Simple Program with OpenGL & GLUT. Books OpenGL Programming Guide (Red-book) OpenGL Reference Manual (Blue-book) OpenGL Super Bible
 “OpenGL (Open Graphics Library) is a standard specification defining a cross- language cross-platform API for writing applications that produce 2D and.
1 Figures are extracted from Angel's book (ISBN x) The Human Visual System vs The Pinhole camera Human Visual System Visible Spectrum Pinhole.
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.
Intro to OpenGL (Version 2) Geb Thomas. Setting Up GLUT You will need GLUT for opening windows We can use the version made by Nate Robins: –
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.
Transformations Angel Angel: Interactive Computer Graphics5E © Addison-Wesley
Introduction to OpenGL & HW1 Announcement 劉軒銘, 網媒所 碩二 ICG 2012 Fall.
Color spaces. Draw Buffers Color models. Mathmatical Protocols for defining colors with numbers  RGB Red, Green, Blue  HSV Hue, Saturation, Value(Brightness)‏
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
CS552: Computer Graphics Lecture 6: Viewing in 2D.
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.
1 Geometric Transformations-II Modelling Transforms By Dr.Ureerat Suksawatchon.
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 Graphics Programming. Graphics API.
Implement of transformation,projection, viewing Hanyang University Jungsik Park.
Introduction to Graphics Programming. Graphics: Conceptual Model Real Object Human Eye Display Device Graphics System Synthetic Model Synthetic Camera.
CS380 LAB II OpenGL Donghyuk Kim Reference1. [OpenGL course slides by Rasmus Stenholt] Reference2. [
CSC Graphics Programming Budditha Hettige Department of Statistics and Computer Science.
OpenGL Matrices and Transformations Angel, Chapter 3 slides from AW, Red Book, etc. CSCI 6360/4360.
OpenGL and GLUT Review Daniel Ritchie Monday, October 3 rd, 2011.
CSC Graphics Programming
Basic Program with OpenGL and GLUT
OpenGL Transformations
OpenGL Transformations
Computer Graphics OpenGL Transformations
Reference1. [OpenGL course slides by Rasmus Stenholt]
OpenGL (Open Graphics Library) Mr. B.A.Swamy Assistant Professor Dept of CSE.
Lab 3 Geometric Drawing Lab 3 Geometric Drawing.
גרפיקה ממוחשבת: מבוא ל-OpenGL
Geometric Transformations
Computer Graphics, KKU. Lecture 13
Chapter 4/5 glMatrixMode Modeling Transformations glTranslate glScale
Introduction to OpenGL
Geometric Transformations
Lecture 6 and 7 Transformations
Advanced Graphics Algorithms Ying Zhu Georgia State University
OpenGL Transformations
OpenGL, GLUT, Transformations I Week 2, Wed Jan 16
Geometric Transformations
OpenGL Transformations
Presentation transcript:

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

Homework1 Please draw a walking robot!

TAs will offer… 1.Ex1a:Rotate/Translate/Push/PopMatrix 2.Ex1b:draw polygon/Keyboard function

First open Ex1b… A basic OpenGL main function looks like: int main(int argc, char** argv){ glutInit(&argc, argv); glutInitWindowSize(800, 800); glutInitWindowPosition(0, 0); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); glutCreateWindow("Homework_1b"); glutDisplayFunc(display); glutReshapeFunc(reshape); glutKeyboardFunc(keyboard); glutSpecialFunc(specialkey); glutMainLoop(); return 0; }

What is in the Main function? Windows size/starting position/name. Display mode(how many color channels? …etc) Tell the system “which function” handle the operations glutInitWindowSize(800, 800); glutInitWindowPosition(0, 0); glutCreateWindow("Homework_1b"); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); glutDisplayFunc(display); glutReshapeFunc(reshape); glutKeyboardFunc(keyboard); glutSpecialFunc(specialkey);

void glutInit(int *argcp, char **argv); ▫Initializing the GLUT library ▫Should be called before any other GLUT funcitons ▫ void glutInitDisplayMode(unsigned int mode); ▫Specify a display mode for windows created. ▫GLUT_RGB / GLUT_RGBA / GLUT_INDEX ▫GLUT_SINGLE / GLUT_DOUBLE ▫GLUT_DEPTH / GLUT_STENCIL / GLUT_ACCUM ▫ ml

What is Display? void glutDisplayFunc(void (*func)(void)); ▫Automatically called when the windows needs redraw (focus on/in, …etc) ▫draw function handler ▫call glutPostRedisplay() if you need to redraw immediately ▫ tml

What is in the Display function? The draw part looks: glPushMatrix(); glTranslatef(-400+movement[0][0], movement[0][1], movement[0][2]); glColor3f(0.0, 0.0, 1.0); glBegin(GL_QUADS); glVertex3f(-100.0, 200.0, 250.0); glVertex3f(-100.0, , 250.0); glVertex3f(100.0, , 250.0); glVertex3f(100.0, 200.0, 250.0); glEnd(); glPopMatrix();

Indicate the color(R,G,B) From glBegin() to glEnd(): Indicate every points’ position/color(if need)/normal,…et c glColor3f(0.0, 0.0, 1.0); glBegin(GL_QUADS); glVertex3f(-100.0, 200.0, 250.0); glVertex3f(-100.0, , 250.0); glVertex3f(100.0, , 250.0); glVertex3f(100.0, 200.0, 250.0); glEnd();

Next 1a…

Adding glutTimerFunc(TimerFunction); glRotatef(45, 0.0,1.0,0.0); glTranslatef(0,0,500); drawCooridinate() is another function just draw the cooridinates

Basic prior: Everything in OpenGL is represented as a matrix operation. glMatrixMode(): Decide which matrix is now operated. glTranslatef( 0, 0, -1 );

glTranslate{fd}( TYPE x,TYPE y,TYPE z ); ▫Multiplies current matrix by a matrix that moves an object by x,y,z ▫ glTranslatef( 0, 0, -1 );

glRotate{fd}( TYPR angle,TYPE x,TYPR y,TYPE 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);

void glPushMatrix(); ▫Push current matrix into matrix stack. Void glPopMatrix(); ▫Pop matrix from matrix stack ▫These stack operations of matrix is very useful for constructing a hierarchical structure. ▫

To more details Step by step

drawCooridinate(); glutSolidTeapot(100.0); //glRotatef(45, 0.0,1.0,0.0); //glTranslatef(0,0,500); //drawCooridinate(); //glutSolidTeapot(50.0); //glTranslatef(0,0,-1000); //glutSolidTeapot(50.0); Current Matrix

drawCooridinate(); glutSolidTeapot(100.0); glRotatef(45, 0.0,1.0,0.0); glTranslatef(0,0,500); drawCooridinate(); //glutSolidTeapot(50.0); //glTranslatef(0,0,-1000); //glutSolidTeapot(50.0); Current Matrix

drawCooridinate(); glutSolidTeapot(100.0); glRotatef(45, 0.0,1.0,0.0); glTranslatef(0,0,500); drawCooridinate(); glutSolidTeapot(50.0); //glTranslatef(0,0,-1000); //glutSolidTeapot(50.0); Current Matrix

… glTranslatef(0,0,-1000); glutSolidTeapot(50.0); Current Matrix

Question If I want to “back” to the initial matrix, I can… ▫1. glTranslatef(0,0, 1000); ▫ glTranslatef(0,0, -500); ▫ glRotatef(-45, 0.0,1.0,0.0); ▫Work, but stupid! ▫1a. glTranslatef(0,0,500); ▫ glRotatef(-45,0.0,1.0,0.0); …. Not good Current Matrix

2. Adding push/popMatrix as follows: glPushMatrix(); drawCooridinate(); glutSolidTeapot(100.0); glRotatef(45, 0.0,1.0,0.0); glTranslatef(0,0,500); drawCooridinate(); glutSolidTeapot(50.0); glTranslatef(0,0,-1000); glutSolidTeapot(50.0); glPopMatrix();

glPushMatrix(); glRotatef(theta,0.0,1.0,0.0); ….. glPopMatrix(); glTranslatef(0,200,0); GLUquadricObj *quadObj=gluNewQuadric(); gluQuadricDrawStyle(quadObj,GLU_SILHOUETTE); gluSphere(quadObj,50,20,20); glTranslatef(0,-400,0); gluQuadricDrawStyle(quadObj,GLU_FILL); glColor3f(1.0,0.0,0.0); glScalef(10.0,1.0,1.0); gluSphere(quadObj,50,20,20);

Hw1b void keyboard(unsigned char key, int x, int y){ switch(key){ case '2'://type 2, move forward (axis Z) movement[selected][2]+=10.0; break; case '8'://type 8, move backward(axis Z) movement[selected][2]-=10.0; break; case '4'://type 4, move left(axis X) movement[selected][0]-=10.0; break; case '6'://type 6, move wight(axis X) movement[selected][0]+=10.0; …….. case 27: exit(0); break; }

Hwk1 Requirement Please draw a robot which can walk! ▫At least, robot have body(sphere or cube or etc.) with 2 feet, each has more than 2 part. ▫Users can control each joints’ rotation. ▫The robot can walk (by user changing the rotation degree of joints) ▫The robot can walk around. Bonus: Design a special movement with rotation / translate

Reference NeHe Productions