Recently I have been playing with some of the drawing functions in gdi32.dll. I've found the rect and line functions are at least two times faster than native b+ commands. The only problem I have is that the shapes flicker, especially in fullscreen. Can someone verify they get the same behavior and hopefully offer a solution?
Userlib:
.lib "user32.dll"
GetDC%(hwnd%)
ReleaseDC%(hwnd%, hdc%)
GetActiveWindow%()
RedrawWindow%(hwnd%, lprcUpdate%, hrgnUpdate%, fuRedraw%)
UpdateWindow%(hWnd%)
.lib "gdi32.dll"
CreatePen%(nPenStyle%, nWidth%, crColor%)
DeleteObject%(hObject%)
SelectObject%(hdc%, hObject%)
Rectangle%(hdc%, X1%, Y1%, X2%, Y2%)
(make sure to erase duplicate declarations in your other decls files)
b3d/b+ code:
Graphics 640, 480, 16, 1
; // Get Device Context
hWnd% = GetActiveWindow()
Global DC% = GetDC(hWnd%)
If Not DC% Then End ; Failed
ReleaseDC hWnd%, DC% ; Release
; // Pen Styles
Const PS_SOLID = 0
Const PS_DOT = 2
Const TB_RED = 255
Const TB_BLUE = 16711680
Const TB_GREEN = 65280
Local fps_Count = 0, fps_Current = 0, fps_Time# = MilliSecs() + 1 ; FPS Counter
turbo_Pen PS_SOLID, 5, TB_RED
tmpX = 50: tmpY = 50
While Not KeyDown(1)
Cls
fps_Count = fps_Count + 1
If MilliSecs() >= fps_Time Then fps_Current = fps_Count: fps_Count = 0: fps_Time = fps_Time + 1000
Turbo_Rect 50, 50, tmpX, tmpY ; Draw Rect with api
tmpX = tmpX + 1: tmpY = tmpY + 1
If KeyDown(1) Then End
Color 255, 255, 255: Text 1, 1, "FPS: " + fps_Current
;RedrawWindow hWnd, 0, 0, 1
;UpdateWindow hWnd
Flip 1
Wend: End
Function Turbo_Rect(X, Y, W, H)
Rectangle DC%, X, Y, X + W, Y + H
End Function
Function turbo_Pen(Style, Width, CrCol)
DeleteObject tb_Pen
tb_Pen = CreatePen(Style, Width, CrCol)
DeleteObject SelectObject(DC%, tb_Pen)
End Function
I tried Redraw and UpdateWindow but they didnt help with the flicker.
|