Graphics Graphics Korea University kucg.korea.ac.kr Graphics Programming 고려대학교 컴퓨터 그래픽스 연구실.

Slides:



Advertisements
Similar presentations
Chapter 2: Graphics Programming
Advertisements

Pemrograman OpenGL Dasar
Basic of computer graphics with OpenGL. Handful graphics function  OpenGL :  by silicon graphics  PHIGS :  Programmer’s Hierarchical Graphics System.
© 2004, Tom Duff and George Ledin Jr1 Lectures OpenGL Introduction By Tom Duff Pixar Animation Studios Emeryville, California and George Ledin Jr Sonoma.
OpenGL (Graphics Library) Software Interface to graphics software Allows to create interactive programs that produce color images of moving 3D objects.
CSC 461: Lecture 51 CSC461 Lecture 5: Simple OpenGL Program Objectives: Discuss a simple program Discuss a simple program Introduce the OpenGL program.
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Programming with OpenGL Part 2: Complete Programs Ed Angel Professor of Computer Science,
OpenGL and Projections
1 CSC461 Lecture 7: 3D Programming in OpenGL Objectives: Develop 2D and 3D examples -- Sierpinski gasket: a fractal Develop 2D and 3D examples -- Sierpinski.
ITEPC 06 - Workshop on Fractal Creation Chiew-Lan Tai and Oscar Au.
Sierpinski Gasket Program
CAP 4703 Computer Graphic Methods Prof. Roy Levow Lecture 2.
COS 397 Computer Graphics Assoc. Prof. Svetla Boytcheva AUBG 2013 COS 397 Computer Graphics Practical Session №1 Introduction to OpenGL, GLFW and CG.
Introduction to OpenGL and GLUT GLUT. What is OpenGL? An application programming interface (API) A (low-level) Graphics rendering API Generate high-quality.
Geometric Primitives Used in Open GL Polygons Polygon is : Flat shape with three or more straight sides. It could be either : convex or concave.
CSE 470: Computer Graphics. 10/15/ Defining a Vertex A 2D vertex: glVertex2f(GLfloat x, GLfloat y); 2D vertexfloating pointopenGL parameter type.
Computer Graphics CS 385 January 31, Fractals Some definitions Object which is self-similar at all scales. Regardless of scale the same level of.
Graphics Programming Chapter 2. CS 480/680 2Chapter 2 -- Graphics Programming Introduction: Introduction: Our approach is programming oriented. Our approach.
Ch 2 Graphics Programming page 1 CSC 367 Coordinate Systems (2.1.2) Device coordinates, or screen coordinates (pixels) put limitations on programmers 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);
Basic of computer graphics with OpenGL
1 Programming with OpenGL Part 3: Three Dimensions Yuanfeng Zhou Shandong University.
Computer Graphics I, Fall 2010 Programming with OpenGL Part 3: Three Dimensions.
1 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 Programming with OpenGL Review.
Chapter 2 Computer Graphics and Visualization.   Programming oriented approach is used.  Minimal application programmer's interface (API) is used which.
1 Chapter 2 Graphics Programming. 2 Using OpenGL in Visual C++ – 1/3 Opengl32.dll and glu32.dll should be in the system folder Opengl32.lib and glu32.lib.
Projections. Viewports Windows can have separate viewports void glViewport(GLint x, GLint y, GLsizei width, GLsizei height ) x, y - Specify the lower.
NoufNaief.net 1 TA: Nouf Al-Harbi.
Doç. Dr. Cemil Öz SAÜ Bilgisayar Mühendisliği Dr. Cemil Öz.
Graphics: Conceptual Model
Geometric Primitives Used in Open GL Drawing Triangles glBegin(GL_TRIANGELS); glVertex2i(p0); glVertex2i(p1); glVertex2i(p2); glVertex2i(p3); glVertex2i(p4);
Introduction to OpenGL Programming
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Programming with OpenGL Part 3: Three Dimensions Ed Angel Professor of Computer Science,
1 Programming with OpenGL Part 2: Complete Programs.
OpenGL API 2D Graphic Primitives Angel Angel: Interactive Computer Graphics5E © Addison-Wesley
31/1/2006Based on: Angel (4th Edition) & Akeine-Möller & Haines (2nd Edition)1 CSC345: Advanced Graphics & Virtual Environments Lecture 2: Introduction.
OpenGL: Introduction #include main() { OpenWindow() ; glClearColor(0.0, 0.0, 0.0, 0.0); glClear(GL_COLOR_BUFFER_BIT); glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0,
Introduction to Graphics Programming. Graphics API.
Introduction to Graphics Programming. Graphics: Conceptual Model Real Object Human Eye Display Device Graphics System Synthetic Model Synthetic Camera.
Computer Graphics I, Fall Programming with OpenGL Part 2: Complete Programs.
OpenGL CS418 Computer Graphics John C. Hart. OpenGL: Event-driven How in OpenGL? Programmer registers callback functions Callback function called when.
INTRODUCTION TO OPENGL
Computer Graphics (Fall 2003) COMS 4160, Lecture 5: OpenGL 1 Ravi Ramamoorthi Many slides courtesy Greg Humphreys.
Chapter (2)1 Computer Graphics - Chapter 2 Graphics Programming Objectives are to learn about: An example: The Sierpinski Gasket The OpenGL API Primitives.
Program Studi S-1 Teknik Informatika FMIPA Universitas Padjadjaran
The Human Visual System vs The Pinhole camera
Course code:10CS65 | Computer Graphics and Visualization
Programming with OpenGL Part 2: Complete Programs
Materi Anatomi OpenGL Fungsi GLUT Posisi Kamera Proyeksi
Programming with OpenGL Part 3: Three Dimensions
OpenGL API 2D Graphic Primitives
Programming with OpenGL Part 2: Complete Programs
Graphics Programming (I)
OpenGL (Open Graphics Library) Mr. B.A.Swamy Assistant Professor Dept of CSE.
Lab 3 Geometric Drawing Lab 3 Geometric Drawing.
גרפיקה ממוחשבת: מבוא ל-OpenGL
Drawing in the plane 455.
Programming with OpenGL Part 3: Three Dimensions
Introduction to OpenGL
Interactive Computer Graphics Graphics Programming
Chapter 2 Computer Graphics and Visualization SSE, Mukka
OpenGL program.
Programming with OpenGL Part 2: Complete Programs
Programming with OpenGL Part 2: Complete Programs
Programming with OpenGL Part 3: Three Dimensions
Programming with OpenGL Part 2: Complete Programs
Angel: Interactive Computer Graphics5E © Addison-Wesley 2009
Programming with OpenGL Part 3: Three Dimensions
Angel: Interactive Computer Graphics5E © Addison-Wesley 2009
Presentation transcript:

