Thanks Enigma , i found this topic from google. Your first example does not works, cannot use the object context with dynamic vars, but the second example works fine. My solution is call the init functions of glut from main file without class and call the class for drawing from static function:
#include <time.h>
#include "core/Log.h"
#include "core/Core.h"
Log log;
Core core; // <- The solution (Declare out of main function
// and call the consructor, make the context)
clock_t last_clock;
float fps = 60.0; // Limit to 60 FPS
void draw()
{
core.draw(); // <- The solution (call object function)
// Limit FPS
while((((float)clock() - (float)last_clock) / (float)CLOCKS_PER_SEC) < (1.0 / fps)){}
last_clock = clock();
glutPostRedisplay();
}
int main(int argc, char **argv)
{
core.init();
last_clock = clock();
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE);
glutInitWindowSize(800, 800);
glutInitWindowPosition(100, 100);
glutCreateWindow("GLEngine");
glutDisplayFunc(draw); // <- The solution (call static function)
glutMainLoop();
return 0;
}
In the Core object call the physical objects:
void Core::draw()
{
glClearColor(0.4, 0.4, 0.4, 1.0); // Background
glClear(GL_COLOR_BUFFER_BIT);
// Draw objects here ...
glFlush(); // Finish of drawing
}