Sierpinski Gasket Program

Slides:



Advertisements
Similar presentations
Coordinate System.
Advertisements

Basic of computer graphics with OpenGL. Handful graphics function  OpenGL :  by silicon graphics  PHIGS :  Programmer’s Hierarchical Graphics System.
1 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 Programming with OpenGL Part 3: Three Dimensions.
© 2004, Tom Duff and George Ledin Jr1 Lectures OpenGL Introduction By Tom Duff Pixar Animation Studios Emeryville, California and George Ledin Jr Sonoma.
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,
CSC 461: Lecture 51 CSC461 Lecture 5: Simple OpenGL Program Objectives: Discuss a simple program Discuss a simple program Introduce the OpenGL program.
Hidden Surfaces and Shading CS BSP Tree T1T1 T2T2 E if (f 1 (E) < 0) then draw T 1 draw T 2 else draw T 2 draw T 1 f 1 (p) = 0 is the.
1 CSC461 Lecture 7: 3D Programming in OpenGL Objectives: Develop 2D and 3D examples -- Sierpinski gasket: a fractal Develop 2D and 3D examples -- Sierpinski.
InteractionHofstra University1 Graphics Programming Input and Interaction.
Lighting & Material. Example 1/5 #include ” glut.h ” void display(); void reshape(int, int); void lighting(); int main(int argc, char** argv) { glutInit(&argc,
Write a Simple Program with OpenGL & GLUT. Books and Web Books OpenGL Programming Guide (Red-book) OpenGL Reference Manual (Blue-book) OpenGL Super Bible.
CAP 4703 Computer Graphic Methods Prof. Roy Levow Lecture 2.
Computer Graphics, KKU. Lecture 131 Transformation and Viewing in OpenGL.
Demetriou/Loizidou – ACSC330 – Chapter 2 Graphics Programming Dr. Giorgos A. Demetriou Dr. Stephania Loizidou Himona Computer Science Frederick Institute.
Write a Simple Program with OpenGL & GLUT. Books OpenGL Programming Guide (Red-book) OpenGL Reference Manual (Blue-book) OpenGL Super Bible
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.
Introduction to GL Geb Thomas. Example Code int main(int argc, char **argv) { glutInit(&argc, argv); glutInitDisplayMode ( GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH);
1Computer Graphics Programming with OpenGL Three Dimensions – 2 Lecture 7 John Shearer Culture Lab – space 2
Chun-Yuan Lin Graphics Programming 2015/11/17 1 CG.
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.
1 Chapter 2: Graphics Programming Bryson Payne CSCI 3600 NGCSU.
CS 480/680 Computer Graphics Programming with Open GL Part 6: Three Dimensions Dr. Frederick C Harris, Jr. Fall 2011.
CH8 Frame Buffer Object 1. Introduction Name OpenGL :Frame Buffer Object DirectX:Render Target Usage Render to Texture 2.
COMPUTER GRAPHICS Hochiminh city University of Technology Faculty of Computer Science and Engineering CHAPTER 02: Graphics Programming.
Draw a Simple Object. Pixel pipeline Vertex pipeline Course Map Transformation & Lighting Primitive assembly Viewport culling & clipping Texture blending.
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.
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.
Projections. Viewports Windows can have separate viewports void glViewport(GLint x, GLint y, GLsizei width, GLsizei height ) x, y - Specify the lower.
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 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Programming with OpenGL Part 3: Three Dimensions Ed Angel Professor of Computer Science,
1 E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012 Programming with OpenGL Part 6: Three Dimensions Ed Angel Professor.
CS559: Computer Graphics Lecture 12: OpenGL - Transformation Li Zhang Spring 2008.
31/1/2006Based on: Angel (4th Edition) & Akeine-Möller & Haines (2nd Edition)1 CSC345: Advanced Graphics & Virtual Environments Lecture 2: Introduction.
CS559: Computer Graphics Lecture 12: OpenGL: ModelView Li Zhang Spring 2010.
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.
Graphics Graphics Korea University kucg.korea.ac.kr Graphics Programming 고려대학교 컴퓨터 그래픽스 연구실.
Implement of transformation,projection, viewing Hanyang University Jungsik Park.
CSC Graphics Programming Budditha Hettige Department of Statistics and Computer Science.
Computer Graphics I, Fall Programming with OpenGL Part 2: Complete Programs.
CS380 LAB II OpenGL Donghyuk Kim Reference1. [OpenGL course slides by Rasmus Stenholt] Reference2. [
Chapter (2)1 Computer Graphics - Chapter 2 Graphics Programming Objectives are to learn about: An example: The Sierpinski Gasket The OpenGL API Primitives.
CSC Graphics Programming
Graphics Programming Chun-Yuan Lin CG 2018/5/15.
Course code:10CS65 | Computer Graphics and Visualization
Programming with OpenGL Part 1: Background
Programming with OpenGL Part 3: Three Dimensions
OpenGL (Open Graphics Library) Mr. B.A.Swamy Assistant Professor Dept of CSE.
Introduction to Computer Graphics with WebGL
Lighting and Shading Lab 8:.
CSC461: Lecture 24 Lighting and Shading in OpenGL
Programming with OpenGL Part 3: Three Dimensions
Introduction to OpenGL
OpenGL program.
Introduction to Computer Graphics with WebGL
Programming with OpenGL Part 6: Three Dimensions
Lighting and Shading Lab 8:.
Programming with OpenGL Part 3: Three Dimensions
Angel: Interactive Computer Graphics5E © Addison-Wesley 2009
Programming with OpenGL Part 3: Three Dimensions
Angel: Interactive Computer Graphics5E © Addison-Wesley 2009
Presentation transcript:

Sierpinski Gasket Program CGV Lab Program 1 Sierpinski Gasket Program

Writing Assignment Write the program to create a 2-D sierpinski Gasket, using 5000 points which are randomly selected

Quick recap of 2nd 2-D gasket program We considered a triangle by specifying its 3 vertices Subdivided the triangle into 4 triangles by Locating mid points on each edge Joining one vertex with 2 midpoints of the corresponding edges Repeat till we perform the prescribed no of recursions Draw solid triangles only at the last step

Output of 2-d gasket program by subdividing triangles

Lab Program 1 Program to recursively subdivide a tetrahedron to form 3D Sierpinski gasket. The number of recursive steps is to be specified by the user.

3-D gasket by subdividing tetrahedron

Program Code #include <GL/glut.h> #endif /* initial tetrahedron */ GLfloat v[4][3]={{0.0, 0.0, 1.0}, {0.0, 0.942809, -0.33333}, {-0.816497, -0.471405, -0.333333}, {0.816497, -0.471405, -0.333333}}; GLfloat colors[4][3] = {{1.0, 0.0, 0.0}, {0.0, 1.0, 0.0}, {0.0, 0.0, 1.0}, {0.0, 0.0, 0.0}}; int n;

void triangle(GLfloat. va, GLfloat. vb, GLfloat void triangle(GLfloat *va, GLfloat *vb, GLfloat *vc) { glVertex3fv(va); glVertex3fv(vb); glVertex3fv(vc); } void tetra(GLfloat *a, GLfloat *b, GLfloat *c, GLfloat *d) glColor3fv(colors[0]); triangle(a, b, c); glColor3fv(colors[1]); triangle(a, c, d); glColor3fv(colors[2]); triangle(a, d, b); glColor3fv(colors[3]); triangle(b, d, c);

void divide_tetra(GLfloat. a, GLfloat. b, GLfloat. c, GLfloat void divide_tetra(GLfloat *a, GLfloat *b, GLfloat *c, GLfloat *d, int m) { GLfloat mid[6][3]; int j; if(m>0) /* compute six midpoints */ for(j=0; j<3; j++) mid[0][j]=(a[j]+b[j])/2; for(j=0; j<3; j++) mid[1][j]=(a[j]+c[j])/2; for(j=0; j<3; j++) mid[2][j]=(a[j]+d[j])/2; for(j=0; j<3; j++) mid[3][j]=(b[j]+c[j])/2; for(j=0; j<3; j++) mid[4][j]=(c[j]+d[j])/2; for(j=0; j<3; j++) mid[5][j]=(b[j]+d[j])/2; /* create 4 tetrahedrons by subdivision */ divide_tetra(a, mid[0], mid[1], mid[2], m-1); divide_tetra(mid[0], b, mid[3], mid[5], m-1); divide_tetra(mid[1], mid[3], c, mid[4], m-1); divide_tetra(mid[2], mid[4], d, mid[5], m-1); } else tetra(a,b,c,d); /* draw tetrahedron at end of recursion */

void display() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glBegin(GL_TRIANGLES); divide_tetra(v[0], v[1], v[2], v[3], n); glEnd(); glFlush(); } void myReshape(int w, int h) glViewport(0, 0, w, h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); if (w <= h) glOrtho(-2.0, 2.0, -2.0 * (GLfloat) h / (GLfloat) w, 2.0 * (GLfloat) h / (GLfloat) w, -10.0, 10.0); else glOrtho(-2.0 * (GLfloat) w / (GLfloat) h, 2.0 * (GLfloat) w / (GLfloat) h, -2.0, 2.0, -10.0, 10.0); glMatrixMode(GL_MODELVIEW); glutPostRedisplay();

Aspect ratio Aspect ratio of a rectangle is the ratio of rectangle’s width to its height Make sure that the clipping window and display window have the same aspect ratio Viewing rectangle Display window

viewport A viewport is a rectangular area of the display window By default it is the entire window It can be set to any smaller size in pixels via the function void glViewport(GLint x, GLint y, Glsizei w, Glsizei h) (x,y) – lower-left corner of the viewport ( relative to lower left corner of the window ) w – width., h – height We specify the values in pixels

Viewport contd..

int main(int argc, char. argv) { n=4; / int main(int argc, char **argv) { n=4; /* enter number of subdivision steps here */ glutInit(&argc, argv); glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH); glutInitWindowSize(500, 500); glutCreateWindow("3D Gasket"); glutReshapeFunc(myReshape); glutDisplayFunc(display); glEnable(GL_DEPTH_TEST); glClearColor (1.0, 1.0, 1.0, 1.0); glutMainLoop(); }

We are using recursive subdivision of tetrahedron We are using an algo z-buffer algorithm to remove hidden surface That is why z(or depth ) buffer is used

Desired output