
Texture Arrays with GLControl
Posted Monday, 30 May, 2011 - 23:21 by CopernicusTheNines inHi! 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
Re: Texture Arrays with GLControl
Oh. Duh. I forgot to do this:
Works fine!