コード例 #1
0
ファイル: localError.cpp プロジェクト: dcoeurjo/thicknessExpe
int main ( int argc, char * argv[] ) {
    // argv[1] = thickness values ( .TXT file ) 
    // argv[2] = thickness values ( noised ) ( .TXT file ) 
    if ( argc != 3 ) {
        std::cerr << "Not the good number of arguments" << std::endl ;
        return -1 ;
    }
    std::vector<double> sdfValues  = readSdfValues(argv[1]) ;
    std::vector<double> sdfNoisedValues  = readSdfValues(argv[2]) ; 
    int size = sdfValues.size() ; 
    std::vector<float> localError(size,0.0) ;
    // Important note : The facet numbering is the same for the different OFF files
    std::string noiseName = argv[2] ;
    std::string errorResults = noiseName.substr(0,noiseName.size()-4)+"-local-error.txt";
    std::ofstream errorFile(errorResults.c_str(), std::ios::out);
    if (!errorFile) { 
        std::cerr << " Error in creating file " <<  std::endl;
        return -1 ;
    } 
    // Calculations
    int j ;
    for ( j = 0 ; j < size ; j++ ) {
         localError[j] = error(sdfValues[j],sdfNoisedValues[j]);
    } ;
    // Sort the values 
    std::sort(localError.begin(),localError.end());
    // Put in file
    for ( j = 0 ; j < size ; j++) {
        errorFile << (j+1)*100.0/( (float) size) << " " << localError[j] << std::endl ;
    };
    return 0;
}
コード例 #2
0
ファイル: client.cpp プロジェクト: Anna-Sentyakova/qblokus
LocalClient::LocalClient():lastpingtime(QTime::currentTime()) {
	localtimer.setInterval(PING_INTERVAL);
	connect(&localtimer, SIGNAL(timeout()), this, SLOT(localTimerCheck()));
	socket = new TCPSocket;
	receiver = new MessageReceiver(socket);
	qRegisterMetaType<PlayersListMessage>("PlayersListMessage");
	qRegisterMetaType<ClientConnectMessage>("ClientConnectMessage");
	qRegisterMetaType<ServerReadyMessage>("ServerReadyMessage");
	qRegisterMetaType<ConnectionAcceptedMessage>("ConnectionAcceptedMessage");
	qRegisterMetaType<PingMessage>("PingMessage");
	qRegisterMetaType<StartGameMessage>("StartGameMessage");
	qRegisterMetaType<RestartGameMessage>("RestartGameMessage");
	qRegisterMetaType<TurnMessage>("TurnMessage");
	qRegisterMetaType<ClientDisconnectMessage>("ClientDisconnectMessage");
	qRegisterMetaType<SurrenderMessage>("SurrenderMessage");
	qRegisterMetaType<ChatMessage>("ChatMessage");
	connect(receiver, SIGNAL(chatMessageReceive(ChatMessage)), this, SLOT(localChatMessageReceive(ChatMessage)));
	connect(receiver, SIGNAL(playersListMessageReceive(PlayersListMessage)), this, SLOT(localPlayersListMessageReceive(PlayersListMessage)));
	connect(receiver, SIGNAL(serverReadyMessageReceive(ServerReadyMessage)), this, SLOT(localServerReadyMessageReceive(ServerReadyMessage)));
	connect(receiver, SIGNAL(clientConnectMessageReceive(ClientConnectMessage)), this, SLOT(localClientConnectMessageReceive(ClientConnectMessage)));
	connect(receiver, SIGNAL(clientDisconnectMessageReceive(ClientDisconnectMessage)), this, SLOT(localClientDisconnectMessageReceive(ClientDisconnectMessage)));
	connect(receiver, SIGNAL(connectionAcceptedMessageReceive(ConnectionAcceptedMessage)), this, SLOT(localConnectionAcceptedMessageReceive(ConnectionAcceptedMessage)));
	connect(receiver, SIGNAL(pingMessageReceive(PingMessage)), this, SLOT(localPingMessageReceive(PingMessage)));
	connect(receiver, SIGNAL(startGameMessageReceive(StartGameMessage)), this, SLOT(localStartGameMessageReceive(StartGameMessage)));
	connect(receiver, SIGNAL(restartGameMessageReceive(RestartGameMessage)), this, SLOT(localRestartGameMessageReceive(RestartGameMessage)));
	connect(receiver, SIGNAL(turnMessageReceive(TurnMessage)), this, SLOT(localTurnMessageReceive(TurnMessage)));
	connect(receiver, SIGNAL(surrenderMessageReceive(SurrenderMessage)), this, SLOT(localSurrenderMessageReceive(SurrenderMessage)));
	connect(socket, SIGNAL(connected()), this, SLOT(localConnected()));
	connect(socket, SIGNAL(disconnected()), this, SLOT(localDisconnected()));
	connect(socket, SIGNAL(error()), this, SLOT(localError()));
}
コード例 #3
0
ファイル: axis.c プロジェクト: gplv2/rlib
gint imod(gint y, gint x, gint *quo, gint *rem) {
	if (x==0)   
		return (localError("imod: received zero denominator"),-1);

	*quo=(int)(((double)y)/(double)x);
	*rem=y - x*(*quo);
	return 0;
}
コード例 #4
0
	void GlXOffscreenContext::clearActive()
	{
		if (!isReady())
			return;

		if (!glXMakeCurrent(_display, None, NULL))
			localError("Unable to release context.");
	}
