3

I'm having a problem with GLKit in a project that is similar to GLPaint.

First of all, I'm not using GLKViewController, but only a GLKView which is added to my class.

My problem is that when I draw in my GLKView, the content flickers. It looks as if I was drawing in a certain frame buffer in the first call to GLKViewDelegate's drawRect and next call it was a different frame buffer, then next call it came back to the first one, etc. I have tested this possibility and it does not seem to be the case, both render buffer and frame buffer are the same in all the drawing.

Here is how my drawing works (similar to GLPaint sample code):

On touch events, I call renderStroke to generate points that are used in the drawing to apply the textures and present a line. I am using custom shaders, so I place the buffer containing these points in a pre-specified spot so the shader has access to it:

// Give the vertex positions to the vertex shader
glVertexAttribPointer(ATTRIB_POSITION, 2, GL_FLOAT, 0, 0, vertexBuffer);
glEnableVertexAttribArray(ATTRIB_POSITION);

Then, in the draw method, I call glDrawArrays:

- (void)glkView:(GLKView *)view drawInRect:(CGRect)rect {
    glDrawArrays(GL_POINTS, 0, self.verticesCount);
}

Here is how I initialize the GLKView:

self.glView = [[GLKView alloc] initWithFrame:self.frame];
self.glView.context = _context;
self.glView.delegate = self;
self.glView.drawableColorFormat = GLKViewDrawableColorFormatRGBA8888;
self.glView.drawableStencilFormat = GLKViewDrawableStencilFormat8;
self.glView.enableSetNeedsDisplay = NO;
self.glView.userInteractionEnabled = NO;
[self addSubview:self.glView];

The texture, modelViewProjection matrix seem to work properly since I can see the right texture applied to every point.

I've been searching ways to debug this, but everything I saw seemed normal. Is there something I'm missing?

Thanks!

EDIT:

I am wondering, when drawRect is called, is the color_render_buffer and stencil_buffer meant to be cleared before further drawing is done? My goal here is to keep the drawing I have done previously and draw other content on top of it. Without GLKit, this is normally done using kEAGLDrawablePropertyRetainedBacking. I have set it on the glView layer using:

CAEAGLLayer * const eaglLayer = (CAEAGLLayer*) self.glView.layer;
eaglLayer.opaque = NO;
eaglLayer.drawableProperties = @{kEAGLDrawablePropertyRetainedBacking : @(YES)};

This does not seem to work however.

ebp
  • 61
  • 4
  • Nope, you can check this thread I created on the apple forum where I describe some of my toughts on the problem. Here is the link: [https://devforums.apple.com/thread/162592?tstart=15] – ebp Sep 08 '12 at 21:44
  • This answer works: http://stackoverflow.com/questions/9395743/glkview-set-drawable-properties/13684498#13684498 – aoakenfo Mar 09 '14 at 05:56

1 Answers1

0

Is a glClear() being done on color and depth buffers on each frame redraw? I don't see it in the code above.

M-V
  • 5,167
  • 7
  • 52
  • 55
  • No I don't use glClear() at each redraw. If I did that would actually clear everything I have drawn so far, but that is not the case here. I want to retain what is in the framebuffer and add the new drawing. – ebp Aug 08 '12 at 13:24
  • Well, then I think you should be drawing to the front buffer and issuing a glFlush(), assuming that the window is double buffered. – M-V Aug 09 '12 at 01:22
  • Hmmm I'm not sure I understand how that would be done using glKit. Is there really a way to draw specifically in the front buffer? – ebp Aug 09 '12 at 13:37
  • I guess glDrawBuffer(GL_FRONT) is not available on OpenGL ES? How about glFlush() - did you try it? – M-V Aug 09 '12 at 14:41
  • I don't understand the moment I should call glFlush and the effect it would have. glFlush — force execution of GL commands in finite time – ebp Aug 09 '12 at 14:46
  • I forgot to confirm, but glDrawBuffer is indeed unavailable in OpenGL ES. – ebp Aug 09 '12 at 14:57
  • 1
    I have tried but it did not fix the issue. Just for information, the problem would be that before redrawing the view, the buffer that is presented is swaped? Because it seems like there are 2 buffers that are alternatively presented.For example, when I draw a straight line, I will see a first stroke, a space, another stroke, space etc. When I draw something else, I will see the opposite, a space, stroke, space, stroke. If the two content were combined, this would make a full line. – ebp Aug 09 '12 at 15:15