I would like to draw simple shapes onto a texture and then resize that texture and get access to the pixel data. Is there a way to “draw onto” something, as you can on a PGraphics object in Processing? You can resize and get the pixels of an ofImage, but you can’t draw shapes on to it. That seems to be the case with ofTexture as well.
you want an FBO ( http://www.opengl.org/wiki/Framebuffer-Object ); there is an easy to use ofFbo class in OF and here’s a basic example of how you can use it:
ofFbo myFbo; float width = 100; float height = 100; myFbo.allocate(width,height,GL_RGBA); //the stuff between begin() and end() is drawn into the fbo myFbo.begin(); ofClear(0,0,0,255); //let's clear the fbo with solid black ofCircle(width/2,height/2,20); //draw a circle in the middle myFbo.end(); //now let's draw the fbo in the middle of the screen and resize it by 0.5 myFbo.draw(ofGetWidth()/2,ofGetHeight()/2,width/2,height/2);
Great thanks! Only one more issue, is it possibly to actually downsample it and retrieve the downsampled pixel values, rather than just display it at that size.
sure; the best way to do it probably depends on what you need to achieve.
If you only need to do it once, you could readToPixels() and then resize() the generated pixels. If you need speed (i.e. you drawing lots of stuff in the fbo every frame) displaying to the desired size is faster because the load in on the GPU.
You can probably downscale (or project onto a half-resolution area) on the render pipeline, then draw on the FBO, and you’d get an already downsampled sprite.
I’m sorry, my vocabulary is probably not the best, but the idea should be about correct