Getting a pixels colour?

BlitzMax Forums/BlitzMax Beginners Area/Getting a pixels colour?

Oddball(Posted 2005) [#1]
Hi there, I've been playing around with the BlitzMax demo, and I was wondering if there is any way to read pixel data from the back buffer, or any where else for that matter. The equivalent Blitz3D command would be GetColor or ReadPixel.


Perturbatio(Posted 2005) [#2]
You can use ReadPixel (it must be used with a pixmap).


ImaginaryHuman(Posted 2005) [#3]
To read the backbuffer you have to use glReadPixels(). Standard OpenGL is unfortunately very poor with regards to reading the buffer, although quite competent at drawing it.


tonyg(Posted 2005) [#4]
Here's an example of writepixel...
click


skidracer(Posted 2005) [#5]
It's a bit long winded but next BlitzMax update will allow a more efficient method:

Function ReadBackBuffer(x,y)
	Global	grab
	Local	rgba,pixmap
	
	If Not grab grab=CreateImage(1,1,1,DYNAMICIMAGE)
	GrabImage grab,x,y
	pixmap=LockImage(grab,0,True,False)
	rgba=ReadPixel(pixmap,0,0)
	UnlockImage pixmap
	Return rgba
End Function



Oddball(Posted 2005) [#6]
Thanks guys. I've got it sorted now.