I was playing around with online openGL tutorials and I keep getting this error:
A fatal error has been detected by the Java Runtime Environment:
EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x00000000599e8030, pid=6016, tid=5956
Problematic frame:
C [atio6axx.dll+0x2a8030] DrvPresentBuffers+0x2627e0
Failed to write core dump. Minidumps are not enabled by default on client versions of Windows
Here’s the code I’m trying:
public class Triangle {
private static Shaders shader;
private static int vaoID;
public static void main(String[] args) {
initGL();
run();
}
public static void initGL() {
try {
Display.setDisplayMode(new DisplayMode(500, 500));
Display.setVSyncEnabled(true);
PixelFormat pf = new PixelFormat();
ContextAttribs attribs = new ContextAttribs(3, 2);
attribs.withForwardCompatible(true);
attribs.withProfileCore(true);
Display.create(pf, attribs);
initTriangle();
GL11.glViewport(0, 0, 500, 500);
GL11.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
} catch (LWJGLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static void run() {
while (!Display.isCloseRequested()) {
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
draw();
Display.update();
Display.sync(60);
}
Display.destroy();
}
public static int initTriangle() {
shader = new Shaders();
shader.init("res/shaders/vertex.vs", "res/shaders/fragment.fs");
float[] positionData = new float[] { 0f, 0f, 0f, -1f, 0f, 0f, 0f, 1f, 0f };
float[] colorData = new float[] { 0f, 0f, 1f, 1f, 0f, 0f, 0f, 1f, 0f };
FloatBuffer positionBuffer = BufferUtils.createFloatBuffer(positionData.length);
positionBuffer.put(positionData);
positionBuffer.flip();
FloatBuffer colorBuffer = BufferUtils.createFloatBuffer(colorData.length);
colorBuffer.put(colorData);
colorBuffer.flip();
int positionBufferHandle = GL15.glGenBuffers();
GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, positionBufferHandle);
GL15.glBufferData(GL15.GL_ARRAY_BUFFER, positionBuffer, GL15.GL_STATIC_DRAW);
// create VBO for color values
int colorBufferHandle = GL15.glGenBuffers();
GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, colorBufferHandle);
GL15.glBufferData(GL15.GL_ARRAY_BUFFER, colorBuffer, GL15.GL_STATIC_DRAW);
// unbind VBO
GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
// create vertex array object (VAO)
int vaoHandle = GL30.glGenVertexArrays();
GL30.glBindVertexArray(vaoHandle);
GL20.glEnableVertexAttribArray(0);
GL20.glEnableVertexAttribArray(1);
// assign vertex VBO to slot 0 of VAO
GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, positionBufferHandle);
GL20.glVertexAttribPointer(0, 3, GL11.GL_FLOAT, false, 0, 0);
// assign vertex VBO to slot 1 of VAO
GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, colorBufferHandle);
GL20.glVertexAttribPointer(1, 3, GL11.GL_FLOAT, false, 0, 0);
// unbind VBO
GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
return vaoHandle;
}
public static void draw() {
GL20.glUseProgram(shader.getProgramID());
GL30.glBindVertexArray(vaoID);
GL20.glEnableVertexAttribArray(0); // VertexPosition
GL20.glEnableVertexAttribArray(1); // VertexColor
GL11.glDrawArrays(GL11.GL_TRIANGLES, 0, 3);
GL20.glDisableVertexAttribArray(0); // VertexPosition
GL20.glDisableVertexAttribArray(1); // VertexPosition
if (glGetError() != GL_NO_ERROR) {
throw new RuntimeException("OpenGL error: ");
}
}
}
What am I doing wrong?