显示全黑的OpenTK纹理

时间:2012-10-17 14:06:30

标签: c# textures opentk dds-format

好吧所以我已经采取了一些在其他程序上工作正常的代码,我把它复制到我正在处理的新程序中它似乎不起作用,据我所知我已经有了那里所有需要的线条,但是出现纹理的区域只显示黑色方块。

我想我错过了一条线,但我不知道它是什么。至少可以说,我很困惑。

这是我的opengl设置:

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);

这是加载纹理并返回纹理id的方法,我将它存储在我的变量中。 (file.writeallbytes只是一个测试,我可以在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;
}

我的绘图方法如下:

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);
}

编辑:纹理确实显示,但纹理是全黑的,即使我设置了另一个颜色值(通常会改变纹理的色调)

0 个答案:

没有答案
相关问题