Page 1 of 1

bug 3D + Sprite

Posted: Fri Jun 06, 2025 9:57 am
by pf shadoko
on 1st texture creation it's ok, but if you recreate it, the alpha component of the mipmaps is altered
I hope it's reproducible, can you confirm?

to test, press space
if you remove the displaysprite, it doesn't bug.

Code: Select all

InitEngine3D()
InitSprite()
InitKeyboard()
InitMouse()

ExamineDesktops():dx=DesktopWidth(0)*0.8:dy=DesktopHeight(0)*0.8
OpenWindow(0, 0,0, DesktopUnscaledX(dx),DesktopUnscaledY(dy), "3D + Sprite -> bug alpha mipmap - [espace] [Esc] quit",#PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(0), 0, 0, dx, dy, 0, 0, 0)
AmbientColor($111111*7)

CreateCamera(0, 0, 0, 100, 100)
MoveCamera(0, 0, 50, 200, #PB_Absolute)
CameraLookAt(0,0,0,0)
CameraBackColor(0,$884488)

CreateLight(0,$ffffff,0,1000,-4000)
CreateSprite(0,256,256,#PB_Sprite_AlphaBlending)

Procedure initmat()
  l=512
  CreateTexture(0, l, l)
  StartDrawing(TextureOutput(0))
  DrawingMode(#PB_2DDrawing_AllChannels)
  For i=0 To 255:Box(i,i,l-2*i,l-2*i,RGBA(255,255,255,i)):Next
  StopDrawing()
  CreateMaterial(0,TextureID(0))
  MaterialBlendingMode(0,#PB_Material_AlphaBlend)
  CreatePlane(0,1000,1000,10,10,10,10)
  CreateEntity(0,MeshID(0),MaterialID(0),0,00,0)
  MaterialCullingMode(0,#PB_Material_NoCulling)
EndProcedure

initmat()

Define.f KeyX, KeyY, MouseX, MouseY
Repeat
  While WindowEvent():Wend
  
  ExamineMouse()
  MouseX = -MouseDeltaX() *  0.05
  MouseY = -MouseDeltaY() *  0.05
  
  ExamineKeyboard()    
  KeyX = (KeyboardPushed(#PB_Key_Right)-KeyboardPushed(#PB_Key_Left))
  Keyy = (KeyboardPushed(#PB_Key_Down)-KeyboardPushed(#PB_Key_Up)-MouseWheel()*20)
  If KeyboardReleased(#PB_Key_Space):initmat():EndIf
   
  RotateCamera(0, MouseY, MouseX, 0, #PB_Relative)
  MoveCamera  (0, KeyX, 0, KeyY)
  
  RenderWorld()
  DisplaySprite(0,8,8)
  FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape) Or Quit = 1 Or MouseButton(3)


Re: bug 3D + Sprite

Posted: Fri Jun 06, 2025 10:50 am
by miso
I confirm. If sprite is displayed before flipbuffers, the texture creation is different. I modified the example to show it better, leftshift displays the sprite
(and makes the issue)

Code: Select all

InitEngine3D()
InitSprite()
InitKeyboard()
InitMouse()

ExamineDesktops():dx=DesktopWidth(0)*0.8:dy=DesktopHeight(0)*0.8
OpenWindow(0, 0,0, DesktopUnscaledX(dx),DesktopUnscaledY(dy), "3D + Sprite -> bug alpha mipmap - [espace] [Esc] quit",#PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(0), 0, 0, dx, dy, 0, 0, 0)
AmbientColor($111111*7)

CreateCamera(0, 0, 0, 100, 100)
MoveCamera(0, 0, 50, 200, #PB_Absolute)
CameraLookAt(0,0,0,0)
CameraBackColor(0,$884488)

CreateLight(0,$ffffff,0,1000,-4000)
CreateSprite(0,256,256,#PB_Sprite_AlphaBlending)

Procedure initmat()
  l=512
  CreateTexture(0, l, l)
  StartDrawing(TextureOutput(0))
  DrawingMode(#PB_2DDrawing_AllChannels)
  For i=0 To 255:Box(i,i,l-2*i,l-2*i,RGBA(255,255,255,i)):Next
  StopDrawing()
  CreateMaterial(0,TextureID(0))
  MaterialBlendingMode(0,#PB_Material_AlphaBlend)
  CreatePlane(0,1000,1000,10,10,10,10)
  CreateEntity(0,MeshID(0),MaterialID(0),0,00,0)
  MaterialCullingMode(0,#PB_Material_NoCulling)
EndProcedure

initmat()

Define.f KeyX, KeyY, MouseX, MouseY
Repeat
  While WindowEvent():Wend
  
  ExamineMouse()
  MouseX = -MouseDeltaX() *  0.05
  MouseY = -MouseDeltaY() *  0.05
  
  ExamineKeyboard()    
  KeyX = (KeyboardPushed(#PB_Key_Right)-KeyboardPushed(#PB_Key_Left))
  Keyy = (KeyboardPushed(#PB_Key_Down)-KeyboardPushed(#PB_Key_Up)-MouseWheel()*20)
  If KeyboardReleased(#PB_Key_Space):initmat():EndIf
   
  RotateCamera(0, MouseY, MouseX, 0, #PB_Relative)
  MoveCamera  (0, KeyX, 0, KeyY)
  
  RenderWorld()
  If KeyboardPushed(#PB_Key_LeftShift) : DisplayTransparentSprite(0,8,8) : EndIf
  FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape) Or Quit = 1 Or MouseButton(3)