Problem with BackBuffer and CopyRect

Blitz3D Forums/Blitz3D Programming/Problem with BackBuffer and CopyRect

KuRiX(Posted 2005) [#1]
Everybody says that i can render, then copyrect to a texturebuffer and use the texture, but i can't get it to work. Here is my code, press Up Key to see the problem:

Graphics3D 640,480,16,2
SetBuffer BackBuffer()

c = CreateCamera()

cube = CreateCube()
PositionEntity cube,0,0,5
CameraClsColor c,100,100,100
t = CreateTexture(640,480)

While (Not KeyHit(1))
	CopyRect 0,0,640,480,0,0,BackBuffer(),TextureBuffer(t)

	If (KeyDown(200)) EntityTexture cube,t
	RenderWorld	
	Flip
Wend

End


P.D: I think that the problem is that the texture created will be of 1024x512, so copying 640x480 gives only part of the texture. But i don't want to use the resizeimage, so... what to do?


KuRiX(Posted 2005) [#2]
Ok, the only way it is to set the Viewport to a reasonable texture size (example: 512x512).

Well, but... greater viewports are slower, no?
wow, CopyRect is slow as Hell!!!


jfk EO-11110(Posted 2005) [#3]
use the faster texture flag "256"!!!


KuRiX(Posted 2005) [#4]
Well, thanks, it is faster indeed... 2x.

Anyway it is too slow to be used with 4 viewports. I think i will optimize the refresh time by only refreshing when needed. Thanks!


BlitzSupport(Posted 2005) [#5]
I ran into this with my 'real mirrors' code quite a while ago. My 'solution' was to step back to the nearest power-of-two size if the texture was going to be wider or higher than the display size. See the realmirrors.bb file, at the very top and at the start of CreateRealMirror ().


KuRiX(Posted 2005) [#6]
Hello James. Thanks for the post. I have 4 viewports, with 320x240 each. I tried 256x256 for each, but the result was too poor, so i needed to change to 512x512, that is really slower...

Thanks anyway!


Sledge(Posted 2005) [#7]
Although texture sizes should be powers of two, they don't need to be. In your original example, KuRiX, you could scale and position the texture so that the rendered section gets mapped onto the object without the blank edges showing. If you were sneaky.


KuRiX(Posted 2005) [#8]
As Blitz3D help says, although you select a texture size different of power of two, the graphics card cannot allow this, and it is automatically resized.

I have tried to create a 320,240 texture size but when checking for its size it says 512x256.

If ResizeImage were really fast, i could draw to a 320x240 image then resize to 512x512 texture, but it isn't.


jfk EO-11110(Posted 2005) [#9]
Why don't you use 512*256 in the first place, instead of 512*512? it's closer to 320*240.


KuRiX(Posted 2005) [#10]
Yeah, that is what i thought, but i can't believe that when doing this it appears streched!

This should be my fault, i hope.

Thanks!

P.D: After Doing some tests, i have notices that certainly the texure will be streched, so aspect ratio is changed in the object textured (the image)


jfk EO-11110(Posted 2005) [#11]
Yes, but this is going to happen anyway, no matter if it's 512*256 or 512*512.

What you can do is: use 512*256, but copyrect only 320*240, then set the UV Coords of the mesh in a way that will use the 320*240 area only. So it won't be stretched.

u2#=(320.0/512.0)
v2#=(240.0/256.0)

where a quad would use:
u0,v0____u1,v1
¦            ¦
¦            ¦
¦            ¦
u3,v3____u2,v2 



KuRiX(Posted 2005) [#12]
MMM, yes, this looks like a possible solution. Thanks