2013-07-02 40 views
0

我正在使用以下代碼來渲染一維紋理。但是在一些圖形卡中,它只呈現純白色的圖像。我注意到有時它在安裝卡的驅動程序後被修復。某些圖形卡中的白色OpenGL紋理

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

任何人都可以幫忙嗎?

+0

某些驅動程序/卡片(特別是較舊的驅動程序/卡片)在2種大小的紋理的非功率方面存在問題。 –

+0

我如何設置一個紋理爲兩個冪次之一? – melmi

+0

通過填充它的下一個冪。在你的情況下,你會添加3個額外的像素,並將'glTexImage1D'中的寬度更改爲8. –

回答

3

一些老的顯卡/驅動程序不正確地與紋理,其尺寸不是2

在你的情況的功率,你要創建寬度5的一維結構,這是不是工作兩個冪。因此,解決方法是在調用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); 
+0

謝謝你的回答。 – melmi