Results 1 to 9 of 9

Thread: Where are the pixels of the current scene stored

  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
    Senior Member Frequent Contributor scratt's Avatar
    Join Date
    May 2008
    Location
    Thailand
    Posts
    555

    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
    Join Date
    Oct 2004
    Posts
    4,654

    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,367

    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;
    		}

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

    Re: Where are the pixels of the current scene sto

    You allocate to much memory though it is not the problem here, it should be:

    GLubyte imageData[WIDTH*HEIGHT*3];

    use the hex modifier as I suggested:

    cout << hex << imageData[ i ] << imageData[ i + 1 ] << imageData[ i + 2 ] << endl;

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

    Re: Where are the pixels of the current scene sto

    still
    ???
    ???
    ???

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

    Re: Where are the pixels of the current scene sto


Similar Threads

  1. How is depth stored?
    By imported_qnoper in forum OpenGL: Advanced Coding
    Replies: 2
    Last Post: 04-10-2016, 08:07 AM
  2. Value stored in Z-Buffer
    By myk45 in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 03-08-2013, 04:40 AM
  3. where is stored my cl_mem
    By alpha in forum OpenCL
    Replies: 3
    Last Post: 02-05-2010, 05:41 PM
  4. In which DLL are OpenGL extensions stored?
    By halo in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 12-19-2003, 12:36 PM
  5. Where is the texture data stored
    By BK in forum OpenGL: Basic Coding
    Replies: 7
    Last Post: 10-17-2000, 03:49 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