Hello~
I think this is whats going on
- if you are using Cocos2d-x 3.x, Rendertexture no longer binds the framebuffer immediately, so your [quote=“lucas0, post:1, topic:14712”]
glReadPixels(x, y, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, buffer);
[/quote]
will reads the current frame buffer (the screen), and you will get a different color
what you could do is
-
make a node, implement a “draw” function, the draw function should does nothing other than glreadpixel and returns the value. you then visit this node inside the rt->begin() and rt->end()
-
you could modify the RenderTexture class and change onbegin() onEnd() from protected to public. This allows you to manually call those function which will immediately change the framebuffer to the rendertexture, allows your glreadpixel to read from the correct buffer. the drawback is you can not do normal sprite->visit() inside this