diff --git a/examples/introduction/video_recording.jl b/examples/introduction/video_recording.jl new file mode 100644 index 0000000..55a6e8f --- /dev/null +++ b/examples/introduction/video_recording.jl @@ -0,0 +1,47 @@ +using Colors, GLVisualize, GLAbstraction, GLWindow + +if !isdefined(:runtests) + window = glscreen() +end +description = """ +Example of how to record a video from GLVisualize +""" +kitty = visualize(loadasset("cat.obj")) +_view(kitty, window) + +# save video to report dir, or in some tmp dir we'll delete later +path = if haskey(ENV, "CI_REPORT_DIR") + ENV["CI_REPORT_DIR"] * "/videorecord.mkv" +else + homedir() +end +name = "" +while true # for some reason, folder retured by mktempdir isn't usable -.- + name = path * "/$(randstring()).mkv" + isfile(name) || break +end + +# create a stream to which we can add frames +io, buffer = GLVisualize.create_video_stream(name, window) +for i=1:10 # record 10 frames + # do something + GLAbstraction.set_arg!(kitty, :color, RGBA{Float32}(1, 0, 1-(i/10), i/10)) + #render current frame + # if you call @async renderloop(window) you can replace this part with yield + GLWindow.render_frame(window) + GLWindow.swapbuffers(window) + GLWindow.poll_reactive() + + # add the frame from the current window + GLVisualize.add_frame!(io, window, buffer) +end +# closing the stream will trigger writing the video! +close(io) + +if !isdefined(:runtests) + renderloop(window) +end +# clean up, only when we're not recording this! +if !haskey(ENV, "CI_REPORT_DIR") + rm(name) +end diff --git a/test/test_static.jl b/test/test_static.jl index 2b58e52..fa7fa24 100644 --- a/test/test_static.jl +++ b/test/test_static.jl @@ -70,8 +70,10 @@ config = ExampleRunner.RunnerConfig( ) window = config.window -imgpath = joinpath(full_folder, "images") -isdir(imgpath) || mkdir(imgpath) +if recording + imgpath = joinpath(full_folder, "images") + isdir(imgpath) || mkdir(imgpath) +end for path in config.files isopen(config.rootscreen) || break @@ -117,7 +119,7 @@ end if recording open(joinpath(full_folder, "report.md"), "w") do io println(io, "### Test Images:") - create_mosaic(io, full_folder) + create_mosaic(io, imgpath) if !isempty(failures) println(io, "### Failures:") for (k, dict) in failures