Results 1 to 2 of 2

Thread: [Solved] Picking oddities

  1. #1
    Junior Member Newbie
    Join Date
    Sep 2009
    Posts
    2

    [Solved] Picking oddities

    Hi,

    Hope someone can help on my picking/selection problem.

    I have some 2D geometries on the screen. I manage to do picking sucessfully with

    viewport(0, 0, windowWidth, windowHeight) and
    glOrtho(0, windowWidth, 0, windowHeight, anyNearZ, -anyNearZ) and default orientation looking down into negative z-axis.

    Oddity #1:
    Even though the documentation says glPickMatrix takes window coordinates, I actually need to convert the mouse coord to world coord to get it to work. Why?

    Oddity #2:
    If I change my glOrtho to center on (0, 0, 0) with glOrtho(-windowWidth/2, windowWidth/2, -windowHeight/2, windowHeight/2, anyNearZ, -anyNearZ) it doesnt work anymore. the GL_SELECT buffer gets drawn some offset distance away from the actual geometry i am trying to pick. e.g. say my 5x5 SQAURE is at (10, 10), i need to click somewhere at (30, 10) with only a 2x2 hit area to detect the hit. What can be wrong?

    Code :
    void select(int x, int y)
    {
    	// if there are no shapes, nothing to select
    	if(shape.size() <= 0) return;
     
    	int buffSize = shape.size() * 4;
    	GLuint* buff = new GLuint[buffSize];
     	GLint hits = 0;
    	GLint view[4];
     
     	glSelectBuffer(buffSize, buff);
    	glViewport(0, 0, worldWidth, worldHeight);
     	glGetIntegerv(GL_VIEWPORT, view);
     	glRenderMode(GL_SELECT);
     	glInitNames();
    	// Now fill the stack with one element
    	// otherwise glLoadName will generate an error
    	// TODO: Is this because glLoadName will PopName before PushName
     	glPushName(0);
     	glMatrixMode(GL_PROJECTION);
     	glPushMatrix();
     		glLoadIdentity();
     		gluPickMatrix(x, y, 1.0, 1.0, view);
    		glOrtho(-worldWidth/2, worldWidth/2,
    			-worldHeight/2, worldHeight/2,
    			 worldWidth, -worldWidth);
    		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    		glMatrixMode(GL_MODELVIEW);
    		glLoadIdentity();
    		for(int i = 0; i < shape.size(); i++)
    		{
    			glLoadName(i);
    			shape[i]->Draw();
    		}
     
    	glFlush();
    	glutSwapBuffers();
     
     	glMatrixMode(GL_PROJECTION);
     	glPopMatrix();
    	// total number of hits
     	hits = glRenderMode(GL_RENDER);
     
    	delete [] buff;
     
     	glMatrixMode(GL_MODELVIEW);
    }

  2. #2
    Junior Member Newbie
    Join Date
    Sep 2009
    Posts
    2

    Re: Picking oddities

    OK.... it happens all the time... right after I post in the forums, I manage to stumble upon the answers.

    By trial and error, I manage to solve my problems. glPickMatrix takes window coordinates except y is flipped as in

    y = windowHeight - 1 - y;

    The everything else works alright. Thanks.

Similar Threads

  1. Computing screen coordinates oddities
    By NeXEkho in forum OpenGL: GLSL
    Replies: 3
    Last Post: 01-02-2011, 12:02 AM
  2. Picking without depth-buffer information[SOLVED]
    By potatosoftware in forum OpenGL: Advanced Coding
    Replies: 3
    Last Post: 10-20-2010, 07:37 PM
  3. Alpha Blending Oddities
    By J2900 in forum OpenGL: Basic Coding
    Replies: 6
    Last Post: 03-21-2009, 12:15 PM
  4. glPixelZoom oddities with glDrawPixels
    By brown12 in forum OpenGL: Advanced Coding
    Replies: 1
    Last Post: 10-30-2000, 09:33 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean