display function not working while using OpenGL

i am trying to draw a line using OpenGL while the both end coordinates of the line are set in the idle function , but it is not getting drawn while I am sending the endpoint coordinates over the network using sockets. below is the snap of the code

int  main(int argc, char **argv) 
glutInitWindowSize( 1024,1024);       /* A x A pixel screen window  */

glutInitDisplayMode( GLUT_RGB | GLUT_SINGLE);
glutCreateWindow("Skeleton Tracker"); /* window title                   */
glutDisplayFunc(display);         /* tell OpenGL main loop what     */

//first create the connection then we wil talk about the data transfer...
 /*****Code for server connection *****/

return 0;

void processrequest()
byte_sent = send(ClientSocket,(char*)&msg_pkt,sizeof(MSG_PACKET),0);
ofile<<"\nByte sent for start generating "<<byte_sent<<endl;



void display(void)
glClearColor(1.0f, 1.0f, 1.0f, 1.0f);                
glClear(GL_COLOR_BUFFER_BIT);     /* clear the window */
glColor3f ( 0.0, 1.0 , 0.0);       /* draw in light red */
glVertex2f(x[0] , y[0]);
glVertex2f(x[1] , y[1]);



void idle(void)

printf("\nIn Idle function\n");

nRetVal = recv(ClientSocket , (char*)mainbuf , 192,0);

printf("\nAmount of data received : %d\n" , nRetVal);
memcpy(buf , mainbuf ,  sizeof(buf));   //buf is of 8 bytes to hold 2 floating nos.

memcpy( &x[p] ,buf , 4); // upto 3
x[p] = x[p]/10.0;

memcpy( &y[p] ,buf+4 , 4); //upto 7
y[p] = y[p]/10.0;




Design of your program is questionable - you have blocking recv() function in your idle function which is not good, idle should be as fast as possible to not affect your rendering.

consider creating one thread for rendering and the second thread for network communication, or at least use non-blockable recv() in your idle function to check whether there is any data on the socket available before reading (recv'ing) from it.

Thanks buddies for your time ... actually I forget to define the orthographic projection matrix before calling the glutMainloop ...

gluOrtho2D( -250, 250, -250, 250);

its working now.

Need Your Help

Is it acceptable to modify the text sent with the HTTP status code?

http http-headers http-status-codes

I'm implementing a 'testing mode' with my website which will forbid access to certain pages while they are undergoing construction, making them only accessible to administrators for private testing...

Java overriding inherited string


I have an Abstract class, which is derived by another Concrete class. In my abstract class I have a property which is called in method of the same Abstract class. This property is empty in Abstract...