FBO to pixmap?

BlitzMax Forums/BlitzMax Programming/FBO to pixmap?

ima747(Posted 2010) [#1]
I'm trying to overcome some clipping issues with opengl drawing beyond the screen bounds on windows when using GrabImagePixmap()

I've got a render to texture example almost working but then I realized this is rendering directly to the openGL texture, and I don't know how to get that data back into a pixmap so I can save it...

Looks like FBO is what I need however I still don't know how to get the data back to a pixmap if I get this approach working either...

Can someone point me towards a complete example of how to perform drawing operations (drawimage, drawtext, drawline, etc.) and then capture the output to a pixmap without using GrabImage()?


_JIM(Posted 2010) [#2]
Maybe create an image with DYNAMIC_IMAGE flag and associate that pixmap to it? Worth a shot.


ImaginaryHuman(Posted 2010) [#3]
If the texture is not bigger than the screen, draw it to the backbuffer and grabpixmap.


ima747(Posted 2010) [#4]
the image IS bigger than the screen, and I'm experiencing clipping issues on windows (not mac interestingly), hence my need to avoid grabpixmap etc.

dynamic image flag does not work, as when you draw with open gl to a texture you're drawing directly to the texture, which skips the pixmap associated with the image. The pixmap comes out clear.


Kryzon(Posted 2010) [#5]
Did you try setting up a bigger viewport and\or disabling the Scissor test, clipping etc.?

glDisable(GL_SCISSOR)



ima747(Posted 2010) [#6]
viewport is set to the size I wish to grab off the backbuffer (larger than the screen)

glDisable(GL_SCISSOR) gives me an error saying it doesn't know what GL_SCISSOR is. Poked through some files and tried glDisable(GL_SCISSOR_TEST) instead, but no change, output is still clipped when I grab.


Sanctus(Posted 2010) [#7]
Ah dude I'm sorry. When I explained I messed up a bit. You need to use PBO (pixel buffer objects) not FBO. It's almost the same thing. The difference is that FBO's render to texture and thus can only be used later in the program from the video memory while you can use pixel buffer object to read the pixels with something like glReadPixels(you might want to pass the pixelmap.buffer or something like that).
And disabling the scissor won't work since this is a openGL issue (at least on windows).


ima747(Posted 2010) [#8]
After much poking, and without knowing exactly what I've done it seems to be working now... I think the glDisable(GL_SCISSOR_TEST) combined with resizing some things got it up and going but it feels like a house of cards since I don't know quite which hammer swing made it work... I'm glad this isn't a key component of anything really big I'm working on :0)

Thanks for the help!

I think this topic is still worth keeping active to try to get a good render to target then target to pixmap feature flushed out...


Sanctus(Posted 2010) [#9]
I actually really need this and at one point I'll be writing one module myself if nobody else does.


Kryzon(Posted 2010) [#10]
If someone does create a render-to-target module, you absolutely must use FBOs.
They're fast (faster than glReadPixels and PBOs) and, nowadays, very supported.
Plus, their content does not (unwillingly) come back to the client (the CPU); part of the reason why they're fast.

I think the glDisable(GL_SCISSOR_TEST) combined with resizing some things got it up and going but it feels like a house of cards since I don't know quite which hammer swing made it work...

Make sure to realize the order of the calls you're taking. Since OpenGL is a state-machine, the order in which the calls are made is very important.
I remembered the glOrtho() function (it's related to view clipping size), might be worth a look too - just be careful to set back the previous states when rendering regular things.


ima747(Posted 2010) [#11]
It had something to do with oversizing the canvas space and then not resizing it later, combined with disabling the scissor... I think...

as for rendering to texture there's some good code in the archives by klepto http://www.blitzbasic.com/codearcs/codearcs.php?code=2222 that works when copy/pasted and I was making good progress integrating it with my existing code, but again, it doesn't render to a space you can get to without a grabpixmap so it's of no use for me at the moment... but a great starting point for render to texture for live use...