C# 某些图形卡中的白色OpenGL纹理

C# 某些图形卡中的白色OpenGL纹理,c#,opengl,opentk,C#,Opengl,Opentk,我使用下面的代码来渲染1D纹理。但在一些图形卡中,它只呈现纯白色。我注意到有时在安装了卡的驱动程序后它会被修复 byte[,] Texture8 = new byte[,] { { 000, 000, 255 }, { 000, 255, 255 }, { 000, 255, 000 }, { 255, 255, 000 },

我使用下面的代码来渲染1D纹理。但在一些图形卡中,它只呈现纯白色。我注意到有时在安装了卡的驱动程序后它会被修复

          byte[,] Texture8 = new byte[,]
        {
            { 000, 000, 255 },   
            { 000, 255, 255 },   
            { 000, 255, 000 },   
            { 255, 255, 000 },   
            { 255, 000, 000 }   
        };

        GL.Enable(EnableCap.Texture1D);

        // Set pixel storage mode 
        GL.PixelStore(PixelStoreParameter.UnpackAlignment, 1);

        // Generate a texture name
        texture = GL.GenTexture();

        // Create a texture object
        GL.BindTexture(TextureTarget.ProxyTexture1D, texture);
        GL.TexParameter(TextureTarget.Texture1D, 
                        TextureParameterName.TextureMagFilter, 
                        (int)All.Nearest);
        GL.TexParameter(TextureTarget.Texture1D, 
                        TextureParameterName.TextureMinFilter, 
                        (int)All.Nearest);
        GL.TexImage1D(TextureTarget.Texture1D, 0, 
                      PixelInternalFormat.Three, /*with*/5, 0, 
                      PixelFormat.Rgb, 
                      PixelType.UnsignedByte, Texture8);

有人能帮忙吗?

一些旧的图形卡/驱动程序无法正确处理尺寸不是2的幂的纹理

在您的例子中,您正在创建宽度为5的1d纹理,这不是二的幂。因此,解决方案是在调用
glTexImage1D
之前,将纹理填充到最接近的二(8)次方

byte[,] Texture8 = new byte[,]
{
    { 000, 000, 255 },
    { 000, 255, 255 },
    { 000, 255, 000 },
    { 255, 255, 000 },
    { 255, 000, 000 },
    { 000, 000, 000 },
    { 000, 000, 000 },
    { 000, 000, 000 }
};

// ...

GL.TexImage1D(TextureTarget.Texture1D, 0, 
              PixelInternalFormat.Three, /*with*/8, 0, 
              PixelFormat.Rgb, 
              PixelType.UnsignedByte, Texture8);

一些旧的图形卡/驱动程序无法正确处理尺寸不是2的幂的纹理

在您的例子中,您正在创建宽度为5的1d纹理,这不是二的幂。因此,解决方案是在调用
glTexImage1D
之前,将纹理填充到最接近的二(8)次方

byte[,] Texture8 = new byte[,]
{
    { 000, 000, 255 },
    { 000, 255, 255 },
    { 000, 255, 000 },
    { 255, 255, 000 },
    { 255, 000, 000 },
    { 000, 000, 000 },
    { 000, 000, 000 },
    { 000, 000, 000 }
};

// ...

GL.TexImage1D(TextureTarget.Texture1D, 0, 
              PixelInternalFormat.Three, /*with*/8, 0, 
              PixelFormat.Rgb, 
              PixelType.UnsignedByte, Texture8);

某些驱动程序/卡(尤其是较旧的驱动程序/卡)存在非2次方大小纹理的问题。如何将纹理设置为2次方1?将其填充为下一次2次方。在本例中,您需要添加3个额外像素,并将
glTexImage1D
中的宽度更改为8。@M.Elmi:您不需要将纹理设置为2的幂。你就这样供应吧。你知道,做任意一个维度,使它跟随d=2^nOK。我测试了它,它成功了。非常感谢你。如果你们中有人可以发布回复,将其标记为答案。一些驱动程序/卡(尤其是较旧的驱动程序/卡)存在非2次方大小纹理的问题。我如何将纹理设置为2次方1?通过将其填充到下一次方2。在本例中,您需要添加3个额外像素,并将
glTexImage1D
中的宽度更改为8。@M.Elmi:您不需要将纹理设置为2的幂。你就这样供应吧。你知道,做任意一个维度,使它跟随d=2^nOK。我测试了它,它成功了。非常感谢你。如果你们中的一个人可以发布你们的回复,将其标记为答案。谢谢你们的回答。谢谢你们的回答。