Multi File Programs

Hi, I’m just starting to learn OpenGL. Right now I’m doing a project that involves taking an existing program and altering it to be a multiple file program. The function prototypes go in Functions.h, the function bodies go in Functions.cpp, and main and the global variable declarations go in Driver.cpp. I know how to do this in a regular C++ program, but I guess functions in OpenGL are a little different.

Here’s some of my code:


//Driver.cpp
#include <windows.h>
#include <gl/glut.h>
#include "Functions.h"

int main(int argc, char* argv[])
{
	Bounce square;
	glutInit(&argc, argv);
	glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA);
	glutInitWindowSize(800,600);
    glutCreateWindow("Bounce");
	glutDisplayFunc(square.RenderScene);
    glutReshapeFunc(ChangeSize);
	glutTimerFunc(33, TimerFunction, 1);

	SetupRC();

	glutMainLoop();
        
    return 0;
}


//Functions.h

class Bounce
{
private:

public:
	Bounce();
	void RenderScene(void);

};



//Functions.cpp
#include <windows.h>
#include <gl/glut.h>
#include "Functions.h"

Bounce::Bounce()
{
}

void Bounce::RenderScene(void)
{
	glClear(GL_COLOR_BUFFER_BIT);

	glColor3f(1.0f, 0.0f, 0.0f);

	glRectf(x, y, x + rsize, y - rsize);

	glutSwapBuffers();
}

The errors I get are:
error C3867: ‘Bounce::RenderScene’: function call missing argument list; use ‘&Bounce::RenderScene’ to create a pointer to member
Functions.cpp
error C2065: ‘x’ : undeclared identifier
error C2065: ‘y’ : undeclared identifier
error C2065: ‘rsize’ : undeclared identifier

It’s the first error that I really don’t understand. Can anyone explain what I’m doing wrong?

The problem in this code is that you are trying to pass a member function pointer square.RenderScene to glutDisplayFunc which takes a non-member function. It doesn’t work that way. The solution is to create a non-member regular function that you pass to the glutDisplayFunc. This non-member function then calls the RenderScene member of the Bounce class.

Okay, that seems to work! Thanks a lot!