Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm currently porting a game written in C# with XNA library to Android with Monogame. I have a Texture2D and i'm trying to get an array of uint in this way:

Texture2d textureDeform = game.Content.Load<Texture2D>("Texture/terrain");
uint[] pixelDeformData = new uint[textureDeform.Width * textureDeform.Height];
textureDeform.GetData(pixelDeformData, 0, textureDeform.Width * textureDeform.Height);

I get the following exception:

System.Exception: Error creating framebuffer: Zero at Microsoft.Xna.Framework.Graphics.Texture2D.GetTextureData (Int32 ThreadPriorityLevel) [0x00000] in :0

I found that the problem is in private byte[] GetTextureData(int ThreadPriorityLevel) creating the framebuffer:

private byte[] GetTextureData(int ThreadPriorityLevel)
            int framebufferId = -1;
            int renderBufferID = -1;

            GL.GenFramebuffers(1, ref framebufferId);  // framebufferId is still -1 , why can't be created?
            GL.BindFramebuffer(All.Framebuffer, framebufferId);
            //renderBufferIDs = new int[currentRenderTargets];
            GL.GenRenderbuffers(1, ref renderBufferID);

            // attach the texture to FBO color attachment point
            GL.FramebufferTexture2D(All.Framebuffer, All.ColorAttachment0,
                                    All.Texture2D, this.glTexture, 0);

            // create a renderbuffer object to store depth info
            GL.BindRenderbuffer(All.Renderbuffer, renderBufferID);
            GL.RenderbufferStorage(All.Renderbuffer, All.DepthComponent24Oes,
                                   Width, Height);

            // attach the renderbuffer to depth attachment point
            GL.FramebufferRenderbuffer(All.Framebuffer, All.DepthAttachment,
                                       All.Renderbuffer, renderBufferID);

            All status = GL.CheckFramebufferStatus(All.Framebuffer);

            if (status != All.FramebufferComplete)
                throw new Exception("Error creating framebuffer: " + status);


The frameBufferId is still -1, seems that framebuffer could not be generated and I don't know why. Any help would be appreciated, thank you in advance.

share|improve this question

closed as off-topic by Josh Petrie Dec 30 '13 at 18:35

  • This question does not appear to be about game development within the scope defined in the help center.
If this question can be reworded to fit the rules in the help center, please edit the question.

It's possible that this feature isn't supported on Android. Maybe the MonoGame forums could help. – craftworkgames Sep 15 '13 at 22:58
I'm not entirely sure how Monogame grabs pixel data under the hood, but to my knowledge, OpenGL ES2.0 doesn't really support grabbing pixel data from textures stored in video memory due to a lack of support for Pixel Buffer Objects. That being said, I'm not sure why this code fails to create a Frame Buffer Object – Unreal_Me Sep 17 '13 at 2:27
You may want to try catching a MonoGameGLException that gets thrown inside of GraphicsExtensions.CheckGLError() if there's a GL Error. This might give you more useful information – Unreal_Me Sep 17 '13 at 2:40
This question appears to be off-topic because it is either about debugging your code for you or a Monogame bug. – Anko Sep 17 '13 at 7:28
This question appears to be off-topic because it is about debugging your code for you. – Josh Petrie Dec 30 '13 at 18:35

I would look at the "ref" parameter. Your frame ID might be zero and when you use the "ref" it will add 0 + -1 = -1.. Microsoft example...

class RefExample
    static void Method(ref int i)
        // Rest the mouse pointer over i to verify that it is an int. 
        // The following statement would cause a compiler error if i 
        // were boxed as an object.
        i = i + 44;

    static void Main()
        int val = 1;
        Method(ref val);

        // Output: 45
share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.