glamtk

view test.c @ 1:dfbd12d1f566

finished the checkbox control, did some reorg as well.
author John Tsiombikas <nuclear@member.fsf.org>
date Thu, 30 Dec 2010 15:10:25 +0200
parents b04d49e4599c
children 3d661dd17af3
line source
1 #include <stdio.h>
2 #include <stdlib.h>
3 #ifndef __APPLE__
4 #include <GL/glut.h>
5 #else
6 #include <GLUT/glut.h>
7 #endif
8 #include "imtk.h"
10 void disp(void);
11 void gui(void);
12 void reshape(int x, int y);
13 void keyb(unsigned char key, int x, int y);
14 void keyb_up(unsigned char key, int x, int y);
15 void skeyb(int key, int x, int y);
16 void skeyb_up(int key, int x, int y);
17 void mouse(int bn, int state, int x, int y);
18 void motion(int x, int y);
21 int main(int argc, char **argv)
22 {
23 glutInitWindowSize(800, 600);
24 glutInit(&argc, argv);
25 glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);
26 glutCreateWindow("imgui test");
28 glutDisplayFunc(disp);
29 glutReshapeFunc(reshape);
30 glutKeyboardFunc(keyb);
31 glutKeyboardUpFunc(keyb_up);
32 glutSpecialFunc(skeyb);
33 glutSpecialUpFunc(skeyb_up);
34 glutMouseFunc(mouse);
35 glutMotionFunc(motion);
36 glutPassiveMotionFunc(motion);
38 glutMainLoop();
39 return 0;
40 }
42 void disp(void)
43 {
44 glClearColor(0.6, 0.6, 0.6, 0.0);
45 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
47 gui();
49 glutSwapBuffers();
50 }
52 void gui(void)
53 {
54 static int bnshow;
56 imtk_begin();
58 if(imtk_button(IMUID, "foobar", 100, 100)) {
59 printf("clicked button 0\n");
60 }
61 if(imtk_button(IMUID, "xyzzy", 100, 200)) {
62 printf("clicked button 1\n");
63 }
64 if(imtk_button(IMUID, "Quit", 100, 500)) {
65 exit(0);
66 }
68 if((bnshow = imtk_checkbox(IMUID, "show hidden button", 100, 260, bnshow))) {
69 if(imtk_button(IMUID, "I was hidden!", 130, 300)) {
70 printf("you clicked the hidden button!\n");
71 }
72 }
74 imtk_end();
75 }
77 void reshape(int x, int y)
78 {
79 glViewport(0, 0, x, y);
80 imtk_inp_reshape(x, y);
82 glMatrixMode(GL_PROJECTION);
83 glLoadIdentity();
84 glTranslatef(-1, -1, 0);
85 glScalef(2.0 / x, 2.0 / y, 1.0);
86 }
88 void keyb(unsigned char key, int x, int y)
89 {
90 switch(key) {
91 case 27:
92 exit(0);
94 default:
95 break;
96 }
98 imtk_inp_key(key, IMTK_DOWN);
99 }
101 void keyb_up(unsigned char key, int x, int y)
102 {
103 imtk_inp_key(key, IMTK_UP);
104 }
106 void skeyb(int key, int x, int y)
107 {
108 imtk_inp_key(key, IMTK_DOWN);
109 }
111 void skeyb_up(int key, int x, int y)
112 {
113 imtk_inp_key(key, IMTK_UP);
114 }
116 void mouse(int bn, int state, int x, int y)
117 {
118 imtk_inp_mouse(bn, state == GLUT_DOWN ? IMTK_DOWN : IMTK_UP);
119 }
121 void motion(int x, int y)
122 {
123 imtk_inp_motion(x, y);
124 }