Note that there are some explanatory texts on larger screens.

plurals
  1. POIf not GL_QUADS, then how?
    text
    copied!<p>I'm developing a simple 2D game in Java using the LWJGL wrapper for OpenGL. <BR>For the rendering method, I use VBOs. It seems very good and faster the the other rendering methods.<br>I was reading some articles and was seeking for some questions here on StackOverflow and I discovered that using 2 triangles is better than using one quad, since modern GPUs show only triangles (And it'll be a waste to let the GPU translate that quad into triangles).</p> <p>The only way I know is creating 2 buffers for storing the vertex data and the texture coordinates data. and that's for a quad, this is how I do it:</p> <pre><code>int vertexID; //Holding the GL buffer ID for the Vertex int texCoordsID; //Holding the GL buffer ID for the texture coords void init(){ //BufferUtils is a Utility class provided by the SlickUtil library, I use it for creating buffers. //Create float buffer for storing vertex data FloatBuffer vertexBuffer = BufferUtils.createFloatBuffer(4 * 2); //Put vertex data inside the buffer vertexBuffer.put(new float[]{ 0, 0, 100, 0, 100, 100, 0, 100 }); //Rewind the buffer vertexBuffer.rewind(); FloatBuffer texCoordsBuffer = BufferUtils.createFloatBuffer(4 * 2); texCoordsBuffer.put(new float[]{ 0, 0, 1, 0, 1, 1, 0, 1 }); texCoordsBuffer.rewind(); vertexID = glGenBuffers(); glBindBuffer(GL_ARRAY_BUFFER, vertexID); glBufferData(GL_ARRAY_BUFFER, vertexBuffer, GL_STATIC_DRAW); glBindBuffer(GL_ARRAY_BUFFER, 0); texCoordsID = glGenBuffers(); glBindBuffer(GL_ARRAY_BUFFER, texCoordsID); glBufferData(GL_ARRAY_BUFFER, texCoordsBuffer, GL_STATIC_DRAW); glBindBuffer(GL_ARRAY_BUFFER, 0); } void render(){ glBindTexture(GL_TEXTURE_2D, texture.id); //Not so important. glBindBuffer(GL_ARRAY_BUFFER, vertexID); glVertexPointer(2, GL_FLOAT, 0, 0); glBindBuffer(GL_ARRAY_BUFFER, texCoordsID); glTexCoordPointer(2, GL_FLOAT, 0, 0); glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_TEXTURE_COORD_ARRAY); glDrawArrays(GL_QUADS, 0, 4); glDisableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_TEXTURE_COORD_ARRAY); } </code></pre> <p>Now my main question is, how can you split it into 2 triangles instead of 1 quad?<br> And a side question: does it really matter for a 2D game? does it make a slight change?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload