2015-12-11 179 views
0

我開始學習OpenGL,並找到我的紋理問題。我在png格式中有清晰的紋理,這是我在四邊形上設置的。經過測試,我發現一些奇怪的線條。OpenTK C#紋理紋理

如何刪除該行? Image with bug

繪製場景:

GL.BindTexture(TextureTarget.Texture2D, TextureId); 
GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha); 
GL.Enable(EnableCap.Blend); 

GL.Begin(BeginMode.Quads); 

GL.TexCoord2(new Vector2(0, 0));   GL.Vertex2(new Vector2(0, 0)); 
GL.TexCoord2(new Vector2(0.125F, 0));  GL.Vertex2(new Vector2(size.Width, 0)); 
GL.TexCoord2(new Vector2(0.125F, -1));  GL.Vertex2(new Vector2(size.Width, size.Height)); 
GL.TexCoord2(new Vector2(0, -1));   GL.Vertex2(new Vector2(0, size.Height)); 

GL.End(); 

GL.Disable(EnableCap.Blend); 

註冊質地:

Bitmap bitmap = new Bitmap(path); 
int texture = 0; 

GL.Enable(EnableCap.Texture2D); 

GL.Hint(HintTarget.PerspectiveCorrectionHint, HintMode.Nicest); 

GL.GenTextures(1, out texture); 
GL.BindTexture(TextureTarget.Texture2D, texture); 
GL.TexEnv(TextureEnvTarget.TextureEnv, TextureEnvParameter.TextureEnvMode, (float)TextureEnvMode.Modulate); 
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear); 
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear); 

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

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

bitmap.UnlockBits(data); 

回答

0

這個問題似乎是紋理被重複。如果紋理coodinate不在0到1範圍內,OpenGL將「取」「反面」的顏色。由於計算不準確,出現僞影。

你可以嘗試設置兩個紋理參數

TextureParameterName.TextureWrapS 
TextureParameterName.TextureWrapT 

TextureWrapMode.ClampToEdge 

使用GL.TexParameter()

也可以考慮更換-1與1