Presentation is loading. Please wait.

Presentation is loading. Please wait.

LAB 5 Drawing Objects Lab 5 Drawing Objects.

Similar presentations


Presentation on theme: "LAB 5 Drawing Objects Lab 5 Drawing Objects."— Presentation transcript:

1 LAB 5 Drawing Objects Lab 5 Drawing Objects

2  Example to draw circle  Drawing Objects:
 Sphere  Cube  Torus  Icosahedron  Octahedron  Tetrahedron  Dodecahedron  Cone  Teapot  practices

3 glutCreateWindow("draw circle"); glClearColor(0.95, 0.90, 0.85, 0.0);
#include <windows.h> #include <gl\glut.h> #include <math.h> void main(void) #define PI } int numPoints= 500; int Radius =50; void draw(void) glutInitDisplayMode(GLUT_RGB); glutInitWindowPosition(100,100); glutInitWindowSize(200,200); } glutCreateWindow("draw circle"); glClearColor(0.95, 0.90, 0.85, 0.0); glClear(GL_COLOR_BUFFER_BIT); glColor3f(0.0,0.6,0.6); glutDisplayFunc(draw); glBegin(GL_POLYGON); for (int i=0; i<numPoints; i++) gluOrtho2D(-100.0, 100.0, , 100.0); } glutMainLoop(); float angle = i * (2.0*PI/numPoints); float x = cos(angle)*Radius; { float y = sin(angle)*Radius; glVertex2f(x , y); { glEnd(); glFlush(); {

4  The GLUT library provides several objects that are rather tedious to build. These objects are fully defined, with normal, and they are useful for experimenting with lighting. A “wire” object displays as a wire frame. A “solid” object looks like a solid, but you should define its material properties yourself.

5 GLUT provides functions for the 3D objects:  Sphere
 Cube  Torus  Icosahedron  Octahedron  Tetrahedron  Dodecahedron  Cone  Teapot

6  void glutSolidSphere(GLdouble radius, GLint slices, GLint stacks);
 void glutWireSphere(GLdouble radius, GLint slices, GLint stacks); Where:  radius : The radius of the sphere.  slices : The number of subdivisions around the Z axis (similar to lines of longitude).  stacks : The number of subdivisions along the Z axis (similar to lines of latitude).

7

8  glutSolidSphere(15,10,70);  glutWireSphere(15,10,70);

9

10 GLdouble outerRadius, GLint nsides, GLint rings); Where:
 void glutSolidTorus(Gldouble innerRadius ,GLdouble outerRadius, GLint nsides, GLint rings);  void glutWireTorus(GLdouble innerRadius, GLdouble outerRadius, GLint nsides, GLint rings); Where:  innerRadius : Inner radius of the torus.  outerRadius : Outer radius of the torus.  nsides : Number of sides for each radial section.  rings : Number of radial divisions for the torus.

11

12  glutSolidTorus(5,10,15,50);

13 void glutSolidCube(GLdouble size); void glutWireCube(GLdouble size);

14  GlutSolidCube(20);  glutWireCube(20);

15  void glutSolidCone(GLdouble base, GLdouble height, GLint slices, GLint stacks);
 void glutWireCone(GLdouble base, GLdouble height, GLint slices, GLint stacks); Where:  base : The radius of the base of the cone.  height :The height of the cone.  slices : The number of subdivisions around the Z axis.  stacks :The number of subdivisions along the Z axis.

16  glutSolidCone(5,2,70,10);

17  void glutSolidTeapot(GLdouble size);  void glutWireTeapot(GLdouble size); Where:
 size :Relative size of the teapot. Example: glutSolidTeapot(10);

18  void glutSolidIcosahedron(void); Example: glutSolidIcosahedron();  void glutWireIcosahedron(void); Example: glutWireIcosahedron();

19  void glutSolidOctahedron(void); Example: glutSolidOctahedron ();  void glutWireOctahedron(void); Example: glutWireOctahedron ();

20  void glutSolidTetrahedron(void); Example: glutSolidTetrahedron();  void glutWireTetrahedron(void); Example: glutWireTetrahedron();

21  void glutSolidDodecahedron(void); Example: glutSolidDodecahedron();  void glutWireDodecahedron(void); Example: glutWireDodecahedron();

22 #include <windows.h> #include <GL/glut.h> void draw(void)
} glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //glEnable(GL_DEPTH_TEST); //glEnable(GL_LIGHTING); //glEnable(GL_LIGHT0); //glDisable(GL_CULL_FACE); //glEnable(GL_COLOR_MATERIAL); glColor3ub (204,0,102); glutSolidTeapot(10); glFlush(); {

23 void main() } glutInitWindowSize(200,200); glutInitDisplayMode(GLUT_DEPTH); glutCreateWindow("Teapot"); glutDisplayFunc(draw); glClearColor(0.95, 0.90, 0.85, 0.0); //glMatrixMode(GL_PROJECTION); //glLoadIdentity(); glOrtho(-21.0, 21.0, -21.0, 21.0, -20.0, 20.0); //glMatrixMode(GL_MODELVIEW); //glLoadIdentity(); glutMainLoop(); {

24

25 Draw the following shapes: Solid Sphere glutSolidSphere (0.4, 16, 16)
1) Solid Cube glutSolidCube (1.0) 2) Solid cone glutSolidCone (1.0, 2.0, 3, 4); 3) Redraw the previous objects as a wire frame.


Download ppt "LAB 5 Drawing Objects Lab 5 Drawing Objects."

Similar presentations


Ads by Google