Graphics Graphics Korea University kucg.korea.ac.kr Graphics Programming 고려대학교 컴퓨터 그래픽스 연구실

KUCG Graphics Korea University kucg.korea.ac.kr Contents Our Goal in This Chapter Programming of the Sierpinski gasket How To? Programming with OpenGL and C/C++  OpenGL API (Application Programmer’s Interface)  Primitives  Attributes  Color  Viewing  Control Functions

KUCG Graphics Korea University kucg.korea.ac.kr The Sierpinski Gasket What is? Interesting shape in area such as fractal geometry Object that can be defined recursively and randomly How to? Start with three vertices in the plane 1. Pick an initial point at random inside the triangle 2. Select one of the three vertices at random 3. Find the point halfway between the initial point and the randomly selected vertex 4. Display this new point by putting some sort of marker, such as a small circle, at its location 5. Replace the initial point with this new point 6. Return to step 2

KUCG Graphics Korea University kucg.korea.ac.kr Generation of the Sierpinski Gasket v2v2 v1v1 v3v3 p0p0 p1p1 p2p2

KUCG Graphics Korea University kucg.korea.ac.kr Algorithm of the Sierpinski Gasket main( ) { initialize_the_system( ); for( some_number_of_points ) { pt = generate_a_point( ); display_the_point(pt); } cleanup( ); } main( ) { initialize_the_system( ); for( some_number_of_points ) { pt = generate_a_point( ); display_the_point(pt); } cleanup( ); }

