genColorFrameBuffer tex width height = do
  traceIO $ "tex size = " ++ (show (width,height))
  !fbo <- genObjectName :: IO FramebufferObject
  bindFramebuffer Framebuffer $= fbo

  !rbo <- genObjectName :: IO RenderbufferObject 
  bindRenderbuffer Renderbuffer $= rbo
  renderbufferStorage Renderbuffer DepthComponent'
                      (RenderbufferSize width height)

  framebufferRenderbuffer Framebuffer DepthAttachment Renderbuffer rbo
  framebufferTexture2D Framebuffer (ColorAttachment 0) Texture2D tex 0
 
  drawBuffers $= [FBOColorAttachment 0] 

  -- unbind
  bindRenderbuffer Renderbuffer $= noRenderbufferObject 
  bindFramebuffer Framebuffer $= defaultFramebufferObject
  return fbo
genColorFrameBuffer tex width height = do
  traceIO $ "tex size = " ++ (show (width,height))
  !fbo <- genObjectName :: IO FramebufferObject
  bindFramebuffer Framebuffer $= fbo

  !rbo <- genObjectName :: IO RenderbufferObject 
  bindRenderbuffer Renderbuffer $= rbo
  renderbufferStorage Renderbuffer DepthComponent'
                      (RenderbufferSize width height)

  framebufferRenderbuffer Framebuffer DepthAttachment Renderbuffer rbo
  framebufferTexture2D Framebuffer (ColorAttachment 0) Texture2D tex 0
 
  drawBuffers $= [FBOColorAttachment 0] 

  -- unbind
  bindRenderbuffer Renderbuffer $= noRenderbufferObject 
  bindFramebuffer Framebuffer $= defaultFramebufferObject
  return fbo
genColorFrameBuffer tex width height = do
  traceIO $ "tex size = " ++ (show (width,height))
  !fbo <- genObjectName :: IO FramebufferObject
  bindFramebuffer Framebuffer $= fbo

  !rbo <- genObjectName :: IO RenderbufferObject 
  bindRenderbuffer Renderbuffer $= rbo
  renderbufferStorage Renderbuffer DepthComponent'
                      (RenderbufferSize width height)

  framebufferRenderbuffer Framebuffer DepthAttachment Renderbuffer rbo
  framebufferTexture2D Framebuffer (ColorAttachment 0) Texture2D tex 0
 
  drawBuffers $= [FBOColorAttachment 0] 

  -- unbind
  bindRenderbuffer Renderbuffer $= noRenderbufferObject 
  bindFramebuffer Framebuffer $= defaultFramebufferObject
  return fbo