这是我的代码:
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 应用程序中创建地图着色网格