CreateSprite and OpenGL Subsystem

Post bugreports for the Windows version here
User avatar
Paul
PureBasic Expert
PureBasic Expert
Posts: 1243
Joined: Fri Apr 25, 2003 4:34 pm
Location: Canada
Contact:

CreateSprite and OpenGL Subsystem

Post by Paul »

There seems to be a problem when using CreateSprite() and the OpenGL subsystem and this code snippet demonstrates...
(Drawing commands have issues when drawing on a sprite created using CreateSprite() with the #PB_Sprite_AlphaBlending flag)

3rd Window opened in the code snippet requires a 256x256 image you can download here...
https://reelmedia.org/test/box.bmp

Code: Select all

InitSprite()
#screen=1
#sprite=2

If OpenWindow(#screen,0,0,640,480,"Screen",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
  OpenWindowedScreen(WindowID(#screen),0,0,640,480,1,0,0)
  
  CreateSprite(#sprite,256,256)
  If StartDrawing(SpriteOutput(#sprite))
    Box(0,0,256,256,$0000FF)
    StopDrawing()
  EndIf
  
  Repeat
    ClearScreen($FF0000)
    DisplaySprite(#sprite,50,50) ;red displayed - OK
    FlipBuffers()
  Until WaitWindowEvent(1)=#PB_Event_CloseWindow
  CloseWindow(#screen)
EndIf


If OpenWindow(#screen,0,0,640,480,"Screen",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
  OpenWindowedScreen(WindowID(#screen),0,0,640,480,1,0,0)
  
  CreateSprite(#sprite,256,256,#PB_Sprite_AlphaBlending)
  If StartDrawing(SpriteOutput(#sprite))
    Box(0,0,256,256,$0000FF)
    StopDrawing()
  EndIf
    
  Repeat
    ClearScreen($FF0000)
    DisplaySprite(#sprite,50,50) ;black displayed - ERR
    FlipBuffers()
  Until WaitWindowEvent(1)=#PB_Event_CloseWindow
  CloseWindow(#screen)
EndIf


If OpenWindow(#screen,0,0,640,480,"Screen",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
  OpenWindowedScreen(WindowID(#screen),0,0,640,480,1,0,0)
  
  LoadSprite(#sprite,"box.bmp",#PB_Sprite_AlphaBlending)
  If StartDrawing(SpriteOutput(#sprite))
    Box(0,0,256,256,$0000FF)
    StopDrawing()
  EndIf
    
  Repeat
    ClearScreen($FF0000)
    DisplaySprite(#sprite,50,50) ;red displayed - OK
    FlipBuffers()
  Until WaitWindowEvent(1)=#PB_Event_CloseWindow
  CloseWindow(#screen)
EndIf
With the Default OpenGL subsystem...
First window which uses CreateSprite() without flags allows the red box to be drawn on the sprite and displays as expected.
Second window which uses CreateSprite() with #PB_Sprite_AlphaBlending flag, drawing a red box on the sprite does not work and the box displays as empty.
Third window which loads a black 256x256 image using LoadSprite() with #PB_Sprite_AlphaBlending flag allows the red box to be drawn on the sprite and displays as expected.
Image


If the Subsystem is set to DirectX11, all windows display as expected...
Image
Last edited by Paul on Wed Aug 24, 2022 12:07 am, edited 3 times in total.
Image Image
User avatar
Paul
PureBasic Expert
PureBasic Expert
Posts: 1243
Joined: Fri Apr 25, 2003 4:34 pm
Location: Canada
Contact:

Re: CreateSprite and OpenGL Subsystem

Post by Paul »

On a related note, if the Subsystem is set to DirectX9 and "DPI aware" is not enabled, all windows display as expected...
Image

BUT ... if the Subsystem is set to DirectX9 and "DPI aware" IS enabled, the windows do not adhere to the "Auto Stretch" option in the OpenWindowedScreen() command. (4k monitor @ 175% scaling)...
Image
Image Image
User avatar
STARGÅTE
Addict
Addict
Posts: 2067
Joined: Thu Jan 10, 2008 1:30 pm
Location: Germany, Glienicke
Contact:

Re: CreateSprite and OpenGL Subsystem

Post by STARGÅTE »

If you create a sprite with #PB_Sprite_AlphaBlending, the sprite has 32 bit.
This code works for me, even if #PB_2DDrawing_AlphaBlend is not officially supported für SpriteOutput.

Code: Select all

  CreateSprite(#sprite,256,256,#PB_Sprite_AlphaBlending)
  If StartDrawing(SpriteOutput(#sprite))
    DrawingMode(#PB_2DDrawing_AlphaBlend)
    Box(0,0,256,256,$FF0000FF)
    StopDrawing()
  EndIf
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and moreTypeface - Sprite-based font include/module
User avatar
ChrisR
Addict
Addict
Posts: 1127
Joined: Sun Jan 08, 2017 10:27 pm
Location: France

Re: CreateSprite and OpenGL Subsystem

Post by ChrisR »

Yes and it also works with the other alpha channel drawing modes.
Shouldn't DrawingMode(#PB_2DDrawing_AlphaBlend) be set by default, when StartDrawing a Sprite that has the flag #PB_Sprite_AlphaBlending ?
User avatar
Paul
PureBasic Expert
PureBasic Expert
Posts: 1243
Joined: Fri Apr 25, 2003 4:34 pm
Location: Canada
Contact:

Re: CreateSprite and OpenGL Subsystem

Post by Paul »

STARGÅTE wrote: Wed Aug 24, 2022 6:44 am If you create a sprite with #PB_Sprite_AlphaBlending, the sprite has 32 bit.
This code works for me, even if #PB_2DDrawing_AlphaBlend is not officially supported für SpriteOutput.

Code: Select all

  CreateSprite(#sprite,256,256,#PB_Sprite_AlphaBlending)
  If StartDrawing(SpriteOutput(#sprite))
    DrawingMode(#PB_2DDrawing_AlphaBlend)
    Box(0,0,256,256,$FF0000FF)
    StopDrawing()
  EndIf
Yes, but it does not explain why DrawingMode() is only needed with OpenGL subsystem and why it is not needed when drawing on an image acquired with LoadSprite() + #PB_Sprite_AlphaBlending
Image Image
User avatar
IceSoft
Addict
Addict
Posts: 1616
Joined: Thu Jun 24, 2004 8:51 am
Location: Germany

Re: CreateSprite and OpenGL Subsystem

Post by IceSoft »

STARGÅTE wrote: Wed Aug 24, 2022 6:44 am If you create a sprite with #PB_Sprite_AlphaBlending, the sprite has 32 bit.
This code works for me, even if #PB_2DDrawing_AlphaBlend is not officially supported für SpriteOutput.

Code: Select all

  CreateSprite(#sprite,256,256,#PB_Sprite_AlphaBlending)
  If StartDrawing(SpriteOutput(#sprite))
    DrawingMode(#PB_2DDrawing_AlphaBlend)
    Box(0,0,256,256,$FF0000FF)
    StopDrawing()
  EndIf
Works also here +> get red box
without DrawingMode(#PB_2DDrawing_AlphaBlend) i get a black box
Belive!
<Wrapper>4PB, PB<game>, =QONK=, PetriDish, Movie2Image, PictureManager,...
Post Reply