Jump to content

View more

Image of the Day

Boxes as reward for our ranking mode. ヾ(☆▽☆)
#indiedev #gamedev #gameart #screenshotsaturday https://t.co/ALF1InmM7K
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.


Sign up now

Conversion of GL error to string?

4: Adsense

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   

179
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!

#2 baumep   Members   

373
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   

126
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.