LAB 5 Drawing Objects Lab 5 Drawing Objects
Example to draw circle Drawing Objects: Sphere Cube Torus Icosahedron Octahedron Tetrahedron Dodecahedron Cone Teapot practices
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 3.14159265 } 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, 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(); {
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.
GLUT provides functions for the 3D objects: Sphere Cube Torus Icosahedron Octahedron Tetrahedron Dodecahedron Cone Teapot
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).
glutSolidSphere(15,10,70); glutWireSphere(15,10,70);
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.
glutSolidTorus(5,10,15,50);
void glutSolidCube(GLdouble size); void glutWireCube(GLdouble size);
GlutSolidCube(20); glutWireCube(20);
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.
glutSolidCone(5,2,70,10);
void glutSolidTeapot(GLdouble size); void glutWireTeapot(GLdouble size); Where: size :Relative size of the teapot. Example: glutSolidTeapot(10);
void glutSolidIcosahedron(void); Example: glutSolidIcosahedron(); void glutWireIcosahedron(void); Example: glutWireIcosahedron();
void glutSolidOctahedron(void); Example: glutSolidOctahedron (); void glutWireOctahedron(void); Example: glutWireOctahedron ();
void glutSolidTetrahedron(void); Example: glutSolidTetrahedron(); void glutWireTetrahedron(void); Example: glutWireTetrahedron();
void glutSolidDodecahedron(void); Example: glutSolidDodecahedron(); void glutWireDodecahedron(void); Example: glutWireDodecahedron();
#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(); {
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(); {
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.