2013-01-07 56 views
5

我想渲染带纹理的正方形。 它的工作,除了我在两个三角形相遇的对角线边缘上得到像素线。OpenGL三角形不需要的边缘

纹理:

Texture used on the squares

渲染的三个正方形结果,每个方块由两个三角形的:

Render result

线仅会出现在对角线上。垂直或水平边缘上不显示任何内容。

代码:

import qualified Graphics.Rendering.OpenGL as GL 
import qualified Graphics.UI.GLFW   as GLFW 

初始化:

GL.lineSmooth $= GL.Enabled 
GL.polygonSmooth $= GL.Enabled 
GL.blend   $= GL.Enabled -- A 
GL.blendFunc  $= (GL.SrcAlpha, GL.OneMinusSrcAlpha) 
GL.lineWidth  $= 1.5 

载入纹理:

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] 

渲染四:

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 

我尝试过渲染GL.PolygonsGL.Quads:结果相同。

当我评论标记为-- A的行时,它们会消失。为什么?

回答

8

问题出在线GL.polygonSmooth $= GL.Enabled。它似乎可以平滑多边形的所有边缘,即使在其上还有另一个边缘。

删除此行可行,甚至保留GL.blend $= GL.Enabled

Common Mistakes page at OpenGL wiki说:

[多边形平滑]不是抗混叠一个推荐方法。改为使用 多重采样。

+0

你的神,可怕的多边形平滑!我已经忘记了这种古老的憎恶仍然隐藏在赖利。好的赶上和进一步的海克力旅程祝你好运! (继续,并切换到缓冲对象的某个时间。) – Kos

+0

@Kos,我仍然在学习OpenGL,不知道任何关于“缓冲区对象”。感谢您提供改进建议,我现在开始搜索并了解它。 :) –