PDA

View Full Version : blank screen when using glutTimerFunc()



Haroon
03-23-2012, 10:26 AM
I'm try to run a socket connection in the glutTimerFunc(), also tried glutIdleFunc() but screen goes blank when using any of these functions.

Please help?

Here is my main program:

int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize(1000, 900); // (width, height)
glutInitWindowPosition(10, 10);
glutCreateWindow("Test1");
glutDisplayFunc(display);

//glutIdleFunc(IdleFunc);
glutKeyboardFunc(keyboard);
glutSpecialFunc(specialFunc);
glutTimerFunc(0,Timer,0);
init();
glutMainLoop();

return 0;
}

V-man
03-23-2012, 12:11 PM
It has been a long time since I did socket programming. What I do remember was that the listening socket would lock the entire thread. The solution is to run it in a second thread. You might want to do some web searches on threading (pthread).

Dark Photon
03-23-2012, 04:50 PM
It has been a long time since I did socket programming. What I do remember was that the listening socket would lock the entire thread. The solution is to run it in a second thread. You might want to do some web searches on threading (pthread).
That's definitely one option (the better one IMO).

Another option is to set the socket to non-blocking (one of: FNDELAY/O_NDELAY/O_NONBLOCK/FIONBIO) and then be prepared for most any net call to return "would block" (EWOULDBLOCK, EAGAIN, etc.) And if you're doing I/O to multiple connections in one thread, you'll find you probably want this anyway, regardless whether it's the GL thread or not.