change screen resolution at runtime

Hi everybody

any help on how to change BGE screen resolution at runtime?.

I know how to set screen resolution before i create a .exe. but i want to be able to change it after at runtime.

Im reading a lot of python scripting and searching to know how to do this but i cant find anything.

Any help?

Thank you very much.

you can chose the resolution and many many other things when you call the runtime, so i suggest you to make a sorta launcher program:

here is the help RTFM xD



usage:   blenderplayer [-w [-p l t w h]] [-g gamengineoptions] [-s stereomode] filename.blend
  -h: Prints this command summary
  -w: display in a window
  -p: specify window position
       l = window left coordinate
       t = window top coordinate
       w = window width
       h = window height
  -f: start game in full screen mode
       fw = full screen mode pixel width
       fh = full screen mode pixel height
       fb = full screen mode bits per pixel
       ff = full screen mode frequency
  -s: start player in stereo
       stereomode: hwpageflip       (Quad buffered shutter glasses)
                   syncdoubling     (Above Below)
                   sidebyside       (Left Right)
                   anaglyph         (Red-Blue glasses)
                   vinterlace       (Vertical interlace for autostereo display)
                             depending on the type of stereo you want
  -g: game engine options:
       Name            Default      Description
       ----------------------------------------
       fixedtime          0         Do the same timestep each frame "Enable all frames"
       nomipmap           0         Disable mipmaps
       show_framerate     0         Show the frame rate
       show_properties    0         Show debug properties
       show_profile       0         Show profiling information
       vertexarrays       1         Enable vertex arrays
       blender_material   0         Enable material settings

example: blenderplayer -p 10 10 320 200 -g noaudio c:\loadtest.blend
example: blenderplayer -g vertexarrays = 0 c:\loadtest.blend

Thank you very much cyborg.

I was hoping to find some python code to be able to change res from an interface inside the runtime. Just like games does.

If i cant find the way i will try restarting the application with the commands u showed me.

I don’t believe there is a way, without going hacker-ninja style.
If there was a way, it would probably have something to do with the Rasterizer module.

Thanks for writing

Im afraid it has to be ninja style chase.
The Rasterizer module only provides window information. I tried that
Im working on it with the blenderplayer commands and scripting a game actuator. If i get something ill let u know.

Ok i got it.
Ninja Style!

1.-Create some objects (cubes, spheres,…) that will work as buttons.

2.-On one of them create 2 mouse sensors.
First one set to “Mouse over any”
second one set to “Left Button”

3.-Connect both to a python controller script

4.- The script:


#Mackraken script
#Use it as u want

import Rasterizer as R
import GameLogic as G
import os 

#when rollover any object mouse will be visible
R.showMouse(1)

cont = G.getCurrentController()
obj = cont.getOwner()

#2 sensors, one to detect roll over an object and another to detect left mouse button #pressed

mclic = cont.getSensor("m2")
mover = cont.getSensor("m1")

#if mouse is over an object and you press LMB

if mover.isPositive() and mclic.isPositive():
#get the object
    obhit = mover.getHitObject()
#change the resolution
    if obhit.name=="OBr800":
        obj.debug = "800"
        prog = "C:/runtime/screen.exe"
        args = [" -p 0 0 800 600 C:/runtime/screen.exe"]
        
        print os.execvp(prog, (prog,) + tuple(args))
        
    elif obhit.name=="OBr1024":
        obj.debug = "1024"
        prog = "C:/runtime/screen.exe"
        args = [" -p 0 0 1024 768 C:/runtime/screen.exe"]
        
        print os.execvp(prog, (prog,) + tuple(args))

hello
ninja style it is!

http://tbn1.google.com/images?q=tbn:tQ31tvM49NRGVM:http://wichq.gamona.de/Bilder/ninja.jpg

i just converted your script to be compliant with 2.49 final.
everything does what it should (the .exe restarts), but it doesnt change the resolution.

seems like -p is not a valid parameter of the os.execvp() method anymore?
maybe its because windoof is not accepting the -p argument?

#Mackraken script - ninja style
#Use it as u want
#manarius ported to 2.49
#still use it as u want

import Rasterizer as R
import GameLogic as G
import os 

#when rollover any object mouse will be visible
R.showMouse(1)

