OpenTK Texture showing up full black

2k Views Asked by At

Allright so I've taken some code that works fine on other programs, I've copied it into a new program I'm working on and it doesn't seem to work, as far as I know I've got all the needed lines in there, but the areas where a texture is suppost to appear just display black squares.

I think I'm missing a line but I've got no idea what it is. I'm quite puzzled to say the least.

Here is my opengl setup:

GL.ClearColor(Color.Black);
GL.MatrixMode(MatrixMode.Projection);
GL.LoadIdentity();
GL.Viewport(0, 0, glControl1.Width, glControl1.Height);
GL.Ortho(0, 800, 600, 0, -30, 30);

This is the method that loads the textures and returns the texture id, I store that in my variable. (the file.writeallbytes is just a test, I could open that no problem in photoshop)

private int loadTexture(String path)
{
    GL.Enable(EnableCap.Texture2D);

    byte[] ddsBytes = Media.GetFile("\\"+path.Replace("\\\\","\\")).Skip(20).ToArray();
    File.WriteAllBytes("Derp.dds", ddsBytes);

    int texId = GL.GenTexture();
    GL.BindTexture(TextureTarget.Texture2D, texId);

    Bitmap image = null;

    DDSReader.DDSImage ddsImg = new DDSReader.DDSImage(ddsBytes);
    image = ddsImg.BitmapImage;
    ddsImg = null;

    BitmapData bmpData = image.LockBits(new Rectangle(0, 0, image.Width, image.Height), ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb);

    GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, bmpData.Width, bmpData.Height, 0, OpenTK.Graphics.OpenGL.PixelFormat.Bgra, PixelType.UnsignedByte, bmpData.Scan0);

    image.UnlockBits(bmpData);
    GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear);
    GL.TexEnv(TextureEnvTarget.TextureEnv, TextureEnvParameter.TextureEnvMode, (int)All.Modulate);

    return texId;
}

And my drawing method looks like this:

public void Draw()
{
    if (TexID == -1)
    {
        GL.Color4(Color[0], Color[1], Color[2], (byte)100);
    }
    else
    {
        GL.Color3((byte)255,(byte)255,(byte)255);
        GL.Enable(EnableCap.Texture2D);
        GL.BindTexture(TextureTarget.Texture2D, TexID);
    }

    GL.Begin(BeginMode.TriangleStrip);
    GL.TexCoord2(0, 0);
    GL.Vertex2(X, Y + Height);
    GL.TexCoord2(0, 1);
    GL.Vertex2(X, Y);
    GL.TexCoord2(1, 0);
    GL.Vertex2(X + Width, Y + Height);
    GL.TexCoord2(1, 1);
    GL.Vertex2(X  +Width, Y);
    GL.End();

    GL.Disable(EnableCap.Texture2D);
}

EDIT: The texture does show up, but the texture is full black, even when I set another color value (which usually changes the hue of the texture)

0

There are 0 best solutions below