Hristo
Hristo

Reputation: 6540

OpenGL ES 2 2D layered drawing

I am rewriting an iPad drawing application with OpenGL ES2 instead of Core Graphics. I have already written a subclass of GLKView that can draw line segments and I can just drag a GLKView in my storyboard and set it a custom class. So far, drawing works, but I also want to implement layers like in Photoshop and GIMP.

I thought of creating multiple GLKViews for each layer and letting UIKit handle the blending and reordering, but that won't allow blend modes and may not have a good performance.

So far, I think doing everything in one GLKView is the best solution. I guess I will have to use some kind off buffer as a layer. My app should also be able to handle undo/redo, so maybe I will have to use textures to store previous data.

However, I am new to openGL so my question is: How should I implement layers?

Upvotes: 0

Views: 584

Answers (1)

Christian Rau
Christian Rau

Reputation: 45948

Since the question is very broad, here is a broad and general answer that should give you some starting points for more detailed researches.

Probably a good way would be to manage the individual layers as individual textures. With the use of framebuffer objects (FBOs) you can easily render directly into a texture for drawing inside the layers. Each texture would (more or less) persistently store the image of a single layer. For combining the layers you would then render each of the layer textures one over the other (in the appropriate order, whatever that may be) using a simple textured quad and with the blending functions you need.

Upvotes: 4

Related Questions