Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <GL/glut.h>
- #include <math.h>
- float angle = 0.0f;
- void changeSize(int w, int h)
- {
- if (h == 0) h = 1;
- float ratio = w * 1.0 / h;
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- glViewport(0, 0, w, h);
- gluPerspective(45.0f, ratio, 0.1f, 100.0f);
- glMatrixMode(GL_MODELVIEW);
- }
- void myRotatef(GLfloat a, GLfloat x, GLfloat y, GLfloat z)
- {
- a = a * 3.14 / 18.0; // convert to radians
- GLfloat s = sin(a);
- GLfloat c = cos(a);
- GLfloat t = 1.0 - c;
- GLfloat tx = t * x;
- GLfloat ty = t * y;
- GLfloat tz = t * z;
- GLfloat sz = s * z;
- GLfloat sy = s * y;
- GLfloat sx = s * x;
- float matrix[16];
- matrix[0] = tx * x + c;
- matrix[1] = tx * y + sz;
- matrix[2] = tx * z - sy;
- matrix[3] = 0;
- matrix[4] = tx * y - sz;
- matrix[5] = ty * y + c;
- matrix[6] = ty * z + sx;
- matrix[7] = 0;
- matrix[8] = tx * z + sy;
- matrix[9] = ty * z - sx;
- matrix[10] = tz * z + c;
- matrix[11] = 0;
- matrix[12] = 0;
- matrix[13] = 0;
- matrix[14] = 0;
- matrix[15] = 1;
- glMultMatrixf(&matrix[0]);
- }
- void myDrawLetter()
- {
- glBegin(GL_QUADS); // Begin drawing the color cube with 6 quads
- // Top face (y = 1.0f)
- // Define vertices in counter-clockwise (CCW) order with normal pointing out
- glColor3f(0.0f, 1.0f, 0.0f); // Green
- glVertex3f( 1.0f, 1.0f, -1.0f);
- glVertex3f(-1.0f, 1.0f, -1.0f);
- glVertex3f(-1.0f, 1.0f, 1.0f);
- glVertex3f( 1.0f, 1.0f, 1.0f);
- // Bottom face (y = -1.0f)
- glColor3f(1.0f, 0.5f, 0.0f); // Orange
- glVertex3f( 1.0f, -1.0f, 1.0f);
- glVertex3f(-1.0f, -1.0f, 1.0f);
- glVertex3f(-1.0f, -1.0f, -1.0f);
- glVertex3f( 1.0f, -1.0f, -1.0f);
- // Front face (z = 1.0f)
- glColor3f(1.0f, 0.0f, 0.0f); // Red
- glVertex3f( 1.0f, 1.0f, 1.0f);
- glVertex3f(-1.0f, 1.0f, 1.0f);
- glVertex3f(-1.0f, -1.0f, 1.0f);
- glVertex3f( 1.0f, -1.0f, 1.0f);
- // Back face (z = -1.0f)
- glColor3f(1.0f, 1.0f, 0.0f); // Yellow
- glVertex3f( 1.0f, -1.0f, -1.0f);
- glVertex3f(-1.0f, -1.0f, -1.0f);
- glVertex3f(-1.0f, 1.0f, -1.0f);
- glVertex3f( 1.0f, 1.0f, -1.0f);
- // Left face (x = -1.0f)
- glColor3f(0.0f, 0.0f, 1.0f); // Blue
- glVertex3f(-1.0f, 1.0f, 1.0f);
- glVertex3f(-1.0f, 1.0f, -1.0f);
- glVertex3f(-1.0f, -1.0f, -1.0f);
- glVertex3f(-1.0f, -1.0f, 1.0f);
- // Right face (x = 1.0f)
- glColor3f(1.0f, 0.0f, 1.0f); // Magenta
- glVertex3f(1.0f, 1.0f, -1.0f);
- glVertex3f(1.0f, 1.0f, 1.0f);
- glVertex3f(1.0f, -1.0f, 1.0f);
- glVertex3f(1.0f, -1.0f, -1.0f);
- glEnd(); // End of drawing color-cube
- }
- void renderScene()
- {
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- glEnable(GL_DEPTH_TEST);
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
- gluLookAt( 10.0f, 10.0f, 10.0f,
- 0.0f, 0.0f, 0.0f,
- 5.0f, 5.0f, 0.0f);
- myRotatef(angle*10, 0.0f, 1.0f, 0.0f);
- //glRotatef(angle*10, 0.0f, 1.0f, 0.0f);
- myDrawLetter();
- angle+=0.05f;
- glutSwapBuffers();
- }
- int main(int argc, char **argv)
- {
- glutInit(&argc, argv);
- glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
- glutInitWindowPosition(100,100);
- glutInitWindowSize(400,400);
- glutCreateWindow("Quartenion");
- glutDisplayFunc(renderScene);
- glutReshapeFunc(changeSize);
- glutIdleFunc(renderScene);
- glutMainLoop();
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement