我开始学习OpenGL并发现纹理问题。我有一个png格式的清晰纹理,我在四边形上设置。经过测试,我发现了一些奇怪的线条。
我如何删除这些行? 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 :(得分:0)
问题似乎是纹理重复出现。如果纹理坐标不在0到1的范围内,则OpenGL“获取”“相对侧”的颜色。然后由于计算不精确而出现伪影。
您可以尝试设置两个纹理参数
TextureParameterName.TextureWrapS
TextureParameterName.TextureWrapT
到
TextureWrapMode.ClampToEdge
使用GL.TexParameter()
还要考虑用-1替换-1。