PDA

View Full Version : function display



arthas
02-26-2008, 02:50 AM
Hi guys, probably is a stupid question but..is it possible to call the fuction display if it isn't in the same class of glutDisplayFunc? I mean, is it possible:

class A:



int main(int argc, char **argv)
{
glutInitWindowSize(30,30);
glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH);
glutInit(&argc, argv);
glutCreateWindow("example");
glutDisplayFunc(display);
return 0;
}


class B:


static void display(void)
{
do something..
}

Dark Photon
02-26-2008, 05:50 AM
Hi guys, probably is a stupid question but..is it possible to call the fuction display if it isn't in the same class of glutDisplayFunc? I mean, is it possible:
Try it and see. I don't know why you'd introduce that complexity, but any "function pointer" type object taking no args should do (a static method qualifies; an instance method doesn't). Only question is whether C++ typing will get in your way.

avis
02-26-2008, 11:21 AM
Hi arthas,
I am sure,Its possible. It works.

arthas
02-26-2008, 12:26 PM
it doesn't work to me :-( . I tried to declare in the main:


extern void display(display);


I tried to create an header file, but it doesn't work too.. i'm a newbie, but i think that the problem is the definition of the function display. when the program is all in one file, there isn't the problem, but when I split it, the compiler expect a definition of it, that there isn't... But I don't know how to write it! anyone knows how to solve the problem?

avis
02-26-2008, 12:34 PM
Hi arthas,
Can you post what error your getting, its much better if u can post your buildlog file.

arthas
02-26-2008, 01:16 PM
in the file main.cpp:


extern void display(void);

int main(int argc, char **argv)
{
glutInitWindowSize(30,30);
glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH);
glutInit(&argc, argv);
glutCreateWindow("example");
glutDisplayFunc(display);

return 0;}

and in the file draw.cpp(same path and project):


static void display(void)
{
.. draws the scene..
}


the build log is:

Linking...
main.obj : error LNK2019: unresolved external symbol "void __cdecl display(void)" (?display@@YAXXZ) referenced in function _main
C:\...Program.exe : fatal error LNK1120: 1 unresolved externals

Y-tension
02-26-2008, 02:35 PM
Use glutDisplayFunc(ClassB::display); This is the syntax for referencing static member functions. Of course make sure that the class header is included in main's source file.

avis
02-26-2008, 11:09 PM
Hi arthas,
The problem is compiler unable to find display function definition. static function should have the definition in file scope. move your display function definition inside the header file.I hope your including the header file,a file which u given display function declaration.

Komat
02-27-2008, 02:01 AM
Remove the static keyword.

arthas
02-27-2008, 02:06 AM
Hi avis, I've included in the file main.cpp, the line
#include "Draw.h"
and I created, a file Draw.h, that contains the declaration
static void display(void);
the result is :
>Compiling...
>main.cpp
>c:\..main.cpp(55) : error C2129: static function 'void display(void)' declared but not defined
> c:\..draw.h(1) : see declaration of 'display'
so the problem is the definiton.. I only need to clean the code, moving the function display in another file, there isn't a way?

arthas
02-27-2008, 02:37 AM
Solved!!!!!!!! The problem was Static!!!! the function declared static is in the scope of the file it is declared/defined in, so only a c++ problem, not opengl