video mode

Started by ponderitus, February 07, 2019, 09:51:14 AM

Previous topic - Next topic
hey, i used to run this at the start of game set the video mode.
function sol.main:on_started()
-- Set Video Mode.
sol.video.set_mode("hq2x")


but now in 1.6 i get this :-
"Warning: The function sol.video.set_mode() is deprecated since Solarus 1.6. Use sol.video.set_shader() instead."

but when i change this :-
-- This function is called when Solarus starts.
function sol.main:on_started()
-- Set Video Mode.
sol.video.set_shader("hq2x")


i now get this :-
"Error: In on_started: main.lua:15: bad argument #2 to set_shader (shader or nil expected, got no value)
stack traceback:
[C]: at 0x01a54540
[C]: in function 'set_shader'
main.lua:15: in function <main.lua:13>"

I have the same issue in options_menu
      if self.cursor_position == 1 then
        -- Change the video mode.
        sol.video.switch_mode()
        self.video_mode_text:set_text(sol.video.get_mode())
      else


Warning: The function sol.video.switch_mode() is deprecated since Solarus 1.6. Use sol.video.set_shader() instead.
Warning: The function sol.video.get_mode() is deprecated since Solarus 1.6. Use sol.video.get_shader() instead.

but when i change that to :-
      if self.cursor_position == 1 then
        -- Change the video mode.
--        sol.video.switch_mode()
sol.video.set_shader()
    --    self.video_mode_text:set_text(sol.video.get_mode())
self.video_mode_text:set_text(sol.video.get_shader())
      else


i now get this error :-
"Error: In on_command_pressed: scripts/menus/pause_options.lua:229: bad argument #2 to set_shader (shader or nil expected, got no value)
stack traceback:
[C]: at 0x018d4540
[C]: in function 'set_shader'
scripts/menus/pause_options.lua:229: in function <scripts/menus/pause_options.lua:200>"

I looked at the scripts for the development games and on github and they have the same script in pause_options.

You need to have the "hq2x" shader in data/shaders. Looks like the solarus-free-resource-pack has the shader, so copy it into your quest project.

February 07, 2019, 02:40:15 PM #2 Last Edit: February 08, 2019, 12:26:21 AM by ponderitus
yeah its in there,  along with the grayscale, 6xbrx and sepia, with the hq2x.frag.glsl,

as in, it was there beforehand so is not the fix

February 08, 2019, 01:27:31 AM #3 Last Edit: February 08, 2019, 01:30:01 AM by llamazing
I see what you are doing wrong.

sol.video.set_shader() takes a shader object as a parameter, not a string.

So instead of:
Code (lua) Select
sol.video.set_shader("hq2x")

You want to do:
Code (lua) Select
  sol.video.set_shader(sol.shader.create("hq2x"))

yeah thanks, that worked for starting the game but doesnt work with the pause menu, im getting all this now

Error: In on_started: scripts/menus/pause_options.lua:27: bad argument #1 to create (Bad field 'text' (string expected, got shader))
stack traceback:
[C]: at 0x01774540
[C]: in function 'create'
scripts/menus/pause_options.lua:27: in function <scripts/menus/pause_options.lua:6>
[C]: in function 'start'
scripts/menus/pause_submenu.lua:126: in function 'next_submenu'
scripts/menus/pause_map.lua:100: in function <scripts/menus/pause_map.lua:87>
Error: In on_draw: scripts/menus/pause_options.lua:176: attempt to index field 'cursor_sprite' (a nil value)
stack traceback:
[C]: in function '__index'
scripts/menus/pause_options.lua:176: in function <scripts/menus/pause_options.lua:170>
Error: In on_draw: scripts/menus/pause_options.lua:176: attempt to index field 'cursor_sprite' (a nil value)
stack traceback:
[C]: in function '__index'
scripts/menus/pause_options.lua:176: in function <scripts/menus/pause_options.lua:170>


this second error errors about 100 times but i didnt want to copy it all in.

Quote(shader or nil expected, got no value)

Why does it say "no value" instead of "string"?
RIP Aaron Swartz

i have no idea, this stuff is way to advanced for me to know whats happening, it was a miracle that i got it to work on 1.5 so when it broke changing to 1.6 i died a little inside.

