Sign in to follow this  

Working with glGetString(GL_VENDOR)

This topic is 3670 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
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*.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
So you would make your utility function:

// notice the char POINTER
char *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");

Share this post


Link to post
Share on other sites

This topic is 3670 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this