Hi all, thanks for reading. I have a C++ program that uses OpenGL and GLUT. No matter how many times I click the screen in completely different places I will always get the same numbers in my buffer even though it is initialized to all zero's each time.
Some background may help. This was originally written on an XP laptop and worked fine, porting to Vista with a poor graphics card resulted in clipping and picking errors. Porting to Mac I discovered the same clipping errors were present if I didn't have the graphics set for high performance but the picking error doesn't go away either way.
Now here's some code:
GLuint selectBuf[buffsize]; for(int p=0;p<buffsize;p++){selectBuf[p]=0;}
GLint hits=0;
GLint viewport[4]; // The Size Of The Viewport. [0] Is <x>, [1] Is <y>, [2] Is <length>, [3] Is <width>
glSelectBuffer (buffsize, selectBuf);
glRenderMode(GL_SELECT);
glInitNames();
glPushName(0);
///////////////////////////////////////////////////////Problem exists between here and....!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
glMatrixMode (GL_PROJECTION);
glPushMatrix ();
glLoadIdentity ();
glGetIntegerv(GL_VIEWPORT, viewport);
/* create 5x5 pixel picking region near cursor location */
gluPickMatrix((GLdouble) xmouse, (GLdouble) (viewport[3] - ymouse), 3.0, 3.0, viewport);//(viewport[3] - ymouse) for Windows
///////////////////////////////////////////////////////////////////////////////////...here ????? !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
gluPerspective(videocam.xwinmin, videocam.ywinmin, videocam.camnear, videocam.camfar);
glMatrixMode(GL_MODELVIEW);
cout<<"Buffer contents before picking: ";
for(int i=0;i<buffsize;i++){cout<<selectBuf<<", ";}
draw();
glPopMatrix ();
glFlush();
picking=false;
hits = glRenderMode(GL_RENDER);
cout<<"\nValue of 'hits' immediately after glRendermode() is "<<hits<<endl;
proces*****(hits, selectBuf);
cout<<"DONE processing picks!!!!!!!!!!!!!!!!!!!!!!!\n"<<endl;
And sample data from the buffer looks like this:
Hits = 2
buffer holds: 1 4294766591 4294767615 0 0 4294739967 4294849023 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
The program isn;t graphics intensive so I figure it is a porting issue. I played with argument values to see if I had the coordinate system wrong but that didn't seem to work.
Thanks for your help
Some background may help. This was originally written on an XP laptop and worked fine, porting to Vista with a poor graphics card resulted in clipping and picking errors. Porting to Mac I discovered the same clipping errors were present if I didn't have the graphics set for high performance but the picking error doesn't go away either way.
Now here's some code:
GLuint selectBuf[buffsize]; for(int p=0;p<buffsize;p++){selectBuf[p]=0;}
GLint hits=0;
GLint viewport[4]; // The Size Of The Viewport. [0] Is <x>, [1] Is <y>, [2] Is <length>, [3] Is <width>
glSelectBuffer (buffsize, selectBuf);
glRenderMode(GL_SELECT);
glInitNames();
glPushName(0);
///////////////////////////////////////////////////////Problem exists between here and....!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
glMatrixMode (GL_PROJECTION);
glPushMatrix ();
glLoadIdentity ();
glGetIntegerv(GL_VIEWPORT, viewport);
/* create 5x5 pixel picking region near cursor location */
gluPickMatrix((GLdouble) xmouse, (GLdouble) (viewport[3] - ymouse), 3.0, 3.0, viewport);//(viewport[3] - ymouse) for Windows
///////////////////////////////////////////////////////////////////////////////////...here ????? !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
gluPerspective(videocam.xwinmin, videocam.ywinmin, videocam.camnear, videocam.camfar);
glMatrixMode(GL_MODELVIEW);
cout<<"Buffer contents before picking: ";
for(int i=0;i<buffsize;i++){cout<<selectBuf<<", ";}
draw();
glPopMatrix ();
glFlush();
picking=false;
hits = glRenderMode(GL_RENDER);
cout<<"\nValue of 'hits' immediately after glRendermode() is "<<hits<<endl;
proces*****(hits, selectBuf);
cout<<"DONE processing picks!!!!!!!!!!!!!!!!!!!!!!!\n"<<endl;
And sample data from the buffer looks like this:
Hits = 2
buffer holds: 1 4294766591 4294767615 0 0 4294739967 4294849023 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
The program isn;t graphics intensive so I figure it is a porting issue. I played with argument values to see if I had the coordinate system wrong but that didn't seem to work.
Thanks for your help