コード例 #5
0
ファイル: axis.c プロジェクト: gplv2/rlib
gint zeroRem(gint upDown, gint y, gint x, gint *quo, gint *newY) {
	if (x==0) 
		return (localError("zeroRem: received zero denominator"),-1);
	if (upDown!=-1 && upDown!=1) 
		return (localError("zeroRem: upDown must be +/-1"),-1);
	if (y==0) {
		*quo=0;
		*newY=y;
		return 0;
	} else {
		gint rem;
		imod(y,x,quo,&rem);
		if (rem==0) {
			*newY=y; /*leave quo as is*/
			return 0;
		} else {
			*newY=y+upDown*x-rem;
			(*quo)+=upDown;
			return 0;
		}
	}
}
コード例 #6
0
ファイル: axis.c プロジェクト: bobnsicom/rlib
gint adjustPosAndNegLimits(gint mappedMin, gint mappedMax, gint minTMs, gint maxTMs, gint sd, gint *goodIncs, gint numGoodIncs,
	gint* numTms, gint* tmi, gint* adjMin, gint* adjMax) {
	gint bestAdj=32767;
	gint inc;
	gint found=0;
	gint bestNewMin=0,bestNewMax=0,bestTm=0,bestInc=0;
	gint mapMax=MAPMAX(sd);

	if (MAX(abs(mappedMin),abs(mappedMax))>mapMax)
   	 return (localError("adjustPosAndNegLimits: some data is > supplied mapping upper limit"),-1);

//	for (inc=1;inc<=mapMax;inc++) {
	for (inc=1;inc<=maxTMs;inc++) {
		gint quo1,quo2;
		gint newMin,newMax;
		gint adj,tm;
		zeroRem(-1,mappedMin,inc,&quo1,&newMin);
		zeroRem(1,mappedMax,inc,&quo2,&newMax);
		adj=abs(mappedMin-newMin)+abs(mappedMax-newMax);/* total adjustment                         */
		tm=abs(quo1)+abs(quo2);      /* tick marks; convention here is to not include the first,
						                 (though really it is 1 more than this).                         */
		if (tm>=minTMs && tm<=maxTMs && adj<bestAdj && isGoodInc(inc,sd,goodIncs,numGoodIncs)) {
			bestAdj=adj;
			bestTm=tm;
			bestInc=inc;
			bestNewMin=newMin;
			bestNewMax=newMax;
			found=1;
		}
	}
	if (!found)
		return (localError("adjustPosAndNegLimits: found no acceptable divisor into the limits"),-1);
	*adjMin=bestNewMin;
	*adjMax=bestNewMax;
	*numTms=bestTm;
	*tmi=bestInc;
	return 0;
}
コード例 #7
0
	GlXOffscreenContext::GlXOffscreenContext(uint width, uint height) :
		_display(NULL),
		_fbConfig(None),
		_pBuffer(0),
		_context(NULL),
		_width(width),
		_height(height),
		_ready(false)
	{
		if ((_width == 0) || (_height == 0))
			localError("Both width and height must be greater than zero.");

		createContext();
	}
