From 0e276c2770688b3cc7676ee84c8e35246621f6df Mon Sep 17 00:00:00 2001 From: Alex Schmidt Date: Tue, 18 Dec 2012 16:42:32 +0100 Subject: [PATCH] ... --- .gitignore | 1 + CMakeLists.txt | 11 ++++- cubelooks.cpp | 115 +++++++++++++++++++++++++++++++++++++++++++++ cubelooks.h | 35 ++++++++++++++ cubelooks_test.cpp | 20 ++++++++ 5 files changed, 181 insertions(+), 1 deletion(-) create mode 100644 cubelooks.cpp create mode 100644 cubelooks.h create mode 100644 cubelooks_test.cpp diff --git a/.gitignore b/.gitignore index 9ed9ae9..393c6b3 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ Makefile *.a *~ neigh_test +cubelooks_test diff --git a/CMakeLists.txt b/CMakeLists.txt index e8231bf..0c8d546 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,5 +11,14 @@ add_library(lat_paraq paraq.cpp) add_library(lat_progress progress.cpp) +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_executable(neigh_test neigh_test.cpp) -target_link_libraries(neigh_test lat_neigh) \ No newline at end of file +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 diff --git a/cubelooks.cpp b/cubelooks.cpp new file mode 100644 index 0000000..ca675bd --- /dev/null +++ b/cubelooks.cpp @@ -0,0 +1,115 @@ +#include "cubelooks.h" +#include +#include +#include + +using namespace std; + +/* GLOBAL */ +vector< pair > Envs; + +int cubelooks::cube::allid = 0; + +void cubelooks::cube::draw() +{ + glBegin(GL_QUADS); + glVertex2f(-1, -1); glVertex2f(1, -1); glVertex2f(1, 1); glVertex2f(-1, 1); + glEnd(); +} + +namespace mygl +{ + cubelooks::env* getEnv() + { + for (int ienv=0; ienvcubes.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(); + } + + glutSwapBuffers(); + } + + 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]; + } + + glutInitWindowSize(winsize[0], winsize[1]); + + glutInitWindowPosition(0,0); + + glutCreateWindow("cubelooks"); + + glutDisplayFunc(&displayFunc); + glutReshapeFunc(&reshapeFunc); + //glutIdleFunc(&idleFunc); + + Envs.push_back( pair(pthread_self(), (cubelooks::env*)Env) ); + + glutMainLoop(); + } +}; + +cubelooks::cube::cube() +{ + id = allid; + allid++; +} + +cubelooks::cubelooks(const int& xcubes, const int& ycubes, int *argc, char **argv) +{ + Env.argc = argc; + Env.argv = argv; + Env.layout[0] = xcubes; + Env.layout[1] = ycubes; + for (int icube=0; icube +#include + +using namespace std; + +class cubelooks +{ + public: + class cube { + public: + cube(); + void draw(); + int id; + private: + static int allid; + }; + + struct env { + int *argc; + char **argv; + int layout[2]; + vector cubes; + }; + + cubelooks(const int& xcubes, const int& ycubes, int *argc, char **argv); + + private: + pthread_t glThreadId; + env Env; +}; + +#endif diff --git a/cubelooks_test.cpp b/cubelooks_test.cpp new file mode 100644 index 0000000..f3ea2da --- /dev/null +++ b/cubelooks_test.cpp @@ -0,0 +1,20 @@ +#include "cubelooks.h" +#include "unistd.h" +#include + +using namespace std; + +int main(int argc, char **argv) +{ + + cubelooks clooks(2,1, &argc, argv); + + + + while(true) { + sleep(1); + } + + + return 0; +} -- 2.39.5