Jump to content

  • Log In with Google      Sign In   
  • Create Account


Conversion of GL error to string?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 Cacks   Members   -  Reputation: 110

Like
0Likes
Like

Posted 26 March 2006 - 06:21 AM

Hi guys, how would I convert my openGL errors GLubyte* to a string*?
GLenum errCode;
const GLubyte* errString;
errCode = glGetError();
if (errCode != GL_NO_ERROR)
{
errString = gluErrorString(errCode);
}

I have tries a reinterpret_cast, but can't get it working
GLenum errCode;
	string* errString = NULL;
	errCode = glGetError();
	if (errCode != GL_NO_ERROR)
	{
		errString = reinterpret_cast<const string*>(gluErrorString(errCode));
	}

Thanks for any help given!

Sponsor:

#2 baumep   Members   -  Reputation: 283

Like
0Likes
Like

Posted 26 March 2006 - 06:47 AM

You can not cast a char* to a string*. The first is a pointer to flat memory. The socond ist a pointer to a class object.
You can create a string object from the returned pointer:

GLenum errCode;
string errString;
errCode = glGetError();
if (errCode != GL_NO_ERROR)
{
errString = gluErrorString(errCode);
}





Or allocate the the string object and initializing the string with the GL errortext:

GLenum errCode;
string* errString = 0;
errCode = glGetError();
if (errCode != GL_NO_ERROR)
{
errString = new string(gluErrorString(errCode)); // don't forget to delete the string object, so first solution might be better
}





(Assuming you're using C++)

#3 nullsquared   Members   -  Reputation: 122

Like
0Likes
Like

Posted 26 March 2006 - 07:01 AM

char* != string*

string holds a char* internally so YOU don't have to manage it. You can do something like:

string myError = AFunctionThatReturnsACharPointer();


Since a string's operator= accepts other strings as well as char*. You can also use it's sopy constructor:

string myError(AFunctionThatReturnsACharPointer());



Good luck!




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS