I am trying to call a callback function from
void display(void){
my_draw(&here_is_the_actual_drawing);
}
void here_is_the_actual_drawing(){
glVertex2f(x,y);
}
in main the opengl loop call display .. like
glutDisplayFunc(display);
My question is can we do this ?? I tried in my code it compiles but gets stuck .. [ my_draw will create a thread that will call here_is_the_actual_drawing —- ok so no threads just call back ]
You can not simply just call OpenGL commands from any thread. OpenGL needs a context, and each OpenGL context can be active in only one thread at a time. It is perfectly possible to migrate a context between threads. However this requires that you have full control over context creation and management.
By using a simple framework like (Free)GLUT, GLFW or SDL you do not have control over context management. But technically it is possible.
But not everything whats possible makes sense. Usually keeping all OpenGL operations to a single thread, to be precise the main GUI thread, is the best solution. Multithreaded OpenGL is usefull in only a very small number of situations, and even then only with very limited circumstances.
BTDT (actually my current project makes heavy use of multithreaded OpenGL)