KUCG Graphics Korea University kucg.korea.ac.kr The Pen-Plotter Model (1/3) Conceptual Model Referencing the Output Device Produce images by moving a pen held by a gantry 2 Drawing Functions moveto(x, y); lineto(x, y); Example : moveto(0, 0); (0, 0) (1, 0) lineto(1, 0); (1, 1) lineto(1, 1); (0, 1) lineto(0, 1); lineto(0, 0);

KUCG Graphics Korea University kucg.korea.ac.kr The Pen-Plotter Model (2/3) Vertex Location in space (2D, 3D, 4D) Define the atomic geometric objects  1 : point  2 : line segment  3 : triangle, circle  4 : quadrilateral OpenGL : glVertex*( ) glVertex2i(GLint xi, GLint yi); glVertex3f(GLfloat x, GLfloat y, GLfloat z); glVertex3fv(vertex);  #define GLfloat float  GLfloat vertex[3];

KUCG Graphics Korea University kucg.korea.ac.kr The Pen-Plotter Model (3/3) OpenGL: glBegin( ), glEnd( ) Specify the geometric type Line segment A pair of points glBegin(GL_LINES); glVertex2f(x1, y1); glVertex2f(x2, y2); glEnd( ); glBegin(GL_LINES); glVertex2f(x1, y1); glVertex2f(x2, y2); glEnd( ); glBegin(GL_POINTS); glVertex2f(x1, y1); glVertex2f(x2, y2); glEnd( ); glBegin(GL_POINTS); glVertex2f(x1, y1); glVertex2f(x2, y2); glEnd( ); (x1, y1) (x2, y2) (x1, y1) (x2, y2)

KUCG Graphics Korea University kucg.korea.ac.kr Function of “Display” of the Sierpinski Gasket void display(void) { typedef Glfloat point2[2]; /* arbitrary triangle */ point2 vertices[3] = { {0.0,0.0}, {250.0,500.0}, {500.0,0.0} }; /* any desired initial point */ point2 p = { 75.0,75.0 }; for(int i=0; i<5000; i++) { /* pick a random vertex from 0,1,2 */ int j=rand()%3; /* compute new point */ p[0] = (p[0]+vertices[j][0])/2.0; p[1] = (p[1]+vertices[j][1])/2.0; /* display new point */ glBegin(GL_POINTS); glVertex2fv(p); glEnd(); } glFlush(); } void display(void) { typedef Glfloat point2[2]; /* arbitrary triangle */ point2 vertices[3] = { {0.0,0.0}, {250.0,500.0}, {500.0,0.0} }; /* any desired initial point */ point2 p = { 75.0,75.0 }; for(int i=0; i<5000; i++) { /* pick a random vertex from 0,1,2 */ int j=rand()%3; /* compute new point */ p[0] = (p[0]+vertices[j][0])/2.0; p[1] = (p[1]+vertices[j][1])/2.0; /* display new point */ glBegin(GL_POINTS); glVertex2fv(p); glEnd(); } glFlush(); }

KUCG Graphics Korea University kucg.korea.ac.kr The Sierpinski Gasket Generated with 5000 Points

KUCG Graphics Korea University kucg.korea.ac.kr OpenGL API (1/3) API (Application Programmer’s Interface) Interface between an application program and a graphics system OpenGL API Easy to learn, compared with other APIs Nevertheless powerful Graphics Functions : Black Box Described by only its inputs and outputs Nothing known about its internal working Application Program Graphics Library (API) Hardware Input Device Output Device User Program User Program Graphics System Graphics System Input/Output Devices Input/Output Devices Function CallsOutput DataInput

