I have texture mapped a jpg (256*256 pixels) to a quadrilateral (-1,-1 as bottomleft and 1,1 as topright corner). Then I stretch the texture (-3,-3 and 3,3) to get the zooming effect. Now I am interested in retrieving the RGB values of this stretched texture (texels). How do i do that? glreadpixels returns garbage values. glGetTexImage is giving memory problems (when i try to write the array in a file).
Also, I would like to know how do i determine the size of the texture if the window is 500, 500 and i map the jpeg to the quad as (-1,-1 and 1,1).
glReadPixels(0, 0, 10, 10, GL_BLUE, GL_BYTE, pixels);
is what i am using… the window is 100 by 100 and i am using -1,-1 and 1,1 as the extremes. so how do i know what should be the lowermost pixel to be input to glreadpixels?
Also i wanted to clarify regarding the sequence of the code.
i have put the glreadpixels() after texture mapping (ie, immediately after glTexCoord2f(0.0f, 0.0f), glVertex3f(-1, 1, 0)… (as the scene is being drawn here)
Am I writing the glreadpixels() in the correct place?
I get memory error saying that the memory could not be written, and it won’t allow me to debug saying there was an error in initializing the application… Please suggest some pointers.
Also, make sure you are reading from the right buffer if you are using double buffering. If you do a glRead before you swap buffers, use glReadBuffer(GL_BACK); If you do the read after you swap buffers, you’ll need glReadBuffer(GL_FRONT); By default the read buffer is GL_FRONT for single buffered apps and GL_BACK for double buffered apps.
glReadPixels() works fine (I was using GL_INT as one pf the parameters rather than GL_UNSIGNED_BYTE which gave me huge numbers…)
One more thing I would like to know is when the window is 100 * 100 and i am pasting a 20 by 20 jpeg (on a quad with -1,-1 and 1,1 as extremes) how do i know what is the bottomleft co-ordinate and the width & height that the jpeg occupies on the screen? (it is at the center of the screen). As later on i am interested in stretching the jpeg and then retrieving the RGB values…