
2D byte array to grayscale texture problems.
Posted Tuesday, 11 October, 2011 - 19:41 by JonConley inI am trying to store a 256x256x256 group of voxels as a 2D picture (only need 1 byte, there won't be more than 256 types of voxels). So to also try and debug (and save the voxel patch out I figured I can just store it as a grayscale png file).
Dim2x and Dim2y are just constants which equate to 4096
The for loop before I create the texture is to just go ahead and color part of the image a different shade, that way I'd know if it were showing up, but as of right now it doesn't.
This is what I am trying to do to create the texture:
public Patch() { this.patchVals = new byte[Dim2x, Dim2y]; for(int i = 0; i < 4096; i++) for (int j = 0; j < 1000; j++) { patchVals[i, j] = 128; } this.patch2D = GL.GenTexture(); GL.BindTexture(TextureTarget.Texture2D, patch2D); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)All.Linear); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)All.Linear); GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.CompressedIntensity, Dim2x, Dim2y, 0, PixelFormat.Alpha, PixelType.Byte, patchVals); }
And then to try and render it as a fullscreen quad:
public void Draw2D(int width, int height) { //render code here GL.BindTexture(TextureTarget.Texture2D, patch2D); GL.Enable(EnableCap.Texture2D); GL.MatrixMode(MatrixMode.Projection); GL.LoadIdentity(); GL.Ortho(0, width, height, 0, -1, 1); GL.Begin(BeginMode.Quads); GL.TexCoord2(0f, 0f); GL.Vertex2(0, 0); GL.TexCoord2(1f, 0f); GL.Vertex2(width, 0); GL.TexCoord2(1f, 1f); GL.Vertex2(width, height); GL.TexCoord2(0f, 1f); GL.Vertex2(0, height); GL.End(); }

