Skip to main content
GameDev.net gamedev.net
🔒 Locked

OpenGL C++ window creation

Started by dtauxe Feb 25, 2012 at 11:45 PM 1 replies 1.8k views
Original Post
dtauxe
dtauxe
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:
glutDisplayFunc(renderScene);

When I try to do this now in a createAndShowGUI() method in the myGUI class, I get an error like this:
argument of type 'void (myGUI:<img src='http://public.gamedev.net//public/style_emoticons/<#EMO_DIR#>/smile.png' class='bbc_emoticon' alt=':)' />()' does not match 'void (*)()'

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;
public:

//Constructors
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); }

//Protofunctions
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); }
else
{ myGUI::winX = 500; myGUI::winY = 500;
glutInitWindowSize(myGUI::winX, myGUI::winY); }

glutCreateWindow("myGUI");

glutDisplayFunc(myGUI::renderScene);
glutReshapeFunc(myGUI::changeSize);
glutIdleFunc(myGUI::renderScene);
glutKeyboardFunc(myGUI::processNormalKeys);
glutSpecialFunc(myGUI::processSpecialKeys);

glutMainLoop();
}

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

myGUI window (argc, argv, 1000, 1000);
}
Brother Bob
Brother Bob
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.
dtauxe
dtauxe

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!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.