Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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?
            GraphicsExtensions.CheckGLError();
            GL.BindFramebuffer(All.Framebuffer, framebufferId);
            GraphicsExtensions.CheckGLError();
            //renderBufferIDs = new int[currentRenderTargets];
            GL.GenRenderbuffers(1, ref renderBufferID);
            GraphicsExtensions.CheckGLError();

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

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

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

            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
2  
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

1 Answer 1

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);
        Console.WriteLine(val);

        // Output: 45
    }
}
share|improve this answer

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