Ooops
November 24, 2020, 06:33:43 AM

Author Topic: [bb] Graphics resolution selector by Zethrax [ 1+ years ago ]  (Read 1002 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
Title : Graphics resolution selector
Author : Zethrax
Posted : 1+ years ago

Description : *** Blitz3D Code ***
The 'SelectGraphicsMode' function displays a simple selector to allow a user to choose and set a valid 3D graphics resolution.

The available resolutions are shown in a paged display (Next and Previous navigation links will show if they are needed) with 'Fullscreen' and 'Windowed' hyperlinks that let the user choose which mode they want to use.

Color depths below 32 bits are filtered out (I don't think there's any point in showing these).

This is intended more for use in demo and sample projects than in released products, but it shows the basics involved if you want to expand on it.

For use in a 2D project just change 'Graphics3D' to 'Graphics' and 'CountGfxModes3D' to 'CountGfxModes' in the code below (untested but it should work).

To see it in use in a sample project go to: <a href="codearcs0707.html?code=1137" target="_blank">http://www.blitzbasic.com/codearcs/codearcs.php?code=1137[/url]
Code: [Select]
; The 'SelectGraphicsMode' function displays a simple selector to allow a user to choose and set a valid 3D graphics resolution.

; The available resolutions are shown in a paged display (Next and Previous navigation links will show if they are needed) with 'Fullscreen' and 'Windowed' hyperlinks that let the user choose which mode they want to use.

; Color depths below 32 bits are filtered out (I don't think there's any point in showing these).

; This is intended more for use in demo and sample projects than in released products, but it shows the basics involved if you want to expand on it.

; For use in a 2D project just change 'Graphics3D' to 'Graphics' and 'CountGfxModes3D' to 'CountGfxModes' in the code below (untested but it should work).

; To see it in use in a sample project go to: <a href="codearcs0707.html?code=1137" target="_blank">http://www.blitzbasic.com/codearcs/codearcs.php?code=1137</a>



; === Declarations ===

Dim A_temp_int_array( 0 ) ; A temporary integer array used by some functions. Used by 'SelectGraphicsMode' so declare here.
Global G_font_underlined, G_font ; Globals used with fonts. Used by 'SelectGraphicsMode' so declare here.

Global G_mouseclick_item ; Global used with 'DrawHyperlink'.



; === Functions ===



Function DrawHyperlink( x, y, linktext$, item )
; Draws the specified 'linktext$' as hyperlink text at the x and y locations on the screen.
; If the hyperlinked text is clicked on with the left mouse button then the value of 'item' will be returned in the global variable 'G_mouseclick_item'.
; Otherwise 'G_mouseclick_item' will contain a zero value.

SetFont G_font_underlined

Local width = StringWidth( linktext$ )
Local height = FontHeight()

Local mx = MouseX()
Local my = MouseY()

Local over_item = False

If ( mx >= x ) And ( mx < ( x + width ) )
If ( my >= y ) And ( my < ( y + height ) )
over_item = True
EndIf
EndIf
If over_item ; If the mouse pointer is over the hyperlink...
Color 0,128,0 ; Use the mouseover hyperlink color.
If MouseHit( 1 ) ; If the left mouse button has been pressed...
G_mouseclick_item = item ; Set G_mouseover_item to the item id.
EndIf
Else
Color 62,158,255 ; Use the normal hyperlink color.
EndIf
Text x, y, linktext$
SetFont G_font
Color 255, 255, 255
End Function



Function LoadFonts()
; Note that 'LoadFont' will always return a non-zero handle even if it can't find the font. It seems to default to 'arial' in this case.
G_font_underlined = LoadFont( "arial", 16, True, False, True )
G_font = LoadFont( "arial", 16, True, False, False )
SetFont G_font
End Function



Function SelectGraphicsMode()
; Selects the full screen 3D graphics mode to set.

Graphics3D 470, 500
SetBuffer BackBuffer()
timer = CreateTimer( 60 )

; - Count the number of high-color modes.
num_modes = CountGfxModes3D()
mode_count = 0
For i = 1 To num_modes
If GfxModeDepth( i ) > 31 Then mode_count = mode_count + 1
Next

; - Store all the high-color modes in the array with low-color modes filtered out.
Dim A_temp_int_array( mode_count )
x = 0
For i = 1 To num_modes
If GfxModeDepth( i ) > 31 Then x = x + 1 : A_temp_int_array( x ) = i
Next
num_modes = mode_count

LoadFonts
start_mode = num_modes
num_modes_to_show = 20

Repeat
x = 10 : y = 10
Cls
Color 255,128,0
Text x, y, "[  =======  Select Graphics Mode  =======  ]" : y = y + 20
Color 223,223,0
Text x, y, "(Color modes lower than 32 bit are not shown)" : y = y + 20
Color 255,255,255
mode_count = 0
G_mouseclick_item = 0 ; Zero this global before updating the hyperlinks.
For i = start_mode To 1 Step -1
Text x, y, "Width: " + GfxModeWidth( A_temp_int_array( i ) )
Text x + 90, y, "Height: " + GfxModeHeight( A_temp_int_array( i ) )
Text x + 180, y, "Color Depth: " + GfxModeDepth( A_temp_int_array( i ) )
DrawHyperlink x + 295, y, "Fullscreen", A_temp_int_array( i )
DrawHyperlink x + 380, y, "Windowed", A_temp_int_array( i ) + 1000
y = y + 20
mode_count = mode_count + 1
If mode_count = num_modes_to_show Then Exit ; Show a maximum of 'num_modes_to_show' modes on a page.
Next

If start_mode < num_modes ; If there are previous modes to show...
DrawHyperlink 10, 470, "<<< Prev", -1
EndIf
If ( start_mode - num_modes_to_show ) > 0 ; If there are more modes to show...
DrawHyperlink 220, 470, "Next >>>", -2
EndIf

Flip
WaitTimer timer

;Cls : Print G_mouseclick_item : WaitKey

If G_mouseclick_item > 0 Then Exit ; A graphics mode hyperlink was clicked, so exit the loop and set the mode.

; - Update navigation links.
Select G_mouseclick_item
Case -1 ; Previous page link clicked.
start_mode = start_mode + num_modes_to_show
Case -2 ; Next page link clicked.
start_mode = start_mode - num_modes_to_show
End Select
If KeyHit( 1 ) Then End
Forever

If G_mouseclick_item > 1000 ; If windowed mode was selected...
G_mouseclick_item = G_mouseclick_item - 1000
x = 2 ; Set windowed mode.
Else ; Fullscreen mode was selected.
x = 1 ; Set fullscreen mode.
EndIf

EndGraphics

Graphics3D GfxModeWidth( G_mouseclick_item ), GfxModeHeight( G_mouseclick_item ), GfxModeDepth( G_mouseclick_item ), x
Dim A_temp_int_array( 0 ) ; Free the memory used by this array.
End Function



; === Example Usage ===


SelectGraphicsMode ; Select and set the full screen graphics mode.

WaitKey
End



Code :
Code: BlitzBasic
  1. The code can be found at: http://www.blitzbasic.com/codearcs/codearcs.php?code=3180


Comments :


RemiD(Posted 1+ years ago)

 I also suggest to filter out the resolutions when (Width < Height) or (Width > Height*2)


_PJ_(Posted 1+ years ago)

 RemiD, Why would you filter out, say 21:9 aspect resolutions?


RemiD(Posted 1+ years ago)

 @_PJ_>>i had no idea that 21:9 resolutions existed, and i think it is too large, so i filter it out ;)


 

SimplePortal 2.3.6 © 2008-2014, SimplePortal