From: Alex Schmidt Date: Thu, 20 Dec 2012 18:29:36 +0000 (+0100) Subject: ... X-Git-Url: http://git.treefish.org/~alex/phys/latlib.git/commitdiff_plain/2f7d03857df74cf9edb56fbc1984152a38530ff9 ... --- diff --git a/cubelooks.cpp b/cubelooks.cpp index 6584383..f6b02ef 100644 --- a/cubelooks.cpp +++ b/cubelooks.cpp @@ -1,12 +1,15 @@ #include "cubelooks.h" -#include #include #include #include using namespace std; -cubelooks::env *Env; +vector< pair > Envs; + +bool cubelooks::initDone = false; +GLXDrawable cubelooks::gDrawable; +Display *cubelooks::gDisplay; int cubelooks::cube::allid = 0; @@ -132,8 +135,20 @@ namespace mygl { int rotcube[3]; + cubelooks::env* getEnv() + { + for (int ienv=0; ienvw / Env->layout[0]); int row = Env->layout[1] - y / ((float)Env->h / Env->layout[1]); @@ -147,6 +162,8 @@ namespace mygl 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; @@ -158,6 +175,8 @@ namespace mygl 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; @@ -176,6 +195,8 @@ namespace mygl static void reshapeFunc(int w, int h) { + cubelooks::env *Env = getEnv(); + int neww; int newh; @@ -201,6 +222,8 @@ namespace mygl static void displayFunc() { + cubelooks::env *Env = getEnv(); + glClearColor(0,0,0,0); glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); @@ -227,28 +250,17 @@ namespace mygl static void* glutThread(void *_Env) { - int winsize[2]; + cubelooks::env *Env = (cubelooks::env *)_Env; - glutInit( ((cubelooks::env*)Env)->argc, ((cubelooks::env*)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]; - } + //glXMakeCurrent(0, glutCreateWindow("cubelooks")); - Env->w = winsize[0]; - Env->h = winsize[1]; + //glXCrateContext(0, - glutInitWindowSize(winsize[0], winsize[1]); + //cout << Env->layout[1] << endl; - glutInitWindowPosition(0,0); + glXMakeCurrent( Env->gDisplay, Env->gDrawable, Env->gContext ); - glutCreateWindow("cubelooks"); + //cout << "da" << endl; glutDisplayFunc(&displayFunc); glutReshapeFunc(&reshapeFunc); @@ -259,6 +271,8 @@ namespace mygl glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable( GL_BLEND ); + Envs.push_back( pair(pthread_self(), Env) ); + glutMainLoop(); } }; @@ -282,19 +296,52 @@ cubelooks::cube::cube(int _l) cubelooks::cubelooks(const int& xcubes, const int& ycubes, const int& l, int *argc, char **argv) { - _Env.argc = argc; - _Env.argv = argv; - _Env.layout[0] = xcubes; - _Env.layout[1] = ycubes; - _Env.aspect = (double)xcubes/ycubes; + 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; icubecubes.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 = &_Env; + Env->gContext = glXGetCurrentContext(); + Env->gDisplay = gDisplay; + Env->gDrawable = glXGetCurrentDrawable(); - pthread_create(&glThreadId, 0, &mygl::glutThread, NULL); + glXMakeCurrent(0,0,0); - sleep(2); + pthread_create(&glThreadId, 0, &mygl::glutThread, Env); } diff --git a/cubelooks.h b/cubelooks.h index 6a404a7..4d75332 100644 --- a/cubelooks.h +++ b/cubelooks.h @@ -3,6 +3,12 @@ #include #include +#include +#include +#include +#include +#include + using namespace std; @@ -32,13 +38,18 @@ class cubelooks double aspect; vector 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; - env _Env; + static bool initDone; + static GLXDrawable gDrawable; + static Display *gDisplay; }; #endif diff --git a/cubelooks_test.cpp b/cubelooks_test.cpp index b8880c0..fc6e3f8 100644 --- a/cubelooks_test.cpp +++ b/cubelooks_test.cpp @@ -9,6 +9,10 @@ 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); }