[HOpenGL] Rendering to texture

Alexander Göransson alexander.goransson at gmail.com
Tue Apr 27 03:52:07 EDT 2010


Here's some C code i want to translate to haskell, but i can't find
the proper bindings. I've been greping OpenGL and OpenGLRaw, but i
can't find anything:

    // Let us create an FBO; to do this add the following at the end of initGL:
    glGenFramebuffers(1, &frameBuffer);
    // Bind the framebuffer such that following commands will affect it.
    glBindFramebuffer(GL_FRAMEBUFFER, frameBuffer);

    // Then we will create a texture into which we will be rendering,
directly after add:
    // Create a texture for the frame buffer, with specified filtering,
    // rgba-format and size
    glGenTextures(1, &texFrameBuffer);
    glBindTexture(GL_TEXTURE_2D, texFrameBuffer);
    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, 4, 512, 512, 0, GL_RGBA,
              GL_UNSIGNED_BYTE, NULL);

    // Next we will attach the texture to the FBO:
    glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
              GL_TEXTURE_2D, texFrameBuffer, 0);

And this is the end of initGL:

    texture = ilutGLLoadImage("flake.ppm");

    glActiveTexture(GL_TEXTURE0);
    glBindTexture(GL_TEXTURE_2D, texture);
    glGenerateMipmap(GL_TEXTURE_2D);

    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, 16);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
GL_LINEAR_MIPMAP_LINEAR);

So far i have a modified version of my texture loader but i don't know
if this is correct or what:

whatIsThisIDontEven :: TextureSize2D -> IO TextureObject
whatIsThisIDontEven size = do
    [texObj] <- genObjectNames 1
    activeTexture $= TextureUnit 0
    textureBinding Texture2D $= Just texObj
    generateMipmap Texture2D $= Enabled
    textureFilter  Texture2D $= ((Nearest, Just Nearest), Nearest)
    texImage2D Nothing NoProxy 1 RGBA' size 0
        (PixelData RGBA Float nullPtr)
    return texObj

My problem is that glBindFramebuffer isn't available in the haskell bindings.
At least i can't find it after extensive searching :(

What to do?

 // Alexander


More information about the HOpenGL mailing list