PDA

View Full Version : " glui->add_button " Problem



rafikkk
12-08-2004, 02:04 PM
Hello. This is part of my code and I have two problem with that.


void myLayer( void )
{
...
glui->add_button(" OBLICZ " ,0,trapezy) ;
...
}


void trapezy()
{
dx = (xk - xp) /N;
for (i=1; i<N; i++)
s +=f(xp + i * dx);
s = (s + (f(xp) + f(xk)) /2)*dx;
}When I'm compiling I have these errors:

error C2065: 'trapezy' : undeclared identifier
error C2373: 'trapezy' : redefinition; different type modifiers

When I do that delete this line:

glui->add_button(" OBLICZ " , 0,trapezy) ;everything is ok and program works ok, so I'm doing somethin wrong with "glui->add_button" function.

Can someone tell me what's wrong with that?
thanks a lot, bye

forth
12-09-2004, 03:10 AM
Try to define trapezy before the myLayer function like this:

void trapezy();
void myLayer()
{
...
}

void trapezy()
{
...
}If fails send a full code to the forum or to me personnaly.

rafikkk
12-10-2004, 02:16 AM
thx for help forth, but it have not help :(
after define function trapezy i got error:
error C2664: 'add_button' : cannot convert parameter 3 from 'void (void)' to 'void (__cdecl *)(int)'

but I've red in some doc. that in add_button shub be parameter GLUI_Update_CB and now it works. all corect function:
[CODE]
glui->add_button("TEST",0,(GLUI_Update_CB)trapezy);
[\CODE]

I'm beginner i VC and OpenGL and I have no idea what for is that parameter.

bye and thanks a lot

forth
12-10-2004, 06:08 AM
If that is true than GLUI_Update_CB is a typedef for "void (__cdecl *)(int)" - this is the type of functions whitch your buttons can use as a callback functions. So your trapezy function should be declared as

void __cdecl trapezy (int some_var);Where some_var is... Well, read the documentation you have to find out what the parameter of the callback means. Usually it is the id number of event (button's press, release, focus, blur, or whatever) or something like that, but once again - read the documents.
It seems for me that you are writing the application based only on the examples. It is a good way to start fast, but the documentation is your best friend - you gonna have to learn it by heart to avoid that kind of problems.