Reputation: 2142
I am making a simple game (using the book "iPhone and iPad Game Development for Dummies), but I cannot get it to work. I am making the sample application that is used in the book, so I think I have the correct code. Here is the problem.
I put in the code for OpenGL ES, but I am getting a lot of warnings. Here is the code.
.h file:
#import <UIKit/UIKit.h>
#import <OpenGLES/ES2/gl.h>
#import <OpenGLES/ES2/glext.h>
#import <QuartzCore/QuartzCore.h>
#import <CoreGraphics/CoreGraphics.h>
@interface OpenGL : UIView {
EAGLContext *context;
GLuint *framebuffer;
GLuint *colorRenderBuffer;
GLuint *depthBuffer;
}
- (void) prepareOpenGL;
- (void) render;
@end
.m file:
#import "OpenGL.h"
@implementation OpenGL
- (void) awakeFromNib; {
[self prepareOpenGL];
[self render];
}
- (void) prepareOpenGL; {
context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];
[EAGLContext setCurrentContext:context];
glGenFramebuffers(1, &framebuffer);
glBindFramebuffer(GL_RENDERBUFFER, framebuffer);
glGenRenderbuffers(1, &colorRenderBuffer);
glBindRenderbuffer(GL_RENDERBUFFER, colorRenderBuffer);
[context renderbufferStorage:GL_RENDERBUFFER fromDrawable:(CAEAGLLayer*)self.layer];
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, colorRenderBuffer);
GLint height, width;
glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_WIDTH, &width);
glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_HEIGHT, &height);
glGenRenderbuffers(1, &depthBuffer);
glBindRenderbuffer(GL_RENDERBUFFER, depthBuffer);
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, width, height);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depthBuffer);
GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
if (status != GL_FRAMEBUFFER_COMPLETE) {
NSLog(@"Failed to create a complete render buffer!");
}
}
- (void) render; {
glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
glViewport(0, 0, self.bounds.size.width, self.bounds.size.height);
glClearColor(0.5, 0.0, 0.0, 1.0);
glClear(GL_COLOR_BUFFER_BIT);
glBindRenderbuffer(GL_RENDERBUFFER, colorRenderBuffer);
[context presentRenderbuffer:GL_RENDERBUFFER];
}
+ (Class) layerClass; {
return [CAEAGLLayer class];
}
These are the types of warnings I am getting (I cannot put them all in because there are a lot of them):
Passing argument 2 of 'glGenFramebuffers' from incompatible pointer type.
Passing argument 2 of 'glBindFramebuffers' from incompatible pointer type.
Passing argument 2 of 'glGenRenderbuffers' from incompatible pointer type.
Passing argument 2 of 'glBindRenderbuffers' from incompatible pointer type.
So, if all of this came out of the book, why am I getting these warnings? Am I not importing the right files? I really cannot give you much more information than this because I have no idea about what caused this, and I am totally new to OpenGL ES. Thanks for any and all help!
EDIT: One more thing. I get the warnings wherever things like glGenFramebuffers
are used.
Upvotes: 0
Views: 846
Reputation: 56397
The glGen* functions take a size and a pointer to a GLuint, and you're passing the address of a pointer to a GLuint (a GLuint **), which is what triggers the warning.
Just pass the pointer directly, like this:
glGenFramebuffers(1, framebuffer); glGenRenderbuffers(1, colorRenderBuffer); glGenRenderbuffers(1, depthBuffer);
Also don't forget to allocate memory before passing it to OpenGL.
Upvotes: 3