Hi!
I am just wonderring if I could use GLUT for Object Oriented programming?
Instead of .c file I want to use it for my little app writtten in C++. But I dont want to have too many global variables all declared as usaully at the top of my app. I wonder how I could put the whole Glut program into say Main.cpp and Main.h files.
I tried that and get errors. it complains about display func. it is triggered from main by using glutDisplayFunc( display ) and I am sure this is the problem but I am not sure how to solve it! I’ll just show you how I did my files! if its ok:
//======== CMain.h =================//
#ifndef CMAIN_H //prevents redefinitions
#define CMAIN_H
#include <stdlib.h>
#include <iostream.h>
#include <GL/glut.h>
class CMain
{
public:
CMain();
~CMain();
void reshape(int width, int height);
void display(void);
void init(void);
int main(int argc, char** argv);
private:
int X_CENTRE;
int Y_CENTRE;
int LENGTH;
int R;
};
#endif
//========= CMain.cpp ========//
#include “Main.h”
CMain::CMain()
{
X_CENTRE = 0.0;
Y_CENTRE = 0.0;
LENGTH = 1.0;
R = 10.0;
}
void CMain::reshape(int width, int height)
{
glViewport(0, 0, width, height);
glMatrixMode( GL_PROJECTION );
glLoadIdentity();
glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0);
glMatrixMode( GL_MODELVIEW );
}
void CMain::display(void)
{
glClear (GL_COLOR_BUFFER_BIT);
glColor3f(1.0, 1.0, 1.0);
glLoadIdentity();
for ( int i = 0; i < 100; i++)
{
glRotatef( R , 0.0, 0.0, 1.0 );
glBegin(GL_LINE_LOOP);
glVertex2f( X_CENTRE - LENGTH / 2, Y_CENTRE - LENGTH / 2);
glVertex2f( X_CENTRE - LENGTH / 2, Y_CENTRE + LENGTH / 2);
glVertex2f( X_CENTRE + LENGTH / 2, Y_CENTRE + LENGTH / 2);
glVertex2f( X_CENTRE + LENGTH / 2, Y_CENTRE - LENGTH / 2);
glEnd();
R+=10.0;
}
glFlush();
}
void CMain::init(void)
{
glClearColor (0.0, 0.0, 0.0, 0.0);
}
int CMain::main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize (400, 400);
glutInitWindowPosition (100, 100);
glutCreateWindow (argv[0]);
init();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutMainLoop();
return 0;
}
After compiling I get this errors:
: error C2664: ‘glutDisplayFunc’ : cannot convert parameter 1 from ‘void (void)’ to ‘void (__cdecl *)(void)’
None of the functions with this name in scope match the target type
: error C2664: ‘glutReshapeFunc’ : cannot convert parameter 1 from ‘void (int,int)’ to ‘void (__cdecl *)(int,int)’
None of the functions with this name in scope match the target type
Error executing cl.exe.
Thank you for any sort of help!
[This message has been edited by sandrew (edited 03-12-2002).]