Does anyone know how to do "render to texture" with mipmaps on OpenGL ES 2.0?
This is the code that I have:
// Get the original framebuffer object handle.
glGetIntegerv(GL_FRAMEBUFFER_BINDING, &m_origFrameBuffer);
// Create a frame buffer with only the color buffer attached
glGenFramebuffers(1, &m_groundFrameBuffer);
glBindFramebuffer(GL_FRAMEBUFFER, m_groundFrameBuffer);
//Create the ground map texture
glGenTextures(1, &m_textureID);
glBindTexture(GL_TEXTURE_2D, m_textureID);
// Set the textures parameters
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
// Give an empty image to OpenGL ( the last "0" )
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, m_groundMapSize, m_groundMapSize,
0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
glGenerateMipmap(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, 0); // unbind texture
glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, m_textureID, 0);
int status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
if (status != GL_FRAMEBUFFER_COMPLETE)
{
throw RacException("ground framebuffer not created");
}
This code doesn't work. I get a black texture when the mipmapping kicks in.