Presentation is loading. Please wait.

Presentation is loading. Please wait.

Computer Graphics - Graphics Programming - Hanyang University Jong-Il Park.

Similar presentations


Presentation on theme: "Computer Graphics - Graphics Programming - Hanyang University Jong-Il Park."— Presentation transcript:

1 Computer Graphics - Graphics Programming - Hanyang University Jong-Il Park

2 Division of Electrical and Computer Engineering, Hanyang University Essential Functions in API Objects Viewer Light sources Material properties

3 Division of Electrical and Computer Engineering, Hanyang University Objects Defined by Sets of vertices Relationship between a list of vertices and the object Relationship Simple relationship Line segments, rectangles, polygons, … Complex relationship Circle defined by 3 points or center and one point Primitive Points, line segments, polygons, text …

4 Division of Electrical and Computer Engineering, Hanyang University Eg. Triangle in OpenGL glBegin(GL_POLYGON); glVertex3f(0.0, 0.0, 0.0); glVertex3f(0.0, 1.0, 0.0); glVertex3f(0.0, 0.0, 1.0); glEnd();

5 Division of Electrical and Computer Engineering, Hanyang University Viewer = Virtual Camera Necessary specifications Position Orientation Focal length Film plane

6 Division of Electrical and Computer Engineering, Hanyang University Eg. Viewer in OpenGL Independence Viewer Objects cf. Classical viewing techniques in architecture gluLookAt(cop_x, cop_y, cop_z, at_x, at_y, at_z, …); // position and orientation gluPerspective(field_of_view, aspect_ratio …); // lens, field of view..

7 Division of Electrical and Computer Engineering, Hanyang University Perspective vs. Orthographic Perspective projection Orthographic projection

8 Division of Electrical and Computer Engineering, Hanyang University Viewport glViewport(x,y,w,h)

9 Division of Electrical and Computer Engineering, Hanyang University Modeling-Rendering Paradigm Modeling software Animation software Rendering software M+A+R 3D Studio SOFTIMAGE MAYA … M+R Rhinoceros solidThinking … A+R ArcRender …

10 Division of Electrical and Computer Engineering, Hanyang University Graphics Architecture Early graphics systems Display processors

11 Division of Electrical and Computer Engineering, Hanyang University Pipeline Architectures Principle Throughput The rate at which the data flows through the system Latency The time for a datum to pass through the system

12 Division of Electrical and Computer Engineering, Hanyang University Geometric Pipeline Geometric processing Transformation Concatenating Clipping Projection Rasterization = scan-conversion

13 Division of Electrical and Computer Engineering, Hanyang University OpenGL API Graphics functions Primitive functions Attribute functions Viewing functions Transformation functions Input functions Control functions

14 Division of Electrical and Computer Engineering, Hanyang University OpenGL Pipeline

15 Division of Electrical and Computer Engineering, Hanyang University OpenGL Data Types For portability Eg. glVertex2f() f: suffix standing for GLfloat Suffix Typical C/C++ OpenGL type name bsigned charGLbyte sshortGLshort iint or longGLint, GLsizei ffloatGLfloat ddoubleGLdouble ubunsigned charGLubyte usunsigned shortGLushort uiunsigned int or longGLuint, GLenum

16 Division of Electrical and Computer Engineering, Hanyang University Primitives and Attributes Points and line-segment types glBegin(type); glVertex*(…); … glVertex*(…); glEnd();

17 Division of Electrical and Computer Engineering, Hanyang University Polygon types

18 Division of Electrical and Computer Engineering, Hanyang University Application Structure Configure and open window Initialize OpenGL state Register input callback functions render resize input: keyboard, mouse, etc. Enter event processing loop

19 Division of Electrical and Computer Engineering, Hanyang University Hello World Example #include void display(void) { glClear( GL_COLOR_BUFFER_BIT); glColor3f(0.0, 1.0, 0.0); glBegin(GL_POLYGON); glVertex3f(2.0, 4.0, 0.0); glVertex3f(8.0, 4.0, 0.0); glVertex3f(8.0, 6.0, 0.0); glVertex3f(2.0, 6.0, 0.0); glEnd(); glFlush(); } int main(int argc, char **argv) { printf("hello world\n"); glutInit(&argc, argv); glutInitDisplayMode ( GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH); glutInitWindowPosition(100,100); glutInitWindowSize(300,300); glutCreateWindow ("square"); glClearColor(0.0, 0.0, 0.0, 0.0); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0.0, 10.0, 0.0, 10.0, -1.0, 1.0); glutDisplayFunc(display); glutMainLoop(); return 0; } #include int main(int argc, char **argv) { printf("hello world\n"); glutInit(&argc, argv); glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH); Initialize GLUT and processes command line options

20 Division of Electrical and Computer Engineering, Hanyang University RGBred, green, and blue, typically 8 bits per pixelGLUT_RGB A alpha or accumulation buffer; used for compositing images GLUT_RGBA Zdepth value, used for Z-buffer visibility tests GLUT_DEPT H double buffer extra copy of all buffers, used for smooth animation GLUT_DOUB LE stencil buffer several extra bits, useful in compositing images GLUT_STEN CIL glutInitDisplayMode();

