我正在使用 pyopenGL 开发 FEM 应用程序 为什么我在渲染一些四边形时会得到这个结果 值和颜色是对称的
获得更好结果的一些想法 这里是一些代码行: 着色器:
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)