id happily just take out the option to change the "graphics" like i have in the save_game menu. and just start the game in HQ2X. but i cant seem to take it out the options_menu or have the options_menu run correctly without it in

Nothing is broken by 1.6. sol.video.set_mode is deprecated but still supported.

Quote from: Christopho on February 08, 2019, 07:43:49 PM
Nothing is broken by 1.6. sol.video.set_mode is deprecated but still supported.

Might as well fix it now since it will go away some day.

sol.video.switch_mode() does not have an equivalent function in v1.6, so you'll have to write your own.

Add the following code the the beginning of your options_menu:
Code (lua) Select

local video_mode_index = 1 --index for the current video mode, default is no shader
local video_modes = { --list of shaders to use for the video mode
  false, --don't use a shader
  sol.shader.create("scale2x"),
  sol.shader.create("hq2x"),
  sol.shader.create("hq4x"),
}

--cycles between video modes
local function switch_video_mode()
  --advance to next video mode
  video_mode_index = video_mode_index + 1
  if video_mode_index > #video_modes then video_mode_index = 1 end

  --set the shader for the current video mode
  local shader = video_modes[video_mode_index] or nil
  sol.video.set_shader(shader)

  return shader and shader:get_id() or "normal" --return string naming the current video mode
end


And the code you posted becomes:
Code (lua) Select

      if self.cursor_position == 1 then
        -- Change the video mode.
        self.video_mode_text:set_text(switch_video_mode())
      else


yes that worked for switching it, now when i open the pause_options after changing shader, or starting the game with one active i get this

Info: Shader: 'hq2x'
Error: In on_started: scripts/menus/pause_options.lua:53: bad argument #1 to create (Bad field 'text' (string expected, got shader))
stack traceback:
[C]: at 0x01774540
[C]: in function 'create'
scripts/menus/pause_options.lua:53: in function <scripts/menus/pause_options.lua:32>
[C]: in function 'start'
scripts/menus/pause_submenu.lua:126: in function 'next_submenu'
scripts/menus/pause_map.lua:100: in function <scripts/menus/pause_map.lua:87>

this is 32-60 of pause_options
function options_submenu:on_started()

  submenu.on_started(self)

  local font, font_size = language_manager:get_menu_font()
  local width, height = sol.video.get_quest_size()
  local center_x, center_y = width / 2, height / 2

  self.column_color = { 255, 255, 255}
  self.text_color = { 115, 59, 22 }

  self.video_mode_label_text = sol.text_surface.create{
    horizontal_alignment = "left",
    vertical_alignment = "top",
    font = font,
    font_size = font_size,
    text_key = "selection_menu.options.video_mode",
    color = self.text_color,
  }
  self.video_mode_label_text:set_xy(center_x - 50, center_y - 58)

    self.video_mode_text = sol.text_surface.create{ -------------------------------------------------line 53
    horizontal_alignment = "right",
    vertical_alignment = "top",
    font = font,
    font_size = font_size,
    text = sol.video.get_shader(),
    color = self.text_color,
  }


submenu

  local submenu_index = self.game:get_value("pause_last_submenu")
  submenu_index = (submenu_index % #submenus) + 1
  self.game:set_value("pause_last_submenu", submenu_index)
  sol.menu.start(self.game.pause_menu, submenus[submenu_index], false)


pause_map
  elseif command == "right" then
    self:next_submenu()
    handled = true


I know this option doesnt even work the same anymore, but it would be pretty cool to be able to flick the game into grayscale at the touch of a button, go even more retro and feel like you're on the gameboy  ;D

Change line 58 from:
Code (lua) Select
text = sol.video.get_shader(),
to:
Code (lua) Select
text = sol.video.get_shader() and sol.video.get_shader():get_id() or "Normal",

If you plan on translating your game to other languages, then you should probably use string.dat entries for the names of the video modes, though.

wow, that fixed everything. thanks for all your help over the last few days. As for the translating I dont really know how id do that, I learnt all that i know from Christopho's tutorials a few years back and then reading scripts. I wish they had never finished there's still so so much to learn. As for now though the game can switch between English and French no problem so maybe its ok already? (French probably makes no sense as i cant speak it lol)