maximize window

Started by Ashmoor, April 03, 2020, 21:02:15

Previous topic - Next topic

Ashmoor

I have the following code:

Code (blitzmax) Select


Global imageLoc:String = "graphics\p1_wallpaper.jpg"
Global wallpaper_src:TImage = LoadImage(imageLoc)
Global screenShotImg:TImage


Global appWidth:Int = 1920
Global appHeight:Int = 1080


Graphics(1366, 768, 0, 60)
SetVirtualResolution (appWidth, appHeight)
SetViewport(0, 0, appWidth, appHeight)

Repeat
'draw here
Cls
DrawImage(wallpaper_src, 0, 0)
'If screenShotImg DrawImage(screenShotImg, 0, 0)
Flip

'update here
x = VirtualMouseX()
y = VirtualMouseY()

If KeyHit(KEY_ESCAPE) Or AppTerminate() Then End

If KeyHit (KEY_S) Then
screenShotImg = Null
screenShotImg = TakeScreenshot(appWidth, appHeight)
EndIf
Forever


Function TakeScreenshot:TImage(xIni:Int = 800, yIni:Int = 600)
Local ssImg:TImage
Local ssImg_dx = xIni
Local ssImg_dy = yIni

ssImg = CreateImage(ssImg_dx, ssImg_dy, 1, FILTEREDIMAGE | DYNAMICIMAGE)

GrabImage(ssImg, 0, 0)

Return ssImg

End Function


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?



GW

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.

Ashmoor

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?

_PJ_

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?


Derron

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:

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

GW

#5
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.

Ashmoor

@_PJ_

QuoteThe 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) Select


Local hWnd:Int = GetActiveWindow()
Local style:Int = GetWindowLongA(hWnd, GWL_STYLE)
style:|(WS_MINIMIZEBOX)
style:|WS_MAXIMIZEBOX
SetWindowLongA(hWnd, GWL_STYLE, style)
DrawMenuBar(hWnd)
ShowWindow(hWNd, SW_SHOWNORMAL)



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.

QuoteI 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.

QuoteSetVirtualViewport 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.

QuoteYou 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.


Ashmoor

@GW
QuoteNot 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
QuoteI 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.