Conversion of GL error to string?

Started by
1 comment, last by nullsquared 18 years ago
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!
Reject the basic asumption of civialisation especially the importance of material possessions
Advertisement
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++)
baumep
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!

This topic is closed to new replies.

Advertisement