我目前一直在学习 Vertex Arrays 和 VBO 的 b/c 我目前了解到它比“立即”渲染(如使用 glBegin)更好/更快,尽管这要容易得多。我做了一个小程序(实际上只是一个测试),它创建了一个按钮,当你将鼠标悬停在按钮上时,它会改变颜色,但是每当我启动它时,程序就会崩溃并显示以下错误消息:
A fatal error has been detected by the Java Runtime Environment:
EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x000000006875c490, pid=5708, tid=7148
JRE version: 7.0_21-b11
Java VM: Java HotSpot(TM) 64-Bit Server VM (23.21-b01 mixed mode windows-amd64 compressed oops)
Problematic frame:
C [atio6axx.dll+0x20c490] DrvPresentBuffers+0x1cb680
Failed to write core dump. Minidumps are not enabled by default on client versions of Windows
An error report file with more information is saved as:
C:\Users\UserNameHere\Desktop\Java\workspace\LWJGL Tutorials\hs_err_pid5708.log
If you would like to submit a bug report, please visit:
http://bugreport.sun.com/bugreport/crash.jsp
The crash happened outside the Java Virtual Machine in native code.
See problematic frame for where to report the bug.
我的代码
package testandothertutorials;
import static org.lwjgl.opengl.GL11.*;
import static org.lwjgl.opengl.GL15.*;
import java.nio.FloatBuffer;
import org.lwjgl.BufferUtils;
import org.lwjgl.LWJGLException;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode;
public class VBOMenu {
int WIDTH = 640;
int HEIGHT = 480;
float button[] = {
//Left bottom triangle
30, 60, 0,
30, 30, 0,
60, 30, 0,
//Right top triangle
60, 30, 0,
60, 60, 0,
30, 60, 0
};
public VBOMenu() {
try {
Display.setDisplayMode(new DisplayMode(WIDTH, HEIGHT));
Display.setTitle("Vertex Arrays Demo");
Display.create();
} catch(LWJGLException e) {
Display.destroy();
}
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, 640, 480, 0, 1, -1);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
final int amountOfVertices = 4;
final int colorSize = 4;
final int vertexSize = 4;
FloatBuffer firstVertexData = BufferUtils.createFloatBuffer(button.length);
firstVertexData.put(button);
firstVertexData.flip();
FloatBuffer unselColorData = BufferUtils.createFloatBuffer(colorSize); //The color that will be set when the menu is launched
unselColorData.put(new float[] {0, 1, 0});
unselColorData.flip();
FloatBuffer selColorData = BufferUtils.createFloatBuffer(colorSize); //The color that will be set when the mouse hovers over the button
selColorData.put(new float[] {0, 2, 0});
selColorData.flip();
int firstVertexHandle = glGenBuffers();
glBindBuffer(GL_ARRAY_BUFFER, firstVertexHandle);
glBufferData(GL_ARRAY_BUFFER, firstVertexData, GL_STATIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, 0);
int unselColorHandle = glGenBuffers();
glBindBuffer(GL_ARRAY_BUFFER, unselColorHandle);
glBufferData(GL_ARRAY_BUFFER, unselColorData, GL_STATIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, 0);
int selColorHandle = glGenBuffers();
glBindBuffer(GL_ARRAY_BUFFER, selColorHandle);
glBufferData(GL_ARRAY_BUFFER, selColorData, GL_STATIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, 0);
boolean isRunning = true;
while(isRunning) {
glClear(GL_COLOR_BUFFER_BIT);
glBindBuffer(GL_ARRAY_BUFFER, firstVertexHandle);
glVertexPointer(vertexSize, GL_FLOAT, 0, 0l);
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_COLOR_ARRAY);
glDrawArrays(GL_TRIANGLES, 0, amountOfVertices);
glDisableClientState(GL_COLOR_ARRAY);
glDisableClientState(GL_VERTEX_ARRAY);
Display.update();
Display.sync(60);
if(Display.isCloseRequested())
isRunning = false;
}
glDeleteBuffers(firstVertexHandle);
Display.destroy();
}
public static void main(String[] args) {
new VBOMenu();
}
}