我嘗試使用VBO來渲染我的3D對象。VBO紋理不能正常工作LWJGL
我創建這個類:
public class Object3DTexturedRendered {
private TextureRendered texture;
private int vboId = 0;
private int vboiId = 0;
private int vbotId = 0;
private int verticesTexCoords[][];
private int verticesIndex[];
private FloatBuffer verticesBuffer;
private FloatBuffer texturesBuffer;
private IntBuffer indexBuffer;
public Object3DTexturedRendered() {
}
public Object3DTexturedRendered(TextureRendered _texture) {
texture = _texture;
}
public void renderVBO() {
glEnable(GL_TEXTURE_2D);
if (texture.getTexture() != null) {
texture.getTexture().bind();
}
ARBVertexBufferObject.glBindBufferARB(ARBVertexBufferObject.GL_ARRAY_BUFFER_ARB, vboId);
glVertexPointer(3, GL_FLOAT, 0, 0L);
ARBVertexBufferObject.glBindBufferARB(ARBVertexBufferObject.GL_ARRAY_BUFFER_ARB, vbotId);
glTexCoordPointer(2, GL_FLOAT, 0, 0L);
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
ARBVertexBufferObject.glBindBufferARB(ARBVertexBufferObject.GL_ELEMENT_ARRAY_BUFFER_ARB, vboiId);
glDrawRangeElements(GL_TRIANGLES, 0, (verticesIndex.length - 1), verticesIndex.length,
GL_UNSIGNED_INT, 0L);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glDisableClientState(GL_VERTEX_ARRAY);
ARBVertexBufferObject.glBindBufferARB(ARBVertexBufferObject.GL_ARRAY_BUFFER_ARB, 0);
ARBVertexBufferObject.glBindBufferARB(ARBVertexBufferObject.GL_ELEMENT_ARRAY_BUFFER_ARB, 0);
glDisable(GL_TEXTURE_2D);
}
public void initRenderVBO(FloatPointRendered[] listPointsRendered, int _verticesTexCoords[][], int _verticesIndex[]) {
verticesTexCoords = _verticesTexCoords;
verticesIndex = _verticesIndex;
verticesBuffer = BufferUtils.createFloatBuffer(verticesTexCoords.length * 3);
texturesBuffer = BufferUtils.createFloatBuffer(verticesTexCoords.length * 2);
for (int[] _ipoint : verticesTexCoords) {
FloatPointRendered _point = listPointsRendered[_ipoint[0]];
float[] uv = texture.getXYtoFloat(_ipoint[1], _ipoint[2]);
verticesBuffer.put(_point.positionToFloatArray());
texturesBuffer.put(uv);
}
verticesBuffer.flip();
texturesBuffer.flip();
indexBuffer = BufferUtils.createIntBuffer(verticesIndex.length);
indexBuffer.put(verticesIndex);
indexBuffer.flip();
if (GLContext.getCapabilities().GL_ARB_vertex_buffer_object) {
IntBuffer vboID = BufferUtils.createIntBuffer(3);
ARBVertexBufferObject.glGenBuffersARB(vboID);
vboId = vboID.get(0);
ARBVertexBufferObject.glBindBufferARB(ARBVertexBufferObject.GL_ARRAY_BUFFER_ARB, vboId);
ARBVertexBufferObject.glBufferDataARB(ARBVertexBufferObject.GL_ARRAY_BUFFER_ARB, verticesBuffer, ARBVertexBufferObject.GL_STATIC_DRAW_ARB);
vbotId = vboID.get(1);
ARBVertexBufferObject.glBindBufferARB(ARBVertexBufferObject.GL_ARRAY_BUFFER_ARB, vbotId);
ARBVertexBufferObject.glBufferDataARB(ARBVertexBufferObject.GL_ARRAY_BUFFER_ARB, texturesBuffer, ARBVertexBufferObject.GL_STATIC_DRAW_ARB);
vboiId = vboID.get(2);
ARBVertexBufferObject.glBindBufferARB(ARBVertexBufferObject.GL_ELEMENT_ARRAY_BUFFER_ARB, vboiId);
ARBVertexBufferObject.glBufferDataARB(ARBVertexBufferObject.GL_ELEMENT_ARRAY_BUFFER_ARB, indexBuffer, ARBVertexBufferObject.GL_STATIC_DRAW_ARB);
}
}
我的目標都是正確呈現,但我有一個問題與質感。 我的紋理被踩到了。看看這個圖像......爲什麼我的紋理是這樣的,以及我如何修復這個錯誤。
battleofground.fr_game_render_error_vbo_texture.png
已解決! 事實上,我不正確地將我的紋理切割成我的GL_TRIANGLES渲染! – beaucoralk
關於堆棧溢出,我們不在標題中加入「已解決」。如果你已經解決了你的問題,那麼發佈解決方案作爲其他人看到的答案,而不是作爲評論。 –