[Resolved] Unused screen area!

Everything else that doesn't fall into one of the other PB categories.
User avatar
SPH
Enthusiast
Enthusiast
Posts: 572
Joined: Tue Jan 04, 2011 6:21 pm

[Resolved] Unused screen area!

Post by SPH »

Hi,
I don't understand one thing. When I open an OpenGLGadget at a size other than the desktop (1024/768 vs 1920/1080), the screen is drawn at the top left and puts the rest of the image in white...
Look :
Image

Code: Select all

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Erreur d'affichage en OpenGL   ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; PB6.0 - SPH(2022) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


;EnableExplicit

;-CONSTANTS
Enumeration
  #MainWindow
  #OpenGLGadget
EndEnumeration

;These two GL constants are used for texture creation. Don't change their values.
#GL_BGR = $80E0
#GL_BGRA = $80E1

InitSprite()

;;;;;;;;;  Screen : 1024 / 768 ;;;;;;;;;
ddw=1024
ddh=768
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  
;-STRUCTURES
Structure Integer2
  X.i
  Y.i
EndStructure
Global.Integer2 WindowDim
WindowDim\X = ddw
WindowDim\Y = ddh


;-DEFINES
Define.i Event
Define.i WindowFlags = #PB_Window_ScreenCentered | #PB_Window_MinimizeGadget


;-DECLARES
Declare Render()
Declare Render2DQuad(OGLTexture.i, StartX.d, StartY.d, Width.i, Height.i, Z.d)
Declare SetupOpenGL()
Declare SetupGLTexture(ImageHandle.i)


