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
|