CopernicusTheNines's picture

Texture Arrays with GLControl

Hi! I'm trying to use a texture array in a C# winforms form with a GLControl for my rendering. I'm having a lot of trouble.

I have this basic function set up to just build me a blank, all white texture array:

      private int LoadTexture3D()
        {
            int numsubtextures = 4;
            int texture;
            GL.GenTextures(1, out texture);
            GL.BindTexture(TextureTarget.Texture2DArray, texture);
 
            byte[] fakeData = new byte[512 * 512 * 4 * numsubtextures];
            for (int i = 0; i < 512 * 512 * 4 * numsubtextures; i++)
                fakeData[i] = (byte)255;
 
            GCHandle pinnedArray = GCHandle.Alloc(fakeData, GCHandleType.Pinned);
            IntPtr pointer = pinnedArray.AddrOfPinnedObject();
 
            GL.TexImage3D(TextureTarget.Texture2DArray, 0, PixelInternalFormat.Rgba, 512, 512, numsubtextures, 0, OpenTK.Graphics.OpenGL.PixelFormat.Bgra, PixelType.UnsignedByte, pointer);
            GL.Flush();
 
            pinnedArray.Free();
 
            GL.BindTexture(TextureTarget.Texture2DArray, 0);
 
            return texture;
        }

But, when I bind that texture (using TextureTarget.Texture2DArray) and use it to render, i always get black! I made sure to start my shader with "#version 120" and "#extension GL_EXT_texture_array : enable", it uses a sampler2DArray and calls texture2DArray with a vec3 that has the z component set to the depth of the array to sample from (and x/y set appropriately).

I have this exact same process working in C++, yet when I try to do it in a GLControl I seem to be getting a black texture. Help?

(EDIT): I also can't get 3D textures working. What gives?


Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
CopernicusTheNines's picture

Oh. Duh. I forgot to do this:

            GL.TexParameter(TextureTarget.Texture2DArray, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Nearest);
            GL.TexParameter(TextureTarget.Texture2DArray, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Nearest);
            GL.TexParameter(TextureTarget.Texture2DArray, TextureParameterName.TextureWrapT, (int)TextureWrapMode.Clamp);
            GL.TexParameter(TextureTarget.Texture2DArray, TextureParameterName.TextureWrapS, (int)TextureWrapMode.Clamp);
            GL.TexParameter(TextureTarget.Texture2DArray, TextureParameterName.TextureWrapR, (int)TextureWrapMode.Clamp);

Works fine!