nasser / zajal

Experimental creative coding framework
MIT License
161 stars 10 forks source link

Weird screen grabs #70

Closed judy-zz closed 11 years ago

judy-zz commented 11 years ago

I'm running the following code:

@img = Image.new 500, 500
@img_saved = false

draw do
  color_mode :hsv
  @img.draw 0, 0

  255.times do |i|
    h, s, v = (i + time * 100) % 255, 255, 255
    color h, s, v
    circle 200 + sin(i * sin(time * 0.03))*(30 + i),
           200 + cos(i * sin(time * 0.03))*(30 + i),
           1 + i * 0.1
  end

  @img.grab_screen 0, 0, 500, 500

  if !@img_saved && time > 5.0
    @img.save "test.png"
    @img_saved = true
  end

end

There are a couple weird things going on with the saved screenshot (saved 2 seconds into the sketch being run):

This is the only thing I need fixed right now in order to begin pdiffing images in order to spec everything out and create documentation with said images.

nasser commented 11 years ago

I might know what this is. There are some unresolved OpenGL viewport issues that may be related. I'll look into this first thing today.

As a side note, I'm almost done with a new headless frontend who's primary purpose is screenshot generation. It does all of its rendering offscreen (doesn't open a window) and is a lot faster as a result for multiple screenshots. That should be pushed out today or the next few days.

judy-zz commented 11 years ago

Oh, that will be much easier! I'm looking forward to the fix.

nasser commented 11 years ago

FBOs and bin/renderer are in! Check out https://github.com/nasser/zajal/blob/amsterdam/bin/render, but also this now works

@fbo = Fbo.new width, height

draw do
  Zajal::Graphics::Native.ofSetupScreenPerspective width.to_f, height.to_f, :default, false, 60.0, 0.0, 0.0
  @fbo.capture do
    background 128, 0, 0
    circle 20, 20, 10

    color 0, 128, 255
    circle 80, 80, 10
  end
end

mouse_down do
  @fbo.to_pixels.save "~/Desktop/foo.png"
end

The only sticking point is the Zajal::Graphics::Native.ofSetupScreenPerspective, which is needed because FBOs treat the bottom left corner as 0,0 (like all of OpenGL) but openFrameworks treats the top left corner as 0,0 (to emulate processing). This call basically disables v-flipping.

I am also considering making all rendering in Zajal FBO based. It is much more flexible than what we're doing right now, allows for really nice smoothing, and we always have access to a 'current fbo' object that we can grab pixels from. We'll see.

We could do away with this convention all together and possibly be better for it, but that's another discussion. Let me know if this works for your testing framework.

nasser commented 11 years ago

I'm leaving this issue open because I still need to investigate what was causing your screenshots to come out weird in the first place.

nasser commented 11 years ago

Ok. So, your screenshots were coming out weird because you were grabbing a 500x500 screenshot of a 400x400 app (the default size). Grabbing a 400x400 screenshot works.

Image#grab_screen should raise an error if you try and take a screenshot larger than the app. I'm working on that now.