Download presentation
Presentation is loading. Please wait.
Published byΕυρυδίκη Αγγελόπουλος Modified over 6 years ago
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).
8
glutSolidSphere(15,10,70); glutWireSphere(15,10,70);
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.
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(); {
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.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.