友人と私は現在、LWJGL 2D 関連の作業を行っています。私はVBOに取り組んでいて、それを機能させることができました。これを使用してタイルを描画すると、機能します。ただし、私の FPS は大幅に低下します。おそらく私は何か間違ったことをしています。
これが私のコードです。
public void drawTextureRect(float x, float y, float width, float height,
String textureName) {
// Bind the texture to draw
texture = loadTexture(textureName);
texture.bind();
// Set triangle vertex data
FloatBuffer vertices = BufferUtils.createFloatBuffer(6);
vertices.put(new float[] { x, y, x + width, y, x, height + y });
// Set texture coordinates
FloatBuffer textcoord = BufferUtils.createFloatBuffer(6);
textcoord.put(new float[] { 0, 0, 1, 0, 0, 1 });
// Allow OpenGL to interpret the Text Coordinates & Vertex Data
textcoord.flip();
vertices.flip();
int VertexHandle = glGenBuffers();
glBindBuffer(GL_ARRAY_BUFFER, VertexHandle);
glBufferData(GL_ARRAY_BUFFER, vertices, GL_STATIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, 0);
int TextureHandle = glGenBuffers();
glBindBuffer(GL_ARRAY_BUFFER, TextureHandle);
glBufferData(GL_ARRAY_BUFFER, textcoord, GL_STATIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindBuffer(GL_ARRAY_BUFFER, VertexHandle);
glVertexPointer(2, GL_FLOAT, 0, 0L);
glBindBuffer(GL_ARRAY_BUFFER, TextureHandle);
glTexCoordPointer(2, GL_FLOAT, 0, 0L);
// Enable Vertex and Texture Arrays
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
// Draw Triangle
glDrawArrays(GL_TRIANGLES, 0, 3);
// Unable Vertex and Textures
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glDisableClientState(GL_VERTEX_ARRAY);
/* SECOND TRIANGLE */
// Set Second Triangle Coordinates
FloatBuffer vertices2 = BufferUtils.createFloatBuffer(6);
vertices2.put(new float[] { x + width, y + height, x, height + y,
x + width, y });
// Set Second Texture Coordinates
FloatBuffer textcoord2 = BufferUtils.createFloatBuffer(6);
textcoord2.put(new float[] { 1, 1, 0, 1, 1, 0 });
// Allow OpenGl to interpret the Text Coordinates & Vertex Data
textcoord2.flip();
vertices2.flip();
int VertexHandle2 = glGenBuffers();
glBindBuffer(GL_ARRAY_BUFFER, VertexHandle2);
glBufferData(GL_ARRAY_BUFFER, vertices2, GL_STATIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, 0);
int TexCord = glGenBuffers();
glBindBuffer(GL_ARRAY_BUFFER, TexCord);
glBufferData(GL_ARRAY_BUFFER, textcoord2, GL_STATIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindBuffer(GL_ARRAY_BUFFER, VertexHandle2);
glVertexPointer(2, GL_FLOAT, 0, 0L);
glBindBuffer(GL_ARRAY_BUFFER, TexCord);
glTexCoordPointer(2, GL_FLOAT, 0, 0L);
// Enable Vertex and Texture Arrays
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
// Draw Triangle
glDrawArrays(GL_TRIANGLES, 0, 3);
// Unable Vertex and Textures
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glDisableClientState(GL_VERTEX_ARRAY);
glDeleteBuffers(TextureHandle);
glDeleteBuffers(TexCord);
glDeleteBuffers(VertexHandle);
glDeleteBuffers(VertexHandle2);
}`