Presentation is loading. Please wait.

Presentation is loading. Please wait.

Computer Graphics Prof. Muhammad Saeed Dept. of Computer Science & IT Federal Urdu University of Arts, Sciences and Technology.

Similar presentations

Presentation on theme: "Computer Graphics Prof. Muhammad Saeed Dept. of Computer Science & IT Federal Urdu University of Arts, Sciences and Technology."— Presentation transcript:

1 Computer Graphics Prof. Muhammad Saeed Dept. of Computer Science & IT Federal Urdu University of Arts, Sciences and Technology

2 FUUASTDept. of Comp. Sc.& IT2 Computer Graphics 3.OpenGL using Tao Framework in C#

3 FUUASTDept. of Comp. Sc.& IT3 1.Introduction 1.C# Wrapper (Tao Framework) i. Introduction to Tao framework ii.The installation and use in C# 2.Two Dimensional i.Functions structure a.end characters: i, f, d and v to end:2, 3,4 ii.2D window and viewport a.gluOrtho2D(left,right,bottom,right); b.glViewport(x,y,width,height); iii.Projection Matrix Mode a.glMatrixMode(GL_PROJECTION) b.glLoadIdentity() OpenGL Computer Graphics

4 FUUASTDept. of Comp. Sc.& IT4 OpenGL Computer Graphics iv.Drawing primitives a.Points: glBegin(GL_POINTS); glVertex2d(x,y); …… ; glEnd(); b.Lines: glBegin(GL_LINES); glVertex2d(x,y); glVertex2d(x,y); ……. ;glEnd(); glBegin(GL_LINE_STRIP); …….. ; glEnd(); glBegin(GL_LINE_LOOP); ……. ;glEnd(); c.Triangles: glBegin(GL_TRIANGLES); ……. ; glEnd(); glBegin(GL_TRIANGLE_STRIP); ……. ; glEnd(); glBegin(GL_TRIANGLE_FAN); ……. ; glEnd(); d.Quads: glBegin(GL_QUADS); ……….. ; glEnd(); glBegin(GL_QUAD_STRIP); ……. glEnd(); e.Polygons: glBegin(GL_POLYGON); …….. ; glEnd();,

5 v.Colors: a.Drawing color: glColor3d(red, green, blue); b.Background Color: glClearColor(red, green, blue, alpha); c.Clear Screen(Frame Buffer): glClear(GL_COLOR_BUFFER_BIT); d.Color Gradient: Every vertex with different color. 2. Three Dimensional Initials i.Viewing Systems : a.2D b.Orthographic c.Perspective. FUUASTDept. of Comp. Sc.& IT5 OpenGL Computer Graphics

6 FUUASTDept. of Comp. Sc.& IT6 Computer Graphics Orthographic Viewing System x y z N Near PlaneFar Plane F left right top bottom

7 FUUASTDept. of Comp. Sc.& IT7 Computer Graphics Projection Matrix and Orthographic Viewing a.Orthographic: glMatrixMode(GL_PROJECTION); glLoadIdentity();glOrtho(-x, x,-y, y, near far);

8 FUUASTDept. of Comp. Sc.& IT8 Computer Graphics N d top, left right, bottom F Perspective Viewing System

9 FUUASTDept. of Comp. Sc.& IT9 Computer Graphics Projection Matrix and Perspective viewing b. Perspective: glMatrixMode(GL_PROJECTION); glLoadIdentity();gluPerspective(view angle, aspect ratio, near, far);

10 FUUASTDept. of Comp. Sc.& IT10 Viewing Model Camera Analogy Setting Model Focus Photograph Viewing Modeling Projection Viewport Setting Model Focus Photograph Viewing Modeling Projection Viewport OpenGL Computer Graphics

11 FUUASTDept. of Comp. Sc.& IT11 OpenGL Computer Graphics ii.Camera Setting: glMatrixMode(GL_MODELVIEW); glLoadIdentity(); gluLookAt( x1, y1, z1, x2, y2, z2, x, y, z); iii.Lights: Ambient, Diffuse and Specular. ( Defs. and Discussion ) a.Position glLightfv(GL_LIGHT0, GL_POSITION, pos); b.Ambient Light: glLightfv(GL_LIGHT0, GL_AMBIENT, amb); c. Diffuse: glLightfv(GL_LIGHT0, GL_DIFFUSE, diff); d. Specular: glLightfv(GL_LIGHT0, GL_SPECULAR, spec); Pos, amb, diff, spec are arrays of size 4. containing respective position and color values.

12 FUUASTDept. of Comp. Sc.& IT12 OpenGL Computer Graphics e. Enabling of light: glEnable(GL_LIGHTING); glEnable(GL_LIGHT0) ; iv.Shading Model: a.1)Gouraud Shading 2)Phong Shading b.1)glShadeModel(GL_SMOOTH); 2)glShadeModel(GL_FLAT); v.Buffers: a)Double Buffer b)Frame Buffer c)Accummulation Buffer vi.Hidden Surface Removal Depth Buffer (Z-Buffer) glEnable(GL_DEPTH_TEST); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

13 1. Vectors i.component representation ii.Addition, dot product and cross product iii.Unit, parallel and normal vector on a plane iv.Equation of a plane and normal vector 2.3D Curves i.3D implicit and parametric curves (list given) ii.Bezier Curves and B-Splines 4. Meshes and surfaces 1.Meshes i.meshes by curve equations, Sine curve, and sphere etc. ii.Meshes by rotation and translation 3.3D Mathematics FUUASTDept. of Comp. Sc.& IT13 OpenGL Computer Graphics

