
OpenGL Drawing Examples Using GLUT Library
Explore OpenGL drawing examples using the GLUT library to create points, quads, polygons, and more. Learn how to set up the environment, draw shapes, and display them on the screen with sample code snippets and visual representations.
Download Presentation

Please find below an Image/Link to download the presentation.
The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.
You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.
The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.
E N D
Presentation Transcript
#include <GL/glut.h> void draw_points() {glClearColor(1,1,1,1); glClear(GL_COLOR_BUFFER_BIT); glEnable(GL_POINT_SMOOTH); glColor3f(1,0,0); glPointSize(20); glBegin(GL_POINTS); glColor3f(0,1,0); glVertex2i(10,10); glColor3f(1,0,0); glVertex2i(15,15); glEnd(); glFlush();} int main(int argc, char** argv) {glutInit(&argc,argv); glutInitWindowPosition(50,50); glutInitWindowSize(640,512); glutInitDisplayMode(GLUT_SINGLE|GLUT_ RGB); glutCreateWindow("Drawing multiple points"); glMatrixMode(GL_PROJECTION); gluOrtho2D(0,30,-10,25); glutDisplayFunc(draw_points); glutMainLoop(); return 0; } -lopengl32 -lfreeglut -lglu32
glColor3f(0,0,1); glVertex2f(22.5,22.5); glVertex2f(30,15); glVertex2f(30,25); glEnd(); glFlush();} int main(int argc, char** argv) { glutInit(&argc,argv); glutInitWindowPosition(50,50); glutInitWindowSize(640,512); glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB); glutCreateWindow("Drawing quads"); glMatrixMode(GL_PROJECTION); gluOrtho2D(-20,40,-10,25); glutDisplayFunc(display); glutMainLoop(); return 0;} #include <GL/glut.h> void display() {glClearColor(1,1,1,0); glClear(GL_COLOR_BUFFER_BIT); glColor3f(0,1,0); glBegin(GL_QUADS); glVertex2f(5,5); glVertex2f(30,5); glVertex2f(25,10); glVertex2f(10,10); glEnd(); glBegin(GL_QUAD_STRIP); glVertex2f(0,15); glVertex2f(0,25); glColor3f(0,1,0); glVertex2f(7.5,17.5); glVertex2f(7.5,22.5); glVertex2f(15,15); glVertex2f(15,25); glVertex2f(22.5,17.5); -lopengl32 -lfreeglut -lglu32
#include <GL/glut.h> void display() { glClearColor(1,1,1,0); glClear(GL_COLOR_BUFFER_BIT); glColor3f(0,1,0); glBegin(GL_POLYGON); glVertex2f(2.5,0); glVertex2f(7.5,0); glVertex2f(10,5); glVertex2f(7.5,10); glVertex2f(2.5,10); glVertex2f(0,5); glEnd(); glFlush(); } int main(int argc, char** argv) { glutInit(&argc,argv); glutInitWindowPosition(50,50); glutInitWindowSize(640,512); glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB); glutCreateWindow("Drawing poly"); glMatrixMode(GL_PROJECTION); gluOrtho2D(-20,40,-10,25); glutDisplayFunc(display); glutMainLoop(); return 0; } -lopengl32 -lfreeglut -lglu32
glVertex2i(15,0); glEnd(); glColor3f(0,0,1); glBegin(GL_LINE_LOOP); glVertex2i(0,15); glVertex2i(0,20); glVertex2i(5,25); glVertex2i(10,20); glVertex2i(10,15); glEnd();glFlush();} int main(int argc, char** argv) {glutInit(&argc,argv); glutInitWindowPosition(50,50); glutInitWindowSize(640,512); glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB); glutCreateWindow("Drawing line"); glMatrixMode(GL_PROJECTION); gluOrtho2D(-20,40,-10,25); glutDisplayFunc(display); glutMainLoop(); return 0; } #include <GL/glut.h> void display() {glClearColor(1,1,1,0); glClear(GL_COLOR_BUFFER_BIT); glLineWidth(3); glColor3f(1,0,0); glBegin(GL_LINES); glVertex2i(0,0); glVertex2i(10,0); glVertex2i(0,10); glVertex2i(10,10); glEnd(); glColor3f(0,1,0); glBegin(GL_LINE_STRIP); glVertex2i(15,10); glVertex2i(20,10); glVertex2i(25,5); glVertex2i(20,0); -lopengl32 -lfreeglut -lglu32
glColor3f(0,0,1); glBegin(GL_TRIANGLE_FAN); glVertex2f(0,10); glVertex2f(10,10); glColor3f(1,0,1); glVertex2f(9.5,13); glVertex2f(8,15); glVertex2f(5,18); glColor3f(0,1,1); glVertex2f(0,20); glEnd(); glFlush(); } int main(int argc, char** argv) {glutInit(&argc,argv); glutInitWindowPosition(50,50); glutInitWindowSize(640,480); glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB); glutCreateWindow("Drawing triangles"); glMatrixMode(GL_PROJECTION); gluOrtho2D(-5,30,-5,30); glutDisplayFunc(display); glutMainLoop(); return 0;} #include <GL/glut.h> void display() { glClearColor(1,1,1,0); glClear(GL_COLOR_BUFFER_BIT); glColor3f(1,0,0); glBegin(GL_TRIANGLES); glVertex2f(0,0); glVertex2f(5,0); glVertex2f(0,5); glVertex2f(7.5,0); glVertex2f(12.5,0); glVertex2f(7.5,5); glEnd(); glColor3f(0,1,0); glBegin(GL_TRIANGLE_STRIP); glVertex2f(17.5,5); glVertex2f(22.5,0); glVertex2f(22.5,5); glVertex2f(25,5); glEnd();
#include <GL/glut.h> void display() { glClearColor(1,1,1,0); glClear(GL_COLOR_BUFFER_BIT); glColor3f(1,0,0); glRectf(0,0,15,10); glColor3f(0,1,0); glRectf(20,0,30,10); glColor3f(0,0,1); glRectf(12.5,15,25.5,25); glFlush();} int main(int argc, char** argv) {glutInit(&argc,argv); glutInitWindowPosition(50,50); glutInitWindowSize(640,480); glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB); glutCreateWindow("Drawing rectangles"); glMatrixMode(GL_PROJECTION); gluOrtho2D(-5,35,-5,30); glutDisplayFunc(display); glutMainLoop(); return 0;}
#include <GL/glut.h> void display() { glClearColor(1,1,1,0); glClear(GL_COLOR_BUFFER_BIT); for (int i=5; i>=1; i--) {glColor3f(1*i%2,0+i%2,0+i%3); glRectf(10-i*2,10-i*2,15+i*2,10+i*2);} glFlush();} int main(int argc, char** argv) {glutInit(&argc,argv); glutInitWindowPosition(50,50); glutInitWindowSize(640,480); glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB); glutCreateWindow("Drawing rectangles"); glMatrixMode(GL_PROJECTION); gluOrtho2D(-5,35,-5,30); glutDisplayFunc(display); glutMainLoop(); return 0; }
glBegin(GL_LINE_LOOP); for(i=0;i<pointsPerQuarter/2;i++) { //Define points in first quadrant x[i]=radius*cos(i*angleStep); y[i]=radius*sin(i*angleStep); x[pointsPerQuarter-1-i]=y[i]; y[pointsPerQuarter-1-i]=x[i]; //Define points in second quadrant x[pointsPerQuarter+i]=-y[i]; y[pointsPerQuarter+i]=x[i]; x[2*pointsPerQuarter-1-i]=-x[i]; y[2*pointsPerQuarter-1-i]=y[i]; //Define points in third quadrant x[2*pointsPerQuarter+i]=-x[i]; y[2*pointsPerQuarter+i]=-y[i]; x[3*pointsPerQuarter-1-i]=-y[i]; y[3*pointsPerQuarter-1-i]=-x[i]; //Define points in fourth quadrant x[3*pointsPerQuarter+i]=y[i]; y[3*pointsPerQuarter+i]=-x[i]; x[4*pointsPerQuarter-1-i]=x[i]; y[4*pointsPerQuarter-1-i]=-y[i]; } for (i=0;i<circlePoints;i++) { glVertex2f(x[i],y[i]); } glEnd(); glFlush(); } int main(int argc, char** argv) { glutInit(&argc,argv); glutInitWindowPosition(50,50); glutInitWindowSize(640,480); glutInitDisplayMode(GLUT_SINGLE|GLUT_RGBA); glutCreateWindow("Circle drawing"); glMatrixMode(GL_PROJECTION); gluOrtho2D(-32,32,-24,24); glutDisplayFunc(display); glutMainLoop(); return 0; } #include <GL/glut.h> #include <math.h> #define PI 3.14159 #define circlePoints 256 int i; void display() { GLfloat angleStep=2*PI/(float)circlePoints; GLuint pointsPerQuarter=circlePoints/4; GLfloat x[circlePoints]; GLfloat y[circlePoints]; GLfloat radius=10; glClearColor(0,0,0,0); glClear(GL_COLOR_BUFFER_BIT); glColor3f(0,1,0); glLineWidth(3);
#include <GL/glut.h> void display() {glClearColor(0,0,0,0); glClear(GL_COLOR_BUFFER_BIT); glColor3f(0.5,0,0); //Front face of a polygon - Vertices defined in counter clockwise order glBegin(GL_POLYGON); glVertex2i(0,0); glVertex2i(10,0); glVertex2i(15,10); glVertex2i(10,20); glVertex2i(0,20); glEnd(); //Back face of a polygon //Vertices defined in clockwise order glColor3f(0,0.5,0); glBegin(GL_POLYGON); glVertex2i(30,0); glVertex2i(25,10); glVertex2i(30,20); glVertex2i(40,20); glVertex2i(40,0); glEnd();glFlush();} int main(int argc, char** argv) { glutInit(&argc,argv); glutInitWindowPosition(50,50); glutInitWindowSize(640,480); glutInitDisplayMode(GLUT_SINGLE|GLUT_RGBA); glutCreateWindow("Polygon front and back faces"); glMatrixMode(GL_PROJECTION); gluOrtho2D(-10,50,-10,50); //Polygon front faces are to be filled. glPolygonMode(GL_FRONT,GL_FILL); //Polygon back faces are to be drawn as lines glPolygonMode(GL_BACK,GL_LINE); glutDisplayFunc(display); glutMainLoop(); return 0; }
#include <GL/glut.h> void display() { glClearColor(0,0,0,0); glClear(GL_COLOR_BUFFER_BIT); //Front face of a polygon - Vertices defined in counter clockwise order for (int i=0; i<=3; i++) { glLineWidth(i*2+1); glColor3f(0.5,i/2.0,i/2.0); glBegin(GL_POLYGON); glVertex2i(0-i*2,0+i*2); glVertex2i(10-i*2,0+i*2); glVertex2i(10-i*2,20+i*2); glVertex2i(0-i*2,20+i*2); glEnd(); } glFlush(); } int main(int argc, char** argv) { glutInit(&argc,argv); glutInitWindowPosition(50,50); glutInitWindowSize(640,480); glutInitDisplayMode(GLUT_SINGLE|GLUT_RGBA); glutCreateWindow("Polygon front and back faces"); glMatrixMode(GL_PROJECTION); gluOrtho2D(-10,50,-10,50); //Polygon front faces are to be filled. glPolygonMode(GL_FRONT,GL_LINE); //Polygon back faces are to be drawn as lines //glPolygonMode(GL_BACK,GL_LINE); glutDisplayFunc(display); glutMainLoop(); return 0; }
#include <GL/glut.h> GLuint x1=10,y1=10; GLuint x2=20,y2=20; void display() {glClearColor(1,1,1,0); glClear(GL_COLOR_BUFFER_BIT); glColor3f(1,0,0); glRecti(x1,y1,x2,y2); glFlush();} void keyboard(unsigned char key,int x, int y) { if (key=='t') {y1++; y2++;} if (key=='g') {y1--; y2--;} if (key=='f') {x1--; x2--;} if (key=='h') {x1++; x2++;} Keyboard EVENT glutPostRedisplay(); } int main(int argc, char** argv) { glutInit(&argc,argv); glutInitWindowPosition(50,50); glutInitWindowSize(640,480); glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB); glutCreateWindow("Keyboard events"); glMatrixMode(GL_PROJECTION); gluOrtho2D(-5,35,-5,30); glutDisplayFunc(display); glutKeyboardFunc(keyboard); glutMainLoop(); return 0; } a b to
void specialKeys(int key,int x, int y) { if (key==GLUT_KEY_UP) { y1++; y2++; } if (key==GLUT_KEY_DOWN) { y1--; y2--; } if (key==GLUT_KEY_LEFT) { x1--; x2--; } if (key==GLUT_KEY_RIGHT) { x1++; x2++; } glutPostRedisplay(); } if (key=='a') { y1++; y2--; x1++; x2--; } if (key=='b') { y1--; y2++; x1--; x2++; } glutSpecialFunc(specialKeys); main a b to
#include <GL/glut.h> //Clipping window limits float xwmin=-50, xwmax=50, ywmin=-50, ywmax=50; //Application window dimensions int windowWidth=640, windowHeight=480; GLfloat xw1,yw1,xw2,yw2; void display() { glClearColor(1,1,1,0); glClear(GL_COLOR_BUFFER_BIT); glRectf(xw1,yw1,xw2,yw2); glFlush(); } void mouseButtonClicked(int button,int state,int x, int y) { if(state==GLUT_DOWN) { xw1=(float)(xwmin+(float)(x)*(xwmax-xwmin)/(float)(windowWidth)); yw1=(float)(ywmin+(float)(windowHeight-y)*(ywmax- ywmin)/(float)(windowHeight)); xw2=xw1+20; yw2=yw1+20; if (button==GLUT_LEFT_BUTTON) glColor3f(1,0,0); else if (button==GLUT_MIDDLE_BUTTON) glColor3f(0,1,0); else if (button==GLUT_RIGHT_BUTTON) glColor3f(0,0,1); //Generate a display event glutPostRedisplay();}} Mouse EVENT: , , int main(int argc, char** argv) { glutInit(&argc,argv); glutInitWindowPosition(50,50); glutInitWindowSize(windowWidth,windowHeight); glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB); glutCreateWindow("Mouse click events"); glMatrixMode(GL_PROJECTION); gluOrtho2D(xwmin,xwmax,ywmin,ywmax); glutDisplayFunc(display); glutMouseFunc(mouseButtonClicked); glutMainLoop(); return 0; } Mouse EVENT 1: , , 2:
#include <GL/glut.h> //Clipping window limits float xwmin=-50, xwmax=50, ywmin=-50, ywmax=50; //Application window dimensions int windowWidth=640, windowHeight=480; GLfloat xw1=0,yw1=0; GLfloat xw2=xw1+20,yw2=yw1+20; void display() {glClearColor(1,1,1,0); glColor3f(0,0,1); glClear(GL_COLOR_BUFFER_BIT); glRectf(xw1,yw1,xw2,yw2); glFlush();} void mouseActiveMotion(int x, int y) { xw1=(float)(xwmin+(float)(x)*(float)(xwmax- xwmin)/(float)(windowWidth)); yw1=(float)(ywmin+(float)(windowHeight-y)*(float)(ywmax- ywmin)/(float)(windowHeight)); xw2=xw1+20; yw2=yw1+20; glutPostRedisplay(); } Mouse EVENT: int main(int argc, char** argv) {glutInit(&argc,argv); glutInitWindowPosition(50,50); glutInitWindowSize(windowWidth,windowHeight); glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB); glutCreateWindow("Mouse active motion events"); glMatrixMode(GL_PROJECTION); gluOrtho2D(xwmin,xwmax,ywmin,ywmax); glutDisplayFunc(display); glutMotionFunc(mouseActiveMotion); glutMainLoop(); return 0; }
#include <GL/glut.h> int windowWidth=640, windowHeight=480; int xwmin=-50; int ywmin=-50; int xwmax=50; int ywmax=50; GLfloat xw1=10,yw1=10; GLfloat xw2=xw1+100,yw2=yw1+100; void display() { glClearColor(1,1,1,0); glColor3f(0,0,1); glClear(GL_COLOR_BUFFER_BIT); glRectf(xw1,yw1,xw2,yw2); glFlush(); } void mousePassiveMotion(int x, int y) { xw1=(float)(xwmin+(float)(x)*(float)(xwmax- xwmin)/(float)(windowWidth)); yw1=(float)(ywmin+(float)(windowHeight-y)*(float)(ywmax- ywmin)/(float)(windowHeight)); xw2=xw1+20; yw2=yw1+20; glutPostRedisplay(); } Mouse EVENT: ( ) int main(int argc, char** argv) { glutInit(&argc,argv); glutInitWindowPosition(50,50); glutInitWindowSize(640,480); glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB); glutCreateWindow("Mouse passive motion events"); glMatrixMode(GL_PROJECTION); gluOrtho2D(xwmin,xwmax,ywmin,ywmax); glutDisplayFunc(display); glutPassiveMotionFunc(mousePassiveMotion); glutMainLoop(); return 0; } Mouse EVENT :
#include <GL/glut.h> GLuint x1=10; GLuint y1=10; GLuint x2=x1+100; GLuint y2=y1+100; void display() { glClearColor(1,1,1,0); glClear(GL_COLOR_BUFFER_BIT); glColor3f(1,0,0); glRecti(x1,y1,x2,y2); glFlush(); } void idle() { if (x2>640) { x1=0; x2=x1+100; } else {x1++; x2++;} glutPostRedisplay(); } animation int main(int argc, char** argv) { glutInit(&argc,argv); glutInitWindowPosition(50,50); glutInitWindowSize(640,480); glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB); glutCreateWindow("Idle events (A low-quality animation)"); glMatrixMode(GL_PROJECTION); gluOrtho2D(0,640,0,480); glutDisplayFunc(display); //Register an idle callback function. glutIdleFunc(idle); glutMainLoop(); return 0; } ANIMATION : x1=rand()%640; ( 0-639), rand() 0- 32767
#include <GL/glut.h> GLuint x1=10; GLuint y1=10; GLuint x2=x1+100; GLuint y2=y1+100; void display() { glClearColor(1,1,1,0); glClear(GL_COLOR_BUFFER_BIT); glColor3f(1,0,0); glRecti(x1,y1,x2,y2); glFlush(); } void timerFunction(int value) { //printf("Timer event detected.\nValuePassed: %d\n",value); x1+=100; x2+=100; y1+=100; y2+=100; glutPostRedisplay(); } int main(int argc, char** argv) { glutInit(&argc,argv); glutInitWindowPosition(50,50); glutInitWindowSize(640,480); glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB); glutCreateWindow("Timer event"); glMatrixMode(GL_PROJECTION); gluOrtho2D(0,640,0,480); glutDisplayFunc(display); glutTimerFunc(5000,timerFunction,10); glutMainLoop(); return 0; } TIMER: 5sec
#include <GL/glut.h> GLuint x1=10; GLuint y1=10; TIMER: loop animation void display() { glClearColor(1,1,1,0); glClear(GL_COLOR_BUFFER_BIT); glEnable(GL_POINT_SMOOTH); glColor3f(1,0,0); glPointSize(20); glBegin(GL_POINTS); glVertex2i(x1,y1); glEnd(); glFlush(); } void timerFunction(int value) { x1=rand()%640; y1=rand()%480; glutPostRedisplay(); glutTimerFunc(500,timerFunction,10); } int main(int argc, char** argv) { glutInit(&argc,argv); glutInitWindowPosition(50,50); glutInitWindowSize(640,480); glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB); glutCreateWindow("Timer event"); glMatrixMode(GL_PROJECTION); gluOrtho2D(0,640,0,480); glutDisplayFunc(display); glutTimerFunc(500,timerFunction,10); glutMainLoop(); return 0; }
#include <GL/glut.h> void display() {glLoadIdentity(); glClearColor(1,1,1,0); glClear(GL_COLOR_BUFFER_BIT); glLineWidth(3); glColor3f(0,0,1); glBegin(GL_LINES); glVertex2f(0,-24); glVertex2f(0,24); glVertex2f(-32,0); glVertex2f(32,0); glEnd(); glRecti(0,0,20,10); glColor3f(0,1,0); glRotatef(45,0,0,1); glRecti(0,0,20,10); glBegin(GL_LINES); glVertex2f(0,-24); glVertex2f(0,24); glVertex2f(-32,0); glVertex2f(32,0); glEnd(); glFlush(); } int main(int argc, char** argv) { glutInit(&argc,argv); glutInitWindowPosition(50,50); glutInitWindowSize(640,480); glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB); glutCreateWindow("Rotation example"); glMatrixMode(GL_PROJECTION); gluOrtho2D(-32,32,-24,24); glMatrixMode(GL_MODELVIEW); glutDisplayFunc(display); glutMainLoop(); return 0; }
#include <GL/glut.h> void display() { glLoadIdentity(); glClearColor(1,1,1,0); glClear(GL_COLOR_BUFFER_BIT); glLineWidth(3); glColor3f(0,0,1); glBegin(GL_LINES); glVertex2f(0,-24); glVertex2f(0,24); glVertex2f(-32,0); glVertex2f(32,0); glEnd(); glRecti(0,0,20,10); glColor3f(0,1,0); int main(int argc, char** argv) { glutInit(&argc,argv); glutInitWindowPosition(50,50); glutInitWindowSize(640,480); glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB); glutCreateWindow("Translation example"); glMatrixMode(GL_PROJECTION); gluOrtho2D(-32,32,-24,24); glMatrixMode(GL_MODELVIEW); glutDisplayFunc(display); glutMainLoop(); return 0; } glTranslatef(10,5,0); glBegin(GL_LINES); glVertex2f(0,-24); glVertex2f(0,24); glVertex2f(-32,0); glVertex2f(32,0); glEnd(); glRecti(0,0,20,10); glFlush(); }
#include <GL/glut.h> GLuint x1=0; GLuint y1=0; void display() { glClearColor(1,1,1,0); glClear(GL_COLOR_BUFFER_BIT); glEnable(GL_POINT_SMOOTH); glColor3f(1,0,0); glPointSize(20); glBegin(GL_POINTS); glVertex2i(x1,y1); glEnd(); glFlush(); } void timerFunction(int value) { glTranslatef(2,2,0); glRotatef(45,0,0,1); glutPostRedisplay(); glutTimerFunc(500,timerFunction,10); } int main(int argc, char** argv) { glutInit(&argc,argv); glutInitWindowPosition(50,50); glutInitWindowSize(640,480); glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB); glutCreateWindow("Translation example"); glMatrixMode(GL_PROJECTION); gluOrtho2D(-32,32,-24,24); glMatrixMode(GL_MODELVIEW); glutDisplayFunc(display); glutTimerFunc(500,timerFunction,10); glutMainLoop(); return 0; } , for
#include <GL/glut.h> void display() { glClearColor(1,1,1,0); glClear(GL_COLOR_BUFFER_BIT); glColor3f(1,0.5,0.5); glutWireSphere(40,40,40); glFlush(); } int main(int argc, char **argv) { glutInit(&argc,argv); glutInitWindowPosition(50,50); glutInitWindowSize(800,600); glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB); glutCreateWindow("A cube wireframe"); glMatrixMode(GL_PROJECTION); glOrtho(-80,80,-60,60,0,100); glMatrixMode(GL_MODELVIEW); gluLookAt(-30,-30,40,0,0,0,0,1,0); glutDisplayFunc(display); glutMainLoop(); return 0; } void glutWireSphere( GLdoule radius, GLint slices, GLint stacks ); void glutSolidSphere( GLdoule radius, GLint slices, GLint stacks ); Radius: . Slices: ( ), stacks: ( ) 1: a , b 2: animation .
#include <GL/glut.h> void display() { glColor3f(0,0,1); glClearColor(1,1,1,0); glClear(GL_COLOR_BUFFER_BIT); glutSolidCube(20); glColor3f(1,0,1); gluLookAt(0,20,0,10,0,10,0,1,0); glutWireCube(40); glFlush(); } int main(int argc, char **argv) { glutInit(&argc,argv); glutInitWindowPosition(50,50); glutInitWindowSize(800,600); glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB); glutCreateWindow("A cube wireframe"); glMatrixMode(GL_PROJECTION); glOrtho(-80,80,-60,60,0,100); glMatrixMode(GL_MODELVIEW); gluLookAt(-30,-30,40,0,0,0,0,1,0); glutDisplayFunc(display); glutMainLoop(); return 0; } void glutWireCube ( GLdouble edgeLength ); void glutSolidCube ( GLdouble edgeLength ); edgeLength : . 1: a , b 2: animation . .
#include <GL/glut.h> GLuint x1=40; void display() { glColor3f(0,0,1); glClearColor(1,1,1,0); glClear(GL_COLOR_BUFFER_BIT); glutWireCone(30,60,20,20); glFlush(); } int main(int argc, char **argv) { glutInit(&argc,argv); glutInitWindowPosition(50,50); glutInitWindowSize(800,600); glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB); glutCreateWindow("A cone wireframe"); glMatrixMode(GL_PROJECTION); glOrtho(-80,80,-60,60,0,100); glMatrixMode(GL_MODELVIEW); gluLookAt(0,-40,40,10,0,0,0,1,0); glutDisplayFunc(display); glutMainLoop(); return 0; } glutWireCone(GLdouble base, GLdouble height, GLint slices, Glint stacks); glutSolidCone (GLdouble base, GLdouble height, GLint slices, Glint stacks); base : . Height: Slices: ( ), stacks: ( ) 1: a , b 2: c
#include <GL/glut.h> GLUquadric *cylinder; void display() { glColor3f(0,0,1); glClearColor(1,1,1,0); glClear(GL_COLOR_BUFFER_BIT); gluQuadricDrawStyle(cylinder,GLU_LINE); gluCylinder(cylinder,10,20,40,20,15); glFlush(); } int main(int argc, char **argv) { glutInit(&argc,argv); glutInitWindowPosition(50,50); glutInitWindowSize(800,600); glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB); glutCreateWindow("A cylinder wireframe"); glMatrixMode(GL_PROJECTION); glOrtho(-80,80,-60,60,0,100); glMatrixMode(GL_MODELVIEW); gluLookAt(0,-30,40,0,0,0,0,1,0); cylinder=gluNewQuadric(); glutDisplayFunc(display); glutMainLoop(); return 0; } gluCylinder(GLUquadric *qObj, GLdouble baseRadius, GLdouble topRadius, GLdouble height, GLdouble slices, GLdouble stacks); qObj . baseRadius: topRadius: Height: . Slices: ( ), stacks: ( ) 1: a , b 2: c
#include <GL/glut.h> GLUquadric *disk; void display() { glColor3f(0,0,1); glClearColor(1,1,1,0); glClear(GL_COLOR_BUFFER_BIT); gluQuadricDrawStyle(disk,GLU_LINE); gluDisk(disk,5,20,30,10); glFlush(); } int main(int argc, char **argv) { glutInit(&argc,argv); glutInitWindowPosition(50,50); glutInitWindowSize(800,600); glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB); glutCreateWindow("A disk wireframe"); glMatrixMode(GL_PROJECTION); glOrtho(-80,80,-60,60,0,100); disk=gluNewQuadric(); glutDisplayFunc(display); glutMainLoop(); return 0; } void gluDisk (GLUquadric *quadObject, GLdouble innerRadius, GLdouble outerRadius, Glint slices,Glint loops ); quadObject: . innerRadius: outerRadius : . Slices: ( ), loops 1: a , b 2: c
#include <GL/glut.h> void display() { glColor3f(0,0,1); glClearColor(1,1,1,0); glClear(GL_COLOR_BUFFER_BIT); glutWireTorus(10,40,40,40); glColor3f(0,1,1); glutWireTorus(4,20,40,40); glFlush();} int main(int argc, char **argv) {glutInit(&argc,argv); glutInitWindowPosition(50,50); glutInitWindowSize(800,600); glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB); glutCreateWindow("A torus wireframe"); glMatrixMode(GL_PROJECTION); glOrtho(-80,80,-60,60,0,100); glMatrixMode(GL_MODELVIEW); gluLookAt(0,-40,40,0,0,0,0,1,0); glutKeyboardFunc(keyboard); glutDisplayFunc(display); glutMainLoop(); return 0; } void glutWireTorus(GLdouble innerRadius, GLdouble outerRadius, GLint sides, GLint rings); void glutSolidTorus(GLdouble innerRadius, GLdouble outerRadius, GLint sides, GLint rings); innerRadius : . outerRadius: . Rings: Sides: 1: a , b k , f 2: c