#uncomment this lines to see the not useful informations:
#print dir(os.execvp)
#print help(os.execvp)        
		
cont = G.getCurrentController()
obj = cont.owner

#2 sensors, one to detect roll over an object and another to detect left mouse button #pressed

mclic = cont.sensors["mclic"]
mover = cont.sensors["mover"]

#if mouse is over an object and you press LMB

if mover.positive and mclic.positive:
#get the object
    obhit = mover.hitObject
#change the resolution
    if obhit.name=="OBr800":
        obj["debug"] = "800"
        prog = "E:/Trunk/DAIGANOID/loader/loader6.exe"
        args = [" -p 0 0 320 240 E:/Trunk/DAIGANOID/loader/loader6.exe"]
        
        print os.execvp(prog, (prog,) + tuple(args))

		
    elif obhit.name=="OBr1024":
        obj["debug"] = "1024"
        prog = "E:/Trunk/DAIGANOID/loader/loader6.exe"
        args = [" -p 0 0 1024 768 E:/Trunk/DAIGANOID/loader/loader6.exe"]
        
        print os.execvp(prog, (prog,) + tuple(args))

since i only changed a few lines in the script AFTER i tested the first time it can’t be a problem with my modifications, because it was there from the beginning.

[ignore this]-> REASON: sometimes i act like a silly chimpansee, documentation already was in the second posting…:
does anyone know where to find good documentation about execvp() ?
the python doc hides the possible parameters from me, i cant seem to find them anywhere,
neither does “print dir(os.execvp)” or “print help(os.execvp)” out of blender.

[/ignore this]
:eek:
gonna test it again and reply with the results…
since i want to use fullscreen anyhow.

but the question remains, why -p is not working.

greetings and thanks,
manarius

Well easy question.
Blenderplayer -p has been replaced by -w: width height left top for windowed mode
or
-f: fw fh fb ff (width height bits frequency) for full screen

Ok i have cleaned the code a bit:
and ill post an example.


import GameLogic
import Rasterizer as R
import os

R.showMouse(1)

cont = GameLogic.getCurrentController()

mclic = cont.sensors["mclic"]
mover = cont.sensors["mover"]
infobj= cont.sensors["mover"].owner


if mclic.positive and mover.positive:
    obj = mover.hitObject
    print obj.name
    prog = "D:\\blender\screen.exe"

    if obj.name=="OBSphere": #change to 640x480x16 60Hz
        args = [" -f 640 480 16 60"]
    
    if obj.name=="OBCube": #800x600x16 60hz
        args = [" -f 800 600 16 60"]
    
    if obj.name=="OBCone": #1024x768x16 60hz
        args = [" -f 1024 768 16 60"]
    
    #prints screen width on console
    #this doesnt have so much sense since we are on full screen
    #but there it is

    print R.getWindowWidth()
    infobj.screen=args[0]
    print prog+" "+args[0]
    
    os.execvp(prog, (prog,) + tuple(args))

hmm execvp is doing weird things with the rest of opened windows, but change res works.

Use:
Dowload the blend
Save game as runtime
Modify the line prog = “D:\blender\screen.exe” for the path where your executable is.

Thanks for the update.
Cheers.

We should be able to add an actuator for this, SDL supports switching screen resolutions on all OS’s so I dont think its a big deal.

But if you do want to run an exe file from the BGE, best put in the same directory as your blend file and change…
prog = “D:\blender\screen.exe”
to…
prog = GameLogic.expandPath("//screen.exe")

Try os.spawnl(1, program, arguments). It works pretty good in my Menu. Only the new python26.zip doesn’t like it. Couldn’t figure out why.

I have posted a similar code like yours here:
http://blenderartists.org/forum/showthread.php?t=159784

Sounds great. :wink:

thanks a lot.

@Azan:
thanks i will try that.

@ideasman:
thanks for implementing this as an actuator, thats a great idea. :slight_smile:
i greatly appreciate the work you developer wizards are doing!
you, by far, have the greatest magic mojo of this world!

@all you high mages who congregate around blender and unleash your magic with it:
thanks a lot!
my humble being is grateful, that you exist and looks up to you, honoured to get the great present from you which blender is!
to read about ANY kind of change within Blender is like waiting for christmas!

:smiley:

greetings
manarius