I want to draw some points or polygons to form objects,then I can pick the objects.
The question is that if I put this program above into OnLButtonDown(),there is not anything happened.if I can’t get viewport and glRenderMode(GL_RENDER) is always return 0, I can’t pick any objects.
However, when I call PickPoint() in OnDraw(), I can correctly get viewport and glRenderMode(GL_RENDER).But, after I pick correctly 30 times/objects, I have to press two Left-Button to get a object with screen flare.
Thanks very much!!!
void CWGSView::myDrawScene(GLenum mode)
for(i=0; i<=8; i++)
Seems like you context is not current when you receive mouse click events and it’s because MFC mouse click handling is in a different thread than the one doing the drawing.
The only way you can solve your problem is when your receive a LButtonDown event, set a flag to says you want to pick, and when OnDraw gets called next time, you will pick the object from the function.( the OnDraw function is called from the thread having the context current).
The other solution would be to make the context not current in the drawing thread when it switches and make it current in your thread, but since you don’t when thread switch occurs, this solution is impossible.
Well, you can also implement your own picking function from the data you have if it is possible. In this case you would not need to do any opengl call and the function would work from LButtonDown.