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 glLineWidth(Win->linewidth);
99 glClearColor(Win->bgcolor[0], Win->bgcolor[1], Win->bgcolor[2], Win->bgcolor[3]);
100 glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
102 glMatrixMode(GL_MODELVIEW);
105 glScalef(1.0/Win->layout[0],1.0/Win->layout[1],1.0);
106 glTranslatef(-Win->layout[0]+1, -Win->layout[1]+1, 0);
108 for (int icube=0; icube < Win->cubes.size(); icube++) {
109 Win->cubes.at(icube).draw();
110 if ((icube+1)%Win->layout[0] == 0) {
111 glTranslatef(-2*Win->layout[0]+2, 2, 0);
114 glTranslatef(2, 0, 0);
121 void culooks::drawing::initWindow(int winid)
124 glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGBA|GLUT_DEPTH);
125 glutInitWindowSize(culooks::Windows[winid].second->w, culooks::Windows[winid].second->h);
126 glutInitWindowPosition(winid*100,winid*100);
127 glutCreateWindow( ("culooks / " + culooks::Windows[winid].second->name).c_str() );
129 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
131 glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
132 glHint(GL_POINT_SMOOTH_HINT, GL_NICEST);
133 glHint(GL_POLYGON_SMOOTH_HINT, GL_NICEST);
135 glutDisplayFunc(&drawing::displayFunc);
136 glutReshapeFunc(&drawing::reshapeFunc);
137 glutMotionFunc(&drawing::motionFunc);
138 glutMouseFunc(&drawing::mouseFunc);
139 glutIdleFunc(&drawing::idleFunc);
141 culooks::Windows[winid].first = glutGetWindow();
142 culooks::Windows[winid].second->initialized = true;
143 culooks::Windows[winid].second->redisplay = true;
146 void culooks::drawing::idleFunc()
148 int activeWindow = glutGetWindow();
150 for (int iwin=0; iwin < culooks::Windows.size(); iwin++) {
151 if (!culooks::Windows[iwin].second->initialized)
153 if (culooks::Windows[iwin].second->redisplay) {
154 glutSetWindow(culooks::Windows[iwin].first);
156 culooks::Windows[iwin].second->redisplay = false;
160 glutSetWindow(activeWindow);
163 void* culooks::drawing::glutThread(void *_comArg)
165 comarg *comArg = (comarg*)_comArg;
166 glutInit(comArg->argc, comArg->argv);