晚上好,
我已经使用python而不是c ++来学习本教程learnopengl.com。一切似乎都有效,但我的三角形没有正确显示。
如果我错过了两次以上的话,我检查了每一行,但我找不到问题。
SpriteRenderer | Shader | ResourceManager | Program | Game(将游戏中的路径更改为着色器)
修改
好的,现在我可以看到我的三角形,当我改变
时重要代码段
正矩阵(游戏)
array([[ 0.0025 , 0. , 0. , -1. ],
[ 0. , -0.00333333, 0. , 1. ],
[ 0. , 0. , -1. , -0. ],
[ 0. , 0. , 0. , 1. ]], dtype=float32)
模型矩阵(SpriteRenderer)
T = glm.translation_matrix([position[0],position[1],0])
# bewegt den den pivot zum mittelpunkt
Tcenter = glm.translation_matrix([0.5 * size[0], 0.5 * size[1], 0])
R = glm.rotation_matrix(rotate, [0,0,1])
# bewegt den pivot wieder zurueck
Tback = glm.translation_matrix([-0.5 * size[0], -0.5 * size[1], 0])
# scaliert den koerper
S = glm.compose_matrix(scale = [size[0],size[1],1])
model = glm.concatenate_matrices(T, Tcenter, R, Tback, S)
self._shader.setMatrix4("model", model)
self._shader.setVector("customColor", color)
gl.glBindVertexArray(self._vao);
gl.glDrawArrays(gl.GL_TRIANGLES, 0, 3)
gl.glBindVertexArray(0)
VAO VBO(SpriteRenderer)
vertexBufferData = np.array(([-1, -1],
[ 1, -1],
[ 0, 1]),
dtype='float32')
# ----- VBO ------
# Request a buffer slot from GPU
VBO = gl.glGenBuffers(1)
# Make this buffer the default one
gl.glBindBuffer(gl.GL_ARRAY_BUFFER, VBO)
# Upload data
gl.glBufferData(gl.GL_ARRAY_BUFFER, vertexBufferData.nbytes ,vertexBufferData, gl.GL_STATIC_DRAW)
# ------ VAO ------
# Aktivieren des Vertex Array mit der ID
gl.glBindVertexArray(self._vao)
gl.glEnableVertexAttribArray(0)
gl.glVertexAttribPointer(0, 2, gl.GL_FLOAT, False, 0, c_void_p(0))
#len(vertexBufferData), gl.GL_FLOAT, gl.GL_FALSE,4*4, c_void_p(0))
# unbind das aktuelle vertex objekt VAO und VBO
#gl.glDisableVertexAttribArray(0)
gl.glBindBuffer(gl.GL_ARRAY_BUFFER, 0)
gl.glBindVertexArray(0)
fragmentshader :
#version 330 core
out vec4 color;
uniform vec3 customColor;
void main()
{
color = vec4(customColor, 1.0);
}
vertexshader
#version 330 core
layout(location = 0) in vec2 position;
uniform mat4 model;
uniform mat4 projection;
void main()
{
gl_Position = projection * model * vec4(position.xy, 0.0, 1.0);
}