OpenGL 颜色插值

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

我正在使用 pyopenGL 开发 FEM 应用程序 为什么我在渲染一些四边形时会得到这个结果 值和颜色是对称的 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
smooth 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
smooth in vec4 color;
void main() {
gl_FragColor = color;
}
'''

VAO 和 VBO

        glBindVertexArray(self.vaomquad)
        glBindBuffer(GL_ARRAY_BUFFER,self.vbomquad)
        glBufferData(GL_ARRAY_BUFFER,data=vertquads,usage=GL_STATIC_DRAW,size=sizeof(vertquads))
        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)

绘图:

            glBindVertexArray(self.vaomquad)
            glDrawArrays(GL_QUADS,0,self.nquads*4)
            glBindVertexArray(0)

对于颜色插值,我使用了这个函数:

    def interpolatecolor(self,v,vmin,vmax):
        anum = 1020/(vmax-vmin)
        bnum = -anum*vmin
        numcol = v*anum+bnum
        r,g,b = 0,0,0
        if (numcol>=0 and numcol<255):
            r = 255
            g = numcol
        elif (numcol>=255 and numcol<510):
            r = 255-(numcol-255)
            g = 255
        elif (numcol>=510 and numcol<765):
            b = numcol-510
            g = 255
        elif (numcol>=765 and numcol<=1020):
            g = 255-(numcol-765)
            b = 255
        return (r,g,b,1)
opengl colors interpolation smoothing pyopengl
1个回答
0
投票

我通过添加四边形的重心解决了这个问题,这样我就必须将四边形基元渲染为一组四个三角形(每个四边形 12 个顶点)。插值现在基于四边形的四个顶点。 enter image description here

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