KUCG Graphics Korea University kucg.korea.ac.kr OpenGL API (2/3) 6 Groups of Graphics Functions Primitive functions  what of an API - that object that can be displayed Attributes functions  how of an API : color, filling pattern Viewing functions  describe camera - position, orientation Transformation functions  rotation, translation,scaling Input functions  interactive application : keyboard, mice, data tablet Control functions  multiprocessing multiwindow environment - communicate the window system

KUCG Graphics Korea University kucg.korea.ac.kr OpenGL API (3/3) OpenGL Interface OpenGL functions(names : gl~) : GL Graphics utility library : GLU  Use only GL functions  Contain code for common objects such as spheres Graphics utility toolkit : GLUT  interface with the window system OpenGL Application Program OpenGL Application Program GLU GL GLUT GLX Xlib, Xtk Frame Buffer Frame Buffer

KUCG Graphics Korea University kucg.korea.ac.kr Primitives in OpenGL Points Lines Line segments Polylines Polygons Triangles and quadrilaterals Strips and fans Text Curved objects

KUCG Graphics Korea University kucg.korea.ac.kr Points in OpenGL glBegin(GL_POINTS); glVertex2fv(p0); glVertex2fv(p1); glVertex2fv(p2); glVertex2fv(p3); glVertex2fv(p4); glVertex2fv(p5); glVertex2fv(p6); glVertex2fv(p7); glEnd(); glBegin(GL_POINTS); glVertex2fv(p0); glVertex2fv(p1); glVertex2fv(p2); glVertex2fv(p3); glVertex2fv(p4); glVertex2fv(p5); glVertex2fv(p6); glVertex2fv(p7); glEnd(); p0 p1 p2 p3 p4 p5 p6 p7

KUCG Graphics Korea University kucg.korea.ac.kr Lines in OpenGL (1/3) Line Segments glBegin(GL_LINES); glVertex2fv(p0); glVertex2fv(p1); glVertex2fv(p2); glVertex2fv(p3); glVertex2fv(p4); glVertex2fv(p5); glVertex2fv(p6); glVertex2fv(p7); glEnd(); glBegin(GL_LINES); glVertex2fv(p0); glVertex2fv(p1); glVertex2fv(p2); glVertex2fv(p3); glVertex2fv(p4); glVertex2fv(p5); glVertex2fv(p6); glVertex2fv(p7); glEnd(); p0 p1 p2 p3 p4 p5 p6 p7

KUCG Graphics Korea University kucg.korea.ac.kr Lines in OpenGL (2/3) Polylines – Line Strip glBegin(GL_LINE_STRIP); glVertex2fv(p0); glVertex2fv(p1); glVertex2fv(p2); glVertex2fv(p3); glVertex2fv(p4); glVertex2fv(p5); glVertex2fv(p6); glVertex2fv(p7); glEnd(); glBegin(GL_LINE_STRIP); glVertex2fv(p0); glVertex2fv(p1); glVertex2fv(p2); glVertex2fv(p3); glVertex2fv(p4); glVertex2fv(p5); glVertex2fv(p6); glVertex2fv(p7); glEnd(); p0 p1 p2 p3 p4 p5 p6 p7

KUCG Graphics Korea University kucg.korea.ac.kr Lines in OpenGL (3/3) Polylines – Line Loop glBegin(GL_LINE_LOOP); glVertex2fv(p0); glVertex2fv(p1); glVertex2fv(p2); glVertex2fv(p3); glVertex2fv(p4); glVertex2fv(p5); glVertex2fv(p6); glVertex2fv(p7); glEnd(); glBegin(GL_LINE_LOOP); glVertex2fv(p0); glVertex2fv(p1); glVertex2fv(p2); glVertex2fv(p3); glVertex2fv(p4); glVertex2fv(p5); glVertex2fv(p6); glVertex2fv(p7); glEnd(); p0 p1 p2 p3 p4 p5 p6 p7

