Skip to main content
gamedev.net
🔒 Locked

Incorrect picking when using glPointSize()

Started by Ator 3 replies 700+ views
Original Post
Ator
Ator
Hi I have the following code: glLoadName(1); glPointSize(30); glBegin(GL_POINTS); glVertex2f(x,y); glEnd(); When using the selectionbuffer, I only get a hit if I pick near (x,y), or exactly on it. Picking positions like, for instance, (x+10,y) is invalid. If I instead use GL_POLYGON to draw the square, it works fine. Then I can select the figure in all its coordinates. How come? My picking code: GLuint selectBuf[512]; GLint hits; GLint viewport[4]; glGetIntegerv(GL_VIEWPORT, viewport); glSelectBuffer(512, selectBuf); glRenderMode(GL_SELECT); glInitNames(); glPushName(0); glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); gluPickMatrix(x, viewport[3]-y, 5.0, 5.0, viewport); gluOrtho2D(x1,x2,y1,y2); drawFigures(); glMatrixMode(GL_PROJECTION); glPopMatrix(); glFlush(); hits = glRenderMode(GL_RENDER); Kind Regards Andreas
LilBudyWizer
LilBudyWizer
Because it is what is rendered into the picking region. That's the points and nothing but the points. Instead draw it solid for the picking, then redraw it as points for display.
Keys to success: Ability, ambition and opportunity.
Brother Bob
Brother Bob
Selection in OpenGL works by determining whether the object intersects the clip volume or not. Basically, the object is transformed by the modelvew and projection matrices, and if the object is still within the view volume, a hit is recorded.

No fragments are rasterized, only transformed and compared against the clip volume. However, line width and point size are rasterization parameters, and therefore does not affect selection. What happens is that the point's coordinates are transformed, and even though the point may be rasterized where you perform selection due to the point size, the point's center can fall outside the selection region.

To solve this you need to increase the size of the picking region so that it's large enough to include the center of the point even if you click not on it's center, but still on a rasterized pixel. So if you have a 30 pixel large point, you need a 30 pixel large picking region aswell.
LilBudyWizer
LilBudyWizer
You said "if I instead use GL_POLYGON...". So my assumption is that you are drawing the vertices of a polygon as points and wondering why you can't select the polygon by clicking somewhere logically on the interior of the polygon.

You have a picking region defined by the gluPickMatrix call. That region is a square 5 pixels on a side. The first two parameters are the lower left corner of that region. So assuming (x,y) is the mouse coordinates then you have to click within 5 pixels to the left and/or below a pixel of the point. Assuming you drew in white with a black background that would be the white pixels forming the point and none of the black pixels that are logically part of the polygon since you didn't draw those pixels.
Keys to success: Ability, ambition and opportunity.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.