Sto continuando a fare esperimenti, stavolta con qualcosa di piu' costruttivo. Ho scaricato un codice d'esempio banale, che funziona con le openGL, ed ho provato a farci una classe. Ovviamente non funziona...
In particolare il codice funzionante definisce alcune funzioni, tipo
void display ( void )
void reshape(int w, int h)
void keyboard ( unsigned char key, int x, int y )
e poi le passa ad una funzione delle glut, in questo modo:
glutReshapeFunc ( reshape );
glutKeyboardFunc ( keyboard );
glutDisplayFunc ( display );
Io ho provato a fare una classe, e poi passare i suoi metodi esattamente allo stesso modo:
glutReshapeFunc ( MHgui.reshape );
glutKeyboardFunc ( MHgui.keyboard );
glutDisplayFunc ( MHgui.display );
Ma il compilatore mi restituisce un errore tipo:
error: argument of type `void (MHwindow::)(int, int)' does not match `void (*)(int, int)'
error: argument of type `void (MHwindow::)(unsigned char, int, int)' does not match `void (*)(unsigned char, int, int)'
argument of type `void (MHwindow::)()' does not match `void (*)()'
Per favore, datemi una mano!
qui sotto vi allego un link al codice che funziona e il listato di quello che non funziona...
Codice che funziona:
http://paulyg.f2s.com/prog1.htm
Codice che non funziona:
codice:
#include <windows.h>
#include <GL/glut.h>
#include <stdio.h>
#include <stdlib.h>
class MHwindow
{
private:
int width;
int height;
//*char title;
public:
int getWidth();
int getHeight();
void init();
void display();
void reshape(int w, int h);
void keyboard(unsigned char key, int x, int y);
} ;
int MHwindow::getWidth(){return width;}
int MHwindow::getHeight(){return height;}
void MHwindow::display()
{
glClear ( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
glPushMatrix ( );
glPopMatrix ( );
glutSwapBuffers ( );
}
void MHwindow::reshape(int w, int h)
{
glViewport ( 0, 0, w, h );
glMatrixMode ( GL_PROJECTION );
glLoadIdentity ( );
if ( h==0 )
gluPerspective ( 80, ( float ) w, 1.0, 5000.0 );
else
gluPerspective ( 80, ( float ) w / ( float ) h, 1.0, 5000.0 );
glMatrixMode ( GL_MODELVIEW );
glLoadIdentity ( );
}
void MHwindow::keyboard ( unsigned char key, int x, int y )
{
switch ( key ) {
case 27: /* Escape key */
exit ( 0 );
break;
case 'f':
glutFullScreen ( );
break;
case 'w':
glutReshapeWindow ( 100,100 );
break;
default:
break;
}
}
/* Main Loop
* Open window with initial window size, title bar,
* RGBA display mode, and handle input events.
*/
MHwindow MHgui;
int main ( int argc, char** argv )
{
glutInit ( &argc, argv );
glutInitDisplayMode ( GLUT_RGB | GLUT_DOUBLE );
glutInitWindowSize ( MHgui.getWidth(),MHgui.getHeight() );
glutCreateWindow ( "pippo" );
glEnable ( GL_DEPTH_TEST );
glClearColor ( 0.0, 0.0, 0.0, 0.0 );
glutReshapeFunc ( MHgui.reshape );
glutKeyboardFunc ( MHgui.keyboard );
glutDisplayFunc ( MHgui.display );
glutMainLoop ( );
return 0;
}