9 vector< pair <unsigned long int,cubelooks::env*> > Envs;
11 int cubelooks::cube::allid = 0;
13 void cubelooks::cube::draw()
16 glVertex2f(-1, -1); glVertex2f(1, -1); glVertex2f(1, 1); glVertex2f(-1, 1);
22 cubelooks::env* getEnv()
24 for (int ienv=0; ienv<Envs.size(); ienv++)
25 if ( Envs.at(ienv).first == pthread_self() ) {
26 return Envs.at(ienv).second;
28 cerr << "Something terrible happened: Could not find env-thread-id!" << endl;
32 static void idleFunc()
37 static void reshapeFunc(int w, int h)
39 glutReshapeWindow(10,10);
41 cout << w << ":" << h << endl;
44 static void displayFunc()
46 cubelooks::env *Env = getEnv();
48 glClearColor(0,0,0,0);
49 glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
51 glMatrixMode(GL_MODELVIEW);
54 for (int icube=0; icube < Env->cubes.size(); icube++) {
55 glScalef(1.0/Env->layout[0],1.0/Env->layout[1],1.0);
56 //glRotatef(2, 1, 0, 0);
57 Env->cubes.at(icube).draw();
63 static void* glutThread(void *_Env)
67 cubelooks::env* Env = (cubelooks::env*)_Env;
69 glutInit( ((cubelooks::env*)Env)->argc, ((cubelooks::env*)Env)->argv );
70 glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB|GLUT_DEPTH);
72 if( Env->layout[0] >= Env->layout[1] ) {
74 winsize[1] = (640.0/Env->layout[0])*Env->layout[1];
78 winsize[0] = (640.0/Env->layout[1])*Env->layout[0];
81 glutInitWindowSize(winsize[0], winsize[1]);
83 glutInitWindowPosition(0,0);
85 glutCreateWindow("cubelooks");
87 glutDisplayFunc(&displayFunc);
88 glutReshapeFunc(&reshapeFunc);
89 //glutIdleFunc(&idleFunc);
91 Envs.push_back( pair<unsigned long int,cubelooks::env*>(pthread_self(), (cubelooks::env*)Env) );
97 cubelooks::cube::cube()
103 cubelooks::cubelooks(const int& xcubes, const int& ycubes, int *argc, char **argv)
107 Env.layout[0] = xcubes;
108 Env.layout[1] = ycubes;
109 for (int icube=0; icube<xcubes*ycubes; icube++) {
111 Env.cubes.push_back(newCube);
114 pthread_create(&glThreadId, 0, &mygl::glutThread, &Env);