0

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.

Muarl
  • 1,977
  • 1
  • 14
  • 18

1 Answers1

1

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.
Community
  • 1
  • 1
rickster
  • 124,678
  • 26
  • 272
  • 326
  • First thank you for your answer, i would definitely try to focus on your first recommondation which is view containment. But there are some problems: - the draw method of the GLKView is not called - if i force drawing via code it is still not visible - taking a snapshot of the GLKView shows my Signature, which kind of confuses me Im loading the 'parent' UIView is a nib file, and inserting view below supbview is also not helping ;) – Muarl Mar 18 '14 at 09:33
  • How are you "forcing drawing"? To make a `GLKView` (or any `UIView` subclass) draw itself, you call its `setNeedsDisplay` method, which prepares it for drawing and in turn calls your `drawRect:` or `glkView:drawInRect:` method. – rickster Mar 18 '14 at 16:52
  • The snapshot method of GLKView "forced" the drawing. But i already found my problem which I will edit in my answer. A part of the problem was my own stupidness ;) example: i turned off enableSetNeedsDisplay. – Muarl Mar 19 '14 at 07:43