How to :: ofFbo GL_RGB on OpenGLES


I’m trying to send unsigned char values through using artnet in a format [R][G][B] on a Raspberry PI4 .
I’ve realised that assigning an ofFbo can’t be done with just RGB, but has to be RGBA in OpenGLES:
window initialisation:

// in main.cpp
	ofGLESWindowSettings settings;
// [other sutff]
// [rst  of the code]

Therefore when doing : shader drawing into my Fbo, i then need to remove manually the alpha part of the buffer by doing :

 ofVec2f sPix = { 1, 500};

ofFbo f;
f.allocate(sPix.x, sPix.y, GL_RGB) ; >> give GL_RGBA
ofPixels pix;
pix.allocate(sPix.x, sPix.y, 3);

unsigned char * newPixRGB = new unsigned char[sPix.x * sPix.y * 3];

int nIndex = 0;
for (int i = 0; i < sPix.x; i++) {
	for (int j = 0; j < sPix.y; j++) {
		int oIndex = j + i * sPix.y;

		newPixRGB[nIndex++] = pix[oIndex * 4];
		newPixRGB[nIndex++] = pix[oIndex * 4 + 1];
		newPixRGB[nIndex++] = pix[oIndex * 4 + 2];

This is not the best way to do it:
I’m processing my colors in my shader, but then re processing it individually afterwards to remove the alpha…
How to make it more efficient?
I’ve looked at ofFboSettings, but no luck so far.
Any ideas?



Hi @pierre_tardif00 !
As far as I know you need to do it in a for loop, although it can be optimized. For example:
you can do it in a single for loop instead of 2
try using ++i instead of i++, as well as for nIndex. It is not the same.
Last but not least, remeber to delete taht array you created with new, otherwise you will be leaking memory (and a lot of it). or you can just use a vector, allocate it using resize or reserve and you can forget about leaking memory.

Hi @roymacdonald ,

Yeah the code is concatenated here from several classes, unsigned char * newPixRGB is only declared once. The size of thge buffer is set once so no need to resize it.
Thanks for the tips i’ll try them anyways.
I was more wondering about fast copy an array with special offset of some sort maybe?

as far as I know there is no memcopy with an offset. Actually it is not called but stride.


Ah yeah thanks!

Will check it out.