TextureBuffer() problem on old graphic cards

Blitz3D Forums/Blitz3D Programming/TextureBuffer() problem on old graphic cards

alain(Posted 2011) [#1]
Hi there,

On my application I am capturing the 3D screen to save it as bitmap.

The first method I use is the following:

bu = FrontBuffer()
im = CreateImage(GraphicsWidth(),GraphicsHeight())
CopyRect 0,0,GraphicsWidth(),GraphicsHeight(),0,0,bu,ImageBuffer(im)		
FiSaveImage(im,"test1.jpg") ;Free Image library


This one works well on all machines but is slow.

I changed the way to do this by:

bu = FrontBuffer()
im = CreateTexture(GraphicsWidth(),GraphicsHeight(),1)
CopyRect 0,0,GraphicsWidth(),GraphicsHeight(),0,0,bu,TextureBuffer(im)
ModifiedFiSaveImage (im,"test2.jpg") ; ModifiedFree Image library


I use textures instead of images.

This one is faster but on old machines, the image is black (nothing is copied on the image)

I tried to use power of 2 textures but it doesn't help.

2 questions:
- Why the second version is not working on some hardware?
- How can I detect automatically which version I should use? (I tried to check the result of CreateTexture() but it is always successful)

Here follow my complete test program. On new systems, it should show 1 picture and 2 cubes with a texture (blue with a gray box), and on old system it should display 1 blue picture with a gray box and two black cubes.

Graphics3D 800,600,32,2
SetBuffer BackBuffer()

;images and buffer creation
im = CreateImage(GraphicsWidth(),GraphicsHeight())
If(im=0) Then 	RuntimeError("Unable to create image")
tex1 = CreateTexture(GraphicsWidth(),GraphicsHeight(),1)
If(tex1=0) Then 	RuntimeError("Unable to create texture (1)")
tex2 = CreateTexture(1024,512,1)
If(tex2=0) Then 	RuntimeError("Unable to create texture (2)")


;creating a simple scene
camera=CreateCamera()
CameraClsColor camera,0,0,128
light=CreateLight()
RotateEntity light,40,0,0
cube=CreateCube()
PositionEntity cube,0,0,5
TurnEntity cube,45,20,0
RenderWorld
Flip

;capture it
bu = FrontBuffer()
CopyRect 0,0,GraphicsWidth(),GraphicsHeight(),0,0,bu,ImageBuffer(im)		
CopyRect 0,0,GraphicsWidth(),GraphicsHeight(),0,0,bu,TextureBuffer(tex1)
CopyRect 0,0,GraphicsWidth(),GraphicsHeight(),0,0,bu,TextureBuffer(tex2)

HideEntity cube
CameraClsColor camera,255,255,255

;display the images
cube1 = CreateCube()
cube2 = CreateCube()
EntityTexture cube1,tex1
EntityTexture cube2,tex2
PositionEntity cube1,0,1.3,5
PositionEntity cube2,3,1.3,5


RenderWorld
ScaleImage im,0.3,0.3
DrawImage im,10,50
Flip

WaitKey()

End


Any help appreciated, as I have no old hardware to test with.


jfk EO-11110(Posted 2011) [#2]
So this is directed to FastImage Library. Couldn't you use SaveBuffer(backbuffer(),"test.bmp") ? Or does it have to be JPG? (Is it saving JPG at all?)


alain(Posted 2011) [#3]
I don't use FastImage, only FreeImage to save the bitmap as jpg... but I don't think it is related to FreeImage.

I was using SaveBuffer() in the past, but it very slow, and after I have to convert it to jpg or png. As I am creating a movie from the 3D animation, the speed is really important, that's why I am using texture instead of images it is faster.


jfk EO-11110(Posted 2011) [#4]
Ok, then I was completely wrong. Tho, it might be pretty much of a challenge to do this real fast. Have you thought about to use the Movie saving code from the archives? http://www.blitzbasic.com/codearcs/codearcs.php?code=1661


alain(Posted 2011) [#5]
Just checked this thread:
http://www.blitzbasic.com/Community/posts.php?topic=92689#1059281

And maybe the problem is:

tex2 = CreateTexture(1024,512,1)

that should be replaced by

tex2 = CreateTexture(1024,512,1+256+512)

I will send the updated test program to my customer and we'll see.


alain(Posted 2011) [#6]
ok,

the problem was the flag on createTexture.

using CreateTexture(w,h,1+256+512) it works everywhere.

Thanks Adam Novagen for the tip!


Axel Wheeler(Posted 2011) [#7]

Wow. That was my topic and I didn't realize people kept posting to it.

The strange thing about Adam's code is that DrawImage() is ignoring the black pixels (i.e. not copying them) even though the texture isn't a mask. In fact there are no masks or alpha anything anywhere in the code. So I:

1. Tried changing ClsColor to 0,0,1 and found that it then does copy the color, making it black (well, nearly)

2. Tried DrawBlock() and found that it too copied the black pixels.

So do we conclude that DrawImage() doesn't copy black pixels, even when there are no mask/transparency settings?