我的LWJGL程序存在问题,我尝试纹理的模型看起来很糟糕。我使用光滑加载纹理。
我正在使用的东西: https://www.dropbox.com/sh/3fi9wlq9tt5cey0/AAD7JDh6-KQHLGyHZqjstG6Da?dl=0
有我的渲染代码:
public void render(int id){
glPushMatrix();
ShaderLoader.start();
int vertexBuffer = vboVertexBuffers.get(id);
int textureBuffer = vboTextureBuffers.get(id);
int textureId = textureIds.get(id);
int normalBuffer = vboNormalBuffers.get(id);
int facesAmount = vboFaces.get(id);
glBindTexture(GL_TEXTURE_2D, textureId);
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glEnableClientState(GL_NORMAL_ARRAY);
glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
glVertexPointer(3, GL_FLOAT, 0, 0L);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindBuffer(GL_ARRAY_BUFFER, textureBuffer);
glTexCoordPointer(2, GL_FLOAT, 0, 0L);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindBuffer(GL_ARRAY_BUFFER, normalBuffer);
glNormalPointer(GL_FLOAT, 0, 0L);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glMaterialf(GL_FRONT, GL_SHININESS, 128.f);
glMaterial(GL_FRONT, GL_DIFFUSE, UtilFloatBuffer.asFloatBuffer(new float[]{0.6f, 0.2f, 0.0f, 0}));
glDrawArrays(GL_TRIANGLES, 0, facesAmount);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glDisableClientState(GL_NORMAL_ARRAY);
glBindTexture(GL_TEXTURE_2D, 0);
ShaderLoader.stop();
glPopMatrix();
}
并且有部分代码用于加载从Blender导出的模型(带法线等)
try { while((line = reader.readLine()) != null){ //parsing if(line.startsWith("v ")){ float x = Float.valueOf(line.split(" ")[1]); float y = Float.valueOf(line.split(" ")[2]); float z = Float.valueOf(line.split(" ")[3]); m.vertices.add(new Vector3f(x,y,z)); } else if(line.startsWith("vt ")){ float x = Float.valueOf(line.split(" ")[1]); float y = Float.valueOf(line.split(" ")[2]); m.textureCoords.add(new Vector2f(x,y)); } else if(line.startsWith("vn ")){ float x = Float.valueOf(line.split(" ")[1]); float y = Float.valueOf(line.split(" ")[2]); float z = Float.valueOf(line.split(" ")[3]); m.normals.add(new Vector3f(x,y,z)); } else if(line.startsWith("f ")){ Vector3f vertexIndices = new Vector3f( Float.valueOf(line.split(" ")[1].split("/")[0]), Float.valueOf(line.split(" ")[2].split("/")[0]), Float.valueOf(line.split(" ")[3].split("/")[0]) ); Vector3f textureIndices = new Vector3f( Float.valueOf(line.split(" ")[1].split("/")[1]), Float.valueOf(line.split(" ")[2].split("/")[1]), Float.valueOf(line.split(" ")[3].split("/")[1]) ); Vector3f normalIndices = new Vector3f( Float.valueOf(line.split(" ")[1].split("/")[2]), Float.valueOf(line.split(" ")[2].split("/")[2]), Float.valueOf(line.split(" ")[3].split("/")[2])); m.faces.add(new Face(vertexIndices, textureIndices, normalIndices)); }