Question

i'm trying to create a signature with touch inputs using a GLKView. But now i need a UIImage to be below the signature. Short: I want to draw lines above a UIImage using a custom GLKView.

The problem is that my line gets drawn below the image every time, no matter if i set opaque to NO and insertSubview: belowSubview..

Otherwise i tried with the help of textures but i have no idea how to do this..

I do not want to use a GLKViewController if it is possible ;) Thanks in advance!

Update:

I found my problem and now i get the result that i wanted to have.

Inside the GLKView in the Constructor i initiate the EAGLContext. I forgot to set the context to self.

context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];

if (context) {

    self.opaque = NO; // set view transparent
    self.context = context; // set the context to itself
}

Although setting opaque to NO is not a good solution it is the only efficient solution for my task.

Was it helpful?

Solution

There are a couple of ways worth looking at to do this.

One is to look at view containment instead of layering — make the GLKView a subview of the view you're drawing a UIImage in.

The other is to draw the image in your GLKView using OpenGL ES. It's a little more work, but not too hard if you look over the documentation and the answers already here on SO. And it has some extra benefits: since both the background image and your drawing are going into the same framebuffer, you can control blending in GL. Here's some tips for getting started:

  1. Use GLKTextureLoader to get your image into an OpenGL ES texture.
  2. Set up a GLKBaseEffect instance for drawing with your texture. Don't forget to tell it to prepareToDraw.
  3. Draw a quad using the texture and effect. This answer has a pretty decent starting point for doing that.
  4. After drawing the background image, draw your signature and it'll be on top of the image.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top