Page 1 of 1

UseBuffer() for Mac OS X - simple workaround

Posted: Fri Jul 30, 2010 10:10 pm
by Lebostein
It works! And its fully compatible with Windows or Linux. :D

This code works with fixed sprite numbers only!

Code: Select all

; =======================================
CompilerIf #PB_Compiler_OS = #PB_OS_MacOS
; =======================================

Procedure UseBuffer(Sprite.l)

  Shared UsedSprite.l

  If Sprite = #PB_Default And IsSprite(UsedSprite)

    GrabSprite(UsedSprite, 0, 0, SpriteWidth(UsedSprite), SpriteHeight(UsedSprite))
    UsedSprite = #PB_Default

  ElseIf IsSprite(Sprite)

    DisplaySprite(Sprite, 0, 0)
    UsedSprite = Sprite

  EndIf

EndProcedure

; =======================================
CompilerEndIf
; =======================================

#Sprite1 = 1
#Sprite2 = 2

InitSprite()
OpenWindow(0, 100, 100, 512, 512, "Test", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(0), 0, 0, 512, 512, 0, 0, 0)

TransparentSpriteColor(#PB_Default, $FF00FF)
CreateSprite(#Sprite1, 240, 240)
LoadSprite(#Sprite2, #PB_Compiler_Home + "examples/sources/Data/Geebee2.bmp")

UseBuffer(#Sprite1)
ClearScreen($FF0000)
DisplayTransparentSprite(#Sprite2, 10, 10)
DisplayTransparentSprite(#Sprite2, 100, 10)
DisplayTransparentSprite(#Sprite2, 10, 100)
DisplayTransparentSprite(#Sprite2, 100, 100)
UseBuffer(#PB_Default) ; now required to save the changes!

Repeat
  ClearScreen($0000FF)
  DisplaySprite(#Sprite1, WindowMouseX(0), WindowMouseY(0))
  FlipBuffers()
Until WaitWindowEvent(10) = #PB_Event_CloseWindow
Inside the main loop, use it before you clear the screen:

Code: Select all

Repeat

  UseBuffer(#Sprite1)
  ...
  UseBuffer(#PB_Default) ; now required to save the changes!


  UseBuffer(#Sprite2)
  ...
  UseBuffer(#PB_Default) ; now required to save the changes!


  ClearScreen()
  ...
  FlipBuffers()

Until WaitWindowEvent(10) = #PB_Event_CloseWindow

Re: UseBuffer() for Mac OS X - simple workaround

Posted: Fri Sep 10, 2010 5:00 am
by X
For DirectX7 on windows? Tried with DirectX9, always get that "number is too high" error.

Re: UseBuffer() for Mac OS X - simple workaround

Posted: Wed Nov 10, 2010 5:01 pm
by Lebostein
DirectX 9 on Mac OS? :|

You are in the Mac OS specific forums. But, this code should work with Windows too... Can anybody test this code with Windows?

Re: UseBuffer() for Mac OS X - simple workaround

Posted: Fri Nov 12, 2010 8:47 pm
by Shardik
Lebostein wrote:But, this code should work with Windows too... Can anybody test this code with Windows?
I have tested the first code example of your first posting on following systems with PB 4.51:

- Windows 98 SE (subsystem DirectX7: OK, no subsystem: error "Line: 32 - Invalid memory access (read error at address 4294567295)")
- Windows XP SP2 x86 (subsystem DirectX7: OK, no subsystem: works, but displays black box sprite)
- Windows 7 x64 with PB x86 (subsystem DirectX7: OK, no subsystem: works, but displays black box sprite)
- Windows 7 x64 with PB x64 (subsystem DirectX7: OK, no subsystem: works, but displays black box sprite)
- andLinux/Kubuntu 9.04 x86 (no subsystem: terminates with message "The debugged executable quit unexpectedly")
- Xubuntu 10.04 x86 (no subsystem: OK)
- MacOS X 10.6.4 (no subsystem: OK)