Hi guys, I am trying to compile the red book’s
example of tessellation but I keep getting errors like with this code
gluTessCallback(tobj, GLU_TESS_BEGIN, glBegin);
error: invalid conversion from ‘void (*)(GLenum)’ to ‘void (*)()’
Doesn’t glBegin have the exact function prototype that gluTessCallback is supposed to accept when we use GLU_TESS_BEGIN ?
I don’t think so… I think you have to define those fuctions…
void CALLBACK beginCallback(GLenum which)
{
glBegin(which);
}
gluTessCallback(tobj, GLU_TESS_BEGIN, (void(__stdcall*)())beginCallback);
I think this way it will work…
It did! (sort of…)
I’m using linux so I had to define CALLBACK and change
(void(__stdcall*)()) to (void(CALLBACK*)()) it occurred to me because I saw somewhere that windows define CALLBACK as __stdcall but to be honest with you I’m not certain why I have to cast the function argument, (that is a casting right?).
Edit:
In fact it seems that the casting is the problem because this code compiles:
gluTessCallback(tobj, GLU_TESS_BEGIN, (void(*)())glBegin);
I didn’t say I was using a g++ because I thought any C code compiled under a C++ compiler but I just checked and if I use gcc it works without casting.
I thought that you had to define the callback function because of the parameter… But it seems you don’t have to xD
Well, glad I could “help” (sort of)
And yes, that’s casting ^^
You REALY helped. thanks.
but do you know why the casting is necessary in C++ and not in C?
I hate when something works but I don’t know why it works.
I’m not sure but when I had the same problem as you were having I remember that I read somewhere that these callbacks had to be “casted” only in C++ because of some compatibility problem that C++ has with these callbacks…
But I’m not sure if what I’m saying is correct…
Anyway, if you google it and search for a while, maybe you’ll be able to find the answer… If I had time to do that, I would, but I don’t have xD
So, if you search and find something, please let me know