In a LWJGL project of mine, I have been using a VBO to tile 2D terrain. It has been working fine on macOS and Windows, however, in my linux partition the game doesn't run. The only major difference I can find is that the linux distro reports the OpenGL version as OpenGL version 3.0 Mesa 11.2.2
whereas on macOS for example, it reports OpenGL version 2.1 ATI-1.48.21
. I have tried on various devices with different OpenGL versions and the only thing I can see as being the issue is the mesa library. Here is the class I use to build and render the VBO:
import java.nio.FloatBuffer;
import java.util.ArrayList;
import org.lwjgl.BufferUtils;
import static org.lwjgl.opengl.GL11.*;
import org.lwjgl.opengl.*;
import org.newdawn.slick.Color;
import org.newdawn.slick.opengl.Texture;
import data.DataManager;
public class TerrainVBO {
FloatBuffer verticies;
FloatBuffer textCoords;
ArrayList<Float> verticiesArray = new ArrayList<Float>();
ArrayList<Float> textCoordsArray = new ArrayList<Float>();
int vaoHandle;
float invAtlasWidth;
float invAtlasHeight;
public TerrainVBO(DataManager dm) {
invAtlasWidth = 1f/dm.settings.atlasMap.get("dimensions")[0];
invAtlasHeight = 1f/dm.settings.atlasMap.get("dimensions")[1];
}
public void addVertex(float x, float y) {
verticiesArray.add(x);
verticiesArray.add(y);
}
public void addTexture(float x, float y) {
textCoordsArray.add(x);
textCoordsArray.add(y);
}
public void addQuad(float x, float y, float width, float height) {
addVertex(x,y);
addVertex(x+width,y);
addVertex(x+width,y+height);
addVertex(x,y+height);
}
public void addTextureQuad(int[] pos) {
float x = pos[0] * invAtlasWidth + 0.001f;
float y = pos[1] * invAtlasHeight + 0.001f;
addTexture(x,y);
addTexture(x+invAtlasWidth - 0.002f,y);
addTexture(x+invAtlasWidth - 0.002f,y+invAtlasHeight - 0.002f);
addTexture(x,y+invAtlasHeight - 0.002f);
}
public void preWrite() {
verticies = BufferUtils.createFloatBuffer(verticiesArray.size());
textCoords = BufferUtils.createFloatBuffer(textCoordsArray.size());
for (int i = 0; i < verticiesArray.size(); i++) {
verticies.put(verticiesArray.get(i));
textCoords.put(textCoordsArray.get(i));
}
verticies.flip();
textCoords.flip();
}
public void write(Texture texture) {
Color.white.bind();
glBindTexture(GL_TEXTURE_2D, texture.getTextureID());
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
int verticiesBufferHandle = GL15.glGenBuffers();
GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, verticiesBufferHandle);
GL15.glBufferData(GL15.GL_ARRAY_BUFFER, verticies, GL15.GL_STATIC_DRAW);
glVertexPointer(2, GL_FLOAT, 0, 0L);
int textureBufferHandle = GL15.glGenBuffers();
GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, textureBufferHandle);
GL15.glBufferData(GL15.GL_ARRAY_BUFFER, textCoords, GL15.GL_STATIC_DRAW);
glTexCoordPointer(2, GL_FLOAT, 0, 0);
GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glDrawArrays(GL_QUADS, 0, verticiesArray.size());
glDisableClientState(GL_COLOR_ARRAY);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
}
}
Textured quads are added to the VBO by running addQuad. After that, preWrite prepares the VBO for rendering to the screen and write actually performs the render. Any ideas on why this won't work on the mesa implementation of OpenGL would be greatly appreciated.
Since the program freezes, it never technically crashes and so there is no stack trace. However, this is the error log that gets created by LWJGL: https://cdn.discordapp.com/attachments/225439941415403520/278922035550355457/hs_err_pid24149.log