]> git.treefish.org Git - phys/latlib.git/commitdiff
...
authorAlex Schmidt <alex@treefish.org>
Tue, 18 Dec 2012 15:42:32 +0000 (16:42 +0100)
committerAlex Schmidt <alex@treefish.org>
Tue, 18 Dec 2012 15:42:32 +0000 (16:42 +0100)
.gitignore
CMakeLists.txt
cubelooks.cpp [new file with mode: 0644]
cubelooks.h [new file with mode: 0644]
cubelooks_test.cpp [new file with mode: 0644]

index 9ed9ae97876083206c3fec3dc9d14537fc54a08e..393c6b387699f80f22f8077485f45982ac4081bd 100644 (file)
@@ -5,3 +5,4 @@ Makefile
 *.a
 *~
 neigh_test
+cubelooks_test
index e8231bf3f67c8331cb96356eef61e15a36be102b..0c8d546dd5c33eee37f22e851c28ed026090c0b2 100644 (file)
@@ -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 (file)
index 0000000..ca675bd
--- /dev/null
@@ -0,0 +1,115 @@
+#include "cubelooks.h"
+#include <GL/glut.h>
+#include <iostream>
+#include <string>
+
+using namespace std;
+
+/* GLOBAL */
+vector< pair <unsigned long int,cubelooks::env*> > 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; 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 void idleFunc()
+  {
+    glutPostRedisplay();
+  }
+
+  static void reshapeFunc(int w, int h)
+  {
+    glutReshapeWindow(10,10);
+    glViewport(0,0,w,h);
+    cout << w << ":" << h << endl;
+  }
+
+  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();
+
+    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();
+    }
+
+    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<unsigned long int,cubelooks::env*>(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<xcubes*ycubes; icube++) {
+    cube newCube;
+    Env.cubes.push_back(newCube);
+  }
+
+  pthread_create(&glThreadId, 0, &mygl::glutThread, &Env);
+}
diff --git a/cubelooks.h b/cubelooks.h
new file mode 100644 (file)
index 0000000..6e8faff
--- /dev/null
@@ -0,0 +1,35 @@
+#ifndef CUBELOOKS_H
+#define CUBELOOKS_H
+
+#include <pthread.h>
+#include <vector>
+
+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<cube> 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 (file)
index 0000000..f3ea2da
--- /dev/null
@@ -0,0 +1,20 @@
+#include "cubelooks.h"
+#include "unistd.h"
+#include <iostream>
+
+using namespace std;
+
+int main(int argc, char **argv)
+{
+
+  cubelooks clooks(2,1, &argc, argv);
+
+
+
+  while(true) {
+    sleep(1);
+  }
+  
+
+  return 0;
+}