我尝试使用VBO渲染我的3d对象。
我创建了这个类:
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);
}
}
我的对象都正确呈现,但我的纹理有问题。 我的纹理是跨越的。看看这张图片......为什么我的纹理就像那样,以及如何解决这个问题。