PDA

View Full Version : Multi File Programs



gh001
02-13-2008, 02:20 AM
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(&amp;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?

HenriH
02-13-2008, 02:55 AM
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.

gh001
02-13-2008, 03:27 AM
Okay, that seems to work! Thanks a lot!