Opengl 颜色插值

问题描述 投票:0回答:1

渲染 openGL 三角形时,我得到以下结果 enter image description here

这是我的代码:


GL_VERT_SHADER = '''
#version 330 core
layout (location = 0) in vec3 vertPos; // Input position
layout (location = 1) in vec4 vertCol; // Input color
out vec4 color;
uniform mat4 finalMatrix; // The final matrix
void main() {
gl_Position = finalMatrix * vec4(vertPos.x, vertPos.y, vertPos.z, 1.0);
color = vertCol;
}
'''

GL_FRAG_SHADER = '''
#version 330
in vec4 color;
void main() {
gl_FragColor = color;
}
'''

class frame(OpenGLFrame):
    def initgl(self):
        #viewport defining
        glViewport(0,0,self.width,self.height)
        #depth test enabling (z-buffering) and stencil buffer test
        self.identity = np.array(mat4(1))
        #init program shader
        vertexshader = shaders.compileShader(GL_VERT_SHADER, GL_VERTEX_SHADER)
        fragmentshader = shaders.compileShader(GL_FRAG_SHADER, GL_FRAGMENT_SHADER)
        self.shaderProgram = shaders.compileProgram(vertexshader, fragmentshader)
        vao = glGenVertexArrays(1)
        self.vaosnap  = vao
        glBindVertexArray(vao)
        vbo = glGenBuffers(1)
        glBindBuffer(GL_ARRAY_BUFFER,vbo)
        coins = [-1,-1,0,255,0,0,1,
                 1,-1,0,0,255,0,1,
                 0,1,0,0,0,255,1]
        coins = (GLfloat * len(coins))(*coins)
        glBufferData(GL_ARRAY_BUFFER,data=coins,usage=GL_STATIC_DRAW,size=sizeof(coins))
        glEnableVertexAttribArray(0)
        glVertexAttribPointer(0,3,GL_FLOAT,False,28,None)
        glEnableVertexAttribArray(1)
        glVertexAttribPointer(1,4,GL_FLOAT,False,28,ctypes.c_void_p(12))
        glBindBuffer(GL_ARRAY_BUFFER,0)
        glBindVertexArray(0)



我尝试了解 openGL 如何在原始面中插入颜色,以便在 FEM 应用程序中创建地图着色网格

opengl colors interpolation mesh
1个回答
0
投票

最终我获得了更好的结果 enter image description here

但是我还有另一个问题:如何将贴图设置得更真实,而不会因三角形边缘而导致颜色突然过渡?

© www.soinside.com 2019 - 2024. All rights reserved.