#include <glut.h>
#include <stdio.h>
#include <math.h>
GLfloat angle = 0.0; //angle for cube1
GLfloat tangle = 0.0; //angle for cube2
//-------------------------------------------------------------------
void DrawSphere (void) {
glPushMatrix(); //set where to start the current object
glTranslatef(1.5, 1.5, 0); //move cube2 to the left
glRotatef(tangle, 0.0, 1.0, 0.0);
glRotatef(tangle, 1.0, 0.0, 0.0);
glRotatef(tangle, 0.0, 0.0, 1.0);
glColor3f(0.0, 1.0, 0.0); //change cube2 to green
glutWireSphere(0.5,16,16);
glPopMatrix(); //end the current object transformations
}
//-------------------------------------------------------------------
//-------------------------------------------------------------------
void myDisplay(void)
{
glMatrixMode(GL_MODELVIEW);
glClear(GL_COLOR_BUFFER_BIT);
glLoadIdentity();
DrawSphere();
glFlush();
glutSwapBuffers();
angle+= 0.5;
tangle+= 1.0;
}
/*void myMouse(int button, int state, int x, int y)
{
if ( button == GLUT_LEFT_BUTTON && state == GLUT_DOWN)
glutIdleFunc(myDisplay); // starts animation
else if ( button == GLUT_RIGHT_BUTTON && state == GLUT_DOWN)
glutIdleFunc(NULL); // stops animation
}*/
void myKeyboard(unsigned char key, int x, int y)
{
if (key=='r')
glutIdleFunc(myDisplay);
if (key=='s')
glutIdleFunc(NULL);
}
void myInit(void)
{
glClearColor(0.0, 0.0, 0.0, 0.0); // set the background to black
glColor3f(1.0f, 1.0f, 1.0f); // set the drawing color to white
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0, 3.0, 0.0, 3.0);
}
//-------------------------------------------------------------------
void main( int argc, char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB );
glutInitWindowSize(550,450);
glutInitWindowPosition(0,0);
glutCreateWindow("One Triangle");
//glutMouseFunc(myMouse);
glutDisplayFunc(myDisplay);
glutKeyboardFunc(myKeyboard);
myInit();
glutMainLoop();
}
#include <stdio.h>
#include <math.h>
GLfloat angle = 0.0; //angle for cube1
GLfloat tangle = 0.0; //angle for cube2
//-------------------------------------------------------------------
void DrawSphere (void) {
glPushMatrix(); //set where to start the current object
glTranslatef(1.5, 1.5, 0); //move cube2 to the left
glRotatef(tangle, 0.0, 1.0, 0.0);
glRotatef(tangle, 1.0, 0.0, 0.0);
glRotatef(tangle, 0.0, 0.0, 1.0);
glColor3f(0.0, 1.0, 0.0); //change cube2 to green
glutWireSphere(0.5,16,16);
glPopMatrix(); //end the current object transformations
}
//-------------------------------------------------------------------
//-------------------------------------------------------------------
void myDisplay(void)
{
glMatrixMode(GL_MODELVIEW);
glClear(GL_COLOR_BUFFER_BIT);
glLoadIdentity();
DrawSphere();
glFlush();
glutSwapBuffers();
angle+= 0.5;
tangle+= 1.0;
}
/*void myMouse(int button, int state, int x, int y)
{
if ( button == GLUT_LEFT_BUTTON && state == GLUT_DOWN)
glutIdleFunc(myDisplay); // starts animation
else if ( button == GLUT_RIGHT_BUTTON && state == GLUT_DOWN)
glutIdleFunc(NULL); // stops animation
}*/
void myKeyboard(unsigned char key, int x, int y)
{
if (key=='r')
glutIdleFunc(myDisplay);
if (key=='s')
glutIdleFunc(NULL);
}
void myInit(void)
{
glClearColor(0.0, 0.0, 0.0, 0.0); // set the background to black
glColor3f(1.0f, 1.0f, 1.0f); // set the drawing color to white
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0, 3.0, 0.0, 3.0);
}
//-------------------------------------------------------------------
void main( int argc, char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB );
glutInitWindowSize(550,450);
glutInitWindowPosition(0,0);
glutCreateWindow("One Triangle");
//glutMouseFunc(myMouse);
glutDisplayFunc(myDisplay);
glutKeyboardFunc(myKeyboard);
myInit();
glutMainLoop();
}
ليست هناك تعليقات:
إرسال تعليق