8 int culooks::drawing::rotcube[3];
10 culooks::window* culooks::drawing::getWin()
12 for (int iwin=0; iwin<culooks::Windows.size(); iwin++)
13 if ( culooks::Windows.at(iwin).first == glutGetWindow() ) {
14 return culooks::Windows.at(iwin).second;
16 cerr << "Something terrible happened: Could not find window-id!" << endl;
20 int culooks::drawing::getCubeFromPos(int x, int y)
22 culooks::window *Win = getWin();
24 int col = x / ((float)Win->w / Win->layout[0]);
25 int row = Win->layout[1] - y / ((float)Win->h / Win->layout[1]);
27 return col + row*Win->layout[0];
31 void culooks::drawing::motionFunc(int x, int y)
33 culooks::window *Win = getWin();
35 Win->cubes.at(rotcube[0]).az += rotcube[1] - x;
36 Win->cubes.at(rotcube[0]).alt += rotcube[2] - y;
45 void culooks::drawing::mouseFunc(int button, int state, int x, int y)
47 culooks::window *Win = getWin();
50 rotcube[0] = getCubeFromPos(x,y);
56 Win->cubes.at(getCubeFromPos(x,y)).zoom *= 1.1;
59 else if (button == 3) {
60 Win->cubes.at(getCubeFromPos(x,y)).zoom *= 0.9;
66 void culooks::drawing::reshapeFunc(int w, int h)
68 culooks::window *Win = getWin();
77 else if ( h == Win->h ) {
79 newh = w / Win->aspect;
82 neww = ( pow(Win->aspect,2)*w + Win->aspect*h ) / ( pow(Win->aspect,2) + 1 );
83 newh = ( Win->aspect*w + h ) / ( pow(Win->aspect,2) + 1 );
86 glutReshapeWindow(neww,newh);
87 glViewport(0,0,neww,newh);
93 void culooks::drawing::displayFunc()
95 culooks::window *Win = getWin();
97 glClearColor(Win->bgcolor[0], Win->bgcolor[1], Win->bgcolor[2], Win->bgcolor[3]);
98 glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
100 glMatrixMode(GL_MODELVIEW);
103 glScalef(1.0/Win->layout[0],1.0/Win->layout[1],1.0);
104 glTranslatef(-Win->layout[0]+1, -Win->layout[1]+1, 0);
106 for (int icube=0; icube < Win->cubes.size(); icube++) {
107 Win->cubes.at(icube).draw();
108 if ((icube+1)%Win->layout[0] == 0) {
109 glTranslatef(-2*Win->layout[0]+2, 2, 0);
112 glTranslatef(2, 0, 0);
119 void culooks::drawing::initWindow(int winid)
122 glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGBA|GLUT_DEPTH);
123 glutInitWindowSize(culooks::Windows[winid].second->w, culooks::Windows[winid].second->h);
124 glutInitWindowPosition(winid*100,winid*100);
125 glutCreateWindow( ("culooks / " + culooks::Windows[winid].second->name).c_str() );
127 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
129 glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
130 glHint(GL_POINT_SMOOTH_HINT, GL_NICEST);
131 glHint(GL_POLYGON_SMOOTH_HINT, GL_NICEST);
133 glutDisplayFunc(&drawing::displayFunc);
134 glutReshapeFunc(&drawing::reshapeFunc);
135 glutMotionFunc(&drawing::motionFunc);
136 glutMouseFunc(&drawing::mouseFunc);
137 glutIdleFunc(&drawing::idleFunc);
139 culooks::Windows[winid].first = glutGetWindow();
140 culooks::Windows[winid].second->initialized = true;
141 culooks::Windows[winid].second->redisplay = true;
144 void culooks::drawing::idleFunc()
146 int activeWindow = glutGetWindow();
148 for (int iwin=0; iwin < culooks::Windows.size(); iwin++) {
149 if (!culooks::Windows[iwin].second->initialized)
151 if (culooks::Windows[iwin].second->redisplay) {
152 glutSetWindow(culooks::Windows[iwin].first);
154 culooks::Windows[iwin].second->redisplay = false;
158 glutSetWindow(activeWindow);
161 void* culooks::drawing::glutThread(void *_comArg)
163 comarg *comArg = (comarg*)_comArg;
164 glutInit(comArg->argc, comArg->argv);