Not logged inGosu Forums
Forum back to libgosu.org Help Search Register Login
Up Topic Gosu / Gosu Exchange / list display modes
- - By jahmaican Date 2013-11-28 17:10
Is it possible in ruby/gosu to list all available display modes? (like in love2d?)
Parent - By arrow Date 2013-11-29 15:27
I don't know. You can use Gosu.screen_height and Gosu.screen_width to get the screen resolution, eg. so you can set the game full screen with the systems resolution.
Parent - - By jahmaican Date 2014-02-25 15:38 Edited 2014-02-25 15:53
I managed to do it (on Windows) with a third-party program QRes 1.1. It's a 5KB console app that is capable of listing and changing display modes. Just copy qres.exe to your folder of choice and do something like:
modes = %x(qres.exe /L).each_line.to_a.drop(3)
modes.each_index do |n|
  x = modes[n].match(/[^x]*/)[0]
  y = modes[n].match(/(?<=x)(.*)(?=,)/)[0]
  c = modes[n].match(/(?<=, )(.*)(?= bits)/)[0]
  f = modes[n].match(/(?<=@ )(.*)(?= Hz)/)[0]
  modes[n] = { :x => x, :y => y, :c => c, :f => f }
end
puts modes

I'm not very good with regexes, but it works good enough.

A word of advice - apparently you get the list of modes supported by your GPU, not the monitor, so if you try to change to one of them, you might (and should) give user a prompt if he can see anything (and some kind of timeout in case he couldn't).
Attachment: qres.exe - QRes 1.1 (5k)
Parent - - By Spooner Date 2014-02-26 00:46 Edited 2014-02-26 00:52
Here is a nicer version:


PATTERN = /(?<width>\d+)x(?<height>\d+)
           ,\s
           (?<color_depth>\d+)\sbits
           \s@\s
           (?<refresh_rate>\d+)\sHz
          /x

modes = %x(qres.exe /L).each_line.drop(3).map do |line|
  match = line.match(PATTERN)

  {
    width: match[:width].to_i,
    height: match[:height].to_i,
    color_depth: match[:color_depth].to_i,
    refresh_rate: match[:refresh_rate].to_i,
  }
end

puts modes
puts
puts modes.select {|x| x[:color_depth] == 32 }.sort_by {|x| [x[:width], x[:height]] }


You can get this info via opengl reasonably easily. Maybe this functionality should be in Ashton if jlnr doesn't want to add it to Gosu itself?

EDIT: Fixed dumb bug in the code ;)
Parent - By jlnr (dev) Date 2014-02-26 21:51
I'm still convinced that I should kick the resolution-changing fullscreen code out of Gosu. :) The SDL2 offers "fake fullscreen" now, a desktop-sized window where I can just scale everything in OpenGL. Even if I can't use the SDL2 as the base for Gosu on all platforms, I'm still planning to use that bit of code. (The Linux port of Gosu already works like this.)
Up Topic Gosu / Gosu Exchange / list display modes

Powered by mwForum 2.29.7 © 1999-2015 Markus Wichitill