Working with glGetString(GL_VENDOR)

Started by
9 comments, last by FlyingIsFun1217 16 years, 5 months ago
Hey! I have a logging function in my 'engine', and I would love to be able to use it to print out the results from glGetString(GL_VENDOR) with it. Here's how the function is designed:

void log::logMsg(char *message, ...)

And so obviously, you would pass something like such onto it...

log logInstance;
logInstance.logMsg("Message Here...");

Now what I'm trying to do is pass the string that GL_VENDOR gives onto it, to do something like this (which is in a class function, of course):

char vendor = (char)glGetString(GL_VENDOR);
log::logMsg("%s", vendor);

But I just get the error:
Quote: cannot call member function `void log::logMsg(char*, ...)' without object
What am I missing amidst all of this chaos? Thanks! FlyingIsFun1217
Advertisement
Compare:
log logInstance;logInstance.logMsg("Message Here...");
log::logMsg("%s", vendor);
In addition to what ripoff said glGetString returns a GLubyte pointer not a GLubyte, just cut out the middle man and supply it to the log function (which other people will not doubt comment on due to using variable arguments) with a cast to char*.
Quote:Original post by rip-off
Compare:
log logInstance;logInstance.logMsg("Message Here...");
log::logMsg("%s", vendor);


Do you just mean that I could declare it's class and save myself a buncha typing? I know that... I just refuse, for now.

Quote:Original post by dmail
In addition to what ripoff said glGetString returns a GLubyte pointer not a GLubyte, just cut out the middle man and supply it to the log function (which other people will not doubt comment on due to using variable arguments) with a cast to char*.


So...

log::logMsg("%s", (char*)glGetString(GL_VENDOR));


right? That still gives me the same error.

Thanks again!
FlyingIsFun1217
Compare:



log logInstance;

logInstance< b >.</b >logMsg("Message Here...");



log< b >::< /b >logMsg("%s", vendor);


hmm dooes bold not work in a quote?
You have a member function. To call a member function, you need an instance. In the first sample, you have an instance 'logInstance'. In the second, you have no instance. In fact you are calling it in the same fashion one would use to call a static member function.
So what your saying is that to use the logMsg() function, I have to start an instance of it, just like I was doing with the other functions?

log logInst;logInst.logMsg("%s", (char*)glGetString(GL_VENDOR));


I'm at Best Buy right now... needed to 'borrow' one of their computers to try out the C4 Engine demo (I have Intel graphics :(), so I'll try that when I get home. Hopefully I have a winner :)

Thanks again!
FlyingIsFun1217
I decided just to return the value as a char. This will make things more flexible later (If I want to display it in OGL, or print it, whatever).

So I've gone with a simpler model:

return (char*)glGetString(GL_VENDOR);


in function 'char util::vendor()'.

Now I get errors again. I kinda did before, but only because the program was returning '%s' into the log file. Anyway, when I try and compile it, I just get the dreaded 'invalid conversion from `char*' to `char'' error. If I remove the pointer, turning it into (char)gl..., I get warnings that I'm casting to a different size. Does that matter?

Even when I ignore the warnings and compile as (char)gl..., the output is '%s', not 'Intel', as it should be... :/

Thanks again!
FlyingIsFun1217
glGetString() returns a char pointer. Your utility function just returns a char.

So you need to make your utility function return a char pointer as well. Any time you want to hold more than one char (such as a string) you either need a char array or a char pointer.
So you would make your utility function:
// notice the char POINTERchar *getVendor(void){	return (char *)glGetString(GL_VENDOR);}


But having a separate function for vendor, renderer, version, etc., is dumb. A better way would be to just do it directly. Using your class:
log logInstance;logInstance.logMsg("Your other log stuff");logInstance.logMsg("OpenGL Info:");logInstance.logMsg((char *)glGetString(GL_VENDOR));logInstance.logMsg((char *)glGetString(GL_RENDERER));logInstance.logMsg((char *)glGetString(GL_VERSION));logInstance.logMsg("Any other log stuff you need");

This topic is closed to new replies.

Advertisement