FBO: Render to Texture not working!

Started by
11 comments, last by TheChubu 9 years, 7 months ago

[[UIScreen mainScreen] bounds] should not change. That tells you the maximum contentScaleFactor, which will be 2.0f on retina devices and 1.0f otherwise. The UIView into which you draw (the UIView you use to call renderbufferStorage: fromDrawable:) is what changes, and it will also affect the sizes you pass to renderbufferStorage: fromDrawable:, so be aware.

L. Spiro

I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid

Advertisement

Oops, didn't catch your last response (should have reloaded). But it's working so far, in the simulator at least.

Shogun.

BTW, I think these calls:

glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

Should use glTexParameteri, not glTexParameterf as far as I know.

Then this call:

glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);

Should be:

glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);

"Internal format" parameter specifies the bit quantity (8 bits per pixel in this case).

You might also need to call glDrawBuffers with the color attachment you're writing to (ie, GL_COLOR_ATTACHMENT0), then with GL_BACK_LEFT when you're writing to the default framebuffer (I made the mistake before of calling it with GL_FRONT_LEFT and writing to the front buffer, messing double buffering along the way).

Also, you attach render buffers (RBOs) when you'll never need to sample from the attachment, they're sort of like the non-readable cousin of immutable textures, and used normally for the depth-stencil attachment. If you'll need to sample from the FBO, attach regular textures, then just bind the texture to sample from it.

This http://www.opengl.org/wiki/Framebuffer_Object might be helpful to read too.

"I AM ZE EMPRAH OPENGL 3.3 THE CORE, I DEMAND FROM THEE ZE SHADERZ AND MATRIXEZ"

My journals: dustArtemis ECS framework and Making a Terrain Generator

This topic is closed to new replies.

Advertisement