10 vector< pair <unsigned long int,cubelooks::env*> > Envs;
12 int cubelooks::cube::allid = 0;
14 void cubelooks::cube::draw()
17 glVertex2f(-1, -1); glVertex2f(1, -1); glVertex2f(1, 1); glVertex2f(-1, 1);
23 cubelooks::env* getEnv()
25 for (int ienv=0; ienv<Envs.size(); ienv++)
26 if ( Envs.at(ienv).first == pthread_self() ) {
27 return Envs.at(ienv).second;
29 cerr << "Something terrible happened: Could not find env-thread-id!" << endl;
33 static void idleFunc()
38 static void reshapeFunc(int w, int h)
43 cubelooks::env *Env = getEnv();
49 else if ( h == Env->h ) {
51 newh = w / Env->aspect;
54 neww = ( pow(Env->aspect,2)*w + Env->aspect*h ) / ( pow(Env->aspect,2) + 1 );
55 newh = ( Env->aspect*w + h ) / ( pow(Env->aspect,2) + 1 );
58 glutReshapeWindow(neww,newh);
59 glViewport(0,0,neww,newh);
65 static void displayFunc()
67 cubelooks::env *Env = getEnv();
69 glClearColor(0,0,0,0);
70 glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
72 glMatrixMode(GL_MODELVIEW);
75 glScalef(1.0/Env->layout[0],1.0/Env->layout[1],1.0);
76 glTranslatef(-Env->layout[0]+1, -Env->layout[1]+1, 0);
78 for (int icube=0; icube < Env->cubes.size(); icube++) {
79 //glScalef(1.0/Env->layout[0],1.0/Env->layout[1],1.0);
80 //glRotatef(2, 1, 0, 0);
81 Env->cubes.at(icube).draw();
82 if ((icube+1)%Env->layout[0] == 0) {
83 glTranslatef(-2*Env->layout[0]+2, 2, 0);
86 glTranslatef(2, 0, 0);
93 static void* glutThread(void *_Env)
97 cubelooks::env* Env = (cubelooks::env*)_Env;
99 glutInit( ((cubelooks::env*)Env)->argc, ((cubelooks::env*)Env)->argv );
100 glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB|GLUT_DEPTH);
102 if( Env->layout[0] >= Env->layout[1] ) {
104 winsize[1] = (640.0/Env->layout[0])*Env->layout[1];
108 winsize[0] = (640.0/Env->layout[1])*Env->layout[0];
114 glutInitWindowSize(winsize[0], winsize[1]);
116 glutInitWindowPosition(0,0);
118 glutCreateWindow("cubelooks");
120 glutDisplayFunc(&displayFunc);
121 glutReshapeFunc(&reshapeFunc);
122 //glutIdleFunc(&idleFunc);
124 Envs.push_back( pair<unsigned long int,cubelooks::env*>(pthread_self(), (cubelooks::env*)Env) );
130 cubelooks::cube::cube()
136 cubelooks::cubelooks(const int& xcubes, const int& ycubes, int *argc, char **argv)
140 Env.layout[0] = xcubes;
141 Env.layout[1] = ycubes;
142 Env.aspect = (double)xcubes/ycubes;
143 for (int icube=0; icube<xcubes*ycubes; icube++) {
145 Env.cubes.push_back(newCube);
148 pthread_create(&glThreadId, 0, &mygl::glutThread, &Env);