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.