Hi,
I have written an md3 parser and I'm trying to display the resulting mesh using opengl vertex arrays. This is what I am doing:
for (Mesh mesh : model.getMeshes()) {
Frame currentFrame = mesh.getFrames()[0 /* Get the first frame*/];
GL11.glEnableClientState(GL11.GL_VERTEX_ARRAY);
GL11.glVertexPointer(3, 0, currentFrame.getVertices());
GL11.glDrawElements(GL11.GL_TRIANGLES, mesh.getTriangles());
}
currentFrame.getVertices() is a FloatBuffer containing the <x, y, z> coordinates of each vertice in that frame.
mesh.getTriangles() returns an IntBuffer containing the indices of the vertices of each triangle.
When I run this code I obtain a segmentation fault:
SIGSEGV (0xb) at pc=0x7b3759f8, pid=7246, tid=3084782480
#
# Java VM: Java HotSpot(TM) Server VM (10.0-b19 mixed mode linux-x86)
# Problematic frame:
# C [fglrx_dri.so+0x2809f8]
I think it's unlikely that the error is with the vertices FloatBuffer or the triangles IntBuffer, because if I render each triangle individually, everything works fine. Also, even though it seems to crash while executing graphics card driver code, it happened on another computer with a different graphics card model and driver.
I'm using lwjgl-1.1.4 with java version "1.6.0_04", on a Linux machine.
Can you find any error on my code? Thanks in advance,
LuÃs Pureza
Have you flip()ed the IntBuffer and FloatBuffer after you put the data in them?
Quote from: Fool Running on April 08, 2008, 13:54:34
Have you flip()ed the IntBuffer and FloatBuffer after you put the data in them?
Yes:
// in is a RandomAccessFile
// header contains the mesh's header that contains info like the number of frames, triangles, etc.
IntBuffer triangles = ByteBuffer.allocateDirect(header.getNumTriangles() * 3 * 4).asIntBuffer();
for (int i = 0; i < triangles.capacity(); i++) {
triangles.put(in.readInt());
}
triangles.flip();
I do the same for the vertices buffer.
Thanks,
Luis Pureza
Hi,
I've written simple test case in C using real data extracted from an md3 mesh and using vertex arrays and everything worked fine.
Then, I ported it to Java with lwjgl and I got the segmentation fault again. As I was unable to get any help on this issue, I'm thinking this might be a bug in lwjgl. I've uploaded the simple test case so that you can try it and confirm my results. It is at:
http://student.dei.uc.pt/~pureza/Main.java
If you uncomment the code between glBegin/glEnd inside the render() method, you should see a white backpack.
Can you confirm that it is a bug in LWJGL? Or is it just the fact that I'm a complete n00b in opengl? :-)
Thanks,
LuÃs Pureza
Problem solved! I was not doing .order(ByteOrder.nativeOrder()) on buffer creation!
Special thanks to void256 who diagnosed the problem.