Ooops
May 31, 2020, 09:31:33 PM

Author Topic: maximize window  (Read 353 times)

Offline Ashmoor

  • Jr. Member
  • **
  • Posts: 36
maximize window
« on: April 03, 2020, 09:02:15 PM »
I have the following code:

Code: BlitzMax
  1.  
  2. Global imageLoc:String = "graphics\p1_wallpaper.jpg"
  3. Global wallpaper_src:TImage = LoadImage(imageLoc)
  4. Global screenShotImg:TImage
  5.  
  6.  
  7. Global appWidth:Int = 1920
  8. Global appHeight:Int = 1080
  9.  
  10.  
  11. Graphics(1366, 768, 0, 60)
  12. SetVirtualResolution (appWidth, appHeight)
  13. SetViewport(0, 0, appWidth, appHeight)
  14.  
  15. Repeat
  16. 'draw here
  17.         Cls
  18.                 DrawImage(wallpaper_src, 0, 0)
  19.                 'If screenShotImg DrawImage(screenShotImg, 0, 0)
  20.         Flip
  21.                
  22. 'update here    
  23.         x = VirtualMouseX()
  24.         y = VirtualMouseY()
  25.        
  26.         If KeyHit(KEY_ESCAPE) Or AppTerminate() Then End
  27.  
  28.         If KeyHit (KEY_S) Then
  29.                 screenShotImg = Null
  30.                 screenShotImg = TakeScreenshot(appWidth, appHeight)
  31.         EndIf
  32. Forever
  33.  
  34.  
  35. Function TakeScreenshot:TImage(xIni:Int = 800, yIni:Int = 600)
  36.         Local ssImg:TImage
  37.         Local ssImg_dx = xIni
  38.         Local ssImg_dy = yIni
  39.  
  40.         ssImg = CreateImage(ssImg_dx, ssImg_dy, 1, FILTEREDIMAGE | DYNAMICIMAGE)
  41.        
  42.         GrabImage(ssImg, 0, 0)
  43.        
  44.         Return ssImg
  45.  
  46. End Function
  47.  

And I have some questions. Why does GrabImage not grab from source resolution aka 1920x1080? Is there a way to grab the image at source resolution? Why is the "maximize" window button greyed? How do I unlock it and have it switch the app to full screen when pressed?



Offline GW

  • Full Member
  • ***
  • Posts: 199
Re: maximize window
« Reply #1 on: April 04, 2020, 07:57:45 PM »
Because your source resolution is '1366, 768'.   If you want a 1920 backbuffer then you need to call graphics with 1920,1080.If you want to draw to a buffer that is larger than your backbuffer then you need to create another off screen buffer.  Look around the archives for some 'render to texture' code.

Offline Ashmoor

  • Jr. Member
  • **
  • Posts: 36
