Help or an idea for an 'invisible" draw please

Blitz3D Forums/Blitz3D Programming/Help or an idea for an 'invisible" draw please

bashc(Posted 2011) [#1]
I need an idea or to know if there is some blitz command usefull for to read pinxels from a square or draw in movement whithout draw was visible in screen.
I know I can use an array to store the image, but as image is turning continuosly I am lost for how to do this.

Any idea about how to do this?

An example code:

Graphics 600,480,32,2

grados=180  ; 180 grados for a walk
SetBuffer BackBuffer()
;original=LoadImage("Triden256.bmp")
original=CreateImage(64,64) 


; Set the drawing buffer to the graphic 
SetBuffer ImageBuffer(original) 
	Rect 0,0,64,64,1
	Color 100,200,100
	Rect 8,8,48,48,1
SetBuffer BackBuffer()

trident = CopyImage(original)
Dim tur(grados)
RotateImage trident,-grados
tur(0) = trident

While Not KeyDown(1) 
	
	Cls
	
	LimitG=LimitG+1
	If LimitG =>180 Then LimitG =0
	
	trident=CopyImage(original)
	RotateImage trident, -grados + 2* LimitG
	tur(i) = CopyImage(trident)
	DrawImage tur(i),200,100  ; <---- How Should I do to place this square "as invisible" on screen and I can read pinxels???
	
	
	xm=MouseX() : ym =MouseY()
	LockBuffer BackBuffer()
	col=ReadPixelFast(xm,ym)
	UnlockBuffer BackBuffer()
	
	r=(col Shr 16) And 255
	g=(col Shr 8) And 255
	b=col And 255
	
	Locate 1,200 : Print "Grados: "+limitG + " Red =" + r +" Green = " + g +" Blue =" + b
	
	Flip
	
	
Wend
End





Graythe(Posted 2011) [#2]
You can use the readpixel() command to read the colour of a pixel directly from the imagehandle 'tur(i)' - there is no need to draw the image on the screen.


Kryzon(Posted 2011) [#3]
Yeah, you must notice that ReadPixel() or ReadPixelFast() have an optional [Buffer] argument, that specifies which buffer to read pixels from (if unspecified, it considers the BackBuffer() like you are using now).

If you supply your rectangle's image buffer with ImageBuffer(yourRectangle), you won't need to draw it to the screen.

Last edited 2011


Who was John Galt?(Posted 2011) [#4]
Are you doing anything to the box each frame other than rotating, scaling and translating? If so, you can grab it as an image once and use blitz's collision functions for a much faster method.


bashc(Posted 2011) [#5]
To Kryzon and Graythe

Yeah! That is a good solution!

I am very confused still with use buffers but each time I am understanding more their use.

See now my code:

Graphics 600,480,32,2

grados=180  ; 180 grados for a walk
SetBuffer BackBuffer()
;original=LoadImage("Triden256.bmp")
original=CreateImage(64,64) 


; Set the drawing buffer to the graphic 
SetBuffer ImageBuffer(original) 
	Rect 0,0,64,64,1
	Color 100,200,100
	Rect 8,8,48,48,1
	

trident = CopyImage(original)
Dim tur(grados)
RotateImage trident,-grados
tur(0) = trident

While Not KeyDown(1) 
	
	
	
	LimitG=LimitG+1
	If LimitG =>180 Then LimitG =0
	
	trident=CopyImage(original)
	RotateImage trident, -grados + 2* LimitG
	tur(i) = CopyImage(trident)
	SetBuffer ImageBuffer(original) 
	DrawImage tur(i),200,100  ; <---- How Should I do to place this square "as invisible" on screen and I can read pinxels???
	
	
	xm=MouseX() : ym =MouseY()
	
	LockBuffer ImageBuffer(original) 
	col=ReadPixelFast(xm,ym)
	UnlockBuffer ImageBuffer(original)
	
	r=(col Shr 16) And 255
	g=(col Shr 8) And 255
	b=col And 255
	SetBuffer BackBuffer()
	Cls
	Locate 1,200 : Print "Grados: "+limitG + " Red =" + r +" Green = " + g +" Blue =" + b
	
	Flip
	
	
Wend
End




It works!


@John Galt
Now I am going to sleep but tomorrow a will try to do as you say, (rotating image specially) and surelly I will save a lot of code. That is, becouse I do easy things very complicated. It is some normal and bad in me lol.
I got some of this code from a post from forum and I adapted to my way, but I can see that I could be write it better.

Thank your very much you all for your ideas that helps a lot!


bashc(Posted 2011) [#6]
Now it works better!


Graphics 600,480,32,2

grados=180  ; 180 grados for a walk but culd be 360
;SetBuffer BackBuffer()           ;  if you set drawing operations to the BackBuffer() you will NOT see any of them until you call FLIP.
;original=LoadImage("Triden256.bmp")
original=CreateImage(64,64) 


; Set the drawing buffer to the graphic 
SetBuffer ImageBuffer(original) 
	Rect 0,0,64,64,1
	Color 100,200,100
	Rect 8,8,48,48,1
	
	
trident = CopyImage(original)
Dim tur(grados)
RotateImage trident,-grados
tur(0) = trident
Vertridente=False





While Not KeyDown(1) 
	
	
	If KeyDown(46) Then VerTridente=True  ; See or not to see draw
	If KeyDown(47) Then VerTridente=False
	xm=MouseX() : ym =MouseY()
	
	
	LimitG=LimitG+1
	If LimitG =>180 Then LimitG =0
	
	trident=CopyImage(original)
	RotateImage trident, -grados + 2* LimitG
	
	
	
	
	tur(i) = CopyImage(trident)
	SetBuffer BackBuffer() 
	DrawImage tur(i),200,100 
	
	LockBuffer BackBuffer() 
	
	
	
	col=ReadPixelFast (xm,ym,BackBuffer())
	
	r=(col Shr 16) And 255
	g=(col Shr 8) And 255
	b=col And 255
	
	
	UnlockBuffer BackBuffer()
	SetBuffer BackBuffer()
	
	Cls 
	If VerTridente=True DrawImage tur(i),200,100 
	
		Color 233,255,255
	
		Locate 1,200 : Print "Grados: "+limitG + " Red = " + r +" Green = " + g +" Blue =" + b 
		Locate 1,220 : Print "Keys 'C' And 'V' to see or not to see draw"
		
	Flip
	
	
Wend
End