Jump to content
  • Advertisement
Sign in to follow this  
dtauxe

OpenGL OpenGL C++ window creation

This topic is 2312 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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:
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::)()' 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);
}

Share this post


Link to post
Share on other sites
Advertisement
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.

Share this post


Link to post
Share on other sites

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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!