Using a couple of posts here in StackOverflow, I created what should be a simple rendering to a texture using a framebuffer.
The problem here is that it does not work. Something is broken in the mix since my last texture is just a white square. I am not getting any gl errors. Here is my code.
Declare instance variables.
GLuint texture;
GLuint textureFrameBuffer;
Generate texture and framebuffer.
glGetError();
glEnable(GL_TEXTURE_2D);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_2D, texture);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 512, 128, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
GLint oldFBO;
glGetIntegerv(GL_FRAMEBUFFER_BINDING_OES, &oldFBO);
glGenFramebuffersOES(1, &textureFrameBuffer);
glBindFramebufferOES(GL_FRAMEBUFFER_OES, textureFrameBuffer);
glFramebufferTexture2DOES(GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES, GL_TEXTURE_2D, texture, 0);
glBindFramebufferOES(GL_FRAMEBUFFER_OES, oldFBO);
GLenum err = glGetError();
if (err != GL_NO_ERROR)
{
NSLog(@"Error on framebuffer init. glError: 0x%04X", err);
}
Draw a large line in the framebuffer.
glGetError();
GLint oldFBO;
glGetIntegerv(GL_FRAMEBUFFER_BINDING_OES, &oldFBO);
glBindFramebufferOES(GL_FRAMEBUFFER_OES, textureFrameBuffer);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
[self renderDialog:displayString withSprite:displaySprite withName:displaySpriteName];
glBindFramebufferOES(GL_FRAMEBUFFER_OES, oldFBO);
GLenum err = glGetError();
if (err != GL_NO_ERROR)
{
NSLog(@"Error on string creation. glError: 0x%04X", err);
}
Draw it.
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
glGetError();
[EAGLView enable2D];
glPushMatrix();
float x = 0;
float y = [Globals getPlayableHeight] - dialogRect.size.height;
float w = [Globals getPlayableWidth];
float h = dialogRect.size.height;
GLfloat vertices[] =
{
x, y,
x, y+h,
x+w, y+h,
x+w, y
};
GLfloat texcoords[] =
{
0, 0,
0, h / 128,
w / 512, h / 128,
w / 512, 0
};
glVertexPointer(2, GL_FLOAT, 0, vertices);
glTexCoordPointer(2, GL_FLOAT, 0, texcoords);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_TEXTURE_2D);
[EAGLView bindTexture:texture];
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
glPopMatrix();
GLenum err = glGetError();
if (err != GL_NO_ERROR)
{
NSLog(@"Error on draw. glError: 0x%04X", err);
}
Any external things that I mentioned work fine in other contexts. Any ideas? I know almost nothing about framebuffers, so any troubleshooting help would be great.