BACKBUFFER ACCESS (MAX2d)

BlitzMax Forums/BlitzMax Programming/BACKBUFFER ACCESS (MAX2d)

Canali(Posted 2005) [#1]
Hi,
I'm curious about how to access to the backbuffer in BlitzMax+Max2d before we call the FLIP command.

I'm interested in implementig effect on the backbuffer drawings.

Anyone has tryed yet?

Any sample?

Thx


TartanTangerine (was Indiepath)(Posted 2005) [#2]
These functions are already in Bmax but are called something else - LOL and they are not very well documented.

GrabPixmap - Grabs pixels directly from the backbuffer
DrawPixmap - Draws pixeld directly to the backbuffer

You can't draw a portion of an image to the buffer YET, but It would be simple to write a method to do that.


Canali(Posted 2005) [#3]
Thx Indie,
that's right what I was looking for.

For filters programming I mostly need per-pixel manipulation.

Thx again.


TartanTangerine (was Indiepath)(Posted 2005) [#4]
No problem, now please someone help me with Vertex Buffers.


Azathoth(Posted 2005) [#5]
Is it possible to get a pointer to the back buffer like in purebasic?


TartanTangerine (was Indiepath)(Posted 2005) [#6]
Yes it is.


Azathoth(Posted 2005) [#7]
Um. Ok, how?


TartanTangerine (was Indiepath)(Posted 2005) [#8]
have a delve into the directx modules. If you have a look at the commands I mentioned earlier they are using a pointer to the back buffer to get and send information.


Azathoth(Posted 2005) [#9]
Does it work with OpenGL?


TartanTangerine (was Indiepath)(Posted 2005) [#10]
good question.

I don't think you need it in openGl since you just need to read and write pixels, here's the BlitzMax Code :
Method DrawPixmap( p:TPixmap,x,y )
		Local blend=state_blend
		DisableTex
		SetBlend SOLIDBLEND
		
		Local t:TPixmap=YFlipPixmap(p)
		If t.format<>PF_RGBA8888 t=ConvertPixmap( t,PF_RGBA8888 )
		glRasterPos2i 0,0
		glBitmap 0,0,0,0,x,-y-t.height,Null
		glDrawPixels t.width,t.height,GL_RGBA,GL_UNSIGNED_BYTE,t.pixels
		
		SetBlend blend
	End Method

	Method GrabPixmap:TPixmap( x,y,w,h )
		Local blend=state_blend
		SetBlend SOLIDBLEND
	
		Local p:TPixmap=CreatePixmap( w,h,PF_RGBA8888 )
		glReadPixels x,graphics_height-h-y,w,h,GL_RGBA,GL_UNSIGNED_BYTE,p.pixels
		p=YFlipPixmap(p)

		SetBlend blend
		Return p
	End Method
	



Filax(Posted 2005) [#11]
It is possible to add screen effect like blur or glow ? i have try but ...


TartanTangerine (was Indiepath)(Posted 2005) [#12]
I suppose you could grab the backbuffer and apply that to a quad using the GRabImage function, then do some nice stuff with that image like creating some mipmapps and displaying those full screen - like a quick and dirty blur.

I wonder if GrabImage keeps the stuff in video memory? that would be nice and quick if it did.


Eikon(Posted 2005) [#13]
How do you GrabImage/GrabPixMap if the image is drawn off screen? This would be helpful for a realtime grab without the need to Cls.


TartanTangerine (was Indiepath)(Posted 2005) [#14]
GrabPixMap grabs from the backbuffer. GrabIMages uses this function also but puts the pixmap that is returned by this function into a texture.

Method GrabPixmap:TPixmap( x,y,width,height )
		If islost Return
		Local pixmap:TPixmap
		pixmap=TPixmap.Create(width,height,PF_BGR888)
		Local sdesc:DDSurfaceDesc2=New DDSurfaceDesc2
		sdesc.dwSize=SizeOf(sdesc)
		Local res=PrimaryDevice.backbuffer.Lock(Null,sdesc,DDLOCK_WAIT|DDLOCK_SURFACEMEMORYPTR|DDLOCK_READONLY,Null)
		If res<>DD_OK Return	
		Select sdesc.ddpf_BitCount
		Case 16
			Local s16:Short Ptr=Short Ptr(sdesc.lpSurface+y*sdesc.lPitch+x*2)
			Local d8:Byte Ptr=pixmap.pixels
			For Local i=0 Until height
				For Local j=0 Until width
					Local p=s16[j]
					d8[0]=p Shl 3
					d8[1]=(p Shr 5) Shl 2
					d8[2]=(p Shr 11) Shl 3
					d8:+3
				Next
				d8:+(pixmap.pitch-pixmap.width*3)
				s16:+sdesc.lPitch/2
			Next		
		Case 24
			Local s8:Byte Ptr=sdesc.lpSurface+y*sdesc.lPitch+x*4
			Local d8:Byte Ptr=pixmap.pixels
			For Local i=0 Until height
				memcpy_ d8,s8,pixmap.width*3
				s8:+pixmap.pitch
				d8:+sdesc.lPitch
			Next		
		Case 32
			Local s8:Byte Ptr=sdesc.lpSurface+y*sdesc.lPitch+x*4
			Local d8:Byte Ptr=pixmap.pixels
			For Local i=0 Until height
				For Local j=0 Until width
					d8[0]=s8[0]
					d8[1]=s8[1]
					d8[2]=s8[2]
					d8:+3
					s8:+4
				Next
				d8:+(pixmap.pitch-width*3)
				s8:+sdesc.lPitch-width*4
			Next		
		End Select
		PrimaryDevice.backbuffer.Unlock Null	
		Return pixmap	
	End Method

End Type