Sign in to follow this  

OpenGL OpenGL C++ window creation

Recommended Posts

I've used OpenGL in C before but changing to C++ has caused me some problems.

In C I was able to do this in my main method:

When I try to do this now in a createAndShowGUI() method in the myGUI class, I get an error like this:
[code]argument of type 'void (myGUI::)()' does not match 'void (*)()'[/code]

Does anyone know how I can avoid/work around this? Thanks!

* class myGUI *
* Desc : Handles all the GUI stuff *
class myGUI
int winX;
int winY;

myGUI(int argc, char** argv)
{ setXYsize(defaultXsize, defaultYsize);
createAndShowGUI(argc, argv); }

myGUI(int argc, char** argv, int x, int y)
{ setXYsize(x, y);
createAndShowGUI(argc, argv); }

void createAndShowGUI(int, char**);
void renderScene(void);
void changeSize(int, int);
void processSpecialKeys(int, int, int);
void processNormalKeys(unsigned char, int, int);

void setXYsize(int x, int y)
{ winX = x; winY = y; }
void setXsize(int x)
{ winX = x; }
void setYsize(int y)
{ winY = y; }

* myGui::createAndShowGUI *
* initializes and displays window *
* Args: *
* argc, argv : unmodified vars *
* from main *
void myGUI::createAndShowGUI(int argc, char** argv)
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA);
glutInitWindowPosition(100, 100);
if (myGUI::winX != 0 && myGUI::winY != 0)
{ glutInitWindowSize(myGUI::winX, myGUI::winY); }
{ myGUI::winX = 500; myGUI::winY = 500;
glutInitWindowSize(myGUI::winX, myGUI::winY); }




* MAIN function for testing *
int main(int argc, char** argv)
cout << "Welcome to myGUI!" << endl;

myGUI window (argc, argv, 1000, 1000);

Share this post

Link to post
Share on other sites
[quote name='Brother Bob' timestamp='1330214023' post='4916613']
GLUT doesn't work with non-static member functions. Make the functions and the members of the class static so they are not bound to a specific instance of the myGUI class.

That fixes it. Thank you!

Share this post

Link to post
Share on other sites

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