21 Division of Electrical and Computer Engineering, Hanyang University Hello World Example (2) #include void display(void) { glClear( GL_COLOR_BUFFER_BIT); glColor3f(0.0, 1.0, 0.0); glBegin(GL_POLYGON); glVertex3f(2.0, 4.0, 0.0); glVertex3f(8.0, 4.0, 0.0); glVertex3f(8.0, 6.0, 0.0); glVertex3f(2.0, 6.0, 0.0); glEnd(); glFlush(); } int main(int argc, char **argv) { printf("hello world\n"); glutInit(&argc, argv); glutInitDisplayMode ( GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH); glutInitWindowPosition(100,100); glutInitWindowSize(300,300); glutCreateWindow ("square"); glClearColor(0.0, 0.0, 0.0, 0.0); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0.0, 10.0, 0.0, 10.0, -1.0, 1.0); glutDisplayFunc(display); glutMainLoop(); return 0; } glutInitWindowPosition(100,100); glutInitWindowSize(300,300); glutCreateWindow ("square"); glClearColor(0.0, 0.0, 0.0, 0.0); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0.0, 10.0, 0.0, 10.0, -1.0, 1.0); Set window position, size, and name And create a window Clear color (white) and Set the viewer * GL_MODELVIEW

22 Division of Electrical and Computer Engineering, Hanyang University Hello World Example (3) #include void display(void) { glClear( GL_COLOR_BUFFER_BIT); glColor3f(0.0, 1.0, 0.0); glBegin(GL_POLYGON); glVertex3f(2.0, 4.0, 0.0); glVertex3f(8.0, 4.0, 0.0); glVertex3f(8.0, 6.0, 0.0); glVertex3f(2.0, 6.0, 0.0); glEnd(); glFlush(); } int main(int argc, char **argv) { printf("hello world\n"); glutInit(&argc, argv); glutInitDisplayMode ( GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH); glutInitWindowPosition(100,100); glutInitWindowSize(300,300); glutCreateWindow ("square"); glClearColor(0.0, 0.0, 0.0, 0.0); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0.0, 10.0, 0.0, 10.0, -1.0, 1.0); glutDisplayFunc(display); glutMainLoop(); return 0; } glClear( GL_COLOR_BUFFER_BIT); // screen clear glColor3f(0.0, 1.0, 0.0); // set the color to G glBegin(GL_POLYGON); // draw glVertex3f(2.0, 4.0, 0.0); glVertex3f(8.0, 4.0, 0.0); glVertex3f(8.0, 6.0, 0.0); glVertex3f(2.0, 6.0, 0.0); glEnd(); glFlush(); // send all output to display glutDisplayFunc(display); glutMainLoop(); glutDisplayFunc() registers the call-back function. glutMainLoop() hands execution control over to the glut library Display call-back function

23 Division of Electrical and Computer Engineering, Hanyang University Run and you get

24 Division of Electrical and Computer Engineering, Hanyang University Summary Essential Components Main program main() function Display callback function Optionally, interaction function Mouse callback function Keyboard callback function Reshape callback function

25 Division of Electrical and Computer Engineering, Hanyang University Interaction glutMouseFunc(myMouse) registers myMouse() with the event that occurs when the mouse button is pressed or released glutMotionFunc(myMovedMouse) registers myMovedMouse() with the event that occurs when the mouse is moved while one of the buttons is pressed glutKeyboardFunc(myKeyboard) Registers myKeyboard() with the event that occurs when a keyboard key is pressed

26 Division of Electrical and Computer Engineering, Hanyang University Eg. Placing Dots with Mouse void myMouse(int button, int state, int x, int y) { if(button == GLUT_LEFT_BUTTON && state == GLUT_DOWN) drawDot(x,screenHeight –y); else if(button == GLUT_RIGHT_BUTTON && state == GLUT_DOWN) exit(-1); } void drawDot(GLint x, GLint y) { glBegin(GL_POINTS); glVertex2i(x,y); glEnd(); } Leftbutton draw a dot Rightbutton terminate

27 Division of Electrical and Computer Engineering, Hanyang University Pen-Plotter Model moveto(0,0); lineto(1,0); lineto(1,1); lineto(0,1); lineto(0,0); Used in early graphics systems LOGO, GKS, PostScript…

28 Division of Electrical and Computer Engineering, Hanyang University Homework #3 2D Graphics Programming [OpenGL] Open a window with 480 lines x 640 pixels Build your own paint program capable of drawing dots, lines, line strips, line loop, … Interaction: Use the mouse and the keyboard Hint: Follow the methods in Chap.3 of the textbook Read Chap.4 [Due: 12 Oct.]


Download ppt "Computer Graphics - Graphics Programming - Hanyang University Jong-Il Park."

Similar presentations


Ads by Google