D
D
Dima Yarmolchuk2014-02-15 12:27:45
Objective-C
Dima Yarmolchuk, 2014-02-15 12:27:45

opengl. How to get an RGB array of pixels from an image?

Hello.
The question on OpenGL interests.
How to get an RGB array of pixels from an image? Just three colors, no alpha.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
RPG, 2014-02-15
@RPG

In OpenGL the texture is loaded into video memory from RAM, it's much easier to just not remove the original texture from memory.
It makes sense to unload the framebuffer from OpenGL as a result of the work of some shader, then this is simply done by functions:

glBindFramebuffer(GL_FRAMEBUFFER_EXT, framebuffer->id);
glBindTexture(GL_TEXTURE_2D, framebuffer->image->id);
glReadBuffer(GL_COLOR_ATTACHMENT0_EXT);
GLubyte* img = (GLubyte*) malloc(framebuffer->w * framebuffer->h * sizeof(GLubyte) * 3);
glReadPixels(0, 0, framebuffer->w, framebuffer->h, GL_RGB, GL_UNSIGNED_BYTE, img);

img - pre-created array of required length. It should be noted that this method is very slow and is suitable only for a one-time unloading of the texture.
For iOS, the meaning is the same, just the functions change to *OES.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question