3D, DrawImage, and Double Buffering don't mix

Blitz3D Forums/Blitz3D Beginners Area/3D, DrawImage, and Double Buffering don't mix

Shifty Geezer(Posted 2005) [#1]
I'm using DrawImagineRect to draw controls and a mouse pointer on a 3D scene. It all works swimmingly well, drawing my nice mouse pointer, clicking buttons, with my routines redrawing the interface under the mouse pointer when it's moved - until I switch from a windowed display to a full screen display.

Now the buttons flicker. Note they are outside the render viewport. The mouse pointer works over the 3D rendering, but leaves trails on the interface. I can solve the flickering by drawing to BOTH the frontbuffer and backbuffer, but that's twice as many writes as I need. I'd have thought I write to the backbuffer and then that's flipped to view.

As the rendering is fine when using DrawImage over the 3D rendering viewport, it seems to be behaviour I didn't expect outside the viewport, almost as though outside the viewport is cleared to black each frame or something wierd.

Anyone know how I can solve this rendering problem?
Graphics3D 800,600,32,1
SetBuffer BackBuffer()

Type TG_pointer
	Field image%		; Pointer to image buffer
	Field pos_x%		; x position
	Field pos_y%		; y position
	Field siz_x%		; x size
	Field siz_y%		; y size
End Type
Type TG_background
	Field image%		; Pointer to image buffer
	Field pos_x%		; x position
	Field pos_y%		; y position
	Field siz_x%		; x size
	Field siz_y%		; y size
End Type

Global pointer.TG_pointer
Global background.TG_background

pointer.TG_pointer = New TG_pointer
	pointer\image=LoadImage("icons\pointer.png")
	pointer\pos_x=MouseX()
	pointer\pos_y=MouseY()
	pointer\siz_x=ImageWidth(pointer\image)
	pointer\siz_y=ImageHeight(pointer\image)	

background.TG_background = New TG_background
	background\image=LoadImage("icons\controls.png")
	background\pos_x=700
	background\pos_y=0
	background\siz_x=ImageWidth(background\image)
	background\siz_y=ImageHeight(background\image)

camera=CreateCamera()
CameraZoom camera,20
PositionEntity camera,-25,0,-50
CameraViewport camera,0,0,600,600

light=CreateLight()
AmbientLight 0,0,0
sphere=CreateSphere(20)

PointEntity camera,sphere
DrawImage background\image,600,0

While Not KeyDown( 1 )
	RenderWorld
	TG_Draw_Mouse()
	Flip
Wend

End


; ******************************* FUNCTIONS ************************


Function TG_Draw_Mouse()
	; FUNCTION : draws the mouse pointer, preserving the background interface graphics
	
	If RectsOverlap (pointer\pos_x, pointer\pos_y, pointer\siz_x, pointer\siz_y, background\pos_x, background\pos_y, background\siz_x, background\siz_y)
		DrawImageRect (background\image, pointer\pos_x, pointer\pos_y, pointer\pos_x-background\pos_x,  pointer\pos_y-background\pos_y, pointer\siz_x, pointer\siz_y)
	EndIf
	
	pointer\pos_x=MouseX()
	pointer\pos_y=MouseY()
	DrawImage (pointer\image, pointer\pos_x, pointer\pos_y)
End Function



fall_x(Posted 2005) [#2]
I don't have the time right now to read trough all the code, but I can tell you that I have succesfully used 3d, drawimage and double buffering without flickering, so there is probably a solution.


DJWoodgate(Posted 2005) [#3]
The backbuffer is flipped into view, but what was the front buffer is then sent to the back. And there is nothing on the fronbuffer initially, hence your flickering problem. It's different in windowed mode, there I think the backbuffer is just copied to the frontbuffer.

Personally I would just draw the whole interface graphic and then the mousepointer each frame and avoid the syncing issues. It's not going to cost that much over what you are doing at the moment... you are already mixing 2d and 3d so you are just talking about the difference in speed between blitting a couple of small images and one largish one and a small one. Sure there will be a difference, but it will be tiny.

Function TG_Draw_Mouse()
	; FUNCTION : draws the interface and mouse pointer.
        DrawBlock background\image,600,0
	pointer\pos_x=MouseX()
	pointer\pos_y=MouseY()
	DrawImage (pointer\image, pointer\pos_x, pointer\pos_y)
End Function



Shifty Geezer(Posted 2005) [#4]
I've a choice between rendering without a viewport, rendering full screen, and drawing over the top which works, or rendering to a viewport and manually copying bits of image to fill in the flipped gaps.

Which do you reckon would be faster? The 3D's dead simple stuff.


Mustang(Posted 2005) [#5]
I have layers like 2D > 3D > 2D on top of that on my (game setup) GUI and everything is Smoooooth. I also have a mouse there, all without problems. You just have to use flip intelligently... oh, and I run this in windowed mode too, not in full-screen (which would have been easier).


Shifty Geezer(Posted 2005) [#6]
I don't have a problem in windowed mode. It seems the buffer flipping is automatic in windows. It's only when I go full-creen and draw in an area outside the viewport that the buffers don't get copied or whatever it is that's supposed to happen.


DJWoodgate(Posted 2005) [#7]
I have posted an amended TG_draw_Mouse Function above for you to try. I use drawblock which will ignore use of the mask color.


alexart5(Posted 2012) [#8]
While Not KeyDown( 1 )
RenderWorld
TG_Draw_Mouse()
Flip : cls
Wend


Ross C(Posted 2012) [#9]
You have just bumped a 7 year old post.