Question

OpenGL or SDL segfaults when it reaches the very first statement in the class. I have no idea what is causing it.

class RenderEngine {
    GLuint vertexArrayId;
    GLfloat[] vertexBufferData = [
        -1.0f, -1.0f, 0.0f,
            1.0f, -1.0f, 0.0f,
            0.0f, 1.0f, 0.0f
    ];
    GLuint vertexBufferId;
    public this() {
        glGenVertexArrays(1, &vertexArrayId); // SEGMENTATION FAULT / RETURN -11
        glBindVertexArray(vertexArrayId);
        glGenBuffers(1, &vertexBufferId);
        glBindBuffer(GL_ARRAY_BUFFER, vertexBufferId);
        glBufferData(GL_ARRAY_BUFFER, vertexBufferData.length * GLfloat.sizeof, vertexBufferData.ptr, GL_STATIC_DRAW);
    }

    public void render() {
        glEnableVertexAttribArray(0);
        glBindBuffer(GL_ARRAY_BUFFER, vertexBufferId);
        glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, cast(void*) 0);
        glDrawArrays(GL_TRIANGLES, 0, 3);
        glDisableVertexAttribArray(0);

    }
}
Was it helpful?

Solution

I forgot to setup an OpenGL context. All fixed now.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top