#include "cubelooks.h"
-#include <GL/glut.h>
#include <iostream>
#include <string>
#include <math.h>
using namespace std;
-cubelooks::env *Env;
+vector< pair <unsigned long int,cubelooks::env*> > Envs;
+
+bool cubelooks::initDone = false;
+GLXDrawable cubelooks::gDrawable;
+Display *cubelooks::gDisplay;
int cubelooks::cube::allid = 0;
{
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]);
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;
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;
static void reshapeFunc(int w, int h)
{
+ cubelooks::env *Env = getEnv();
+
int neww;
int newh;
static void displayFunc()
{
+ cubelooks::env *Env = getEnv();
+
glClearColor(0,0,0,0);
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
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);
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::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; icube<xcubes*ycubes; icube++) {
cube newCube(l);
- _Env.cubes.push_back(newCube);
+ 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 = &_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);
}