bug or wrong documentation ?(setbuffer and camera)

Archives Forums/Blitz3D Bug Reports/bug or wrong documentation ?(setbuffer and camera)

RemiD(Posted 2016) [#1]
bug or wrong documentation ?(setbuffer and camera)



Firstly the documentation :
http://www.blitzbasic.com/b3ddocs/command.php?name=SetBuffer&ref=2d_a-z
http://www.blitzbasic.com/b3ddocs/command.php?name=CreateCamera&ref=3d_a-z

Secondly, in order to make more friends (and stimulate the discussion :P), i just want to say that many people on these forums have no clue on how to use setbuffer(backbuffer())... ( many put it after Graphics3d() and hope for the best, ;) )

That being said, what is the problem ?

If i use setbuffer(backbuffer()) before creating the camera, then even if i use setbuffer(imagebuffer(ximage)) or setbuffer(texturebuffer(xtexture)), the camera will always render the scene on the backbuffer...

But ! If i use setbuffer(imagebuffer(ximage)) or setbuffer(texturebuffer(xtexture)) (for example when premaking some images/textures that i will use for the game) and then if i create a camera just after, then even if i use setbuffer(backbuffer()) before renderworld() (i want to render the scene on the backbuffer after all...), then the camera seems to render the scene on the last set imagebuffer/texturebuffer (the last buffer set before creating the camera), which is impossible according to the documentation and illogical according to the code (because the use of setbuffer(backbuffer()) before renderworld() which means "render the 3dscene on the backbuffer" (please)... )...

examples :





This bug or undocumented functionality has made me gave up a code in the past because i had not managed to determine the source of the problem, but this time i have found the source of the problem ! It can happen if you create some images/textures procedurally before creating the camera ! (in my case i created a reticle image of 2x2 pixels so it was impossible to see that the camera rendered the 3dscene on this image !)

To fix/prevent the problem : use setbuffer(backbuffer()) before createcamera(), then use setbuffer(backbuffer()) before renderworld() (apparently useless but nonetheless cool).


RemiD(Posted 2016) [#2]
To be more precise, it seems that the cameraviewport width height are modified by the last set buffer width height, but the camera seems to render on the backbuffer, not on the last set imagebuffer/texturebuffer as i thought...


RemiD(Posted 2016) [#3]
So the solution is either what i have mentionned previously :

use setbuffer(backbuffer()) before createcamera(), then use setbuffer(backbuffer()) before renderworld()



Or as an alternative, don't use setbuffer(backbuffer()) before createcamera() but use CameraViewport(Camera,0,0,GraphicsWidth(),GraphicsHeight()) after having created the camera, then use setbuffer(backbuffer()) before renderworld().

(setbuffer(backbuffer()) before renderworld() is to be able to draw images and textes on the backbuffer after the 3dscene has been rendered on the backbuffer...)


Floyd(Posted 2016) [#4]
As far as I know RenderWorld can only draw to the back buffer.

After SetBuffer FrontBuffer() it appears to draw to the front buffer, but this is being faked. It is still rendering to the back buffer, which is then copied to the front buffer.

SetBuffer can be used with Back,Front,Image,Texture buffers. This will change the buffer used for 2D commands.
In fact, you will notice that the documentation page is located at Blitz3D Docs -> 2D etc.

It looks like the description of SetBuffer() was simply copied from the old 2D Blitz Basic docs.

EDIT: I just thought to check the docs for TextureBuffer() http://www.blitzbasic.com/b3ddocs/command.php?name=TextureBuffer&ref=3d_a-z
It does mention that rendering is always to the back buffer.

Graphics3D 800, 600, 0, 2  ; renders to back buffer
AmbientLight 255, 255, 255

cam = CreateCamera()
PositionEntity cam, 0, 0, -2

sph = CreateSphere()
tex = CreateTexture( 512, 512 )
EntityTexture sph, tex

; Some random dots.

SetBuffer TextureBuffer( tex )
For n = 1 To 5000
	WritePixel Rand(511), Rand(511), Rand(16777215)
Next

; At this point the graphics buffer is still the texture buffer.
; But RenderWorld draws to the back buffer, as always.

Repeat
	TurnEntity sph, 0, 0.1, 0
	RenderWorld
	Flip
Until KeyDown(1)



RemiD(Posted 2016) [#5]
Yes, my conclusions in post#1 were wrong, but what i have posted in post#2 post#3 seem correct (the last set buffer before creating a camera, changes the cameraviewport width height, so it seems to be a bug...)


RemiD(Posted 2016) [#6]
So am i the only one to have noticed this bug ? Strange...


Floyd(Posted 2016) [#7]
I think I noticed this when Biltz3D was new ( 2001? ) but had forgotten about it.

My programs typically begin with things common to all my 3D projects: set Graphics3D, create and position camera etc.

After that are program specific tasks like loading assets and setting buffers and drawing to them.

I can't remember the last time I created a camera after a SetBuffer(). If I did do that it probably had this form:

SetBuffer ImageBuffer( something )
Operate on the image
SetBuffer BackBuffer()
; continue with program

If a CreateCamera() appears after this the viewport issue never arises.