glReadPixels

Started by Mattbooth, February 20, 2005, 13:20:10

Previous topic - Next topic

Mattbooth

Hi caz, forgive my ignorance, just a bit of bad wording...

Even if glReadBuffer sets the buffer to read the front or the back buffer, how do you set the camera angle's in the different buffers?

still cant get anywhere  :oops:

princec

You don't! You always render to the backbuffer.
What exactly is the effect you're trying to do? I've got a funny feeling you're going sort of the wrong way about it.

Cas :)

Mattbooth

quite possibly caz :)

Okay i have a shoal of fish that you can see from the main window

I need to get the RGB values from either side of the fish (in effect what they can see) and interpret it.

So i thought i would have to use the back buffer to change the camera angle get the RGB, same on the other side of the fish, this can then be interpreted, however in the mean time the camera angel is changed back to the main shot of the shoal.

The aim is to calculate in the background without the main image being any different

Anything you can do to save me will be fab :)

princec

Erk, ok. Pretty strange way of going about it! It's going to be pretty bloody slow I think.

For every fish you'll need to clear the buffer, render the scene from the fish's left eye, read the backbuffer; then clear the buffer again, render the scene from the fish's right eye, then read the backbuffer again. Repeat for each fish. Then plonk the camera somewhere interesting and render the scene you want to actually see, and swap the buffers.

Cas :)

Mattbooth

Caz your the man lol

Yep that worked, i agree its going to be rather slow, i cant think of any other way to do it though.

One last question if you dont mind, when i call the update of hte scene to get all the info it updates the back buffer with the next sequence, so they way its being done at the moment with calling update twice in the same scene, its going to jump a frame.

Is there anyway to avoid this my making a copy of the pixels or something?

Thanks mate :)

Mattbooth

slow isnt the word for this, i can make a cuppa between each frame  :roll:

Mattbooth

hi guys,

Well i've tried for the last couple of days to swop the model i got working to my actual program.  As i said its slow but its returning the wrong values.  Instead of getting the camerea view of the fish's eye its still returning the value of hte main screen.  Quite a bit of code below.  The get pixels method words fine as it works on the model.

Method that passes the co-ords of the camera
public void vision(){
        int numFish = cFB.getNumOfFish(); // gets number of fish to draw
        for (int i = 0; i<numFish; i++){
            fish currFish = cFB.getFish(i);  
            threePointHolder poss = currFish.getCameraPos(); // gets the x,y,z position of the fish
           getSideView(poss, true); //sends the xyz to the camera position for left side
           getSideView(poss, false);  //sends the xyz to the camera position for left side
     
        }
             GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
                initGL(); // resets the camera angle
         }


method that clears buffer, sets camera and gets RGB
public void getSideView(threePointHolder newPos, boolean leftP){
        eyex = newPos.getX();
        eyey = newPos.getY();
        eyez = newPos.getZ();
        left = leftP;
              
        GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
        GL11.glEnable(GL11.GL_TEXTURE_2D); // Enable Texture Mapping
        GL11.glShadeModel(GL11.GL_SMOOTH); // Enable Smooth Shading
        GL11.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // Black Background
        GL11.glClearDepth(1.0); // Depth Buffer Setup
        GL11.glEnable(GL11.GL_DEPTH_TEST); // Enables Depth Testing
        GL11.glDepthFunc(GL11.GL_LEQUAL); // The Type Of Depth Testing To Do
        GL11.glMatrixMode(GL11.GL_PROJECTION); // Select The Projection Matrix
        GL11.glLoadIdentity(); // Reset The Projection Matrix
        // Calculate The Aspect Ratio Of The Window
        //GL11.glScalef(0.2f,  0.2f, 0.2f);
        GLU.gluPerspective(10.0f, (float) displayMode.getWidth() / (float) displayMode.getHeight(), 0.1f, 200.0f);
        if (left == false){
            System.out.println("right");
        GLU.gluLookAt(eyex, eyey, eyez, eyex, eyey, (eyez+0.1f), 0.0f,1.0f,0.0f);
        left = true;
        }
        else{
            System.out.println("left");
           GLU.gluLookAt(eyex, eyey, eyez, eyex, eyey, (eyez-0.1f), 0.0f,1.0f,0.0f);
        left = false;
        }
        
        GL11.glMatrixMode(GL11.GL_MODELVIEW); // Select The Modelview Matrix

        // Really Nice Perspective Calculations
        GL11.glHint(GL11.GL_PERSPECTIVE_CORRECTION_HINT, GL11.GL_NICEST);
         
        drawAll();
        
       try{
      getShot();
     
      }
      catch(Exception e){
          System.exit(0);
          System.out.println("ERROR");
      }
      GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
    }

Now i know its passing the right values across from testing but the getting of the RGB from these positions isnt right.  It still gets it from the main screen

and after this code is executed i call
drawAll() // draws everything again
Display.update() //swop buffers.

going out my mind now, all things say it should work, but it gets the RGB of the main screen  :roll: [/code]