*~
neigh_test
cubelooks_test
+culooks_test
find_package(OpenGL REQUIRED)
find_package(GLUT REQUIRED)
include_directories( ${OPENGL_INCLUDE_DIRS} ${GLUT_INCLUDE_DIRS} ../ )
-add_library(lat_cubelooks cubelooks.cpp)
-target_link_libraries(lat_cubelooks ${OPENGL_LIBRARIES} ${GLUT_LIBRARY})
+add_library(lat_culooks culooks.cpp)
+target_link_libraries(lat_culooks ${OPENGL_LIBRARIES} ${GLUT_LIBRARY})
add_executable(neigh_test neigh_test.cpp)
target_link_libraries(neigh_test lat_neigh)
-add_executable(cubelooks_test cubelooks_test.cpp)
-target_link_libraries(cubelooks_test lat_cubelooks)
\ No newline at end of file
+add_executable(culooks_test culooks_test.cpp)
+target_link_libraries(culooks_test lat_culooks)
\ No newline at end of file
+++ /dev/null
-#include "cubelooks.h"
-#include <iostream>
-#include <string>
-#include <math.h>
-
-using namespace std;
-
-vector< pair <unsigned long int,cubelooks::env*> > Envs;
-
-bool cubelooks::initDone = false;
-GLXDrawable cubelooks::gDrawable;
-Display *cubelooks::gDisplay;
-
-int cubelooks::cube::allid = 0;
-
-void cubelooks::cube::drawBox()
-{
- glBegin(GL_LINES);
-
- glVertex3f(-1.0f, 1.0f, -1.0f);
- glVertex3f( 1.0f, 1.0f, -1.0f);
- glVertex3f(-1.0f, -1.0f, -1.0f);
- glVertex3f( 1.0f, -1.0f, -1.0f);
- glVertex3f(-1.0f, 1.0f, 1.0f);
- glVertex3f( 1.0f, 1.0f, 1.0f);
- glVertex3f(-1.0f, -1.0f, 1.0f);
- glVertex3f( 1.0f, -1.0f, 1.0f);
-
- glVertex3f( 1.0f, 1.0f, -1.0f);
- glVertex3f( 1.0f, -1.0f, -1.0f);
- glVertex3f( -1.0f, 1.0f, -1.0f);
- glVertex3f( -1.0f, -1.0f, -1.0f);
- glVertex3f( 1.0f, 1.0f, 1.0f);
- glVertex3f( 1.0f, -1.0f, 1.0f);
- glVertex3f( -1.0f, 1.0f, 1.0f);
- glVertex3f( -1.0f, -1.0f, 1.0f);
-
- glVertex3f( -1.0f, -1.0f, 1.0f);
- glVertex3f( -1.0f, -1.0f, -1.0f);
- glVertex3f( -1.0f, 1.0f, 1.0f);
- glVertex3f( -1.0f, 1.0f, -1.0f);
- glVertex3f( 1.0f, -1.0f, 1.0f);
- glVertex3f( 1.0f, -1.0f, -1.0f);
- glVertex3f( 1.0f, 1.0f, 1.0f);
- glVertex3f( 1.0f, 1.0f, -1.0f);
-
- glEnd();
-}
-
-void cubelooks::cube::drawAll()
-{
- glMatrixMode(GL_MODELVIEW);
- glPushMatrix();
-
- glTranslatef(-1,-1,-1);
-
- for (int iz=0; iz<l; iz++) {
- for (int iy=0; iy<l; iy++) {
- for (int ix=0; ix<l; ix++) {
- glPushMatrix();
- glTranslatef(2.0*ix/l,2.0*iy/l,2.0*iz/l);
- glScalef(2.0/l,2.0/l,2.0/l);
-
- /* draw links */
- glBegin(GL_LINES);
- glColor4f(link[iz*l*l*3*4 + iy*l*3*4 + ix*3*4 + 0*4 + 0],
- link[iz*l*l*3*4 + iy*l*3*4 + ix*3*4 + 0*4 + 1],
- link[iz*l*l*3*4 + iy*l*3*4 + ix*3*4 + 0*4 + 2],
- link[iz*l*l*3*4 + iy*l*3*4 + ix*3*4 + 0*4 + 3]);
- glVertex3f(0,0,0); glVertex3f(1,0,0);
- glColor4f(link[iz*l*l*3*4 + iy*l*3*4 + ix*3*4 + 1*4 + 0],
- link[iz*l*l*3*4 + iy*l*3*4 + ix*3*4 + 1*4 + 1],
- link[iz*l*l*3*4 + iy*l*3*4 + ix*3*4 + 1*4 + 2],
- link[iz*l*l*3*4 + iy*l*3*4 + ix*3*4 + 1*4 + 3]);
- glVertex3f(0,0,0); glVertex3f(0,1,0);
- glColor4f(link[iz*l*l*3*4 + iy*l*3*4 + ix*3*4 + 2*4 + 0],
- link[iz*l*l*3*4 + iy*l*3*4 + ix*3*4 + 2*4 + 1],
- link[iz*l*l*3*4 + iy*l*3*4 + ix*3*4 + 2*4 + 2],
- link[iz*l*l*3*4 + iy*l*3*4 + ix*3*4 + 2*4 + 3]);
- glVertex3f(0,0,0); glVertex3f(0,0,1);
- glEnd();
-
- /* draw plaquettes */
- glColor4f(1,1,1,0.5);
- glBegin(GL_QUADS);
- glColor4f(plaq[iz*l*l*3*4 + iy*l*3*4 + ix*3*4 + 2*4 + 0],
- plaq[iz*l*l*3*4 + iy*l*3*4 + ix*3*4 + 2*4 + 1],
- plaq[iz*l*l*3*4 + iy*l*3*4 + ix*3*4 + 2*4 + 2],
- plaq[iz*l*l*3*4 + iy*l*3*4 + ix*3*4 + 2*4 + 3]);
- glVertex3f(0, 0, 0); glVertex3f(1, 0, 0); glVertex3f(1, 1, 0); glVertex3f(0, 1, 0);
- glColor4f(plaq[iz*l*l*3*4 + iy*l*3*4 + ix*3*4 + 1*4 + 0],
- plaq[iz*l*l*3*4 + iy*l*3*4 + ix*3*4 + 1*4 + 1],
- plaq[iz*l*l*3*4 + iy*l*3*4 + ix*3*4 + 1*4 + 2],
- plaq[iz*l*l*3*4 + iy*l*3*4 + ix*3*4 + 1*4 + 3]);
- glVertex3f(0, 0, 0); glVertex3f(1, 0, 0); glVertex3f(1, 0, 1); glVertex3f(0, 0, 1);
- glColor4f(plaq[iz*l*l*3*4 + iy*l*3*4 + ix*3*4 + 0*4 + 0],
- plaq[iz*l*l*3*4 + iy*l*3*4 + ix*3*4 + 0*4 + 1],
- plaq[iz*l*l*3*4 + iy*l*3*4 + ix*3*4 + 0*4 + 2],
- plaq[iz*l*l*3*4 + iy*l*3*4 + ix*3*4 + 0*4 + 3]);
- glVertex3f(0, 0, 0); glVertex3f(0, 1, 0); glVertex3f(0, 1, 1); glVertex3f(0, 0, 1);
- glEnd();
-
- glPopMatrix();
- }
- }
- }
-
- glPopMatrix();
-}
-
-void cubelooks::cube::draw()
-{
- glMatrixMode(GL_MODELVIEW);
- glPushMatrix();
-
- //cout << zoom << endl;
-
- glScalef(zoom, zoom, zoom);
- glRotatef(az, 0, 1, 0);
- glRotatef(alt, 1, 0, 0);
-
- /*
- glBegin(GL_QUADS);
- glVertex2f(-1, -1); glVertex2f(1, -1); glVertex2f(1, 1); glVertex2f(-1, 1);
- glEnd();
- */
-
- //drawBox();
- drawAll();
-
- glPopMatrix();
-}
-
-namespace mygl
-{
- int rotcube[3];
-
- cubelooks::env* getEnv()
- {
- for (int ienv=0; ienv<Envs.size(); ienv++)
- if ( Envs.at(ienv).first == pthread_self() ) {
- return Envs.at(ienv).second;
- }
- cerr << "Something terrible happened: Could not find env-thread-id!" << endl;
- exit(1);
- }
-
- static int getCubeFromPos(int x, int y)
- {
- cubelooks::env *Env = getEnv();
-
- int col = x / ((float)Env->w / Env->layout[0]);
- int row = Env->layout[1] - y / ((float)Env->h / Env->layout[1]);
-
- return col + row*Env->layout[0];
- }
-
- static void idleFunc()
- {
- glutPostRedisplay();
- }
-
- static void motionFunc(int x, int y)
- {
- cubelooks::env *Env = getEnv();
-
- Env->cubes.at(rotcube[0]).az += rotcube[1] - x;
- Env->cubes.at(rotcube[0]).alt += rotcube[2] - y;
-
- rotcube[1] = x;
- rotcube[2] = y;
-
- glutPostRedisplay();
- }
-
- static void mouseFunc(int button, int state, int x, int y)
- {
- cubelooks::env *Env = getEnv();
-
- if (button == 0) {
- rotcube[0] = getCubeFromPos(x,y);
- rotcube[1] = x;
- rotcube[2] = y;
- }
-
- if (button == 4) {
- Env->cubes.at(getCubeFromPos(x,y)).zoom *= 1.1;
- glutPostRedisplay();
- }
- else if (button == 3) {
- Env->cubes.at(getCubeFromPos(x,y)).zoom *= 0.9;
- glutPostRedisplay();
- }
- }
-
- static void reshapeFunc(int w, int h)
- {
- cubelooks::env *Env = getEnv();
-
- int neww;
- int newh;
-
- if ( w == Env->w ) {
- newh = h;
- neww = Env->aspect*h;
- }
- else if ( h == Env->h ) {
- neww = w;
- newh = w / Env->aspect;
- }
- else {
- neww = ( pow(Env->aspect,2)*w + Env->aspect*h ) / ( pow(Env->aspect,2) + 1 );
- newh = ( Env->aspect*w + h ) / ( pow(Env->aspect,2) + 1 );
- }
-
- glutReshapeWindow(neww,newh);
- glViewport(0,0,neww,newh);
-
- Env->w = neww;
- Env->h = newh;
- }
-
- static void displayFunc()
- {
- cubelooks::env *Env = getEnv();
-
- glClearColor(0,0,0,0);
- glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
-
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
-
- glScalef(1.0/Env->layout[0],1.0/Env->layout[1],1.0);
- glTranslatef(-Env->layout[0]+1, -Env->layout[1]+1, 0);
-
- for (int icube=0; icube < Env->cubes.size(); icube++) {
- //glScalef(1.0/Env->layout[0],1.0/Env->layout[1],1.0);
- //glRotatef(2, 1, 0, 0);
- Env->cubes.at(icube).draw();
- if ((icube+1)%Env->layout[0] == 0) {
- glTranslatef(-2*Env->layout[0]+2, 2, 0);
- }
- else {
- glTranslatef(2, 0, 0);
- }
- }
-
- glutSwapBuffers();
- }
-
- static void* glutThread(void *_Env)
- {
- cubelooks::env *Env = (cubelooks::env *)_Env;
-
- //glXMakeCurrent(0, glutCreateWindow("cubelooks"));
-
- //glXCrateContext(0,
-
- //cout << Env->layout[1] << endl;
-
- glXMakeCurrent( Env->gDisplay, Env->gDrawable, Env->gContext );
-
- //cout << "da" << endl;
-
- glutDisplayFunc(&displayFunc);
- glutReshapeFunc(&reshapeFunc);
- glutMotionFunc(&motionFunc);
- glutMouseFunc(&mouseFunc);
- //glutIdleFunc(&idleFunc);
-
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- glEnable( GL_BLEND );
-
- Envs.push_back( pair<unsigned long int,cubelooks::env*>(pthread_self(), Env) );
-
- glutMainLoop();
- }
-};
-
-cubelooks::cube::cube(int _l)
-{
- l = _l;
- link = new float[l*l*l*3 * 4];
- plaq = new float[l*l*l*3 * 4];
- az = 30;
- alt = -20;
- zoom = 0.6;
- id = allid;
- allid++;
-
- for (int i=0; i<l*l*l*3; i++) {
- link[i*4+0]=1; link[i*4+3]=0.6;
- plaq[i*4+1]=1; plaq[i*4+3]=0.2;
- }
-}
-
-cubelooks::cubelooks(const int& xcubes, const int& ycubes, const int& l, int *argc, char **argv)
-{
- int winsize[2];
- GLXContext context;
- env *Env = new env;
-
- Env->argc = argc;
- Env->argv = argv;
- Env->layout[0] = xcubes;
- Env->layout[1] = ycubes;
- Env->aspect = (double)xcubes/ycubes;
- for (int icube=0; icube<xcubes*ycubes; icube++) {
- cube newCube(l);
- Env->cubes.push_back(newCube);
- }
-
- if ( !initDone ) {
- glutInit( Env->argc, Env->argv );
- glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB|GLUT_DEPTH);
- }
-
- if( Env->layout[0] >= Env->layout[1] ) {
- winsize[0] = 640;
- winsize[1] = (640.0/Env->layout[0])*Env->layout[1];
- }
- else {
- winsize[1] = 640;
- winsize[0] = (640.0/Env->layout[1])*Env->layout[0];
- }
-
- Env->w = winsize[0];
- Env->h = winsize[1];
-
- glutInitWindowSize(winsize[0], winsize[1]);
- glutInitWindowPosition(0,0);
- glutCreateWindow("cubelooks");
-
- if ( !initDone ) {
- gDisplay = glXGetCurrentDisplay();
- gDrawable = glXGetCurrentDrawable();
- initDone = true;
- }
-
- Env->gContext = glXGetCurrentContext();
- Env->gDisplay = gDisplay;
- Env->gDrawable = glXGetCurrentDrawable();
-
- glXMakeCurrent(0,0,0);
-
- pthread_create(&glThreadId, 0, &mygl::glutThread, Env);
-}
+++ /dev/null
-#ifndef CUBELOOKS_H
-#define CUBELOOKS_H
-
-#include <pthread.h>
-#include <vector>
-#include <GL/glut.h>
-#include <GL/glx.h>
-#include <GL/gl.h>
-#include <X11/Xlib.h>
-#include <X11/Xutil.h>
-
-
-using namespace std;
-
-class cubelooks
-{
- public:
- class cube {
- public:
- cube(int l);
- void draw();
- int id;
- float az, alt;
- float zoom;
- private:
- void drawAll();
- void drawBox();
- static int allid;
- float *plaq;
- float *link;
- int l;
- };
-
- struct env {
- int *argc;
- char **argv;
- int layout[2];
- double aspect;
- vector<cube> cubes;
- int w, h;
- GLXDrawable gDrawable;
- Display *gDisplay;
- GLXContext gContext;
- };
-
- cubelooks(const int& xcubes, const int& ycubes, const int& l, int *argc, char **argv);
-
- private:
- pthread_t glThreadId;
- static bool initDone;
- static GLXDrawable gDrawable;
- static Display *gDisplay;
-};
-
-#endif
+++ /dev/null
-#include "cubelooks.h"
-#include "unistd.h"
-#include <iostream>
-
-using namespace std;
-
-int main(int argc, char **argv)
-{
-
- cubelooks clooks(2,1, 6, &argc, argv);
-
- //sleep(2);
-
- //cubelooks clooks2(2,1, 6, &argc, argv);
-
- while(true) {
- sleep(1);
- }
-
-
- return 0;
-}
--- /dev/null
+#include "culooks.h"
+
+#include <iostream>
+#include <math.h>
+
+vector< pair<int,culooks::window*> > culooks::Windows;
+pthread_t culooks::glThreadId;
+
+int culooks::windowid = 0;
+
+int culooks::cube::allid = 0;
+
+using namespace std;
+
+void culooks::cube::draw()
+{
+ glMatrixMode(GL_MODELVIEW);
+ glPushMatrix();
+
+ //cout << zoom << endl;
+
+ glScalef(zoom, zoom, zoom);
+ glRotatef(az, 0, 1, 0);
+ glRotatef(alt, 1, 0, 0);
+
+ /*
+ glBegin(GL_QUADS);
+ glVertex2f(-1, -1); glVertex2f(1, -1); glVertex2f(1, 1); glVertex2f(-1, 1);
+ glEnd();
+ */
+
+ //drawBox();
+ drawAll();
+
+ glPopMatrix();
+}
+
+void culooks::cube::drawAll()
+{
+ glMatrixMode(GL_MODELVIEW);
+ glPushMatrix();
+
+ glTranslatef(-1,-1,-1);
+
+ for (int iz=0; iz<l; iz++) {
+ for (int iy=0; iy<l; iy++) {
+ for (int ix=0; ix<l; ix++) {
+ glPushMatrix();
+ glTranslatef(2.0*ix/l,2.0*iy/l,2.0*iz/l);
+ glScalef(2.0/l,2.0/l,2.0/l);
+
+ /* draw links */
+ glBegin(GL_LINES);
+ glColor4f(link[iz*l*l*3*4 + iy*l*3*4 + ix*3*4 + 0*4 + 0],
+ link[iz*l*l*3*4 + iy*l*3*4 + ix*3*4 + 0*4 + 1],
+ link[iz*l*l*3*4 + iy*l*3*4 + ix*3*4 + 0*4 + 2],
+ link[iz*l*l*3*4 + iy*l*3*4 + ix*3*4 + 0*4 + 3]);
+ glVertex3f(0,0,0); glVertex3f(1,0,0);
+ glColor4f(link[iz*l*l*3*4 + iy*l*3*4 + ix*3*4 + 1*4 + 0],
+ link[iz*l*l*3*4 + iy*l*3*4 + ix*3*4 + 1*4 + 1],
+ link[iz*l*l*3*4 + iy*l*3*4 + ix*3*4 + 1*4 + 2],
+ link[iz*l*l*3*4 + iy*l*3*4 + ix*3*4 + 1*4 + 3]);
+ glVertex3f(0,0,0); glVertex3f(0,1,0);
+ glColor4f(link[iz*l*l*3*4 + iy*l*3*4 + ix*3*4 + 2*4 + 0],
+ link[iz*l*l*3*4 + iy*l*3*4 + ix*3*4 + 2*4 + 1],
+ link[iz*l*l*3*4 + iy*l*3*4 + ix*3*4 + 2*4 + 2],
+ link[iz*l*l*3*4 + iy*l*3*4 + ix*3*4 + 2*4 + 3]);
+ glVertex3f(0,0,0); glVertex3f(0,0,1);
+ glEnd();
+
+ /* draw plaquettes */
+ glColor4f(1,1,1,0.5);
+ glBegin(GL_QUADS);
+ glColor4f(plaq[iz*l*l*3*4 + iy*l*3*4 + ix*3*4 + 2*4 + 0],
+ plaq[iz*l*l*3*4 + iy*l*3*4 + ix*3*4 + 2*4 + 1],
+ plaq[iz*l*l*3*4 + iy*l*3*4 + ix*3*4 + 2*4 + 2],
+ plaq[iz*l*l*3*4 + iy*l*3*4 + ix*3*4 + 2*4 + 3]);
+ glVertex3f(0, 0, 0); glVertex3f(1, 0, 0); glVertex3f(1, 1, 0); glVertex3f(0, 1, 0);
+ glColor4f(plaq[iz*l*l*3*4 + iy*l*3*4 + ix*3*4 + 1*4 + 0],
+ plaq[iz*l*l*3*4 + iy*l*3*4 + ix*3*4 + 1*4 + 1],
+ plaq[iz*l*l*3*4 + iy*l*3*4 + ix*3*4 + 1*4 + 2],
+ plaq[iz*l*l*3*4 + iy*l*3*4 + ix*3*4 + 1*4 + 3]);
+ glVertex3f(0, 0, 0); glVertex3f(1, 0, 0); glVertex3f(1, 0, 1); glVertex3f(0, 0, 1);
+ glColor4f(plaq[iz*l*l*3*4 + iy*l*3*4 + ix*3*4 + 0*4 + 0],
+ plaq[iz*l*l*3*4 + iy*l*3*4 + ix*3*4 + 0*4 + 1],
+ plaq[iz*l*l*3*4 + iy*l*3*4 + ix*3*4 + 0*4 + 2],
+ plaq[iz*l*l*3*4 + iy*l*3*4 + ix*3*4 + 0*4 + 3]);
+ glVertex3f(0, 0, 0); glVertex3f(0, 1, 0); glVertex3f(0, 1, 1); glVertex3f(0, 0, 1);
+ glEnd();
+
+ glPopMatrix();
+ }
+ }
+ }
+
+ glPopMatrix();
+}
+
+namespace mygl
+{
+ int rotcube[3];
+
+ culooks::window* getWin()
+ {
+ for (int iwin=0; iwin<culooks::Windows.size(); iwin++)
+ if ( culooks::Windows.at(iwin).first == glutGetWindow() ) {
+ return culooks::Windows.at(iwin).second;
+ }
+ cerr << "Something terrible happened: Could not find window-id!" << endl;
+ exit(1);
+ }
+
+ static int getCubeFromPos(int x, int y)
+ {
+ culooks::window *Win = getWin();
+
+ int col = x / ((float)Win->w / Win->layout[0]);
+ int row = Win->layout[1] - y / ((float)Win->h / Win->layout[1]);
+
+ return col + row*Win->layout[0];
+ }
+
+
+ static void motionFunc(int x, int y)
+ {
+ cout << x << endl;
+ culooks::window *Win = getWin();
+
+ Win->cubes.at(rotcube[0]).az += rotcube[1] - x;
+ Win->cubes.at(rotcube[0]).alt += rotcube[2] - y;
+
+ rotcube[1] = x;
+ rotcube[2] = y;
+
+
+ glutPostRedisplay();
+ }
+
+ static void mouseFunc(int button, int state, int x, int y)
+ {
+ culooks::window *Win = getWin();
+
+ if (button == 0) {
+ rotcube[0] = getCubeFromPos(x,y);
+ rotcube[1] = x;
+ rotcube[2] = y;
+ }
+
+ if (button == 4) {
+ Win->cubes.at(getCubeFromPos(x,y)).zoom *= 1.1;
+ glutPostRedisplay();
+ }
+ else if (button == 3) {
+ Win->cubes.at(getCubeFromPos(x,y)).zoom *= 0.9;
+ glutPostRedisplay();
+ }
+ }
+
+
+ static void reshapeFunc(int w, int h)
+ {
+ culooks::window *Win = getWin();
+
+ int neww;
+ int newh;
+
+ if ( w == Win->w ) {
+ newh = h;
+ neww = Win->aspect*h;
+ }
+ else if ( h == Win->h ) {
+ neww = w;
+ newh = w / Win->aspect;
+ }
+ else {
+ neww = ( pow(Win->aspect,2)*w + Win->aspect*h ) / ( pow(Win->aspect,2) + 1 );
+ newh = ( Win->aspect*w + h ) / ( pow(Win->aspect,2) + 1 );
+ }
+
+ glutReshapeWindow(neww,newh);
+ glViewport(0,0,neww,newh);
+
+ Win->w = neww;
+ Win->h = newh;
+ }
+
+ static void displayFunc()
+ {
+ cout << ":" << glutGetWindow() << endl;
+
+ culooks::window *Win = getWin();
+
+ glClearColor(0,0,0,0);
+ glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
+
+ glMatrixMode(GL_MODELVIEW);
+ glLoadIdentity();
+
+ glScalef(1.0/Win->layout[0],1.0/Win->layout[1],1.0);
+ glTranslatef(-Win->layout[0]+1, -Win->layout[1]+1, 0);
+
+ for (int icube=0; icube < Win->cubes.size(); icube++) {
+ //glScalef(1.0/Env->layout[0],1.0/Env->layout[1],1.0);
+ //glRotatef(2, 1, 0, 0);
+ Win->cubes.at(icube).draw();
+ if ((icube+1)%Win->layout[0] == 0) {
+ glTranslatef(-2*Win->layout[0]+2, 2, 0);
+ }
+ else {
+ glTranslatef(2, 0, 0);
+ }
+ }
+
+ glutSwapBuffers();
+ }
+
+ static void initWindow(int winid)
+ {
+ glutInitWindowSize(culooks::Windows[winid].second->w, culooks::Windows[winid].second->h);
+ glutInitWindowPosition(winid*100,winid*100);
+ glutCreateWindow( ("culooks / " + culooks::Windows[winid].second->name).c_str() );
+
+ glutDisplayFunc(&mygl::displayFunc);
+ glutReshapeFunc(&mygl::reshapeFunc);
+ glutMotionFunc(&mygl::motionFunc);
+ glutMouseFunc(&mygl::mouseFunc);
+
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+ glEnable( GL_BLEND );
+
+ culooks::Windows[winid].first = glutGetWindow();
+
+ culooks::Windows[winid].second->initialized = true;
+ }
+
+ static void idleFunc_master()
+ {
+ for (int iwin=0; iwin < culooks::Windows.size(); iwin++)
+ if (!culooks::Windows[iwin].second->initialized)
+ initWindow(iwin);
+ }
+
+ static void* glutThread(void *_wincon)
+ {
+ culooks::wincontext *wincon = (culooks::wincontext *)_wincon;
+ glXMakeCurrent( wincon->gDisplay, wincon->gDrawable, wincon->gContext );
+ initWindow(0);
+ glutIdleFunc(&idleFunc_master);
+ glutMainLoop();
+ }
+};
+
+
+culooks::culooks (const char* name, const int& xcubes, const int& ycubes, const int& l, int *argc, char **argv)
+{
+ window *Win = new window;
+ int winsize[2];
+ wincontext wincon;
+
+ if (windowid == 0) {
+ glutInit(argc, argv);
+ glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB|GLUT_DEPTH);
+ }
+
+ Win->layout[0] = xcubes;
+ Win->layout[1] = ycubes;
+ Win->aspect = (double)xcubes/ycubes;
+ for (int icube=0; icube<xcubes*ycubes; icube++) {
+ cube newCube(l);
+ Win->cubes.push_back(newCube);
+ }
+
+ if( Win->layout[0] >= Win->layout[1] ) {
+ winsize[0] = 640;
+ winsize[1] = (640.0/Win->layout[0])*Win->layout[1];
+ }
+ else {
+ winsize[1] = 640;
+ winsize[0] = (640.0/Win->layout[1])*Win->layout[0];
+ }
+
+ Win->w = winsize[0];
+ Win->h = winsize[1];
+
+ Win->name = name;
+
+ Win->initialized = false;
+
+ Windows.push_back( pair<int,culooks::window*>(0, Win) );
+
+ if (windowid == 0) {
+ wincon.gContext = glXGetCurrentContext();
+ wincon.gDisplay = glXGetCurrentDisplay();
+ wincon.gDrawable = glXGetCurrentDrawable();
+
+ glXMakeCurrent(0,0,0);
+
+ pthread_create(&glThreadId, 0, &mygl::glutThread, &wincon);
+ }
+
+ mywid = windowid;
+ windowid++;
+}
+
+culooks::cube::cube(int _l)
+{
+ l = _l;
+ link = new float[l*l*l*3 * 4];
+ plaq = new float[l*l*l*3 * 4];
+ az = 30;
+ alt = -20;
+ zoom = 0.6;
+ id = allid;
+ allid++;
+
+ for (int i=0; i<l*l*l*3; i++) {
+ link[i*4+0]=1; link[i*4+3]=0.6;
+ plaq[i*4+1]=1; plaq[i*4+3]=0.2;
+ }
+}
--- /dev/null
+#ifndef CULOOKS_H
+#define CULOOKS_H
+
+#include <pthread.h>
+#include <vector>
+#include <GL/glut.h>
+#include <GL/glx.h>
+#include <GL/gl.h>
+#include <X11/Xlib.h>
+#include <X11/Xutil.h>
+#include <string>
+
+using namespace std;
+
+class culooks
+{
+ public:
+ class cube {
+ public:
+ cube(int l);
+ void draw();
+ int id;
+ float az, alt;
+ float zoom;
+ private:
+ void drawAll();
+ void drawBox();
+ static int allid;
+ float *plaq;
+ float *link;
+ int l;
+ };
+
+ struct window {
+ int layout[2];
+ double aspect;
+ vector<cube> cubes;
+ int w, h;
+ int gwinid;
+ bool initialized;
+ string name;
+ };
+
+ culooks (const char* name, const int& xcubes, const int& ycubes, const int& l, int *argc, char **argv);
+
+ static vector< pair<int,window*> > Windows;
+
+ struct wincontext {
+ GLXDrawable gDrawable;
+ Display *gDisplay;
+ GLXContext gContext;
+ };
+
+ private:
+ static pthread_t glThreadId;
+ static int windowid;
+ int mywid;
+
+};
+
+#endif
--- /dev/null
+#include "culooks.h"
+#include "unistd.h"
+#include <iostream>
+
+using namespace std;
+
+int main(int argc, char **argv)
+{
+
+ culooks clooks("fenster1", 2,1, 6, &argc, argv);
+ culooks clooks2("fenster2", 4,2, 6, &argc, argv);
+ culooks clooks3("fenster3", 2,1, 6, &argc, argv);
+
+ //sleep(2);
+
+ //cubelooks clooks2(2,1, 6, &argc, argv);
+
+ while(true) {
+ sleep(1);
+ }
+
+
+ return 0;
+}