سؤال

I am using following code to render a 1D texture. But in some graphic cards it renders only a solid white one. I noticed sometimes it is fixed after installing the card's driver.

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

Can anybody help?

هل كانت مفيدة؟

المحلول

Some older graphics cards/drivers don't work properly with textures whose dimensions are not a power of 2.

In your case, you're creating a 1d texture of width 5, which isn't a power of two. So the solution is to pad your texture out to the nearest power of two (8) before calling glTexImage1D.

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);
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top