I'm trying to render a square with texture. It's working, except I'm getting a pixelated line on the diagonal edge where two triangles meet each other.
The texture:
The render result of three squares, each square is made of two triangles:
The line only shows up on diagonal lines. Nothing appears on the vertical or horizontal edges.
Code:
import qualified Graphics.Rendering.OpenGL as GL
import qualified Graphics.UI.GLFW as GLFW
Initialization:
GL.lineSmooth $= GL.Enabled
GL.polygonSmooth $= GL.Enabled
GL.blend $= GL.Enabled -- A
GL.blendFunc $= (GL.SrcAlpha, GL.OneMinusSrcAlpha)
GL.lineWidth $= 1.5
Loading the texture:
GL.texture GL.Texture2D $= GL.Enabled
(texName:_) <- GL.genObjectNames 1
GL.textureBinding GL.Texture2D $= Just texName
GL.textureFilter GL.Texture2D $= ((GL.Nearest, Nothing), GL.Nearest)
_ <- GLFW.loadTexture2D "wall.tga" [GLFW.BuildMipMaps]
Rendering the quad:
GL.textureBinding GL.Texture2D $= Just texName
GL.renderPrimitive GL.TriangleStrip $ do
GL.texCoord $ GL.TexCoord2 0 (1::GL.GLfloat)
GL.vertex $ vertex3 20 0 0
GL.texCoord $ GL.TexCoord2 0 (0::GL.GLfloat)
GL.vertex $ vertex3 20 20 0
GL.texCoord $ GL.TexCoord2 1 (1::GL.GLfloat)
GL.vertex $ vertex3 0 0 0
GL.texCoord $ GL.TexCoord2 1 (0::GL.GLfloat)
GL.vertex $ vertex3 0 20 0
GL.textureBinding GL.Texture2D $= Nothing
I've tried rendering GL.Polygons
and GL.Quads
: same result.
They go away when I comment the line tagged with -- A
. Why?
The problem is with the line GL.polygonSmooth $= GL.Enabled
. It seems to smooth all edges of the polygon, even if there is another edge over it.
Removing this line works, even maintaining the GL.blend $= GL.Enabled
.
The Common Mistakes page at OpenGL wiki says:
[Polygon smooth] is not a recommended method for anti-aliasing. Use Multisampling instead.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With