از اساتید محترم عذرخواهی می کنم ؛ برای حرکت دایره باید از تابع timerfuction استفاده کنی ، بقیه اش رو سعی کن خودت انجام بدی
// circle.c
// OpenGL SuperBible
// Demonstrates point, line, and polygon smoothing
// Program by Richard S. Wright Jr.
// System and OpenGL Stuff
#include <math.h>
#include <gl/glut.h>
#include <stdio.h>
#define SCREEN_X 800
#define SCREEN_Y 600
///////////////////////////////////////////////////
int edgeOnly=0;
void DrawCircle(double radius, int numberOfSides);
GLUquadricObj *qobj;
// Called to draw scene
void RenderScene(void)
{
GLfloat x = 700.0f; // Location and radius of moon
GLfloat y = 500.0f;
GLfloat r = 50.0f;
GLfloat angle = 0.0f; // looping variable
// Clear the window
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// Everything is white
glColor3f(1.0f, 1.0f, 1.0f);
// Draw the "moon"
glBegin(GL_TRIANGLE_FAN);
glVertex2f(x, y);
for(angle = 0; angle < 2.0f * 3.141592f; angle += 0.1f)
glVertex2f(x + (float)cos(angle) * r, y + (float)sin(angle) * r);
glVertex2f(x + r, y);
glEnd();
//Draw the "ball"
glPushMatrix();
glTranslatef(390,117,0);
glColor3f(1,0,0);
edgeOnly=1;
DrawCircle(20, 6);
glPopMatrix();
//Draw the "sun"
glPushMatrix();
glTranslatef(100,500,0);
glColor3f(1,1,0);
edgeOnly=0;
DrawCircle(100, 200);
glPopMatrix();
// Draw distant horizon
glLineWidth(3.5);
glBegin(GL_LINE_STRIP);
glVertex2f(0.0f, 25.0f);
glVertex2f(50.0f, 100.0f);
glVertex2f(100.0f, 25.0f);
glVertex2f(225.0f, 125.0f);
glVertex2f(300.0f, 50.0f);
glVertex2f(375.0f, 100.0f);
glColor3f(1,1,1);
glVertex2f(460.0f, 25.0f);
glVertex2f(525.0f, 100.0f);
glVertex2f(600.0f, 20.0f);
glVertex2f(675.0f, 70.0f);
glVertex2f(750.0f, 25.0f);
glVertex2f(800.0f, 90.0f);
glEnd();
//glLineWidth(1.0);
//Draw the "minicircle1"
glPushMatrix();
glTranslatef(200,300,0);
glColor3f(1,0,0);
glutWireSphere(50,40,10);
glPopMatrix();
//Draw the "minicircle2"
glPushMatrix();
glTranslatef(300,300,0);
glColor3f(0.5,0,0);
glutSolidSphere(40,80,8);// why?
glPopMatrix();
//Draw the "minicircle3"
glPushMatrix();
glTranslatef(400,300,0);
glColor3f(1,1,1);
glutWireCone(30,20,8,10);
glPopMatrix();
//Draw the "minicircle4"
glPushMatrix();
glTranslatef(500,300,0);
glColor3f(1,1,1);
glutSolidCone(35,20,8,10);
glPopMatrix();
//Draw the "minicircle5"
glPushMatrix();
glTranslatef(600,300,0);
glColor3f(0,1,0);
glutWireTorus(0,40,10,6);
glPopMatrix();
//Draw the "minicircle6"
glPushMatrix();
glTranslatef(700,300,0);
glColor3f(1,1,0);
glutSolidTorus(8,40,5,600);// How?
glPopMatrix();
//Draw the "minicircle7"
glPushMatrix();
glTranslatef(200,200,0);
glColor3f(0,0,1);
qobj=gluNewQuadric();
gluQuadricDrawStyle(qobj, GLU_POINT);
gluSphere(qobj,45,80,10);
glPopMatrix();
//Draw the "minicircle8"
glPushMatrix();
glTranslatef(300,200,0);
glColor3f(0,0.5,0);
qobj=gluNewQuadric();
gluQuadricDrawStyle(qobj, GLU_LINE);
gluCylinder(qobj,45,30,10,8,20);
glPopMatrix();
//Draw the "minicircle9"
glPushMatrix();
glTranslatef(400,200,0);
glColor3f(0,0,0.5);
qobj=gluNewQuadric();
gluQuadricDrawStyle(qobj, GLU_FILL);
gluDisk(qobj,0,30,6,8);
glPopMatrix();
//Draw the "minicircle10"
glPushMatrix();
glTranslatef(500,200,0);
glColor3f(1,1,0.5);
qobj=gluNewQuadric();
gluQuadricDrawStyle(qobj, GLU_SILHOUETTE);
gluPartialDisk(qobj,0,50,60,8,0,325);
glPopMatrix();
// Swap buffers
glutSwapBuffers();
}
void DrawCircle(double radius, int numberOfSides)
{
int vertex;
// if edge only, use line strips; otherwise , use polygons
if(edgeOnly)
glBegin(GL_LINE_STRIP);
else
glBegin(GL_POLYGON);
// calculate each vertex on the circle
for ( vertex =0;vertex<numberOfSides;vertex++)
{
// calculate the angle of current vertex
// ( vertex # * 2 * PI ) / # of sides
float angle_c = (float) vertex * 2.0 * 3.14159 / numberOfSides;
// draw the current vertex at the correct radius
glVertex2f(cos(angle_c)*radius, sin(angle_c)*radius);
}
// if drawing edge only, then need to complete the loop with first vertex
if(edgeOnly)
glVertex2f(radius, 0.0);
glEnd();
}
// This function does any needed initialization on the rendering
// context.
void SetupRC()
{
//int i;
// Black background
glClearColor(0.0f, 0.0f, 0.0f, 1.0f );
// Set drawing color to white
glColor3f(0.0f, 0.0f, 0.0f);
}
void ChangeSize(int w, int h)
{
// Prevent a divide by zero
if(h == 0)
h = 1;
// Set Viewport to window dimensions
glViewport(0, 0, w, h);
// Reset projection matrix stack
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
// Establish clipping volume (left, right, bottom, top, near, far)
gluOrtho2D(0.0, SCREEN_X, 0.0, SCREEN_Y);
// Reset Model view matrix stack
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
int main(int argc, char* argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize(800, 600);
glutCreateWindow("My Moon");
glutReshapeFunc(ChangeSize);
glutDisplayFunc(RenderScene);
SetupRC();
printf("This program represents some methods for circle drawing\n");
glutMainLoop();
return 0;
}
این برنامه رو اجرا کن ببین ،