132001f49Smrg/* 232001f49Smrg * Draw a triangle with rotation 332001f49Smrg */ 432001f49Smrg 532001f49Smrg#include <stdio.h> 632001f49Smrg#include <stdlib.h> 732001f49Smrg#include "glut_wrap.h" 832001f49Smrg 932001f49Smrg 1032001f49Smrgstatic int win; 1132001f49Smrgstatic float rot = 0.0f; 1232001f49Smrg 1332001f49Smrg 1432001f49Smrgstatic void 1532001f49SmrgReshape(int width, int height) 1632001f49Smrg{ 1732001f49Smrg glViewport(0, 0, width, height); 1832001f49Smrg 1932001f49Smrg glMatrixMode(GL_PROJECTION); 2032001f49Smrg glLoadIdentity(); 2132001f49Smrg glMatrixMode(GL_MODELVIEW); 2232001f49Smrg glLoadIdentity(); 2332001f49Smrg} 2432001f49Smrg 2532001f49Smrg 2632001f49Smrgstatic void 2732001f49SmrgKey(unsigned char key, int x, int y) 2832001f49Smrg{ 2932001f49Smrg if (key == 27) { 3032001f49Smrg glutDestroyWindow(win); 3132001f49Smrg exit(0); 3232001f49Smrg } 3332001f49Smrg else if (key == 'r') { 3432001f49Smrg rot += 5.0f; 3532001f49Smrg glutPostRedisplay(); 3632001f49Smrg } 3732001f49Smrg else if (key == 'R') { 3832001f49Smrg rot -= 5.0f; 3932001f49Smrg glutPostRedisplay(); 4032001f49Smrg } 4132001f49Smrg} 4232001f49Smrg 4332001f49Smrg 4432001f49Smrgstatic void 4532001f49SmrgDraw(void) 4632001f49Smrg{ 4732001f49Smrg glClear(GL_COLOR_BUFFER_BIT); 4832001f49Smrg 4932001f49Smrg glPushMatrix(); 5032001f49Smrg glRotatef(rot, 0.0, 0.0, 1.0f); 5132001f49Smrg 5232001f49Smrg glBegin(GL_TRIANGLES); 5332001f49Smrg glColor3f(1.0f, 0.0f, 0.0f); 5432001f49Smrg glVertex3f(-0.8f, -0.8f, 0.0f); 5532001f49Smrg glColor3f(0.0f, 1.0f, 0.0f); 5632001f49Smrg glVertex3f(0.8f, -0.8f, 0.0f); 5732001f49Smrg glColor3f(0.0f, 0.0f, 1.0f); 5832001f49Smrg glVertex3f(0.0f, 0.8f, 0.0f); 5932001f49Smrg glEnd(); 6032001f49Smrg 6132001f49Smrg glPopMatrix(); 6232001f49Smrg 6332001f49Smrg glutSwapBuffers(); 6432001f49Smrg} 6532001f49Smrg 6632001f49Smrg 6732001f49Smrgstatic void 6832001f49SmrgInit(void) 6932001f49Smrg{ 7032001f49Smrg fprintf(stderr, "GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER)); 7132001f49Smrg fprintf(stderr, "GL_VERSION = %s\n", (char *) glGetString(GL_VERSION)); 7232001f49Smrg fprintf(stderr, "GL_VENDOR = %s\n", (char *) glGetString(GL_VENDOR)); 7332001f49Smrg fflush(stderr); 7432001f49Smrg 7532001f49Smrg glClearColor(0.3, 0.3, 0.7, 0.0); 7632001f49Smrg} 7732001f49Smrg 7832001f49Smrg 7932001f49Smrgint 8032001f49Smrgmain(int argc, char **argv) 8132001f49Smrg{ 8232001f49Smrg glutInit(&argc, argv); 8332001f49Smrg 8432001f49Smrg if (argc > 1) { 8532001f49Smrg rot = atof(argv[1]); 8632001f49Smrg printf("Using rotation %g\n", rot); 8732001f49Smrg fflush(stdout); 8832001f49Smrg } 8932001f49Smrg 9032001f49Smrg glutInitWindowPosition(0, 0); 9132001f49Smrg glutInitWindowSize(250, 250); 9232001f49Smrg 9332001f49Smrg glutInitDisplayMode(GLUT_RGB | GLUT_ALPHA | GLUT_DOUBLE); 9432001f49Smrg 9532001f49Smrg win = glutCreateWindow(*argv); 9632001f49Smrg if (!win) { 9732001f49Smrg exit(1); 9832001f49Smrg } 9932001f49Smrg 10032001f49Smrg Init(); 10132001f49Smrg 10232001f49Smrg glutReshapeFunc(Reshape); 10332001f49Smrg glutKeyboardFunc(Key); 10432001f49Smrg glutDisplayFunc(Draw); 10532001f49Smrg glutMainLoop(); 10632001f49Smrg return 0; 10732001f49Smrg} 108