Text & MaskImage

Archives Forums/Blitz3D Bug Reports/Text & MaskImage

Gillissie(Posted 2007) [#1]
This is a very strange bug that only seems to happen on the new GeForce 8800 series video cards. Maybe it's a driver issue, but in the cases I've seen, all were running the latest version of the Forceware drivers, (97.92) on Windows XP home edition.

To summarize what's happening, image buffers created using CreateImage and written to with Text are getting randomly corrupted pixelation. Code is like this:

h = CreateImage(460,40)
SetBuffer (h)
ClsColor 0,0,0
Cls
Color 255,255,255
SetFont myFont
Text 5,5,"Some Text"
SetBuffer BackBuffer()


This works perfectly as expected on most cards, but not the 8800 series (GTS, GTX) cards.

Even stranger, if I use a different mask color than the default black, then the corrupted pixels don't appear.

h = CreateImage(460,40)
SetBuffer (h)
ClsColor 0,255,255
Cls
MaskImage h,0,255,255
Color 255,255,255
SetFont myFont
Text 5,5,"Some Text"
SetBuffer BackBuffer()


This must be a bug in either the video drivers, or the way Blitz handles writing Text on a buffer. The reason I suspect Blitz is because of the difference in handling the mask color. Any ideas?

I should mention one more thing, I can only reproduce this in my full game code. A simple example program didn't cause the glitch. I suspect that image buffers are getting mixed up or something, and my simple example isn't using enough buffers to cause a problem.


Gillissie(Posted 2007) [#2]
More info that may be related. When trying to black out an image, whether I use Cls with ClsColor 0,0,0 or if I use DrawRect with Color 0,0,0 this video card seems to ignore the command.


Matty(Posted 2007) [#3]
Setbuffer(h) is wrong as h is not a buffer but an image handle, you need to do as follows:

setbuffer(imagebuffer(h))


jfk EO-11110(Posted 2007) [#4]
Additionally, It turned out on a few machines you'll get a MAV if you try to D2D draw or text directly to an imagebuffer or texturebuffer. I know this sucks, but for ultimate compatibility you better draw things to the backbuffer, then copyrect to the imagebuffer or texturebuffer.


Gillissie(Posted 2007) [#5]
Matty: You're right, but that was just example code I whipped up right here, so it's not actually what my program does.

What I've found is that the 8800 series video card (or its drivers) simply has a lot of issues. It seems to be related to images that are created using CreateImage(). LoadImage seems to work fine. It doesn't seem to be specifically Text related or masking related, but it only seems to happen when those features are used on the created image. The glitches are so random that it's hard to nail down.

However, it would be great if Mark could take a look at the CreateImage function and see if it's doing something that might cause issues that LoadImage doesn't.


Gillissie(Posted 2007) [#6]
To support my theory of a bug with CreateImage on the 8800 video cards, I am now doing this as a workaround, and it works good. This example replaces CreateImage(100,100)

h = LoadImage("Black.png") ; 1x1 black image
ScaleImage h,100,100

Of course, this can't be used as a realtime solution, but it could probably be optimized for that by loading a master "black.png" image and using CopyImage instead of LoadImage.


RGR(Posted 2007) [#7]
.

Last edited 2012


Gillissie(Posted 2007) [#8]
I think you're thinking of textures, not images. And I think you're referring to alpha blending, not masking. I can verify this is only an issue on 8800 video cards. I think it's a driver issue, but I'm wondering if it may be a Blitz issue too, since only one command has the issue.


t3K|Mac(Posted 2007) [#9]
i upgraded to a 8800 gts card and i have now the same issue here.

even jfks solution (copying from backbuffer to texturebuffer) does not work correctly. if the destination texture is non-alpha, everything works fine.
if i add flag 2 to the destination texture, copying from backbuffer/imagebuffer/.. causes texture distortion.

a small testcode:

Graphics3D 800,600,32,2
cam=CreateCamera()
MoveEntity cam,-1,0,-2
CameraClsColor cam,50,50,50
spr=CreateSprite()

a$=Input("alpha'ed texture (y/n)?")
If a$="n" Then flags=1+256 Else flags=1+2+256

tex=CreateTexture(256,256,flags)

EntityTexture spr,tex

img=CreateImage(256,256)

SetBuffer BackBuffer()

While Not KeyHit(1)
	Cls
	If KeyHit(20) ; t
		SetBuffer TextureBuffer(tex)
		Color Rnd(255),Rnd(255),Rnd(255)
		Text 5,226,"Written directly to Texturebuffer"
		SetBuffer BackBuffer()
		; just for comparing images....
		CopyRect 0,0,256,200,0,0,TextureBuffer(tex),ImageBuffer(img)
	EndIf
	If KeyHit(23) ; i
		SetBuffer BackBuffer()
		Color Rnd(255),Rnd(255),Rnd(255)
		Text 0,0,"Copy from backbuffer"
		CopyRect 0,0,256,200,0,0,BackBuffer(),TextureBuffer(tex)
	EndIf
	CopyRect 0,0,256,256,0,-1,TextureBuffer(tex),TextureBuffer(tex)
	RenderWorld
	Text 0,0,"press t/i several times and compare the imagebuffer to the texture - they should look the same"
	DrawImage img,0,15
	Flip
Wend
End



any hints, help, tricks?