;-MAIN WINDOW
win=OpenWindow(#MainWindow, 0, 0,ddw,ddh, "Titre",#PB_Window_Maximize|#PB_Window_BorderLess)
If win=0
  MessageRequester("Erreur","OpenWindow() impossible")
  End
EndIf

screenGL=OpenGLGadget(#OpenGLGadget,0,0,ddw,ddh)
If screenGL=0
  MessageRequester("Erreur","OpenGLGadget() impossible")
  End
EndIf


SetupOpenGL()

AddKeyboardShortcut(0,  #PB_Shortcut_Escape, 666) ; quitter

glOrtho_(0,ddw,ddh,0,-1,1)
glMatrixMode_(#GL_MODELVIEW)
glLoadIdentity_()
glClear_(0)

;*********************************************************************************************************************************

;;;;;;;;;;;
timer=ElapsedMilliseconds()

glClearColor_(0,0,0, 1.0)
; ShowCursor_(0)
;-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#################;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;### D E B U T ###;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#################;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Repeat
  
  glClear_(#GL_COLOR_BUFFER_BIT | #GL_DEPTH_BUFFER_BIT)
  
  
  ;*****
  Repeat
    Event = WindowEvent()
    
    Select Event
      Case #PB_Event_Gadget
        Select EventGadget()
          Case 1
            Resx = GetGadgetAttribute(1, #PB_OpenGL_MouseX)
            Resy = GetGadgetAttribute(1, #PB_OpenGL_MouseY)
            ;;;;;;;         
            Select EventType()
                ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;             
            EndSelect
        EndSelect
      Case #PB_Event_Menu
        Select EventMenu()
          Case 666
            timer=ElapsedMilliseconds()-timer
            End
        EndSelect
    EndSelect
    
  Until Event = 0
  
  
  ;##############################################
  ;##############################################
  ;##############################################
  ;##############################################
  
  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  ;;;;;;;; Traçage de vos polygones ;;;;;;;;
  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  
  For i=1 To 5
    glBegin_(#GL_POLYGON);
    glBlendFunc_(#GL_SRC_ALPHA,#GL_ONE_MINUS_SRC_ALPHA)
    glColor4f_(Random(255)/255,Random(255)/255,Random(255)/255,Random(255)/255)
    
    For u=1 To 5
      glVertex2f_(Random(ddw),Random(ddh));
    Next u
    
    glEnd_()                      ; 
  Next i
  ;;;;;;;;;;;;;;;
  
  SetGadgetAttribute(#OpenGLGadget, #PB_OpenGL_FlipBuffers, #True)
  
  
ForEver

End


Procedure Render()
  
  ;Clearing buffers and resetting clear color to remove old graphics from the last frame.
  glClear_(#GL_COLOR_BUFFER_BIT | #GL_DEPTH_BUFFER_BIT)
  ;  glClearColor_(0.2, 0.2, 0.2, 1.0)
  glClearColor_(0,0,0,1)
  
  ;## DRAWING TEXTURES/IMAGES
  ;First enable the Texture system.
  glEnable_(#GL_TEXTURE_2D)
  
  ;This procedure will create a quad and apply a texture to it.
  ;The Texture variable contains the texture created earlier using SetupGLTexture().
  Render2DQuad(Texture1, 0, 0, ImageWidth(Image1), ImageHeight(Image1), -2)
  ; Render2DQuad(Texture2, 0, 0, ImageWidth(Image2), ImageHeight(Image2), -1)
  
  ;After all the textures have been displayed disable the texture system.
  ;Otherwise it will conflict with the non texture graphics.
  glDisable_(#GL_TEXTURE_2D)
  
EndProcedure

Procedure Render2DQuad(OGLTexture.i, StartX.d, StartY.d, Width.i, Height.i, Z.d)
  
  ;The texture is first bound which tells OpenGL to use this texture for any future rendering.
  glBindTexture_(#GL_TEXTURE_2D, OGLTexture)
  glBegin_(#GL_QUADS)
  glColor4f_   (1,1,1,1)
  glNormal3f_  (0,0,1.0)
  glTexCoord2f_(1.0,1.0)
  glVertex3f_  (StartX+Width,StartY,Z)
  glTexCoord2f_(0.0,1.0)
  glVertex3f_  (StartX,StartY,Z)
  glTexCoord2f_(0.0,0.0)
  glVertex3f_  (StartX,StartY+Height,Z)
  glTexCoord2f_(1.0,0.0)
  glVertex3f_  (StartX+Width,StartY+Height,Z)
  glEnd_()
  
EndProcedure

Procedure SetupOpenGL()
  
  glMatrixMode_(#GL_PROJECTION)
  
  glOrtho_(0.0, WindowDim\X, WindowDim\Y, 0.0, -1000.0, 1000.0)
  
  glMatrixMode_(#GL_MODELVIEW)
  
  ; glEnable_(#GL_DEPTH_TEST)
  
  glEnable_(#GL_BLEND)
  glBlendFunc_(#GL_SRC_ALPHA, #GL_ONE_MINUS_SRC_ALPHA)
  
EndProcedure
Do you have a solution/explanation?
Thx
Last edited by SPH on Mon Aug 01, 2022 10:19 am, edited 1 time in total.

!i!i!i!i!i!i!i!i!i!
!i!i!i!i!i!i!
!i!i!i!
//// Informations ////
Portable LENOVO ideapad 110-17ACL 64 bits
Version de PB : 6.12LTS - 64 bits
User avatar
Demivec
Addict
Addict
Posts: 4269
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: Unused screen area!

Post by Demivec »

SPH wrote: Sun Jul 31, 2022 1:39 pm Hi,
I don't understand one thing. When I open an OpenGLGadget at a size other than the desktop (1024/768 vs 1920/1080), the screen is drawn at the top left and puts the rest of the image in white...
...
snip
...

Do you have a solution/explanation?
Thx
Your abbreviated code:

Code: Select all

;;;;;;;;;  Screen : 1024 / 768 ;;;;;;;;;
ddw=1024
ddh=768
win=OpenWindow(#MainWindow, 0, 0,ddw,ddh, "Titre", #PB_Window_Maximize|#PB_Window_BorderLess)
screenGL=OpenGLGadget(#OpenGLGadget,0,0,ddw,ddh)
You set the size of the OpenGLGadget to ddw x ddh and also the size of the window the same. You then maximize the window. This leaves the empty space around the OpenGLGadget if the screen size is bigger than ddw x ddh.
User avatar
SPH
Enthusiast
Enthusiast
Posts: 572
Joined: Tue Jan 04, 2011 6:21 pm

Re: Unused screen area!

Post by SPH »

Still, an OpenScreen of 1024/768 spans the entire screen.

Code: Select all

If InitSprite() = 0 Or InitKeyboard() = 0 Or InitMouse() = 0
  MessageRequester("Erreur", "Impossible d'initialiser l'écran.")
  End
EndIf

 ;Ouverture de l'écran
If OpenScreen(1024,768,32,"Exemple OpenScreen") = 0
  MessageRequester("Erreur", "Impossible d'ouvrir l'écran.")
  End
EndIf

 ;Curseur de la souris
CreateSprite(0,20,20,#PB_Sprite_PixelCollision)
StartDrawing(SpriteOutput(0))
Box(0, 0, 20, 20, RGB(255, 255, 255))
StopDrawing()

Repeat
  
  ;Effacer complètement l'écran et afficher un fond gris
  ClearScreen(RGB(128,128,128))
  
  ;On lit les évènements clavier et souris
  ExamineMouse()
  ExamineKeyboard()
  
  ;Position de la souris
  x = MouseX()
  y = MouseY()
  
  DisplaySprite(0, X, Y)
  
  
  FlipBuffers()
  
Until KeyboardPushed(#PB_Key_Escape) ;On quitte l'application en  appuyant sur la touche Echap (ESC)
I begin to understand !

If I want to be in full screen (in openGL), I have to display the same resolution as the windows desktop then. Exact ?

!i!i!i!i!i!i!i!i!i!
!i!i!i!i!i!i!
!i!i!i!
//// Informations ////
Portable LENOVO ideapad 110-17ACL 64 bits
Version de PB : 6.12LTS - 64 bits
User avatar
Demivec
Addict
Addict
Posts: 4269
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: Unused screen area!

Post by Demivec »

SPH wrote: Sun Jul 31, 2022 4:14 pm Still, an OpenScreen of 1024/768 spans the entire screen.

I begin to understand !

If I want to be in full screen (in openGL), I have to display the same resolution as the windows desktop then. Exact ?
You are correct.

A screen changes the resolution. A window doesn't.
User avatar
SPH
Enthusiast
Enthusiast
Posts: 572
Joined: Tue Jan 04, 2011 6:21 pm

Re: Unused screen area!

Post by SPH »

Ok, thank you very much !

I understand now. :idea:

!i!i!i!i!i!i!i!i!i!
!i!i!i!i!i!i!
!i!i!i!
//// Informations ////
Portable LENOVO ideapad 110-17ACL 64 bits
Version de PB : 6.12LTS - 64 bits
Post Reply