Yeah, hi. I’m having some troubble getting vertex arrays to work. I ran some simpler tests that worked but when I try to load an obj-file and render it the program crashes without a hint of what is wrong. (This is for an assignment but i really can’t figgure out how to do this, and besides, it’s only the very top of the iceberg. sigh)
Test class:
public class Test01 implements GLEventListener {
private JFrame javaWindow;
private GLCanvas glCanvas;
private Animator a;
private Model test;
/**
* @param width
* @param height
*/
public Test01( int width, int height ) {
javaWindow = new JFrame();
javaWindow.setSize( width, height );
javaWindow.setLocation( 50, 50 );
javaWindow.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
glCanvas = new GLCanvas();
// Makes this GLEventListener listen to the events sent by the glCanvas (ie glCanvas.display() or events sent
// when resizing the window)
glCanvas.addGLEventListener( this );
// Add the canvas to the window
javaWindow.getContentPane().add( glCanvas );
// Show the window!
javaWindow.setVisible( true );
a = new Animator(glCanvas);
}
/**
* Starts the main loop
*
*/
public void start()
{
a.start();
}
public void init( GLAutoDrawable arg0 )
{
System.out.println( "Init event!" );
final GL gl = glCanvas.getGL();
gl.glClearDepth( 1.0f ); // Depth Buffer Setup
gl.glEnable( GL.GL_DEPTH_TEST ); // Enables Depth Testing
gl.glDepthFunc( GL.GL_LEQUAL );
gl.glClearColor( 0.2f, 0.2f, 0.37f, 1.0f );
gl.glShadeModel( GL.GL_SMOOTH );
test = ObjectLoader.loadOBJ("data\\meshes\\cube.obj");
}
public void display( GLAutoDrawable arg0 )
{
final GL gl = glCanvas.getGL();
gl.glClear( GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT ); // Clear the color buffer (frame buffer) and
// depth buffer (Z-buffer)
gl.glEnableClientState(GL.GL_VERTEX_ARRAY);
test.draw(gl);
gl.glDisableClientState(GL.GL_VERTEX_ARRAY);
gl.glFlush();
}
public void displayChanged( GLAutoDrawable arg0, boolean arg1, boolean arg2 )
{
}
public void reshape( GLAutoDrawable arg0, int x, int y, int width, int height )
{
System.out.println( "Reshape event! Setting viewport and projection" );
final GL gl = glCanvas.getGL();
final GLU glu = new GLU();
if ( height <= 0 ) // avoid a divide by zero error!
height = 1;
final float h = (float) width / (float) height;
gl.glViewport( 0, 0, width, height );
gl.glMatrixMode( GL.GL_PROJECTION );
gl.glLoadIdentity();
glu.gluPerspective( 45.0f, h, 1.0, 20.0 );
gl.glMatrixMode( GL.GL_MODELVIEW );
gl.glLoadIdentity();
}
public static void main( String[] args )
{
Test01 main = new Test01( 640, 480 );
main.start();
}
}
The model class:
public class Model
{
// private boolean hasNormals, hasTexture;
// private Material material;
private FloatBuffer faces; //, colors, normals, texCords;
public Model(FloatBuffer faces)
{
this.faces = faces;
}
public void draw(GL gl)
{
gl.glVertexPointer(3, GL.GL_TRIANGLES, 0, faces);
gl.glDrawArrays(GL.GL_TRIANGLES, 0, (faces.capacity() / 3));
}
public FloatBuffer getFaces()
{
return faces;
}
}
And the crash info i suppose:
# An unexpected error has been detected by Java Runtime Environment:
#
# EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x037955f2, pid=3044, tid=2560
#
# Java VM: Java HotSpot(TM) Client VM (1.6.0_03-b05 mixed mode, sharing)
# Problematic frame:
# C 0x037955f2
#
******
--------------- S Y S T E M ---------------
OS: Windows XP Build 2600 Service Pack 2
CPU:total 1 (1 cores per cpu, 1 threads per core) family 15 model 2 stepping 7, cmov, cx8, fxsr, mmx, sse, sse2
Memory: 4k page, physical 785904k(193428k free), swap 1136468k(598216k free)
vm_info: Java HotSpot(TM) Client VM (1.6.0_03-b05) for windows-x86, built on Sep 24 2007 22:24:33 by "java_re" with unknown MS VC++:1310
(Had to cut out some stuff to get below 10000 characters.)
I’ve also tried to get VBOs to work but I get the same (or at least a strikingly similar) problem. Any help will be appreciated.