Results 1 to 5 of 5

Thread: Quick Selection Question

  1. #1
    Member Contributor
    Join Date
    Oct 2006
    Posts
    83

    Quick Selection Question

    Please Help,

    I am new to the OpenGL Selection and have a quick question that I hope someone can help me with. I get the selection to work fine, i.e., I can record "hits" when switching from GL_SELECT to GL_RENDER but the NAME is not stored.

    The output I get (when I select the Object):
    "--------------------------
    HITS: 1
    - - - - - - - - - - - - - -
    Number of Names: 0
    z1: -0.09484
    z2: -0.3213
    names:
    - - - - - - - - - - - - - - -
    ------------------------------"

    The following is the code from which the previous console output comes:
    Code :
    private void proces****s(int hits, IntBuffer buffer) {
            	System.out.println("---------------------------------");
            	System.out.println(" HITS: " + hits);
            	int offset = 0;
            	int names;
            	float z1, z2;
            	for (int i = 0; i < hits; i++) {
                		System.out.println("- - - - - - - - - - - -");
                		System.out.println(" hit: " + (i + 1));
                		names = buffer.get(offset);
                		offset++;
                		z1 = (float) buffer.get(offset)/0x7fffffff;
                		offset++;
                		z2 = (float) buffer.get(offset)/0x7fffffff;
                		offset++;
                		System.out.println(" number of names: " + names);
                		System.out.println(" z1: " + z1);
                		System.out.println(" z2: " + z2);
                		System.out.println(" names: ");
     
                		for (int j = 0; j < names; j++) {
                    		System.out.print("  " + buffer.get(offset));
                    		if (j == (names - 1)) {
                        			System.out.println("<-");
                    		}else {
                        			System.out.println();
                    		}
                    		offset++;
                		}// End of INNER FOR-LOOP
                		System.out.println("- - - - - - - - - - - -");
            	}// End of OUTER FOR-LOOP
            	System.out.println("--------------------------------- ");
        	}// End of proces****s(int,IntBuffer)
    The naming of the Object is done in the following code:
    Code :
      int[] viewport = new int[4];
            	int hits = 0;
     
    		// allocate fast memory. Necessary since glSelectBuffer takes IntBuffer	
    		//
    		ByteBuffer byteBuffer = ByteBuffer.allocateDirect(4*BUFFERSIZE);
            	byteBuffer.order(ByteOrder.nativeOrder());
            	this.selectionBuffer = byteBuffer.asIntBuffer();
     
    		// Get the current Viewport for this Class
    		//
            	this.gl.glGetIntegerv(GL.GL_VIEWPORT, viewport, 0);
     
            	// the hits will be stored in the selection buffer after.
    		//
            	// Note that it's called *before* we change the render mode
    		//
            	this.gl.glSelectBuffer(selectionBuffer.capacity(), this.selectionBuffer);
     
    		// Set the GL Rendering Mode to SELECT
    		//
            	this.gl.glRenderMode(GL.GL_SELECT);
     
    		// clear name stack
    		//
            	this.gl.glInitNames();                      
     
    		// Switch to the Projection Matrix
    		//
            	this.gl.glMatrixMode(GL.GL_PROJECTION);
     
    		// save current projection matrix
    		//
            	this.gl.glPushMatrix();
     
            	// reset the projection matrix
    		//
            	this.gl.glLoadIdentity();                    
     
    		// restrict drawing to around the cursor
    		//
            	this.glu.gluPickMatrix(this.mouseX, viewport[3] - this.mouseY, 5.0d, 5.0d, viewport, 0);
    this.glu.gluPerspective(45, this.ratio, 1, 200);
    this.gl.glMatrixMode(GL.GL_MODELVIEW);
    if (mode == GL.GL_SELECT) {
    				gl.glPushName(20);
    			}
    // Call draw() that is using geometric primatives to render Object
    draw();
     
    this.gl.glMatrixMode(GL.GL_PROJECTION);
    this.gl.glPopMatrix();
    hits = gl.glRenderMode(GL.GL_RENDER);
    this.mode = GL.GL_RENDER;
    proces****s(hits, selectionBuffer);
    Thanks be to anyone that has any idea why this is happening.

  2. #2
    Member Contributor
    Join Date
    Feb 2005
    Posts
    90

    Re: Quick Selection Question

    Hi,

    Where is the glPopName?

    Ido

  3. #3
    Member Contributor
    Join Date
    Oct 2006
    Posts
    83

    Re: Quick Selection Question

    Oops. I think I got the call mixed up with glLoadName()?

  4. #4
    Member Contributor
    Join Date
    Oct 2006
    Posts
    83

    Re: Quick Selection Question

    Still no luck. I tried using both glLoadName(GLUint) and (when that didn't work) I instead did the glPushName(GLUint) (draw Object with primatives) followed by glPopName().

    Perhaps it is my printing out function?

  5. #5
    Member Contributor
    Join Date
    Oct 2006
    Posts
    83

    Re: Quick Selection Question

    Never mind. I found it. I was not setting GL_SELECT when drawing the Model at all so the name stack was never loaded.

    The result of a long day of coding with no breaks.

Similar Threads

  1. Just a quick Question about HDR
    By Twixn in forum OpenGL: Advanced Coding
    Replies: 8
    Last Post: 12-19-2004, 11:07 PM
  2. Quick Question:
    By Krak in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 05-05-2003, 09:24 PM
  3. quick question
    By ArchMiffo in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 11-16-2002, 01:48 PM
  4. Quick Question.....
    By in forum OpenGL: User Software
    Replies: 0
    Last Post: 10-26-2001, 01:15 AM
  5. Quick question
    By in forum OpenGL: User Software
    Replies: 0
    Last Post: 11-01-2000, 03:13 AM

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