/* Copyright (c) Mark J. Kilgard, 1994. */ /* This program is freely distributable without licensing fees and is provided without guarantee or warrantee expressed or implied. This program is -not- in the public domain. */ #include #include #include #include #include #define NUM_DIALS 8 #define NUM_BUTTONS 32 int *dials, *buttons; #undef PI /* Some systems may have this defined. */ #define PI 3.14159265358979323846 void drawCircle(int x, int y, int r, int dir) { float angle; glPushMatrix(); glTranslatef(x,y,0); glBegin(GL_TRIANGLE_FAN); glVertex2f(0,0); for(angle = 2*PI; angle >= 0; angle -= PI/12) { glVertex2f(r*cos(angle),r*sin(angle)); } glEnd(); glColor3f(0,0,1); glBegin(GL_LINES); glVertex2f(0,0); glVertex2f(r*cos(dir*PI/180),r*sin(dir*PI/180)); glEnd(); glPopMatrix(); } void displayDials(void) { int i; for(i=0;i 0 && dial <= NUM_DIALS) { dials[dial - 1] = value % 360; glutPostRedisplay(); } } void dobutton(int button, int state) { if(button > 0 && button <= NUM_BUTTONS) { buttons[button-1] = (state == GLUT_DOWN); glutPostRedisplay(); } } int main(int argc, char **argv) { int width, height; glutInit(&argc, argv); dials = (int*) calloc(NUM_DIALS, sizeof(int)); buttons = (int*) calloc(NUM_BUTTONS, sizeof(int)); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB); width = 240 + 240; height = 100*((NUM_DIALS+1)/2) + 20; if(height < 240) height = 240; glutInitWindowSize(width, height); glutCreateWindow("GLUT dials & buttons"); glClearColor(0.5, 0.5, 0.5, 1.0); glLineWidth(3.0); glutDialsFunc(dodial); glutButtonBoxFunc(dobutton); glutDisplayFunc(display); glutReshapeFunc(reshape); glutInitWindowSize(240, 240); glutMainLoop(); return 0; /* ANSI C requires main to return int. */ }