14 1.3D Objects and Transformations i. Material colors, emission color and shininess glMaterialfv(GL_FRONT, GL_AMBIENT, materialAmbient); glMaterialfv(GL_FRONT, GL_DIFFUSE, materialAmbient); glMaterialfv(GL_FRONT, GL_SPECULAR, materialSpecular); glMaterialfv(GL_FRONT, GL_EMISSION, materialEmission); glMaterialf(GL_FRONT, GL_SHININESS, materialShininess); glColorMaterial(GL_FRONT, GL_DIFFUSE); ii.Drawing sphere, cylinder, cone, disk, partial disk GLUquadric quad = gluNewQuadric(); gluQuadricDrawStyle(quad, GLU_FILL); //GLU_POINT,GLU_LINE,GLU_SILHOUETTE gluQuadricNormals(quad, GLU_SMOOTH); //GLU_FLAT, GLU_NONE gluQuadricOrientation(quad, GLU_INSIDE); //GLU_OUTSIDE gluSphere(quad, radius, slices, stacks); 5.Solid Modeling FUUASTDept. of Comp. Sc.& IT14 OpenGL Computer Graphics

15 FUUASTDept. of Comp. Sc.& IT15 OpenGL Computer Graphics 2.Surfaces and solids i.vertices, edges and surfaces ii.Platonic solids ii.Constructing Cube, Sphere, Tetrahedron etc. 3.Surfaces of rotation surfaces of sine curve, Bezier curve iii.Rotation, translation and scaling of 3D objects glRotated(angle, x, y, z); glTranslated(dx, dy, dz); glScaled(s, s, s); iv.User-defined matrices and OpenGL stacks, shearing matrix glLoadMatrixf(array[16]); glMultMatrixf( array[16]);

16 Structure-deforming Transformati ons 1.Tapering 2.Twisting 3.Bending Dept. of Comp. Sc. & ITFUUAST16 OpenGL Computer Graphics 2.Deformations

17 Dept. of Comp. Sc. & ITFUUAST17 i. Tapering: Original Object Tapered along Z-axis Transformation Equations: X2 = r * X1 Y2 = r * Y1 Z2 = Z1 r = f(Z1) Matrix Form: = OpenGL Computer Graphics

18 Dept. of Comp. Sc. & ITFUUAST18 ii. Twisting: Original Object Twisted along Z-axis Transformation Equations: X2 = X1*cos( ) – Y1*sin( ) Y2 = X1*sin( ) + Y1*cos( ) Z2 = Z1 = f(Z1) Matrix Form: = OpenGL Computer Graphics

19 Dept. of Comp. Sc. & ITFUUAST19 iii. Bending (Composite Transformation): Original Object Bent Bend Region is along Y axis Y min Y Y max Center of the Bend is at Y = Y 0 Radius of Curvature = 1/k Bending angle is: = k( - Y 0 ) Where: = x = X y = Z = Transformation Equations: OpenGL Computer Graphics

20 FUUASTDept. of Comp. Sc.& IT20 OpenGL Computer Graphics 4.Display Lists int num=glGenerateLists(1); glNewList(num, GL_COMPILE); //GL_COMPILE_AND_EXECUTE ………. glEndList(); glCallList(num); 5.Fog glEnable(GL_FOG); float[] fogColor ={ 0.1f, 0.1f, 0.15f, 1.0f }; glFogi(GL_FOG_MODE, GL_EXP); //GL_EXP2;//GL_LINEAR;//GL_EXP; glFogfv(GL_FOG_COLOR, fogColor); glFogf(GL_FOG_DENSITY, 0.2f); glHint(GL_FOG_HINT, GL_NICEST); //GL_FASTEST);//GL_DONT_CARE);//GL_NICEST glFogf(GL_FOG_START, 3.5f); glFogf(GL_FOG_END, 5.0f);

21 FUUASTDept. of Comp. Sc.& IT21 OpenGL Computer Graphics 6.Spot Lights glLighti(GL_LIGHT0, GL_SPOT_CUTOFF, 30);//20 glLightfv(GL_LIGHT0, GL_SPOT_DIRECTION, spotDirection); glLightf(GL_LIGHT0, GL_SPOT_EXPONENT, 1.5f); glLightf(GL_LIGHT0, GL_CONSTANT_ATTENUATION, 1.0f); glLightf(GL_LIGHT0, GL_LINEAR_ATTENUATION, 0.2f); glLightf(GL_LIGHT0, GL_QUADRATIC_ATTENUATION, 0.1f); 7.Blending glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); //glBlendEquation(GL_FUNC_ADD); glEnable(GL_CULL_FACE); glCullFace(GL_BACK);

22 8.Ray Tracing Quad trees, Octree and BSP trees 9.Bitmap Color picColor; Bitmap bitmap = (Bitmap)Bitmap.FromFile(file); //bitmap = new Bitmap(file); bitmapHeight = bitmap.Height; bitmapWidth = bitmap.Width; picColor = bitmap.GetPixel(i, j); bitmap.SetPixel(i, j, picColor); 10. Zooming, Panning, Segmentation and Extruding 11. Texture Mapping 12. Animation FUUASTDept. of Comp. Sc.& IT22 OpenGL Computer Graphics

23 END

Download ppt "Computer Graphics Prof. Muhammad Saeed Dept. of Computer Science & IT Federal Urdu University of Arts, Sciences and Technology."

Similar presentations

Ads by Google