Skip to content

Instantly share code, notes, and snippets.

@aybabtme
Created August 3, 2012 08:18
Show Gist options
  • Save aybabtme/3245752 to your computer and use it in GitHub Desktop.
Save aybabtme/3245752 to your computer and use it in GitHub Desktop.
Passing member functions as parameters for callback
./src/GlutController.cpp:26:21: error: reference to non-static member function must be called
glutSpecialFunc( OnSpecialKeys );
^~~~~~~~~~~~~
./src/GlutController.cpp:27:21: error: reference to non-static member function must be called
glutReshapeFunc( OnChangeSize );
^~~~~~~~~~~~
./src/GlutController.cpp:28:21: error: reference to non-static member function must be called; did you mean to call it with no arguments?
glutDisplayFunc( OnRenderScene );
^~~~~~~~~~~~~
()
./src/GlutController.cpp:28:4: error: no matching function for call to 'glutDisplayFunc'
glutDisplayFunc( OnRenderScene );
^~~~~~~~~~~~~~~
/usr/include/GL/freeglut_std.h:473:26: note: candidate function not viable: cannot convert argument of incomplete type 'void' to 'void (*)()'
./src/GlutController.cpp: In constructor ‘GlutController::GlutController(int, char**)’:
./src/GlutController.cpp:26:35: error: cannot convert ‘GlutController::OnSpecialKeys’ from type ‘void (GlutController::)(int, int, int)’ to type ‘void (*)(int, int, int)’
./src/GlutController.cpp:27:34: error: cannot convert ‘GlutController::OnChangeSize’ from type ‘void (GlutController::)(int, int)’ to type ‘void (*)(int, int)’
./src/GlutController.cpp:28:35: error: cannot convert ‘GlutController::OnRenderScene’ from type ‘void (GlutController::)()’ to type ‘void (*)()’
#include <string>
#include "GlutController.h"
////////////////////////////////////////////////////////////////////////
// Boilerplate
////////////////////////////////////////////////////////////////////////
GlutController::GlutController (int argc, char **argv) {
// Setup window
gltSetWorkingDirectory( argv[0] );
glutInit(&argc, argv);
glutInitDisplayMode( GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH );
glutInitWindowSize( APP_WIDTH, APP_HEIGHT );
glutCreateWindow( APP_NAME );
// Register callbacks
glutSpecialFunc( OnSpecialKeys ); // Error here
glutReshapeFunc( OnChangeSize ); // Error here
glutDisplayFunc( OnRenderScene ); // Error here
// Initialize GLEW
GLenum anError = glewInit();
if( anError != 0 ){
fprintf( stderr, "GLEW Error: %s\n",
glewGetErrorString( anError ));
char *aMessage = (char*) glewGetErrorString( anError );
throw std::runtime_error( aMessage );
}
}
GlutController::~GlutController() {
}
////////////////////////////////////////////////////////////////////////
// Interface
////////////////////////////////////////////////////////////////////////
void GlutController::Start(){
SetupRenderContext();
glutMainLoop();
}
////////////////////////////////////////////////////////////////////////
// Callbacks
////////////////////////////////////////////////////////////////////////
void GlutController::SetupRenderContext(){
mShaderManager.InitializeStockShaders();
glEnable( GL_DEPTH_TEST );
glClearColor( 0.8f, 0.8f, 0.8f, 1.0f );
}
void GlutController::OnChangeSize(int aNewWidth, int aNewHeight){
glViewport(0,0,aNewWidth, aNewHeight);
mViewFrustrum.SetPerspective( APP_CAMERA_FOV,
float( aNewWidth ) / float( aNewHeight ),
APP_CAMERA_NEAR,
APP_CAMERA_FAR );
mProjectionMatrixStack.LoadMatrix(
mViewFrustrum.GetProjectionMatrix() );
mTransformPipeline.SetMatrixStacks(mModelViewMatrixStack,
mProjectionMatrixStack);
}
void GlutController::OnRenderScene(void){
// Render the scene
}
void GlutController::OnSpecialKeys(int key, int x, int y){
// Update the model's positions
}
#ifndef GLEWCONTROLLER_H_
#define GLUTCONTROLLER_H_
#include <stdexcept>
#include <GLTools.h>
#include <GLShaderManager.h>
#include <GLFrustum.h>
#include <GLMatrixStack.h>
#include <GLGeometryTransform.h>
#include <GL/freeglut.h>
#include "Constants.h"
#include "models/IDrawableModel.h"
class GlutController {
public:
// Constructor/Destructor
GlutController(int argc, char **argv);
virtual ~GlutController();
// Interface
void Start(void);
private:
// Fields
GLShaderManager mShaderManager;
GLFrustum mViewFrustrum;
GLMatrixStack mProjectionMatrixStack;
GLMatrixStack mModelViewMatrixStack;
GLGeometryTransform mTransformPipeline;
// Callbacks
void OnSpecialKeys(int key, int x, int y);
void OnChangeSize(int aNewWidth, int aNewHeight);
void OnRenderScene(void);
// Methods
void SetupRenderContext(void);
};
#endif /* GLEWCONTROLLER_H_ */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment