dividuum / info-beamer

The Multimedia Presenter for Lua (for commercial projects, use info-beamer pi instead)
https://info-beamer.com/
Other
227 stars 48 forks source link

load_image in node.render() #52

Closed rocklyve closed 7 years ago

rocklyve commented 7 years ago

Hey, in my project, I have a text file with 3 lines. In one line there is a path to an image file. I want to view the image in my node.lua. I'm not able to execute local background = resource.load_image(IMGname) outside of node.render() because I don't know the path before executing node.render() because I have to read the path from the nth line of the text field. Is there an opportunity to define local background outside of node.render() and declare the variable background inside node.render() with background = resource.load_image(path) background:draw(x,x,x,x) The path variable is the relative or absolute path (I tried both) to the image. I don't know if this should work like this... can you help me? Best regards

dividuum commented 7 years ago

You can solve that like this:

gl.setup(NATIVE_WIDTH, NATIVE_HEIGHT)

local function parse_filename_from_filecontent(content)
     -- parse content and get 3rd line
end

util.file_watch("text-file.txt", function(raw)
    background = resource.load_image(parse_filename_from_filecontent(raw))
end

function node.render()
    util.draw_correct(background, 0, 0, WIDTH, HEIGHT)
end

Don't use absolute paths or relative paths. Just use filenames to files in the current node directory. info-beamer can't (by default) load files outside of the node directory. This is by design.