KUCG Graphics Korea University kucg.korea.ac.kr Polygons (1/2) Definition Object that is closed as a line loop, but that has an interior Simple Polygon No pair of edges of a polygon cross each other Simple Nonsimple

KUCG Graphics Korea University kucg.korea.ac.kr Polygons (2/2) Convexity If all points on the line segment between any two points inside the object, or on its boundary, are inside the object Convex Objects p1 p2

KUCG Graphics Korea University kucg.korea.ac.kr Polygons in OpenGL (1/6) Polygon glBegin(GL_POLYGON); glVertex2fv(p0); glVertex2fv(p1); glVertex2fv(p2); glVertex2fv(p3); glVertex2fv(p4); glVertex2fv(p5); glVertex2fv(p6); glVertex2fv(p7); glEnd(); glBegin(GL_POLYGON); glVertex2fv(p0); glVertex2fv(p1); glVertex2fv(p2); glVertex2fv(p3); glVertex2fv(p4); glVertex2fv(p5); glVertex2fv(p6); glVertex2fv(p7); glEnd(); p0 p1 p2 p3 p4 p5 p6 p7

KUCG Graphics Korea University kucg.korea.ac.kr Polygons in OpenGL (2/6) Quadrilaterals glBegin(GL_QUADS); glVertex2fv(p0); glVertex2fv(p1); glVertex2fv(p2); glVertex2fv(p3); glVertex2fv(p4); glVertex2fv(p5); glVertex2fv(p6); glVertex2fv(p7); glEnd(); glBegin(GL_QUADS); glVertex2fv(p0); glVertex2fv(p1); glVertex2fv(p2); glVertex2fv(p3); glVertex2fv(p4); glVertex2fv(p5); glVertex2fv(p6); glVertex2fv(p7); glEnd(); p0 p1 p2 p3 p4 p5 p6 p7

KUCG Graphics Korea University kucg.korea.ac.kr Polygons in OpenGL (3/6) Quadstrip glBegin(GL_QUAD_STRIP); glVertex2fv(p1); glVertex2fv(p2); glVertex2fv(p3); glVertex2fv(p0); glVertex2fv(p4); glVertex2fv(p7); glVertex2fv(p5); glVertex2fv(p6); glEnd(); glBegin(GL_QUAD_STRIP); glVertex2fv(p1); glVertex2fv(p2); glVertex2fv(p3); glVertex2fv(p0); glVertex2fv(p4); glVertex2fv(p7); glVertex2fv(p5); glVertex2fv(p6); glEnd(); p0 p1 p2 p3 p4 p5 p6 p7

KUCG Graphics Korea University kucg.korea.ac.kr Polygons in OpenGL (4/6) Triangles glBegin(GL_TRIANGLES); glVertex2fv(p0); glVertex2fv(p1); glVertex2fv(p2); glVertex2fv(p3); glVertex2fv(p4); glVertex2fv(p5); glVertex2fv(p6); glVertex2fv(p7); glEnd(); glBegin(GL_TRIANGLES); glVertex2fv(p0); glVertex2fv(p1); glVertex2fv(p2); glVertex2fv(p3); glVertex2fv(p4); glVertex2fv(p5); glVertex2fv(p6); glVertex2fv(p7); glEnd(); p0 p1 p2 p3 p4 p5 p6 p7

KUCG Graphics Korea University kucg.korea.ac.kr Polygons in OpenGL (5/6) Triangle Strip glBegin(GL_TRIANGLE_STRIP); glVertex2fv(p0); glVertex2fv(p7); glVertex2fv(p1); glVertex2fv(p6); glVertex2fv(p2); glVertex2fv(p5); glVertex2fv(p3); glVertex2fv(p4); glEnd(); glBegin(GL_TRIANGLE_STRIP); glVertex2fv(p0); glVertex2fv(p7); glVertex2fv(p1); glVertex2fv(p6); glVertex2fv(p2); glVertex2fv(p5); glVertex2fv(p3); glVertex2fv(p4); glEnd(); p0 p1 p2 p3 p4 p5 p6 p7

