imtk

annotate test.c @ 13:9c7987064bb0

- fixed the frame drawing a bit - added global alpha value and various drawing parameters - backported the checkbox check mark from glamtk - fixed progress bar drawing so that the bevels of the trough and the bar won't overlap
author John Tsiombikas <nuclear@siggraph.org>
date Mon, 18 Apr 2011 06:15:46 +0300
parents 467a520f5c00
children df2bc9406561
rev   line source
nuclear@0 1 #include <stdio.h>
nuclear@0 2 #include <stdlib.h>
nuclear@2 3 #include <assert.h>
nuclear@0 4 #ifndef __APPLE__
nuclear@0 5 #include <GL/glut.h>
nuclear@0 6 #else
nuclear@0 7 #include <GLUT/glut.h>
nuclear@0 8 #endif
nuclear@0 9 #include "imtk.h"
nuclear@0 10
nuclear@0 11 void disp(void);
nuclear@1 12 void gui(void);
nuclear@0 13 void reshape(int x, int y);
nuclear@0 14 void keyb(unsigned char key, int x, int y);
nuclear@0 15 void keyb_up(unsigned char key, int x, int y);
nuclear@0 16 void skeyb(int key, int x, int y);
nuclear@0 17 void skeyb_up(int key, int x, int y);
nuclear@0 18 void mouse(int bn, int state, int x, int y);
nuclear@0 19 void motion(int x, int y);
nuclear@0 20
nuclear@2 21 int xsz, ysz;
nuclear@3 22 float angle;
nuclear@4 23 int objsel;
nuclear@0 24
nuclear@0 25 int main(int argc, char **argv)
nuclear@0 26 {
nuclear@2 27 float lpos[] = {-1, 1, 1, 0};
nuclear@2 28 float white[] = {1, 1, 1, 1};
nuclear@2 29 float color[] = {0.9, 0.8, 0.73, 1};
nuclear@2 30
nuclear@0 31 glutInitWindowSize(800, 600);
nuclear@0 32 glutInit(&argc, argv);
nuclear@0 33 glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);
nuclear@0 34 glutCreateWindow("imgui test");
nuclear@0 35
nuclear@0 36 glutDisplayFunc(disp);
nuclear@0 37 glutReshapeFunc(reshape);
nuclear@0 38 glutKeyboardFunc(keyb);
nuclear@0 39 glutKeyboardUpFunc(keyb_up);
nuclear@0 40 glutSpecialFunc(skeyb);
nuclear@0 41 glutSpecialUpFunc(skeyb_up);
nuclear@0 42 glutMouseFunc(mouse);
nuclear@0 43 glutMotionFunc(motion);
nuclear@0 44 glutPassiveMotionFunc(motion);
nuclear@0 45
nuclear@2 46 glEnable(GL_DEPTH_TEST);
nuclear@2 47 glEnable(GL_CULL_FACE);
nuclear@2 48 glEnable(GL_LIGHTING);
nuclear@2 49 glEnable(GL_LIGHT0);
nuclear@2 50 glLightfv(GL_LIGHT0, GL_POSITION, lpos);
nuclear@2 51
nuclear@2 52 glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, color);
nuclear@2 53 glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, white);
nuclear@2 54 glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 60.0);
nuclear@2 55
nuclear@13 56 /*imtk_set_color(IMTK_BEVEL_LIT_COLOR, 0.3, 0.3, 0.3, 0.5);
nuclear@13 57 imtk_set_color(IMTK_BEVEL_SHAD_COLOR, 0.3, 0.3, 0.3, 0.5);*/
nuclear@13 58
nuclear@0 59 glutMainLoop();
nuclear@0 60 return 0;
nuclear@0 61 }
nuclear@0 62
nuclear@0 63 void disp(void)
nuclear@0 64 {
nuclear@0 65 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
nuclear@0 66
nuclear@13 67 glMatrixMode(GL_MODELVIEW);
nuclear@13 68 glLoadIdentity();
nuclear@13 69 glMatrixMode(GL_PROJECTION);
nuclear@13 70 glPushMatrix();
nuclear@13 71 glLoadIdentity();
nuclear@2 72
nuclear@13 73 glPushAttrib(GL_ENABLE_BIT);
nuclear@13 74 glDisable(GL_LIGHTING);
nuclear@13 75 glDisable(GL_DEPTH_TEST);
nuclear@13 76
nuclear@13 77 glBegin(GL_QUADS);
nuclear@13 78 glColor3f(0.3, 0.4, 0.8);
nuclear@13 79 glVertex2f(-1, -1);
nuclear@13 80 glVertex2f(1, -1);
nuclear@13 81 glColor3f(0.7, 0.3, 0.2);
nuclear@13 82 glVertex2f(1, 1);
nuclear@13 83 glVertex2f(-1, 1);
nuclear@13 84 glEnd();
nuclear@13 85
nuclear@13 86 glPopAttrib();
nuclear@13 87 glPopMatrix();
nuclear@2 88
nuclear@2 89 glMatrixMode(GL_MODELVIEW);
nuclear@2 90 glLoadIdentity();
nuclear@13 91 glTranslatef(0, 0, -4);
nuclear@2 92 glRotatef(25, 1, 0, 0);
nuclear@3 93 glRotatef(angle, 0, 1, 0);
nuclear@2 94
nuclear@4 95 switch(objsel) {
nuclear@4 96 case 0:
nuclear@4 97 glFrontFace(GL_CW);
nuclear@4 98 glutSolidTeapot(1.0);
nuclear@4 99 glFrontFace(GL_CCW);
nuclear@4 100 break;
nuclear@4 101
nuclear@4 102 case 1:
nuclear@4 103 glutSolidTorus(0.5, 1, 12, 24);
nuclear@4 104 break;
nuclear@4 105
nuclear@4 106 case 2:
nuclear@4 107 glutSolidSphere(1.0, 24, 12);
nuclear@4 108 break;
nuclear@4 109
nuclear@4 110 default:
nuclear@4 111 break;
nuclear@4 112 }
nuclear@2 113
nuclear@2 114
nuclear@1 115 gui();
nuclear@1 116
nuclear@1 117 glutSwapBuffers();
nuclear@2 118 assert(glGetError() == GL_NO_ERROR);
nuclear@1 119 }
nuclear@1 120
nuclear@1 121 void gui(void)
nuclear@1 122 {
nuclear@1 123 static int bnshow;
nuclear@2 124 static char textbuf[256];
nuclear@2 125 static char textbuf2[256];
nuclear@3 126 static float val;
nuclear@10 127 static int prev_sel = 0;
nuclear@10 128 char *itemlist;
nuclear@1 129
nuclear@0 130 imtk_begin();
nuclear@0 131
nuclear@13 132 /*glBegin(GL_QUADS);
nuclear@2 133 glColor3f(0.6, 0.6, 0.6);
nuclear@2 134 glVertex2f(0, 0);
nuclear@2 135 glVertex2f(200, 0);
nuclear@2 136 glVertex2f(200, glutGet(GLUT_WINDOW_HEIGHT));
nuclear@2 137 glVertex2f(0, glutGet(GLUT_WINDOW_HEIGHT));
nuclear@13 138 glEnd();*/
nuclear@2 139
nuclear@2 140 if(imtk_button(IMUID, "red", 30, 50)) {
nuclear@2 141 float color[] = {1, 0.4, 0.3, 1};
nuclear@2 142 glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, color);
nuclear@2 143 glutPostRedisplay();
nuclear@0 144 }
nuclear@4 145 if(imtk_button(IMUID, "blue", 30, 80)) {
nuclear@2 146 float color[] = {0.3, 0.4, 1, 1};
nuclear@2 147 glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, color);
nuclear@2 148 glutPostRedisplay();
nuclear@1 149 }
nuclear@1 150
nuclear@10 151 itemlist = imtk_create_list("teapot", "torus", "sphere", NULL);
nuclear@4 152 if((objsel = imtk_listbox(IMUID, itemlist, prev_sel, 30, 120)) != prev_sel) {
nuclear@4 153 prev_sel = objsel;
nuclear@4 154 glutPostRedisplay();
nuclear@4 155 }
nuclear@10 156 imtk_free_list(itemlist);
nuclear@4 157
nuclear@2 158 imtk_textbox(IMUID, textbuf, sizeof textbuf, 30, 200);
nuclear@2 159 imtk_textbox(IMUID, textbuf2, sizeof textbuf2, 30, 250);
nuclear@2 160
nuclear@2 161 if((bnshow = imtk_checkbox(IMUID, "show hidden button", 30, 300, bnshow))) {
nuclear@2 162 if(imtk_button(IMUID, "yellow", 50, 340)) {
nuclear@2 163 float color[] = {0.8, 0.75, 0.3, 1};
nuclear@2 164 glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, color);
nuclear@2 165 glutPostRedisplay();
nuclear@1 166 }
nuclear@1 167 }
nuclear@0 168
nuclear@3 169 val = imtk_slider(IMUID, angle, 0.0, 360.0, 30, 390);
nuclear@3 170 if(val != angle) {
nuclear@3 171 angle = val;
nuclear@3 172 glutPostRedisplay();
nuclear@3 173 }
nuclear@3 174
nuclear@3 175 imtk_progress(IMUID, val / 360.0, 30, 420);
nuclear@3 176
nuclear@13 177 imtk_label("alpha:", 24, 473);
nuclear@13 178 imtk_set_alpha(imtk_slider(IMUID, imtk_get_alpha(), 0.0, 1.0, 60, 470));
nuclear@13 179
nuclear@2 180 if(imtk_button(IMUID, "Quit", 30, 500)) {
nuclear@2 181 exit(0);
nuclear@2 182 }
nuclear@2 183
nuclear@0 184 imtk_end();
nuclear@0 185 }
nuclear@0 186
nuclear@0 187 void reshape(int x, int y)
nuclear@0 188 {
nuclear@2 189 xsz = x;
nuclear@2 190 ysz = y;
nuclear@2 191
nuclear@0 192 glViewport(0, 0, x, y);
nuclear@13 193 imtk_set_viewport(x, y);
nuclear@13 194
nuclear@13 195 glMatrixMode(GL_PROJECTION);
nuclear@13 196 glLoadIdentity();
nuclear@13 197 gluPerspective(45.0, (float)xsz / (float)ysz, 1.0, 1000.0);
nuclear@0 198 }
nuclear@0 199
nuclear@0 200 void keyb(unsigned char key, int x, int y)
nuclear@0 201 {
nuclear@0 202 switch(key) {
nuclear@0 203 case 27:
nuclear@0 204 exit(0);
nuclear@0 205
nuclear@0 206 default:
nuclear@0 207 break;
nuclear@0 208 }
nuclear@0 209
nuclear@0 210 imtk_inp_key(key, IMTK_DOWN);
nuclear@0 211 }
nuclear@0 212
nuclear@0 213 void keyb_up(unsigned char key, int x, int y)
nuclear@0 214 {
nuclear@0 215 imtk_inp_key(key, IMTK_UP);
nuclear@0 216 }
nuclear@0 217
nuclear@0 218 void skeyb(int key, int x, int y)
nuclear@0 219 {
nuclear@0 220 imtk_inp_key(key, IMTK_DOWN);
nuclear@0 221 }
nuclear@0 222
nuclear@0 223 void skeyb_up(int key, int x, int y)
nuclear@0 224 {
nuclear@0 225 imtk_inp_key(key, IMTK_UP);
nuclear@0 226 }
nuclear@0 227
nuclear@0 228 void mouse(int bn, int state, int x, int y)
nuclear@0 229 {
nuclear@0 230 imtk_inp_mouse(bn, state == GLUT_DOWN ? IMTK_DOWN : IMTK_UP);
nuclear@0 231 }
nuclear@0 232
nuclear@0 233 void motion(int x, int y)
nuclear@0 234 {
nuclear@0 235 imtk_inp_motion(x, y);
nuclear@0 236 }