From f9812559e766a409abfbd2d3bae519298339ab65 Mon Sep 17 00:00:00 2001 From: Alex Schmidt Date: Tue, 19 Feb 2013 17:07:19 +0100 Subject: [PATCH] ... --- culooks.cpp | 57 ++++++++++++++++++--- culooks.h | 36 ++++++++++++-- culooks_cube.cpp | 117 +++++++++++++++++++++++++++++++++++++++++--- culooks_drawing.cpp | 40 ++++++++++----- 4 files changed, 220 insertions(+), 30 deletions(-) diff --git a/culooks.cpp b/culooks.cpp index d189c86..a1f386f 100644 --- a/culooks.cpp +++ b/culooks.cpp @@ -1,7 +1,6 @@ #include "culooks.h" #include -#include #include #include @@ -18,11 +17,6 @@ culooks::culooks (const char* name, const int& xcubes, const int& ycubes, const window *Win = new window; int winsize[2]; - 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; @@ -50,11 +44,58 @@ culooks::culooks (const char* name, const int& xcubes, const int& ycubes, const Windows.push_back( pair(0, Win) ); if (windowid == 0) { - glXMakeCurrent(0,0,0); - pthread_create(&glThreadId, 0, &drawing::glutThread, NULL); + comarg comArg; + comArg.argc = argc; + comArg.argv = argv; + pthread_create(&glThreadId, 0, &drawing::glutThread, &comArg); } mywid = windowid; windowid++; } +void culooks::setLink (const int& cubeid, const int& posdir, + const float& red, const float& green, const float& blue, const float& alpha) +{ + Windows[mywid].second->cubes[cubeid].setLink(posdir, red, green, blue, alpha); +} + +void culooks::setPlaq (const int& cubeid, const int& posdir, + const float& red, const float& green, const float& blue, const float& alpha) +{ + Windows[mywid].second->cubes[cubeid].setPlaq(posdir, red, green, blue, alpha); +} + +void culooks::swapBuffers () { + for (int icube=0; icubecubes.size(); icube++) { + Windows[mywid].second->cubes[icube].swapLinkBuffer(); + Windows[mywid].second->cubes[icube].swapPlaqBuffer(); + } + Windows[mywid].second->redisplay = true; +} + +void culooks::hidePlaqs (const int& cubeid) { + Windows[mywid].second->cubes[cubeid].hidePlaqs(); +} + +void culooks::hidePlaqs () { + for (int icube=0; icubecubes.size(); icube++) + Windows[mywid].second->cubes[icube].hidePlaqs(); +} + +void culooks::hideLinks (const int& cubeid) { + Windows[mywid].second->cubes[cubeid].hideLinks(); +} + +void culooks::hideLinks () { + for (int icube=0; icubecubes.size(); icube++) + Windows[mywid].second->cubes[icube].hideLinks(); +} + +void culooks::setBgColor(const float& red, const float& green, const float& blue, const float& alpha) +{ + Windows[mywid].second->bgcolor[0] = red; + Windows[mywid].second->bgcolor[1] = green; + Windows[mywid].second->bgcolor[2] = blue; + Windows[mywid].second->bgcolor[3] = alpha; +} diff --git a/culooks.h b/culooks.h index 76f0919..fe6ca11 100644 --- a/culooks.h +++ b/culooks.h @@ -17,23 +17,51 @@ class culooks public: culooks (const char* name, const int& xcubes, const int& ycubes, const int& l, int *argc, char **argv); + void setLink (const int& cubeid, const int& posdir, + const float& red, const float& green, const float& blue, const float& alpha); + void setPlaq (const int& cubeid, const int& posdir, + const float& red, const float& green, const float& blue, const float& alpha); + void swapBuffers(); + void hidePlaqs(const int& cubeid); + void hidePlaqs(); + void hideLinks(const int& cubeid); + void hideLinks(); + void setBgColor(const float& red, const float& green, const float& blue, const float& alpha); private: + + struct comarg { + int *argc; + char **argv; + }; class cube { public: - cube(int l); + cube (int l); void draw(); int id; float az, alt; float zoom; + void setLink (const int& posdir, + const float& red, const float& green, const float& blue, const float& alpha); + void setPlaq (const int& posdir, + const float& red, const float& green, const float& blue, const float& alpha); + void swapLinkBuffer(); + void swapPlaqBuffer(); + void hidePlaqs(); + void hideLinks(); private: void drawAll(); void drawBox(); - static int allid; + static void drawFrame(); float *plaq; float *link; + float *plaqbuf[2]; + float *linkbuf[2]; int l; + int plaqbuf_active; + int linkbuf_active; + static int allid; }; struct window { @@ -44,6 +72,8 @@ class culooks int gwinid; bool initialized; string name; + float bgcolor[4]; + bool redisplay; }; class drawing @@ -57,7 +87,7 @@ class culooks static void reshapeFunc(int w, int h); static void displayFunc(); static void initWindow(int winid); - static void idleFunc_master(); + static void idleFunc(); public: static void* glutThread(void *leer); }; diff --git a/culooks_cube.cpp b/culooks_cube.cpp index 29976e4..a1d0744 100644 --- a/culooks_cube.cpp +++ b/culooks_cube.cpp @@ -4,17 +4,73 @@ int culooks::cube::allid = 0; +void culooks::cube::setLink (const int& posdir, + const float& red, const float& green, const float& blue, const float& alpha) { + linkbuf[(linkbuf_active+1)%2][ posdir*4 ] = red; + linkbuf[(linkbuf_active+1)%2][ posdir*4 + 1 ] = green; + linkbuf[(linkbuf_active+1)%2][ posdir*4 + 2 ] = blue; + linkbuf[(linkbuf_active+1)%2][ posdir*4 + 3 ] = alpha; +} + +void culooks::cube::setPlaq (const int& posdir, + const float& red, const float& green, const float& blue, const float& alpha) { + plaqbuf[(plaqbuf_active+1)%2][ posdir*4 ] = red; + plaqbuf[(plaqbuf_active+1)%2][ posdir*4 + 1 ] = green; + plaqbuf[(plaqbuf_active+1)%2][ posdir*4 + 2 ] = blue; + plaqbuf[(plaqbuf_active+1)%2][ posdir*4 + 3 ] = alpha; +} + +void culooks::cube::hidePlaqs() +{ + for (int ibuf=0; ibuf<2; ibuf++) + for (int i=0; ibgcolor[0], Win->bgcolor[1], Win->bgcolor[2], Win->bgcolor[3]); glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_MODELVIEW); @@ -118,33 +118,51 @@ void culooks::drawing::displayFunc() void culooks::drawing::initWindow(int winid) { + + glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB|GLUT_DEPTH); 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() ); - + + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glEnable(GL_BLEND); + glHint(GL_LINE_SMOOTH_HINT, GL_NICEST); + glHint(GL_POINT_SMOOTH_HINT, GL_NICEST); + glHint(GL_POLYGON_SMOOTH_HINT, GL_NICEST); + glutDisplayFunc(&drawing::displayFunc); glutReshapeFunc(&drawing::reshapeFunc); glutMotionFunc(&drawing::motionFunc); glutMouseFunc(&drawing::mouseFunc); - - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - glEnable( GL_BLEND ); + glutIdleFunc(&drawing::idleFunc); culooks::Windows[winid].first = glutGetWindow(); - culooks::Windows[winid].second->initialized = true; + culooks::Windows[winid].second->redisplay = true; } -void culooks::drawing::idleFunc_master() +void culooks::drawing::idleFunc() { - for (int iwin=0; iwin < culooks::Windows.size(); iwin++) + int activeWindow = glutGetWindow(); + + for (int iwin=0; iwin < culooks::Windows.size(); iwin++) { if (!culooks::Windows[iwin].second->initialized) initWindow(iwin); + if (culooks::Windows[iwin].second->redisplay) { + glutSetWindow(culooks::Windows[iwin].first); + glutPostRedisplay(); + culooks::Windows[iwin].second->redisplay = false; + } + } + + glutSetWindow(activeWindow); } -void* culooks::drawing::glutThread(void *leer) +void* culooks::drawing::glutThread(void *_comArg) { + comarg *comArg = (comarg*)_comArg; + + glutInit(comArg->argc, comArg->argv); initWindow(0); - glutIdleFunc(&idleFunc_master); glutMainLoop(); } -- 2.39.5