使用JOGL时遇到问题。这是代码和错误消息:
@Override
public void display(GLAutoDrawable drawable) {
GL2 gl = drawable.getGL().getGL2();
gl.glLoadIdentity();
gl.glClear(GL2.GL_COLOR_BUFFER_BIT | GL2.GL_DEPTH_BUFFER_BIT);
gl.glBindTexture(GL2.GL_TEXTURE_2D, tex);
gl.glEnableClientState(GL2.GL_VERTEX_ARRAY);
gl.glEnableClientState(GL2.GL_TEXTURE_COORD_ARRAY);
gl.glEnableClientState(GL2.GL_NORMAL_ARRAY);
gl.glVertexPointer(3, GL2.GL_FLOAT, 0, vertices);
gl.glTexCoordPointer(3, GL2.GL_FLOAT, 0, texCoords);
gl.glTexCoordPointer(3, GL2.GL_FLOAT, 0, normals);
gl.glDrawArrays(gl.GL_QUADS, 0, 4); // error
for (Model.VerticesDescriptor vd : model.vd) {
//if (vd.POLYTYPE == vd.POLY_TYPE_TRIANGLES) gl.glDrawArrays(gl.GL_TRIANGLES, vd.START, vd.END); // error
//if (vd.POLYTYPE == vd.POLY_TYPE_QUADS) gl.glDrawArrays(gl.GL_QUADS, vd.START, vd.END); // error
//else if (vd.POLYTYPE == vd.POLY_TYPE_POLYGON) gl.glDrawArrays(gl.GL_POLYGON, vd.START, vd.END); // error
}
gl.glDisableClientState(GL2.GL_VERTEX_ARRAY);
gl.glDisableClientState(GL2.GL_TEXTURE_COORD_ARRAY);
gl.glDisableClientState(GL2.GL_NORMAL_ARRAY);
}
错误讯息:
#
# A fatal error has been detected by the Java Runtime Environment:
#
# SIGSEGV (0xb) at pc=0x00007efd2dd1fe23, pid=7101, tid=0x00007efcc6bda700
#
# JRE version: OpenJDK Runtime Environment (8.0_151-b12) (build 1.8.0_151-8u151-b12-1~deb9u1-b12)
# Java VM: OpenJDK 64-Bit Server VM (25.151-b12 mixed mode linux-amd64 compressed oops)
# Problematic frame:
# C [libc.so.6+0x128e23]
#
# Failed to write core dump. Core dumps have been disabled. To enable core dumping, try "ulimit -c unlimited" before starting Java again
#
# An error report file with more information is saved as:
# /home/congard/Разработка/eclipse-workspace/Turbo Fly 3D/hs_err_pid7101.log
#
# If you would like to submit a bug report, please visit:
# http://bugreport.java.com/bugreport/crash.jsp
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
#
这个问题可以连接什么?这是我正在制作缓冲区的代码(位于init函数中):
vertices = Buffers.newDirectFloatBuffer(model.vertices.length);
vertices.put(model.vertices).position(0);
texCoords = Buffers.newDirectFloatBuffer(model.texCoords.length);
texCoords.put(model.texCoords).position(0);
normals = Buffers.newDirectFloatBuffer(model.normals.length);
normals.put(model.normals).position(0);
这些缓冲区中有~5000个元素
答案 0 :(得分:1)
所以,错误就在这一行
gl.glTexCoordPointer(3, GL2.GL_FLOAT, 0, normals);
我把它改成了
gl.glNormalPointer(GL2.GL_FLOAT, 0, normals);
现在一切正常