PDA

View Full Version : Animated kaleidoscopes: Do I have the right idea?



Duncan Champney
12-14-2009, 09:56 AM
I want to write an app that will take a still image and generate an animated kaleidoscope. I want to take a triangular subsection of the original image and flip it and rotate it multiple times to create the kaleidoscope image. On a timer I will shift and/or rotate the location of the source triangle and repeat the process. I want to use OpenGL so it is fast enough for smooth animation even for large screens.

My target platform is Macintoshes running Mac OS 10.5 or later.

Here is my thinking:

Set up a full-screen viewport with orthographic projection (I don't need 3D or perspective for this app - I'm just flipping and rotating a triangular section of a source image into a kaleidoscope)

Create a pixel buffer object (PBO) and copy my source image into the PBO. (Scale it down to screen size if needed.)

Create a stencil buffer and set it up to limit drawing to the target triangle in my color buffer.

From what I've read, stencil buffers seem to limit drawing into a target color buffer. It would be helpful if there was an equivalent function to clip SOURCE pixels from my PBO into a triangular slice to be drawn into my kaleidoscope.

Failing that, I guess I would need to apply a transformation matrix so my source image lines up with the target for the current triangle to be drawn into the render buffer, and draw the PBO into the render buffer. I would then apply a transformation to the stencil buffer to move my triangle to it's next location, apply the same transformation to the matrix I use for drawing the PBO into the render buffer, and draw the PBO into the render buffer again.

Once I was done assembling the kaleidoscope from it's component triangles, I would swap buffers to display it to the screen, and start a (platform specific) timer for the next frame.

When the timer went off, I would shift/rotate the matrix used for drawing my PBO into my render buffer, and build another frame of the kaleidoscope.

Would drawing using a stencil buffer enable the hardware to only process pixels that land in the selected part of my stencil buffer, and avoid performing computations on pixels that are not selected in the stencil buffer? And does drawing from a PBO into the render buffer use the current transformation matrix so that I can shift/rotate the pixels from my source PBO image into my destination render buffer?

Another question I have, which might be more appropriate for the Mac-specific forums: Can I be sure that PBOs are available on all Macs running OS 10.5? I think the answer to this is yes, but I'd like to be sure. I would NOT want to have to check for PBO support at runtime and write two separate sets of code for machines with and without PBO support.

If the answer is no, is there a clean, fast way to do this without PBOs? I want to keep all the pixel data in the video hardware so I'm not waiting for transfers back and forth between main memory and video memory. PBOs seem like the way to go for this.

I'd like to be able to get 30 FPS at full screen size out of this, so I get buttery smooth animation of the kaleidoscope, even on lower-end Mac hardware. I don't know if that's a reasonable expectation or not. Assuming there is enough video memory for a full screen stencil buffer and a full-screen sized PBO, I would think that what I am planning is fairly low demand for even the built-in video hardware on low end Macs (at least those that are fast enough to run OS 10.5)

Thanks in advance for any help or suggestions you can offer.



Regards,

ZbuffeR
12-14-2009, 04:12 PM
The no-extension-needed version will only need glCopyTexSubImage2D() once to copy current (part of) framebuffer to a texture. Then render textured triangles with it, until assembling the kaleidoscope. Probably no stencil required either.

You will be able to have very high framerates, 60fps in full hd should doable with basic acceleration.

Do you know what is the "built-in video hardware on low end Macs" ?

Duncan Champney
12-15-2009, 12:28 PM
The no-extension-needed version will only need glCopyTexSubImage2D() once to copy current (part of) framebuffer to a texture. Then render textured triangles with it, until assembling the kaleidoscope. Probably no stencil required either.

You will be able to have very high framerates, 60fps in full hd should doable with basic acceleration.



ZbuffeR,

Thanks for the reply.

I actually haven't tackled OpenGL textures yet. My only openGL app is a fractal renderer that creates height maps of 3D fractals. (You can see sample images in my PBase 3D fractals gallery (http://www.pbase.com/duncanc/3d_fractals&page=all). I'd like to think they are a little more than the usual garden variety Mandelbrot height maps you see all over the place)

I supply a color for every vertex, and use shaded triangle strips to color my fractals.

Textures have to be square, and a power of 2 in size, correct? So I would have to create a texture that's the next larger power of 2 in size, and give everything but my triangular area an alpha value of zero.


Do you know what is the "built-in video hardware on low end Macs" ?

I haven't looked at it in detail. I know that some of the older laptops and "iMacs" have Intel's video chipset rather than NVIDIA or Radion cards. I've been rather underwhelmed by the performance when I've played with such machines as a user. I haven't looked at their stats in detail or benchmarked them however.


Duncan C