I’m looking for a sample application that uses Apple’s new GLKView object (ideally with textures) but not using the GLKViewController object.
I’m going crazy here.
I have a client that wants an app that will make fairly simple use of OpenGL textures drawn onto a distorted mesh.
I need to create 2 side-by-side GLKViews inside a normal view controller, with other UIKit controls on the screen. Thus, GLKViewController really isn’t suitable. It is designed to control a full-screen OpenGLView as it’s main content view, and also has a bunch of timing loop functionality that I don’t want. (This app will draw fairly static images, and when I need to update, I’m happy to call setNeedsDisplay.)
I’ve written a fair amount of OpenGL (fixed pipeline) code for Mac OS, but I’m lost when it comes to OpenGL ES 2.0 and getting everything working. It’s a case of “Everything you know is wrong”, I’m afraid.
I’m trying to use GLKit and GLKView. I can’t find a single example that uses a GLKView without a GLKViewController.
I must be setting things up incorrectly, because something always fails. with a 0X0502 error (GL_INVALID_OPERATION). Right now, it’s a call to glUniformMatrix4fv to set the model view and/or projection matrixex in my vertex shader.
In the init of my subclass of GLKView, I don’t create a renderbuffer or frame buffer because it’s my understanding that the GLKView does that for me. I don’t create or ask for a depth buffer because this is a simple 2D drawing with no depth. (In fact, the default values for drawableColorFormat, drawableDepthFormat, drawableStencilFormat, and drawableMultisample are all correct for my application.
I create an OpenGL 2.0 EAGLContext and install it as the context for the view. I then compile and link my shaders, and create the program and get back a valid program handle. The call to glUseProgram is also not returning an error.
I’m creating and binding a vertex buffer and index buffer, and those “names” also appear valid, and calls to glGetError are not returning errors.
I’m getting back a valid “name” for my texture uniform (this used to be the call that was returning and GL_INVALID_OPERATION error.)
I’m also getting back valid names for my model view matrix uniform variable and projection matrix uniform.
As I say, my code is failing when I try to set the either my model view matrix uniform variable or projection matrix uniform vairable. All I do is code like this:
GLKMatrix4 identity = GLKMatrix4Identity;
glUniformMatrix4fv(_modelViewUniform, 1, 0, (GLfloat*) &identity);
result = glGetError();
But result comes back as GL_INVALID_OPERATION.
If I could find sample code that sets up a GLKView and installs a texture in it, I’m confident that I could use it as a model and figure out what I’m doing wrong.
I’d greatly appreciate either a link to some GLKView sample code (without a GLKViewController) or some advise on what I’m doing wrong.)