Re: maximize window
« Reply #2 on: April 04, 2020, 09:53:36 PM »
Thanks. Render to texture is what I was looking for. Unfortunately it seems too advanced for me at the moment and pretty slow using directX. :( I'll spend more time after shipping this project.

Any idea about the maximize button?

Offline _PJ_

  • Jr. Member
  • **
  • Posts: 65
Re: maximize window
« Reply #3 on: April 24, 2020, 10:04:41 PM »
The MAximise buttin will maximise to the pixels allocated for that window.
This has been set by your Graphics call with no parameter to differ the window size from is, by definition, mazimised - hence the button is inoperable.

From what I can see in BRL.Graphics.mod, the standard driver settings default to a non-resizeable graphics object.

I think you have some things the wrong way around.
You have a larger viewport than the graphcis window - excess rendering will be off the bottom-right of the window.
SetVirtualViewport can stretch a smaller resolution display to fit a larger resolution window. You seem to be using it the other way.

You refer to "source" but there's no way for the code to "know" what the native resolution is. Maybe you could use DesktopWidth() / Height() To obtain full-screen dimensions?


Offline Derron

  • Hero Member
  • *****
  • Posts: 2975
Re: maximize window
« Reply #4 on: April 24, 2020, 10:27:09 PM »
I merged Col's Render2Texture code into Max2D so you could use it more easily. Would support OpenGL, DX9, SDL-OpenGL, SDL2OpenGL and SDLDirectX9 of NG.

https://github.com/bmx-ng/brl.mod/pull/174
https://github.com/bmx-ng/pub.mod/pull/37
https://github.com/bmx-ng/sdl.mod/pull/26

sample:
Code: [Select]
SuperStrict
Framework Brl.StandardIO
Import Brl.RandomDefault
Import Brl.GLMax2D

Graphics(800, 600)
SetBlend AlphaBlend

Local rt:TRenderImage = CreateRenderImage(300, 150, False)

'render into the texture
SetRenderImage(rt)
For Local i :Int = 0 To 100
    SetColor Rand(0,255), Rand(0,255), Rand(0,255)
    DrawText("Hey", Rand(0, rt.width-50), Rand(0, rt.height-20))
Next
SetRenderImage(Null)

SetColor 255,255,255
SetClsColor 40, 80, 160
While Not KeyDown(KEY_ESCAPE)   
    Cls
   
    SetScale 2,2
    DrawImage(rt, MouseX(), MouseY())
   
    Flip
Wend

End

Code is only tested by me for now. Also it seems nobody is really interested in it for now so official inclusion might be rejected or it could take some time to get approved.


bye
Ron

Offline GW

  • Full Member
  • ***
  • Posts: 199
Re: maximize window
« Reply #5 on: April 26, 2020, 08:44:47 AM »
Not sure if it's helpful, but I posted DX9 render to texture code in the archives back in the day HERE.
There is an OpenGL version with the same interface HERE.I've used both versions in projects for the past and they is no real performance hit.

Offline Ashmoor

  • Jr. Member
  • **
  • Posts: 36
Re: maximize window
« Reply #6 on: April 28, 2020, 11:53:43 AM »
@_PJ_

Quote
The MAximise buttin will maximise to the pixels allocated for that window.
This has been set by your Graphics call with no parameter to differ the window size from is, by definition, mazimised - hence the button is inoperable.
From what I can see in BRL.Graphics.mod, the standard driver settings default to a non-resizeable graphics object.

This is what I was asking, if there was a way to enable that button instead of going with the default non-resizeable graphics object. I found a way:

Code: BlitzMax
  1.  
  2. Local hWnd:Int = GetActiveWindow()
  3. Local style:Int = GetWindowLongA(hWnd, GWL_STYLE)
  4. style:|(WS_MINIMIZEBOX)
  5. style:|WS_MAXIMIZEBOX
  6. SetWindowLongA(hWnd, GWL_STYLE, style)
  7. DrawMenuBar(hWnd)
  8. ShowWindow(hWNd, SW_SHOWNORMAL)
  9.  
  10.  

This will enable the maximize button but due to having virtual resolution the mouse cursor will be offset due to the window being "zoomed". If I use my custom pointer and HideMouse() it works fine but it bothers me so I instead check if that button was pressed and toggle full screen if it was.

Quote
I think you have some things the wrong way around.
You have a larger viewport than the graphcis window - excess rendering will be off the bottom-right of the window.

If I set virtual resolution to 1920x1080 and viewport smaller, the game will run in 1920x1080 but will only draw in a smaller rectangle as if it had a mask.

Quote
SetVirtualViewport can stretch a smaller resolution display to fit a larger resolution window. You seem to be using it the other way.

I assume you mean SetVirtualResolution(), and yes it does compress 1920x1080 to a smaller graphics object, works perfect for any smaller display without loss of visual quality. That way I can focus on developing in a single resolution and deploying in several proportional ones.

Quote
You refer to "source" but there's no way for the code to "know" what the native resolution is.

I thought that SetVirtualResolution() was doing some render to texture in a backbuffer somewhere and then scaling that texture down when it came time to draw it. It is super fast.


Offline Ashmoor

  • Jr. Member
  • **
  • Posts: 36
Re: maximize window
« Reply #7 on: April 28, 2020, 12:02:05 PM »
@GW
Quote
Not sure if it's helpful, but I posted DX9 render to texture code in the archives back in the day HERE.
There is an OpenGL version with the same interface HERE.I've used both versions in projects for the past and they is no real performance hit.

Yes, I found them when you said to look for render to texture. The OpenGL version is flawless but the DX9 is running at 3fps on my computer.

@Derron
Quote
I merged Col's Render2Texture code into Max2D so you could use it more easily. Would support OpenGL, DX9, SDL-OpenGL, SDL2OpenGL and SDLDirectX9 of NG.

Thank you.


 

SimplePortal 2.3.6 © 2008-2014, SimplePortal