I have made an class for openGl manipulation. Now the glut call back functions need the pointer of the function as an argument. and I am providing the member function by instantiating an object of the class.And it shows an error like
main.cpp: In function ‘int main(int, char**)’:
main.cpp:23:64: error: cannot convert ‘std::_Bind_helper<false, void (glActivity::*)(), glActivity*>::type {aka std::_Bind<std::_Mem_fn<void (glActivity::*)()>(glActivity*)>}’ to ‘void (*)()’ for argument ‘1’ to ‘void glutDisplayFunc(void (*)())’
glutDisplayFunc(std::bind(&glActivity::display,&GLactivity));
main.cpp:24:51: error: cannot convert ‘GlActivity::reshape’ from type ‘void (GlActivity::)(int, int)’ to type ‘void (*)(int, int)’
glutReshapeFunc(GLactivity.GlActivity::reshape);
my code for header file is here:
#include<GL/freeglut.h>
#include<GL/gl.h>
class GlActivity{
protected:
bool keys[256];
public:
/*Initialize material property,light source,lighting model
*and depth buffer through the constructor call.
*/
GlActivity(){
glShadeModel(GL_FLAT);
//glEnable(GL_LIGHTING);
//glEnable(GL_LIGHT0);
glEnable(GL_DEPTH_TEST);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
}
void Keydown(unsigned char ch,int x,int y){
if(ch == 27) glutExit();
keys[ch]=true;
}
void keyup(unsigned char ch,int x,int y){
keys[ch]=false;
}
void display(void){
}
void reshape( int w,int h){
glViewport(0,0,(GLsizei) w,(GLsizei) h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
if(w <= h)
glOrtho(-1.5,1.5,-1.5*(GLfloat)h/(GLfloat)w,
1.5*(GLfloat)h/(GLfloat)w,-10.0,10.0);
else
glOrtho(-1.5,1.5,-1.5*(GLfloat)w/(GLfloat)h,
1.5*(GLfloat)w/(GLfloat)h,-10.0,10.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
void idle(){}
};
and that for main.cpp is:
#include"matrix.h"
#include"GlActivity.h"
#include <functional>
class glActivity : public GlActivity{
public:
glActivity():GlActivity(){}
void display(){
glBegin(GL_TRIANGLES);
glVertex2f(0.0f,1.0f);
glVertex2f(0.87f,-0.5f);
glVertex2f(-0.87f,-0.5f);
glEnd();
glFlush();
}
};
int main(int argc,char** argv){
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize(500,500);
glutInitWindowPosition(100,100);
glutCreateWindow(argv[0]);
glActivity GLactivity;
glutDisplayFunc(std::bind(&glActivity::display,&GLactivity));
glutReshapeFunc(GLactivity.GlActivity::reshape);
glutKeyboardFunc(GLactivity.GlActivity::keydown);
glutKeyboardFunc(GLactivity.GlActivity::keyup);
glutIdleFunc(GLactivity.GlActivity::idle);
glutMainLoop();
return 0;
}