Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <GL/glut.h>
- #include <cmath>
- float angle = 0.0f;
- void drawRectangle() {
- // Set the color of the rectangle
- glColor3f(1.0f, 0.0f, 0.0f);
- glPushMatrix();
- // Rotate y-axis
- glRotatef(angle, 0.0f, 1.0f, 0.0f);
- // Draw rectangle
- glBegin(GL_QUADS);
- glVertex2f(-0.5f, -0.5f);
- glVertex2f(0.5f, -0.5f);
- glVertex2f(0.5f, 0.5f);
- glVertex2f(-0.5f, 0.5f);
- glEnd();
- glPopMatrix();
- }
- void update(int value) {
- // Update the angle of rotation
- angle += 1.0f;
- if (angle > 360) {
- angle -= 360;
- }
- glutPostRedisplay();
- // 10ms
- glutTimerFunc(10, update, 0);
- }
- int main(int argc, char** argv) {
- // Initialize GLUT
- glutInit(&argc, argv);
- glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
- glutInitWindowSize(500, 500);
- glutCreateWindow("Rotating Rectangle");
- glutDisplayFunc(drawRectangle);
- glutTimerFunc(10, update, 0);
- glutMainLoop();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement