0

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

Keco
  • 69
  • 10
  • Do you get a stacktrace when the error occurs? – Bartvbl Feb 08 '17 at 07:21
  • @Bartvbl Here is a link to the error log LWJGL creates: [link] (https://cdn.discordapp.com/attachments/225439941415403520/278922035550355457/hs_err_pid24149.log) – Keco Feb 08 '17 at 16:20
  • The first thing I notice, is that you construct your buffers every time you try to draw the scene. Don't do that. Build your buffers once, then bind them every frame. As for the crash, these usually occur when you have incorrectly confiogured your buffers. OpenGL tries to read one or more values which are out of bounds, causing it to crash. Something else, I think you need to enable the client states _before_ setting your pointers. Make sure the right buffer is bound when you call the pointer functions too. – Bartvbl Feb 09 '17 at 08:10
  • As far as I can tell the calls for setting up the buffers are all correct, so enabling the client state before configuring your buffer pointers may be the cause of your problems. – Bartvbl Feb 09 '17 at 08:34
  • @Bartvbl I tried enabling the client state at the beginning of the write method but the error persists. I find it strange how the error only occurs on one system. – Keco Feb 12 '17 at 02:06

0 Answers0