LAB 5 Drawing Objects Lab 5 Drawing Objects
LAB 5 Drawing Objects Lab 5 Drawing Objects
�Example to draw circle �Drawing Objects: �Sphere �Cube �Torus �Icosahedron �Octahedron �Tetrahedron �Dodecahedron �Cone �Teapot �practices
#include <windows. h> #include <glglut. h> #include <math. h> #define PI 3. 14159265 int num. Points= 500; int Radius =50; void draw(void) } gl. Clear(GL_COLOR_BUFFER_BIT); gl. Color 3 f(0. 0, 0. 6); gl. Begin(GL_POLYGON); for (int i=0; i<num. Points; i++) } float angle = i * (2. 0*PI/num. Points); float x = cos(angle)*Radius; float y = sin(angle)*Radius; gl. Vertex 2 f(x , y); { gl. End(); gl. Flush(); { void main(void) } glut. Init. Display. Mode(GLUT_RGB); glut. Init. Window. Position(100, 100); glut. Init. Window. Size(200, 200); glut. Create. Window("draw circle"); gl. Clear. Color(0. 95, 0. 90, 0. 85, 0. 0); glut. Display. Func(draw); glu. Ortho 2 D(-100. 0, 100. 0); glut. Main. Loop(); {
�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 3 D objects: �Sphere �Cube �Torus �Icosahedron �Octahedron �Tetrahedron �Dodecahedron �Cone �Teapot
�void glut. Solid. Sphere(GLdouble radius, GLint slices, GLint stacks); �void glut. Wire. Sphere(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).
�glut. Solid. Sphere(15, 10, 70); �glut. Wire. Sphere(15, 10, 70);
�void glut. Solid. Torus(Gldouble inner. Radius , GLdouble outer. Radius, GLint nsides, GLint rings); �void glut. Wire. Torus(GLdouble inner. Radius, GLdouble outer. Radius, GLint nsides, GLint rings); Where: �inner. Radius : Inner radius of the torus. �outer. Radius : Outer radius of the torus. �nsides : Number of sides for each radial section. �rings : Number of radial divisions for the torus.
�glut. Solid. Torus(5, 10, 15, 50);
� void glut. Solid. Cube(GLdouble size); � void glut. Wire. Cube(GLdouble size);
�Glut. Solid. Cube(20); �glut. Wire. Cube(20);
�void glut. Solid. Cone(GLdouble base, GLdouble height, GLint slices, GLint stacks); �void glut. Wire. Cone(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.
�glut. Solid. Cone(5, 2, 70, 10);
�void glut. Solid. Teapot(GLdouble size); �void glut. Wire. Teapot(GLdouble size); Where: �size : Relative size of the teapot. Example: glut. Solid. Teapot(10);
�void glut. Solid. Icosahedron(void); Example: glut. Solid. Icosahedron(); �void glut. Wire. Icosahedron(void); Example: glut. Wire. Icosahedron();
�void glut. Solid. Octahedron(void); Example: glut. Solid. Octahedron (); �void glut. Wire. Octahedron(void); Example: glut. Wire. Octahedron ();
�void glut. Solid. Tetrahedron(void); Example: glut. Solid. Tetrahedron(); �void glut. Wire. Tetrahedron(void); Example: glut. Wire. Tetrahedron();
�void glut. Solid. Dodecahedron(void); Example: glut. Solid. Dodecahedron(); �void glut. Wire. Dodecahedron(void); Example: glut. Wire. Dodecahedron();
#include <windows. h> #include <GL/glut. h> void draw(void) } gl. Clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //gl. Enable(GL_DEPTH_TEST); //gl. Enable(GL_LIGHTING); //gl. Enable(GL_LIGHT 0); //gl. Disable(GL_CULL_FACE); //gl. Enable(GL_COLOR_MATERIAL); gl. Color 3 ub (204, 0, 102); glut. Solid. Teapot(10); gl. Flush(); {
void main() } glut. Init. Window. Size(200, 200); glut. Init. Display. Mode(GLUT_DEPTH); glut. Create. Window("Teapot"); glut. Display. Func(draw); gl. Clear. Color(0. 95, 0. 90, 0. 85, 0. 0); //gl. Matrix. Mode(GL_PROJECTION); //gl. Load. Identity(); gl. Ortho(-21. 0, -20. 0, 20. 0); //gl. Matrix. Mode(GL_MODELVIEW); //gl. Load. Identity(); glut. Main. Loop(); {
Draw the following shapes: 1) Solid Sphere glut. Solid. Sphere (0. 4, 16) 2) Solid Cube glut. Solid. Cube (1. 0) Solid cone glut. Solid. Cone (1. 0, 2. 0, 3, 4); 3) Redraw the previous objects as a wire frame.
- Slides: 21