Using glReadPixels to read pixels doesnt work on Android

Hi,

I am using the following code to retrieve pixels from a ccsprite

texture~~>beginWithClear; // pink background
this~~>visit();
glPixelStorei(GL_PACK_ALIGNMENT, 1);
glReadPixels(0, 0, renderTextureWidth, renderTextureHeight, GL_RGBA, GL_UNSIGNED_BYTE, buffer);
texture~~>end;
texture~~>release();
+this->getTexture()->initWithData(buffer,kCCTexture2DPixelFormat_RGBA8888,this->getTexture()>getPixelsWide,this>getTexture()>getPixelsHigh,CCSizeMake);+
Notice the underlined line
it is there for testing purposes to check whether the bytes were successfully read.

This works fine when I test it on the windows (vs2010) but when I compile it with cygwin and run it on android the image is distorted completely as if glReadPixels did not work properly. Please see screenshots below:

Windows (works):

The screenshot below was taken from android (I took a photo with another phone - please pardon the quality):


win.png (27.7 KB)

I figured out what the problem was - it had to do with the AppDelegate.cpp. My design resolution (ratio) was badly configured.

What do you mean by badly configured? I think I have the same problem because its happening only on android and I can’t seem to find any article related to it.

Inside AppDelegate there was some funky thing i was doing with setContentScaleFactor and setDesignResolution. I dont exactly remember but I do know I replaced the contents of this file with the example from TestCpp. Also I eventually stopped using this technique to draw pixels and used the class (Mutable Texture) - you can find it at http://www.cocos2d-x.org/boards/6/topics/3472 in one of the posts as an attachement.