Author Topic: video mode  (Read 915 times)

ponderitus

  • Jr. Member
  • **
  • Posts: 57
    • View Profile
video mode
« on: February 07, 2019, 09:51:14 am »
hey, i used to run this at the start of game set the video mode.
Code: [Select]
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 :-
Code: [Select]
-- 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
Code: [Select]
      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 :-
Code: [Select]
      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.

llamazing

  • Full Member
  • ***
  • Posts: 191
    • View Profile
Re: video mode
« Reply #1 on: February 07, 2019, 01:54:08 pm »
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.

ponderitus

  • Jr. Member
  • **
  • Posts: 57
    • View Profile
Re: video mode
« Reply #2 on: February 07, 2019, 02:40:15 pm »
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
« Last Edit: February 08, 2019, 12:26:21 am by ponderitus »

llamazing

  • Full Member
  • ***
  • Posts: 191
    • View Profile
Re: video mode
« Reply #3 on: February 08, 2019, 01:27:31 am »
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"))
« Last Edit: February 08, 2019, 01:30:01 am by llamazing »

ponderitus

  • Jr. Member
  • **
  • Posts: 57
    • View Profile
Re: video mode
« Reply #4 on: February 08, 2019, 04:23:44 pm »
yeah thanks, that worked for starting the game but doesnt work with the pause menu, im getting all this now

Code: [Select]
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.

alexgleason

  • Full Member
  • ***
  • Posts: 128
  • Vegan on a Desert Island
    • View Profile
    • Vegan on a Desert Island
Re: video mode
« Reply #5 on: February 08, 2019, 04:24:44 pm »
Quote
(shader or nil expected, got no value)

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

ponderitus

  • Jr. Member
  • **
  • Posts: 57
    • View Profile
Re: video mode
« Reply #6 on: February 08, 2019, 04:43:28 pm »
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

Christopho

  • Administrator
  • Hero Member
  • *****
  • Posts: 1173
    • View Profile
Re: video mode
« Reply #7 on: February 08, 2019, 07:43:49 pm »
Nothing is broken by 1.6. sol.video.set_mode is deprecated but still supported.

llamazing

  • Full Member
  • ***
  • Posts: 191
    • View Profile
Re: video mode
« Reply #8 on: February 08, 2019, 08:12:07 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

ponderitus

  • Jr. Member
  • **
  • Posts: 57
    • View Profile
Re: video mode
« Reply #9 on: February 11, 2019, 09:01:58 am »
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
Code: [Select]
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
Code: [Select]
  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
Code: [Select]
  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

llamazing

  • Full Member
  • ***
  • Posts: 191
    • View Profile
Re: video mode
« Reply #10 on: February 11, 2019, 01:59:01 pm »
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.

ponderitus

  • Jr. Member
  • **
  • Posts: 57
    • View Profile
Re: video mode
« Reply #11 on: February 12, 2019, 10:06:16 am »
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)