我正在嘗試使用OpenGL繪製一條線,而線的兩端座標都設置在空閒功能中,但是當我通過網絡發送端點座標時,使用套接字。下面 是代碼的卡扣使用OpenGL時顯示功能不能正常工作
int main(int argc, char **argv)
{
glutInit(&argc,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 */
glutIdleFunc(idle);
//first create the connection then we wil talk about the data transfer...
/*****Code for server connection *****/
processRequest();
return 0;
}
void processrequest()
{
byte_sent = send(ClientSocket,(char*)&msg_pkt,sizeof(MSG_PACKET),0);
ofile<<"\nByte sent for start generating "<<byte_sent<<endl;
Sleep(1000);
memset(buf,0,sizeof(buf));
glutMainLoop();
}
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 */
glBegin(GL_LINES);
glVertex2f(x[0] , y[0]);
glVertex2f(x[1] , y[1]);
glEnd();
glEnd();
glFlush();
}
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;
glutPostRedisplay();
}
程序員永遠是調試的最佳人選!嘗試單步執行,或者嘗試使用'printf(..)'語句來分析'x [0]','y [0]'等等的值。只是一個(無關)的建議:它總是一個很好的做法,以在不同的線程上執行網絡I/O .. :) – SuperSaiyan
@Thrustmaster值正常。我記錄了這些值,然後刪除了代碼。與OpenGL相關的問題與這些值無關。 – cbinder
什麼是價值? IIRC在這個設置中,座標需要在[-1,1]之內.. – SuperSaiyan