KUCG Graphics Korea University kucg.korea.ac.kr Polygons in OpenGL (6/6) Triangle Fan glBegin(GL_TRIANGLE_FAN); glVertex2fv(p0); glVertex2fv(p1); glVertex2fv(p2); glVertex2fv(p3); glVertex2fv(p4); glVertex2fv(p5); glVertex2fv(p6); glVertex2fv(p7); glEnd(); glBegin(GL_TRIANGLE_FAN); glVertex2fv(p0); glVertex2fv(p1); glVertex2fv(p2); glVertex2fv(p3); glVertex2fv(p4); glVertex2fv(p5); glVertex2fv(p6); glVertex2fv(p7); glEnd(); p0 p1 p2 p3 p4 p5 p6 p7

KUCG Graphics Korea University kucg.korea.ac.kr Attributes Properties that Determines How to Render a Geometric Primitive Color, thickness, pattern of filling, etc. Color Three color theory Color Solid Red Blue Green M Y C Cyan Yellow Magenta G B R Additive ColorSubtractive Color

KUCG Graphics Korea University kucg.korea.ac.kr Color in OpenGL Set the Clear Color glClearColor(1.0, 1.0, 1.0, 1.0)  Opaque: opacity is 1.0  Window is cleared by white color Set the Color State Varible glColor3f(1.0, 0.0, 0.0);  RGB color – red color Set the Size of Points glPointSize(2.0);  2 pixel wide

KUCG Graphics Korea University kucg.korea.ac.kr Viewing Viewing Volume glOrtho(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble near, GLdouble far); gluOrtho2D(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top); Matrix Mode 2 types: model-view, projection glMatrixMode(GL_PROJECTION); glLoadIdentity( ); gluOrtho2D(0.0, 500.0, 0.0, 500.0); glMatrixMode(GL_MODELVIEW); glMatrixMode(GL_PROJECTION); glLoadIdentity( ); gluOrtho2D(0.0, 500.0, 0.0, 500.0); glMatrixMode(GL_MODELVIEW);

KUCG Graphics Korea University kucg.korea.ac.kr Control (1/2) Interaction with Window Systems glutInit(int *argc, char *argv); glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE); glutInitWindowSize(480, 640); glutIntiWindowPosition(0, 0); Aspect Ratio and Viewport glViewprot(GLint x, GLint y,GLsizei w, GLsizei h);

KUCG Graphics Korea University kucg.korea.ac.kr Control (2/2) Example – “main”, “display”, and “myinit” Functions void myinit(void){ /* attributes */ glClearColor(1.0, 1,0, 1,0, 1,0); glColor3f(1.0, 0.0, 0.0); /* set up viewing */ glMatrixMode(GL_PROJECTION); gluLoadIdentity(); gluOrtho2D(0.0, 500.0, 0.0, 500.0); glMatrixMode(GL_MODELVIEW); } void myinit(void){ /* attributes */ glClearColor(1.0, 1,0, 1,0, 1,0); glColor3f(1.0, 0.0, 0.0); /* set up viewing */ glMatrixMode(GL_PROJECTION); gluLoadIdentity(); gluOrtho2D(0.0, 500.0, 0.0, 500.0); glMatrixMode(GL_MODELVIEW); } #include void main(int argc, char **argv){ glutInit(&argc, argv); glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB); glutInitWindowSize(500, 500); glutInitWindowPosition(0, 0); glutCreateWindow(“simple OpenGL example”); glutDisplayFunc(display); myinit(); glutMainLoop(); } #include void main(int argc, char **argv){ glutInit(&argc, argv); glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB); glutInitWindowSize(500, 500); glutInitWindowPosition(0, 0); glutCreateWindow(“simple OpenGL example”); glutDisplayFunc(display); myinit(); glutMainLoop(); }