CreateGraphics without a backbuffer?

BlitzMax Forums/BlitzMax Programming/CreateGraphics without a backbuffer?

Abomination(Posted 2006) [#1]
In the Help-doc it states:
"Graphics created with the GRAPHICS_BACKBUFFER flag must be 'flipped' after you have finished rendering using Flip."
Does this mean one can create a graphics without a BackBuffer?
And if so, then how?
And would the drawing to such a graphics be done directly to the frontbuffer?
i.o.w. Is there any practicallity to set the GraphicsFlags without GRAPHICS_BACKBUFFER.


Dreamora(Posted 2006) [#2]
No it would be the worst idea you could have.
As Max2D is 3D always you would create serious problems by not using double buffering. (most likely the well known flickering)


Abomination(Posted 2006) [#3]
I don't need nor want Double Buffering.
I want to change very small portions of the screen each frame.
So I can take care of the "cleanup" myself. And for speed reasons I don't want to "reDraw" everything.
I could do:
-----------
flip 0
draw something small
flip
-----------
But,(as XLSIOR stated) you can't actually *count* on the backbuffer not getting cleared by the driver.
So I thougt by being able to draw directly to a frontbuffer I could avoid this "potential?" problem.


Abomination(Posted 2006) [#4]
Take a look at this:

SetGraphicsDriver   GLMax2DDriver(),0
Graphics( 800, 600, 32, 60, 0)
HideMouse()
MoveMouse GraphicsWidth()/2, GraphicsHeight() / 2

Local OldMouseX:Float = MouseX()
Local OldMouseY:Float = MouseY()
Local newmousex:Int
Local newMousey:Int
Local t:Int, temp:Int
Local Before:Int=MilliSecs()
Local RightNow:Int
Local fps:Int
Local AFPS:Int,ACount:Int=0
Local Effect=0 

Cls

For t=0 To 100
	SetColor Rand(0,255),Rand(0,255),Rand(0,255)
	DrawRect 20+t*4,20+t*4,100,100
	SetColor 255,255,255
	Plot t,t
	DrawText "test",t*4,t*4
Next


While Not KeyDown( KEY_ESCAPE)
	If KeyDown(KEY_SPACE) Then effect=1-effect
	SetColor 0,0,0
	DrawRect OldMouseX ,oldMouseY,20,20 'cleaning up after the mouse
	SetColor 255,255,255
	newmousex=Int(MouseX())
	newMousey=Int(MouseY())
	SetColor 255,255,255
	DrawRect NewMouseX ,NewMouseY,20,20
	SetColor 155,25,2
	DrawOval newMouseX ,newMouseY,20,20	
	If effect
		For t=0 To 2000
			SetColor Rand(0,255),Rand(0,255),Rand(0,255)
			Plot Rand(40,600),Rand(40,500)
		Next
	Else
		For t=0 To 2000
			SetColor Rand(0,255),Rand(0,255),Rand(0,255)
			DrawRect newMouseX+30+(t/10) ,newMouseY+30,20,20
		Next
	EndIf	
	OldMouseX =newMouseX
	OldMouseY =newMouseY
	
	RightNow=MilliSecs()
	temp=RightNow-Before
	If temp<1 Then temp=1
	FPS=1000/temp
	Before=RightNow
	ACount=ACount+1
	AFPS=(AFPS+FPS)/2
	If ACount=100
		ACount=0
		SetColor 0,0,0
		DrawRect 20 ,20,40,20
		SetColor 255,255,255
		DrawText afps,20,20	
	EndIf	
	Flip 0 'Has probably absolute no meaning(does Nothing?) 
Wend
EndGraphics

Perhaps it's dirty and not save? because I have no knowledge of GraphicsDrivers whatsoever.
But it "seems" to work.


ImaginaryHuman(Posted 2006) [#5]
The easy answer is yes you do not have to have a backbuffer.

Use:

SetGraphicsDriver(WhateverGraphicsDriver(),0)

Make sure you specify 0 (or whatever combination of actual buffers that you want to be the default), and you will get a display without a backbuffer. Everything you draw will draw straight to the visible buffer as soon as the graphics card decides to flush its list of things to do. Typically that means right away.

There ARE some benefits in some situations to using a single-buffered display system. For one, it lets you keep the same previous contents of the front buffer so you can do things like dirty rectangles and updating the custom mouse pointer without having to redraw and flip the entire display.

Yes it MIGHT be prone to tearing because you are drawing to the same buffer that the video scan is reading from to create visible pixels on the screen, and in most cases it is very likely you WILL get some tearing, and for `slower` drawing routines you may see the progress of the screen being drawn in whatever order you draw your objects. But this doesn't mean you should discard the whole idea. It can be useful for certain kinds of applications/game engines.

So just set the default in the driver to not include GRAPHICS_BACKBUFFER and you're all set.


Abomination(Posted 2006) [#6]
Now, that is exactly what I wanted to hear :)
Thanks A.D.
This will speed things up.