There is a number of solutions and what was suggested to you is probably the worst oneI suggest to do it the regular C++ way -- assuming you have a class somewhere that contains your OpenGL code, store your "x" as a member variable of that class. Then you can access it from any code from that class and if you make the variable public or provide a getter for it, you'll be able to access it from outside the class too. Furthermore if the variable is constant, you can define it as "const int x" in the class or in any header file.
As for extern -- "extern" means that "somewhere else" there is a variable declared. But it doesn't create that variable. Somewhere else you need to declare a real variable called the same for the mechanism to work.





I suggest to do it the regular C++ way -- assuming you have a class somewhere that contains your OpenGL code, store your "x" as a member variable of that class. Then you can access it from any code from that class and if you make the variable public or provide a getter for it, you'll be able to access it from outside the class too. Furthermore if the variable is constant, you can define it as "const int x" in the class or in any header file.
Reply With Quote
Bookmarks