Jump to content



OpenGL C++ window creation

  • You cannot reply to this topic
2 replies to this topic

#1 Exemplar   Members   -  Reputation: 100

Like
0Likes
Like

Posted 25 February 2012 - 05:45 PM

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


Ad:

#2 Brother Bob   Moderators   -  Reputation: 1767

Like
0Likes
Like

Posted 25 February 2012 - 05:53 PM

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.

#3 Exemplar   Members   -  Reputation: 100

Like
0Likes
Like

Posted 25 February 2012 - 06:32 PM

View PostBrother Bob, on 25 February 2012 - 05:53 PM, said:

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!






We are working on generating results for this topic
PARTNERS