コード例 #8
0
	bool GlXOffscreenContext::makeActive()
	{
		if (!isReady())
			return false;

		if (isActive())
			return true;

		if (!glXMakeContextCurrent(_display, _pBuffer, _pBuffer, _context))
		{
			localError("Unable to make context active.");
			return false;
		}
		else
			return true;
	}
コード例 #9
0
ファイル: axis.c プロジェクト: gplv2/rlib
int adjust_limits(gdouble  dataMin, gdouble dataMax, gint denyMinEqualsAdjMin, gint minTMs, gint maxTMs, 
	gint* numTms, gdouble* tmi, gdouble* adjMin, gdouble* adjMax, gint *goodIncs, gint numGoodIncs) {

	int     sd = 2;
	int     maxPossibleGoodInc=MAPMAX(sd);
	double  zMin,zMax;      /* zeroized limits (after unmapped above) */
	double  szMin,szMax;    /* shifted zeroized limits */
	int     mszMin,mszMax;  /* mapped shifted zeroized limits */
	int     amszMin,amszMax;/* adjusted mapped shifted zeroized limits */
	double  aszMin,aszMax;  /* adjusted shifted zeroized limits */
	double  azMin,azMax;    /* adjusted zeroized limits */

	int     falseOrigin;    /* if true, we have decided on a false origin        */
	int     mTmi;           /* tick mark interval in mapped range               */
	int     raise;          /* power to which original limits must be raised
                           so as to map into range specified by sd          */
	int     i;              /* loop index */
	int     adjMaxTMs=(denyMinEqualsAdjMin?maxTMs-1:maxTMs);


/*
This is the requested maxTMs UNLESS denyMinEqualsAdjMin is true. In that case
it is possible that one of the limits will be shifted by an extra tickmark
interval after the call to adjustPosAndNegLimits. To account for this
possibility, need to decrement the maximum number of tickmarks available to
the adjstment algorithm in advance, so that the total is gauranteed to be
no more than the specified maximum.
*/

/* test to see parameters make sense */
	if (dataMin>=dataMax)
		return(localError("adjustLimits: bad data range"),-1);

	if (minTMs<=0 || maxTMs<=0)
		return(localError("adjustLimits: negative or zero tickmarks specified"),-1);

if (maxTMs==1 && denyMinEqualsAdjMin)
        return(localError("adjustLimits: cannot specify 1 tickmark AND require a margin"),-1);

if (sd<1 || sd >4)
        return(localError("adjustLimits: sd out of range [1,4]"),-1);


	if(denyMinEqualsAdjMin && dataMin < 0 && dataMax < 0)
		dataMax = 0;


/*check to see that the acceptable increments do not have more significant figures than allowed
 for the limits */
for (i=0;i<numGoodIncs;i++)
    {
    if (goodIncs[i]>maxPossibleGoodInc)
        return (localError("adjustLimits: supplied with a good increment that is too large given the number of significant digits"),-1);
    if (goodIncs[i]<=0)
        return (localError("adjustLimits: supplied with a good increment that is <=0"),-1);
    }

/* see if either limit can be set to zero */
tryToZeroize(dataMin,dataMax,1.0/(double)maxTMs,&zMin,&zMax);

/*
Shift the origin.
Note that shifting the origin may reduce the number of significant figures.
For example (1000,1003) will be shifted to (0,3).
Therefore need to shift the data BEFORE performing the map.
Hence get (0,30) in this case.
*/
if (zMin*zMax>0) /*both of same sign and non-zero */
    {
    if (zMax>0)
        {
        falseOrigin=1; /* positive false origin */
        szMax=zMax-zMin; /* remove offset */
        szMin=0;
        }
    else {
        falseOrigin=-1; /* negative false origin */
        szMin=zMin-zMax; /* remove offset (zMappedMax<0 here) */
        szMax=0;
        }
    }
else
    {
    /* If here, then either zMin =0, or zMax =0,
    or they are both non-zero and of same sign.
    In all these cases do not shift the origin */
    falseOrigin=0;
    szMax=zMax;
    szMin=zMin;
    }

/* map the data */
mapData(szMin,szMax,sd,&mszMin,&mszMax,&raise);

/* adjust limits */
	if(adjustPosAndNegLimits(mszMin,mszMax,minTMs,adjMaxTMs,sd,goodIncs,numGoodIncs,numTms, &mTmi,&amszMin,&amszMax) == -1) {
		*adjMin = dataMin;
		*adjMax = dataMax;
		*numTms = 10;
		return -1;
	}

/* unmap the data */
aszMin=((double)amszMin)*POWER10(-raise);
aszMax=((double)amszMax)*POWER10(-raise);
*tmi=((double)mTmi)*POWER10(-raise);

/* unshift the origin */
if (falseOrigin==1)
    {
    azMin=aszMin+zMin;
    azMax=aszMax+zMin;
    }
else if (falseOrigin==-1)
    {
    azMin=aszMin+zMax;
    azMax=aszMax+zMax;
    }
else
    {
    azMin=aszMin;
    azMax=aszMax;
    }

/* set outputs whilst performing margin adjustment */
if (denyMinEqualsAdjMin
&& falseOrigin==1
&& azMin-dataMin<*tmi)      /* requested margin is absent */
    {
    *adjMin=azMin-*tmi;     /* shift down by extra tickmark interval */
    *adjMax=azMax;
    (*numTms)++;
    }
else if (denyMinEqualsAdjMin
&& falseOrigin==-1
&& azMax-dataMax<*tmi)     /* requested margin is absent */
    {
    *adjMin=azMin;        /* shift down by extra tickmark interval */
    *adjMax=azMax+*tmi;        /* shift up by extra tickmark interval */
    (*numTms)++;
    }
else
    {
    *adjMin=azMin;
    *adjMax=azMax;
    }

return 0;
}
コード例 #10
0
/*
*******************************************************************
* Function: int BehaviourFunction( const CKBehaviorContext& behaviorContext )
*
* Description : The execution function is the function that will be called 
*               during the process loop of the behavior engine, if the behavior 
*               is defined as using an execution function. This function is not 
*               called if the behavior is defined as a graph. This function is the 
*               heart of the behavior: it should compute the essence of the behavior, 
*               in an incremental way. The minimum amount of computing should be 
*               done at each call, to leave time for the other behaviors to run. 
*               The function receives the delay in milliseconds that has elapsed 
*               since the last behavioral process, and should rely on this value to 
*               manage the amount of effect it has on its computation, if the effect 
*               of this computation relies on time.
*
* Parameters :
*    behaviourContext    r   Behavior context reference, which gives access to 
*                            frequently used global objects ( context, level, manager, etc... )
*
* Returns : int, If it is done, it should return CKBR_OK. If it returns 
*                CKBR_ACTIVATENEXTFRAME, the behavior will again be called 
*                during the next process loop.
*
*******************************************************************
*/
int CGBLCHPopulateAvailableRecipients::BehaviourFunction( const CKBehaviorContext& behaviorContext )
{
    enum 
    {
        GETACTIVEPLAYERSARRAY_COLUMN_VIRTOOLSUSERID,
        GETACTIVEPLAYERSARRAY_COLUMN_USERNAME,
        GETACTIVEPLAYERSARRAY_COLUMN_GBLTEAMID
    };
   
    enum 
    {
        AVAILABLERECIPIENTSARRAY_COLUMN_USERNAME,
        AVAILABLERECIPIENTSARRAY_COLUMN_VIRTOOLSUSERID,
        AVAILABLERECIPIENTSARRAY_COLUMN_GBLTEAMID
    };

    CKBehavior *beh = behaviorContext.Behavior;
    CGBLCOError localError(CGBLCOError::EGBLCOErrorType::GBLCO_OK);

    if (!beh)
    {
        assert(NULL);
        return CKBR_BEHAVIORERROR;
    }

    // Get profile controller
    CGBLProfileManager* profileManager = static_cast<CGBLProfileManager*>(beh->GetCKContext()->GetManagerByGuid(GBLProfileManagerGUID));
    if (!profileManager)
    {
        assert(NULL);
        return CKBR_BEHAVIORERROR;
    }

    // Get GBL Loader manager
    GBLLDManager* loaderManager = static_cast<GBLLDManager*>(beh->GetCKContext()->GetManagerByGuid(GBLLDManagerGUID));
    if (!profileManager)
    {
        assert(NULL);
        return CKBR_BEHAVIORERROR;
    }

    // Check we have been passed an array
    CKDataArray* availableRecipientsArray = static_cast<CKDataArray*>(beh->GetInputParameterObject(eParamInputAvailableRecipientsArray));
    if (!availableRecipientsArray)
    {
        return CKBR_BEHAVIORERROR;
    }

    // Clear array and set up structure
    availableRecipientsArray->Clear();
    while (availableRecipientsArray->GetColumnCount())
        availableRecipientsArray->RemoveColumn(0);

    availableRecipientsArray->InsertColumn(-1, CKARRAYTYPE_STRING, "Name");
    availableRecipientsArray->InsertColumn(-1, CKARRAYTYPE_INT, "VirtoolsUserID");
    availableRecipientsArray->InsertColumn(-1, CKARRAYTYPE_PARAMETER, "GBLTeamID", GUID_TEAM_ID);

    // Create a temporary array of active players to be filled in by the Profile Controller
    CKDataArray* tmpActivePlayersArray = (CKDataArray*)beh->GetCKContext()->CreateObject(CKCID_DATAARRAY,
                                    "CGBLCHPopulateAvailableRecipients temp array", 
                                    CK_OBJECTCREATION_DYNAMIC);
    if (!tmpActivePlayersArray)
    {
        assert(NULL);
        return CKBR_BEHAVIORERROR;
    }

    // Create temporary array for team names to be filled in by the Profile Controller
    CKDataArray* tmpTeamNameArray = (CKDataArray*)beh->GetCKContext()->CreateObject(CKCID_DATAARRAY,
                                    "CGBLCHPopulateAvailableRecipients temp array 2", 
                                    CK_OBJECTCREATION_DYNAMIC);
    if (!tmpTeamNameArray)
    {
        assert(NULL);
        return CKBR_BEHAVIORERROR;
    }

    // Get active players
    localError = profileManager->GetActivePlayers(tmpActivePlayersArray);
    if (localError != CGBLCOError::EGBLCOErrorType::GBLCO_OK)
    {
        localError.SetCode(GBLCH_ERRORCODE_UNABLETOGETPROFILEINFORMATION);
        localError.SetDescription((XString)"An error occurred while attempting to retrieve profile information: " + (const char*)localError);
    }
    else
    {
        // Collate Team IDs into local array
        CGBLTeamID teamID;
        XArray<CGBLTeamID> arrayOfTeamIDs;
        XArray<XString> arrayOfTeamNames;
        char* stringBuffer = NULL;

        for (int row = 0;row < tmpActivePlayersArray->GetRowCount();row++)
        {
            // Get Team ID
            teamID = 0;
            if (tmpActivePlayersArray->GetElementValue(row, GETACTIVEPLAYERSARRAY_COLUMN_GBLTEAMID, &teamID))
            {
                if ((int)teamID)
                {
                    // Have we already got this team ID in the array?
                    if (arrayOfTeamIDs.End() == arrayOfTeamIDs.Find(teamID))
                    {
                        // No, add it to the array
                        arrayOfTeamIDs.PushBack(teamID);
                    }
                }
            }
        }

        // Copy team IDs and names into AvailableRecipients array
        for (int team = 0;team < arrayOfTeamIDs.Size();team++)
        {
            availableRecipientsArray->AddRow();
            int row = availableRecipientsArray->GetRowCount() - 1;

            assert(row == team);

            // Get team name
            teamID = arrayOfTeamIDs[team];
            localError = profileManager->GetProfileField((const)teamID, "Name", tmpTeamNameArray);
            if (localError != CGBLCOError::EGBLCOErrorType::GBLCO_OK) {
                localError.SetCode(GBLCH_ERRORCODE_UNABLETOGETPROFILEINFORMATION);
                localError.SetDescription((XString)"An error occurred while attempting to retrieve profile information: " + (const char*)localError);
                break;
            }

            // Place team name into destination array
            stringBuffer = new char[tmpTeamNameArray->GetElementStringValue(0, 0, NULL) + 1];
            tmpTeamNameArray->GetElementStringValue(0, 0, stringBuffer);

            availableRecipientsArray->SetElementStringValue(row, AVAILABLERECIPIENTSARRAY_COLUMN_USERNAME, stringBuffer);

            delete stringBuffer;
            stringBuffer = NULL;

            // Set user ID as 0
            int virtoolsUserID = 0;
            availableRecipientsArray->SetElementValue(row, AVAILABLERECIPIENTSARRAY_COLUMN_VIRTOOLSUSERID, &virtoolsUserID);

            // Set team ID
            availableRecipientsArray->SetElementValue(row, AVAILABLERECIPIENTSARRAY_COLUMN_GBLTEAMID, &arrayOfTeamIDs[team]);
        }
    }
    if (localError == CGBLCOError::EGBLCOErrorType::GBLCO_OK)
    {
        CGBLTeamID teamID;
        char* stringBuffer = NULL;
        int virtoolsUserID;

        // Now copy players (which includes facilitators) into the destination array
        for (int row = 0;row < tmpActivePlayersArray->GetRowCount();row++)
        {
            // Get User ID
            virtoolsUserID = 0;
            if (tmpActivePlayersArray->GetElementValue(row, GETACTIVEPLAYERSARRAY_COLUMN_VIRTOOLSUSERID, &virtoolsUserID))
            {
                // Check this user ID valid
                if (virtoolsUserID)
                {
                    // Add new row to destination array
                    availableRecipientsArray->AddRow();
                    int row = availableRecipientsArray->GetRowCount() - 1;

                    // Set Virtools user ID
                    availableRecipientsArray->SetElementValue(row, AVAILABLERECIPIENTSARRAY_COLUMN_VIRTOOLSUSERID, &virtoolsUserID);

                    // Get name and put into dest array
                    stringBuffer = new char[tmpActivePlayersArray->GetElementStringValue(row, GETACTIVEPLAYERSARRAY_COLUMN_USERNAME, NULL) + 1];
                    tmpActivePlayersArray->GetElementStringValue(row, GETACTIVEPLAYERSARRAY_COLUMN_USERNAME, stringBuffer);
                    
                    availableRecipientsArray->SetElementStringValue(row, AVAILABLERECIPIENTSARRAY_COLUMN_USERNAME, stringBuffer);
                    delete stringBuffer;
                    stringBuffer = NULL;

                    // Set team ID to 0
                    teamID = 0;
                    availableRecipientsArray->SetElementValue(row, AVAILABLERECIPIENTSARRAY_COLUMN_GBLTEAMID, &teamID);
                }
            }
        }
    }
    if (localError == CGBLCOError::EGBLCOErrorType::GBLCO_OK)
    {
        // Remove the current user from the array

        // Get current Virtools User ID from GBL Loader
        int currentVirtoolsUserID = loaderManager->GetVirtoolsUserID();        

        for (int row = availableRecipientsArray->GetRowCount() - 1;row >= 0;row--)
        {
            int virtoolsUserId = 0;
            availableRecipientsArray->GetElementValue(row, AVAILABLERECIPIENTSARRAY_COLUMN_VIRTOOLSUSERID, &virtoolsUserId);

            if (virtoolsUserId == currentVirtoolsUserID)
            {
                // This row is the current user. Remove it
                availableRecipientsArray->RemoveRow(row);
            }
        }
    }

    // Free temporary arrays
    beh->GetCKContext()->DestroyObject(tmpActivePlayersArray);
    beh->GetCKContext()->DestroyObject(tmpTeamNameArray);

    // Did an error occur?
    if (localError == CGBLCOError::EGBLCOErrorType::GBLCO_OK)
    {
        // Output success
        beh->ActivateOutput(eBehOutputDone);
    }
    else
    {
        // Output the error
        TGBLError::SetTGBLError(beh->GetOutputParameter(eParamOutputError), localError, localError, (CKSTRING)(const char*)localError);
        beh->ActivateOutput(eBehOutputError);
    }

    // All done
    return CKBR_OK;
}
コード例 #11
0
	void GlXOffscreenContext::createContext()
	{
		_ready = false;

		_display = XOpenDisplay(NULL);

		if (!_display)
			localError("Unable to open XDisplay.");

		int errorBase, eventBase;
		if (!glXQueryExtension(_display, &errorBase, &eventBase))
			localError("OpenGL GLX Extension not supported.");

		int screen = DefaultScreen(_display);

		int glxVersionMajor, glxVersionMinor;
		glXQueryVersion(_display, &glxVersionMajor, &glxVersionMinor);

		dbg << "GLX Version: " << glxVersionMajor << "." << glxVersionMinor << endl;

		int fbConfigCount = 0;

		int attribList[] =
		{
			//GLX_X_RENDERABLE, True, // Implied
			GLX_DRAWABLE_TYPE, GLX_PBUFFER_BIT,// | GLX_WINDOW_BIT,
			GLX_RENDER_TYPE, GLX_RGBA_BIT,
			GLX_RED_SIZE, 8,
			GLX_BLUE_SIZE, 8,
			GLX_GREEN_SIZE, 8,
			//GLX_ALPHA_SIZE, 8,
			//GLX_MAX_PBUFFER_WIDTH, _width,
			//GLX_MAX_PBUFFER_HEIGHT, _height,
			GLX_DEPTH_SIZE, 24,
			GLX_DOUBLEBUFFER, False,
			None
		};

		GLXFBConfig* fbConfigs = glXChooseFBConfig(_display, screen, attribList, &fbConfigCount);

		if ((fbConfigs == NULL) || (fbConfigCount <= 0))
			localError("Unable to choose fb config.");

		int pBufferAttribList[] =
		{
			GLX_PBUFFER_WIDTH, (int)_width,
			GLX_PBUFFER_HEIGHT, (int)_height,
			GLX_LARGEST_PBUFFER, False,
			None
		};

		for (int i = 0; i < fbConfigCount; ++i)
		{
			_pBuffer = glXCreatePbuffer(_display, fbConfigs[i], pBufferAttribList);

			if (_pBuffer != None)
			{
				dbg << "Found successful frame buffer on attempt " << (i+1) << ".." << endl;
				_fbConfig = fbConfigs[i];
				break;
			}
		}

		XSync(_display, False);

		XFree(fbConfigs);

		if (_pBuffer == None)
			localError("Unable to create pbuffer.");

		// Get visual..
		XVisualInfo* visInfo = glXGetVisualFromFBConfig(_display, _fbConfig);
		if (!visInfo)
		{
			localError("Unable to get X visual.");
		}

		// Create context..
		_context = glXCreateContext(_display, visInfo, NULL, True);

		if (!_context)
		{
			dbg << "Unable to create a direct context, attempting indirect one.." << endl;
			_context = glXCreateContext(_display, visInfo, NULL, False);
		}
		else
		{
			dbg << "Created a direct context.." << endl;
		}

		XFree(visInfo);

		if (!_context)
			localError("Unable to create GL context.");

		if (!glXMakeContextCurrent(_display, _pBuffer, _pBuffer, _context))
			localError("Unable to make context active.");

		// Should be able to use openGL here..

		GLenum glewErr = glewInit();
		if (glewErr != GLEW_OK)
		{
			cerr << "GLEW ERROR: " << glewGetErrorString(glewErr) << endl;
		}

		int majorVersion, minorVersion;
		glGetIntegerv(GL_MAJOR_VERSION, &majorVersion);
		glGetIntegerv(GL_MINOR_VERSION, &minorVersion);

		dbg << "GL Version: " << majorVersion << "." << minorVersion << endl;

		checkGlError("After context creation..");

		// Yay
		_ready = true;
	}