Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 9 of 9

Thread: Where are the pixels of the current scene stored

Hybrid View

  1. #1
    Junior Member Newbie
    Join Date
    Jun 2009
    Posts
    9

    Where are the pixels of the current scene stored

    Hello guys

    Where are the pixels of the current scene stored. Basically, I want to know get the pixels information of the current scene such as color, intensity and position.

  2. #2
    Advanced Member Frequent Contributor scratt's Avatar
    Join Date
    May 2008
    Location
    Thailand
    Posts
    556

    Re: Where are the pixels of the current scene stored

    Depending on how you are drawing your scene the normal case is the pixels end up in the current FrameBuffer.

    You can read pixels from the FrameBuffer using glReadPixels..
    http://www.opengl.org/documentation/...eadpixels.html

    Be aware that this is not the fastest way to get data, so depending on what you are trying to do it may be worth looking at FBO (FrameBufferObjects) and "drawing to textures", and then using shaders or other means to do computation on that data.

    But for now, for what you need glReadPixels should do.

  3. #3
    Senior Member OpenGL Guru Dark Photon's Avatar
    Join Date
    Oct 2004
    Location
    Druidia
    Posts
    2,894

    Re: Where are the pixels of the current scene stored

    Quote Originally Posted by scratt
    Depending on how you are drawing your scene the normal case is the pixels end up in the current FrameBuffer.

    You can read pixels from the FrameBuffer using glReadPixels..
    http://www.opengl.org/documentation/...eadpixels.html
    Also be aware that you may not get the exact same results as are displayed if you have antialiasing enabled (e.g. multisampling) as the same path is not necessarily used to perform the multisample resolve before scan-out as is used to perform the multisample resolve before readback.

    So disable antialiasing and you can be reasonably sure you're going to get the same thing with glReadPixels that you see on the screen.

  4. #4
    Junior Member Newbie
    Join Date
    Jun 2009
    Posts
    9

    Re: Where are the pixels of the current scene sto

    I wrote this code to get the three colors of the pixels
    Code :
    int BIT_R=8;
    		int BIT_G=8;
    		int BIT_B=8;
    		int WIDTH=2;
    		int HEIGHT=2;
    		glReadBuffer(GL_BACK);
    		GLvoid *imageData = malloc(WIDTH*HEIGHT*(BIT_R+BIT_G+BIT_B)); 
    		glReadPixels(0, 0, WIDTH, HEIGHT, GL_RGB, GL_UNSIGNED_BYTE, imageData);
    I tried to fetech the array but I don't know what how the information stored into imageData array
    So how can I store this information into the screen using "cout" as :
    x y R G B
    value value value value value

  5. #5
    Senior Member OpenGL Pro dletozeun's Avatar
    Join Date
    Jan 2006
    Location
    FRANCE
    Posts
    1,370

    Re: Where are the pixels of the current scene sto

    I tried to fetech the array but I don't know what how the information stored into imageData array
    So how can I store this information into the screen using "cout" as :
    x y R G B
    value value value value value
    You mean, how to display imageData array values?

    You can do something like:

    Code :
    int pixelNb = WIDTH*HEIGHT;
    for( int i = 0; i< pixelNb; ++i )
    {
        cout << hex << imageData[ i ] << imageData[ i + 1 ] << imageData[ i + 2 ] << endl;
    }

    Assuming imageData is a array of GLubyte values.

  6. #6
    Junior Member Newbie
    Join Date
    Jun 2009
    Posts
    9

    Re: Where are the pixels of the current scene sto

    I tried the code but I get output like this:
    ???
    ???
    ???
    ...

    the code that I used
    Code :
    int WIDTH=2;
    		int HEIGHT=2;
    		glReadBuffer(GL_BACK);
    		GLubyte imageData[WIDTH*HEIGHT*4] ; 
    		glReadPixels(0, 0, WIDTH, HEIGHT, GL_RGB, GL_UNSIGNED_BYTE, imageData);
    		int pixelNb = WIDTH*HEIGHT;
    		for( int i = 0; i< pixelNb; ++i )
    		{
    			cout << hex  << imageData[ i ] << imageData[ i + 1 ] << imageData[ i + 2 ] << endl;
    		}

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •