Ooops
January 15, 2021, 05:21:52 PM

Author Topic: [bb] Auto-set graphics mode by Neo Genesis10 [ 1+ years ago ]  (Read 552 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
Title : Auto-set graphics mode
Author : Neo Genesis10
Posted : 1+ years ago

Description : Call this function to set your graphics mode. It auto detects what the system is capable of and saves an ini file with the users settings, which can then be altered simply later on. The file is in text format, so is easily altered. You could also edit this function to include other things into your ini file such as difficulty settings, lives or other general setups.

Code :
Code: BlitzBasic
  1. Function GraphicsMode()
  2.  
  3. ini = ReadFile("setup.ini")             ; reads ini file
  4.  
  5. If ini <> 0                             ; Check if ini file exists
  6.         Repeat
  7.                 a$ = ReadLine(ini)      ; read lines
  8.         Until a$ = "[graphics]"         ; ...until it finds the one we need
  9.         a$ = ReadLine(ini)              ; read the following line
  10.         For x = 1 To Len(a$)            ; cycle through till it finds a comma
  11.                 l$ = Mid$(a$,x,1)
  12.                 If l$ = ","
  13.                         num = x
  14.                         Exit
  15.                 EndIf
  16.         Next
  17.         depth = ReadLine(ini)
  18.         If depth = 0 depth = 16         ; if omitted, default to 16-bit for compatibility
  19.         scr_w = Left(a$, num-1)         ; grab the screen width
  20.         scr_h = Right(a$, (Len(a$) - num) )
  21.         If scr_h < 480 Or scr_w < 640
  22.                 scr_h = 480
  23.                 scr_w = 640
  24.         EndIf
  25.         If GfxModeExists(scr_w,scr_h,depth) = False     ; if the graphics mode doesnt exist
  26.                 scr_w = GfxModeWidth(1)                 ; set it up in basic mode
  27.                 scr_h = GfxModeHeight(1)
  28.                 depth = 16
  29.         EndIf
  30.         CloseFile(ini)
  31. Else
  32.         scr_w = 0
  33.         scr_h = 0
  34.         Cls
  35.         Flip
  36.         Cls
  37.  
  38.         Print "Set Graphics Mode"
  39.         For i = 1 To CountGfxModes()
  40.                 Print i+") "+GfxModeWidth(i)+" x "+GfxModeHeight(i)+" x "+GfxModeDepth(i)
  41.         Next
  42.        
  43.         .entermode
  44.         mode = Input(">")
  45.         If mode < 0 Or Mode > CountGfxModes() Goto entermode
  46.         scr_w = GfxModeWidth( mode )
  47.         scr_h = GfxModeHeight( mode )
  48.         depth = GfxModeDepth( mode )
  49.                
  50.         ini = WriteFile("setup.ini")
  51.         WriteLine ini,"[graphics]"
  52.         WriteLine ini,scr_w+","+scr_h
  53.         CloseFile(ini)
  54. EndIf
  55.  
  56. Graphics scr_w,scr_h,depth
  57. SetBuffer BackBuffer()
  58. Return
  59.  
  60. End Function


Comments : none...

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal