[RESOLVED] OpenWindowedScreen & DrawText

Just starting out? Need help? Post your questions and find answers here.
Atlante
User
User
Posts: 22
Joined: Mon Jun 27, 2011 1:39 pm
Location: FRANCE

[RESOLVED] OpenWindowedScreen & DrawText

Post by Atlante »

Hello,

I think i'm finding a bug with this function :
OpenWindowedScreen(WindowID(0), 0, 0, 1, 1, 1, 0, 0) : Auto resizing

Code: Select all

If InitSprite() = 0 Or InitKeyboard() = 0
  MessageRequester("Error", "Sprite system can't be initialized", 0)
  End
EndIf
If InitMouse() = 0
  MessageRequester("Error", "Mouse system can't be initialized correctly", 0)
  End
EndIf

If InitSprite3D() = 0
  MessageRequester("Error", "Sprite3D system can't be initialized correctly", 0)
  End
EndIf

   ExamineDesktops()

  If OpenWindow(0, 0, 0, DesktopWidth(0), DesktopHeight(0), "test", #PB_Window_Maximize | #PB_Window_SizeGadget | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget )
 If OpenWindowedScreen(WindowID(0), 0, 0, 1, 1, 1, 0, 0)  ; automatiquement étiré.
    Else
      MessageRequester("Erreur", "Impossible d'initialiser la graphique 2d", 0)
      End
    EndIf
  EndIf

  Repeat
    
    Repeat
      Event = WindowEvent()
      
      If Event = #PB_Event_CloseWindow
        End 
      EndIf
    Until Event = 0
   
    ClearScreen(RGB(0, 0, 0))
    
   
    
     
  If StartDrawing(ScreenOutput())
       DrawText(20, 20,"TEST 2D")
       DrawText(500, 500,"TEST 2D",RGB(255,0,0))
      StopDrawing()
    EndIf
    
    FlipBuffers() 
    
ForEver

You don't see the test but normaly OpenWindowedScreen = OpenWindow with the auto resizing
If i want see my text :

Code: Select all

If InitSprite() = 0 Or InitKeyboard() = 0
  MessageRequester("Error", "Sprite system can't be initialized", 0)
  End
EndIf
If InitMouse() = 0
  MessageRequester("Error", "Mouse system can't be initialized correctly", 0)
  End
EndIf

If InitSprite3D() = 0
  MessageRequester("Error", "Sprite3D system can't be initialized correctly", 0)
  End
EndIf

   ExamineDesktops()

  If OpenWindow(0, 0, 0, DesktopWidth(0), DesktopHeight(0), "test", #PB_Window_Maximize | #PB_Window_SizeGadget | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget )
 If OpenWindowedScreen(WindowID(0), 0, 0, DesktopWidth(0), DesktopHeight(0), 1, 0, 0)  ; automatiquement étiré.
    Else
      MessageRequester("Erreur", "Impossible d'initialiser la graphique 2d", 0)
      End
    EndIf
  EndIf

  Repeat
    
    Repeat
      Event = WindowEvent()
      
      If Event = #PB_Event_CloseWindow
        End 
      EndIf
    Until Event = 0
   
    ClearScreen(RGB(0, 0, 0))
    
   
    
     
  If StartDrawing(ScreenOutput())
       DrawText(20, 20,"TEST 2D")
       DrawText(500, 500,"TEST 2D",RGB(255,0,0))
      StopDrawing()
    EndIf
    
    FlipBuffers() 
    
ForEver

Last edited by Atlante on Sun Aug 12, 2012 8:21 pm, edited 1 time in total.
Devops Engineer
PB French Moderator
http://www.purebasic.fr/french/
User avatar
Demivec
Addict
Addict
Posts: 4260
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: OpenWindowedScreen & DrawText

Post by Demivec »

Atlante wrote:I think i'm finding a bug with this function :
OpenWindowedScreen(WindowID(0), 0, 0, 1, 1, 1, 0, 0) : Auto resizing
@Atlante: There is a bug with that line. It is the fact that you have a windowed screen that is only one pixel big which is then auto-resized to fill the entire window. Even though it fills the window it still only has 1 pixel, it is simply zoomed in.

To demonstrate this, replace the StartDrawing()/StopDrawing() part with this:

Code: Select all

  If StartDrawing(ScreenOutput())
      Plot(0,0, RGB(0, 0, 255)) ;blue, this will fill the screen
      Plot(1,1, RGB(255, 0, 0)) ;red, this won't be shown on the screen at all
    StopDrawing()
  EndIf
This will plot a blue pixel at (0,0). You will notice though that it fills the entire screen with blue. That is because the screen is a single pixel that has been resized to fill the entire window.

You'll notice the red pixel isn't shown because it is technically outside the region of the screen (which is only 1 pixel large). You can prove this to yourself by running with the debugger on.

To see the text you need to add more pixels to the window screen (i.e. give it a larger width and height).
For instance, try this line instead:

Code: Select all

  If OpenWindowedScreen(WindowID(0), 0, 0, 40, 40, 1, 0, 0)  ; automatiquement étiré.
Atlante
User
User
Posts: 22
Joined: Mon Jun 27, 2011 1:39 pm
Location: FRANCE

Re: OpenWindowedScreen & DrawText

Post by Atlante »

OK, thanks for your explanation, i understand.
have a nice evening ;)
Devops Engineer
PB French Moderator
http://www.purebasic.fr/french/
Post Reply