PureBasic 6.21 (x86 / x64)
I'm not sure if this is related to another Bug Report I posted: 2D Sprites Auto Stretch After CloseScreen.
• The following example demonstrates a 2D sprite within a 3D environment.
• Using OpenWindowedScreen the AutoStretch parameter seems to ignore the 2D sprite.
3D + 2D
Code: Select all
Enumeration
#MainWindow
EndEnumeration
InitEngine3D() : InitSprite() : InitKeyboard()
WindowWidth = 600 : WindowHeight = 600
nFlags = #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_SizeGadget | #PB_Window_ScreenCentered | #PB_Window_Invisible
If OpenWindow(#MainWindow, 0, 0, WindowWidth, WindowHeight, "Include 2D sprites within a 3D environment", nFlags)
SetWindowColor(#MainWindow, RGB(0, 0, 0))
WindowBounds(#MainWindow, WindowWidth, WindowHeight, #PB_Default, #PB_Default)
If OpenWindowedScreen(WindowID(#MainWindow), 0, 0, WindowWidth, WindowHeight, #True, 0, 0)
SetFrameRate(60) : SpriteQuality(#PB_Sprite_BilinearFiltering)
CreateSprite(0, 20, 20, #PB_Sprite_AlphaBlending)
If StartDrawing(SpriteOutput(0))
Box(0, 0, 20, 20, RGB(255, 0, 155))
Box(5, 5, 10, 10, RGB(155, 0, 255))
StopDrawing()
EndIf
direction = 2
Add3DArchive(#PB_Compiler_Home + "examples/3d/Data/Textures", #PB_3DArchive_FileSystem)
Parse3DScripts()
CreateCamera(0, 0, 0, 100, 100)
MoveCamera(0, 0, 5, 0)
CameraLookAt(0, 2, 5, 10)
TextureSky = LoadTexture(#PB_Any, "sky.png")
SkyDome(TextureID(TextureSky), $cc6600, $0088ff, 3, 400, -0.5, 0)
CreateLight(0, $ff88ff, 20000, 40000, 20000)
AmbientColor($010101)
Fog($554488,1, 0, 1024 * 4)
HideWindow(#MainWindow, #False)
Repeat
Repeat
Event = WindowEvent()
Select Event
Case #PB_Event_CloseWindow
Select EventWindow()
Case #MainWindow : Break 2
EndSelect
EndSelect
Until Not Event
FlipBuffers() : RenderWorld() : ExamineKeyboard()
If KeyboardReleased(#PB_Key_Escape) : Break : EndIf
DisplayTransparentSprite(0, x, x)
x + direction
If x > WindowWidth - 20 : direction = -2 : EndIf
If x < 0 : direction = 2 : EndIf
ForEver
EndIf
EndIf
Code: Select all
Enumeration
#MainWindow
EndEnumeration
InitSprite() : InitKeyboard()
WindowWidth = 600 : WindowHeight = 600
nFlags = #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_SizeGadget | #PB_Window_ScreenCentered | #PB_Window_Invisible
If OpenWindow(#MainWindow, 0, 0, WindowWidth, WindowHeight, "Include 2D sprites within a 3D environment", nFlags)
SetWindowColor(#MainWindow, RGB(0, 0, 0))
WindowBounds(#MainWindow, WindowWidth, WindowHeight, #PB_Default, #PB_Default)
If OpenWindowedScreen(WindowID(#MainWindow), 0, 0, WindowWidth, WindowHeight, #True, 0, 0)
SetFrameRate(60) : SpriteQuality(#PB_Sprite_BilinearFiltering)
CreateSprite(0, 20, 20, #PB_Sprite_AlphaBlending)
If StartDrawing(SpriteOutput(0))
Box(0, 0, 20, 20, RGB(255, 0, 155))
Box(5, 5, 10, 10, RGB(155, 0, 255))
StopDrawing()
EndIf
direction = 2
HideWindow(#MainWindow, #False)
Repeat
Repeat
Event = WindowEvent()
Select Event
Case #PB_Event_CloseWindow
Select EventWindow()
Case #MainWindow : Break 2
EndSelect
EndSelect
Until Not Event
FlipBuffers() : ClearScreen($000000) : ExamineKeyboard()
If KeyboardReleased(#PB_Key_Escape) : Break : EndIf
DisplayTransparentSprite(0, x, x)
x + direction
If x > WindowWidth - 20 : direction = -2 : EndIf
If x < 0 : direction = 2 : EndIf
ForEver
EndIf
EndIf