Render to texture failing
I am trying to setup a FBO so I can render to a texture. It works fine in simulator but fails on iPhone 3G with the message "failed to make complete framebuffer object 8cd6". The error code is GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_OES.
Here is the code
I've followed the way it's done on Apple's website topic Using Framebuffer Objects to Render to a Texture.
I have researched this for hours now and cannot figure out why it's failing.
Here is the code
Code:
GLuint framebuffer;
glGenFramebuffersOES(1, &framebuffer);
glBindFramebufferOES(GL_FRAMEBUFFER_OES, framebuffer);
GLuint texture;
glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_2D, texture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 320, 480, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
glFramebufferTexture2DOES(GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES, GL_TEXTURE_2D, texture, 0);
glBindTexture(GL_TEXTURE_2D,0);
GLuint depthRenderbuffer;
glGenRenderbuffersOES(1, &depthRenderbuffer);
glBindRenderbufferOES(GL_RENDERBUFFER_OES, depthRenderbuffer);
glRenderbufferStorageOES(GL_RENDERBUFFER_OES, GL_DEPTH_COMPONENT16_OES, 320, 480);
glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_DEPTH_ATTACHMENT_OES, GL_RENDERBUFFER_OES, depthRenderbuffer);
GLenum status = glCheckFramebufferStatusOES(GL_FRAMEBUFFER_OES);
if(status != GL_FRAMEBUFFER_COMPLETE_OES)
NSLog(@"failed to make complete framebuffer object %x", status);
I've followed the way it's done on Apple's website topic Using Framebuffer Objects to Render to a Texture.
I have researched this for hours now and cannot figure out why it's failing.
Even putting this code into a blank OpenGL ES template in XCode it fails on the 3G (running iOS 4.0.1). Can someone please help?
Having a quick look through your code I believe you can't create a Non-Power-Of-Two textures on the iPhone. Try putting a glGetError() after your glTexImage2D() to test if it fails.
There might be other errors but hopefully that will give you a head start.
There might be other errors but hopefully that will give you a head start.
The Monkey Hustle - Now available on the App Store!
Oh wow, what an idiot I am. Thankyou so much mariocaprino that was it. I can't believe I have spent so much time trying to figure this out!
More specifically, you can't create NPOT textures on MBX devices. You can on SGX.
How can I check if I need to make the texture POT? Any glGetIntegerv() I can check?
Another problem I've encountered is when I switch back to my normal rendering the depth buffer is no longer working.
I have this code
If I don't active the texture rendering then it renders fine, it's only when I go to texture rendering then back again that the depth buffer no longer works.
Looks like all I need is
And to restore the default depth buffer
Another problem I've encountered is when I switch back to my normal rendering the depth buffer is no longer working.
I have this code
Code:
if(m_textureRenderer->IsActive())
{
glBindFramebufferOES(GL_FRAMEBUFFER_OES, m_textureRenderer->GetFrameBuffer());
glBindRenderbufferOES(GL_RENDERBUFFER_OES, m_textureRenderer->GetDepthBuffer());
}
else
{
glBindFramebufferOES(GL_FRAMEBUFFER_OES, m_defaultFramebuffer);
glBindRenderbufferOES(GL_RENDERBUFFER_OES, m_depthRenderbuffer);
}
If I don't active the texture rendering then it renders fine, it's only when I go to texture rendering then back again that the depth buffer no longer works.
Looks like all I need is
Code:
if(m_textureRenderer->IsActive())
glBindFramebufferOES(GL_FRAMEBUFFER_OES, m_textureRenderer->GetFrameBuffer());
else
glBindFramebufferOES(GL_FRAMEBUFFER_OES, m_defaultFramebuffer);
And to restore the default depth buffer
Code:
glBindRenderbufferOES(GL_RENDERBUFFER_OES, m_depthRenderbuffer);
glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_DEPTH_ATTACHMENT_OES, GL_RENDERBUFFER_OES, m_depthRenderbuffer);
(Sep 1, 2010 01:44 AM)headkaze Wrote: How can I check if I need to make the texture POT?
Check for the APPLE_texture_2D_limited_npot extension, as listed in the platform notes.
Quote:I have this code
What are you expecting glBindRenderbuffer to do here?
(Sep 1, 2010 08:23 PM)arekkusu Wrote: What are you expecting glBindRenderbuffer to do here?
I replied to my own post which seems to add to the previous post with a HR between them.
What I wanted to do was switch my game from rendering to the screen to a texture (for a transition) then back again.
I've already figured it out, I just had to add the glFramebufferRenderbufferOES call instead of just binding it otherwise the depth buffer does not work.
Possibly Related Threads...
Thread: | Author | Replies: | Views: | Last Post | |
iPad,render to texture, low framerate | ldynasa | 0 | 3,700 |
Nov 13, 2010 12:34 AM Last Post: ldynasa |
|
GameKit bluetooth failing on iPad? | Cirdan | 0 | 4,978 |
Sep 3, 2010 01:20 AM Last Post: Cirdan |
|
Performance problems with render to texture method | mbw234 | 6 | 8,442 |
Jun 25, 2010 01:47 AM Last Post: Jamie W |
|
Multi-touch failing | Sumaleth | 1 | 3,829 |
Feb 24, 2010 08:49 PM Last Post: Sumaleth |
|
OpenAL alGenSources failing | captainfreedom | 1 | 5,202 |
May 26, 2009 07:45 AM Last Post: captainfreedom |