testing on device gives error opengl es

Problems with Canvas, OpenGL, etc...

testing on device gives error opengl es

Postby mrcoffee » Fri Oct 15, 2010 1:38 pm

hi everybody,

got an problem on testing my app on device (htc desire), but works on emulator

10-15 14:34:05.629: ERROR/AndroidRuntime(25714): FATAL EXCEPTION: GLThread 9
10-15 14:34:05.629: ERROR/AndroidRuntime(25714): java.lang.NullPointerException
10-15 14:34:05.629: ERROR/AndroidRuntime(25714): at com.google.android.gles_jni.GLImpl.glVertexPointer(GLImpl.java:1121)
10-15 14:34:05.629: ERROR/AndroidRuntime(25714): at de.mydrawing.Main.mainLoopIteration(Main.java:72)
10-15 14:34:05.629: ERROR/AndroidRuntime(25714): at de.mydrawing.GameActivity.onDrawFrame(GameActivity.java:180)
10-15 14:34:05.629: ERROR/AndroidRuntime(25714): at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1341)
10-15 14:34:05.629: ERROR/AndroidRuntime(25714): at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1118)



when i comment these lines out it starts but then its black screen

Code: Select all
gl.glVertexPointer(3, GL10.GL_FLOAT, 0, vertices);
gl.glColorPointer( 4, GL10.GL_FLOAT, 0, colors );


anybody an idea what the problem can be?
mrcoffee
Developer
Developer
 
Posts: 37
Joined: Mon Sep 20, 2010 8:10 am
Location: Germany

Top

Re: testing on device gives error opengl es

Postby Jug6ernaut » Tue Oct 19, 2010 9:12 pm

Did you enable GlVectexPointer and glColorPointer?
Jug6ernaut
Junior Developer
Junior Developer
 
Posts: 23
Joined: Thu Jun 17, 2010 7:00 pm

Re: testing on device gives error opengl es

Postby mrcoffee » Thu Oct 21, 2010 9:52 am

hi Jug6ernaut,

i think so,like that
Code: Select all
gl.glEnableClientState(GL10.GL_VERTEX_ARRAY );
gl.glEnableClientState(GL10.GL_COLOR_ARRAY );


am i wrong?
mrcoffee
Developer
Developer
 
Posts: 37
Joined: Mon Sep 20, 2010 8:10 am
Location: Germany

Re: testing on device gives error opengl es

Postby jonbonazza » Thu Oct 21, 2010 8:19 pm

Is vertices a float array or FloatBuffer? If it is a float array, it will compile, but will not work. The last argument in the glVertexPointer(...) and glColorPointer(...) methods is required to be a Buffer type object.

Code: Select all
        ByteBuffer vbb = ByteBuffer.allocateDirect(vertices.length*4);
        vbb.order(ByteOrder.nativeOrder());
        FloatBuffer vBuffer= vbb.asFloatBuffer();
        vBuffer.put(vertices);
        vBuffer.position(0);


Then, after enabling the GL_VERTEX_ARRAY client state (like you did above), you would make a call like so:
gl.glVertexPointer(3, gl.GL_FLOAT, 0, vBuffer);

That should make it run. Whether or not it displays what you wish, however, depends on your array of vertices...
jonbonazza
Master Developer
Master Developer
 
Posts: 665
Joined: Thu Jul 15, 2010 2:58 pm
Location: WV USA

Re: testing on device gives error opengl es

Postby mrcoffee » Tue Oct 26, 2010 11:30 am

hi jonbonazza,

won't work at all,vertices is a float buffer

Code: Select all
private FloatBuffer vertices;
            ByteBuffer buffer = ByteBuffer.allocateDirect( 3 * 4 * 3 );
            buffer.order(ByteOrder.nativeOrder());
            vertices = buffer.asFloatBuffer();
           
            vertices.put( -0.5f );
            vertices.put( -0.5f );
            vertices.put( 0 );
           
            vertices.put( 0.5f );
            vertices.put( -0.5f );
            vertices.put( 0 );
           
            vertices.put( 0 );
            vertices.put( 0.5f );
            vertices.put( 0 );
           
            vertices.rewind();
           
            buffer = ByteBuffer.allocateDirect( 3 * 4 * 4 );
            buffer.order(ByteOrder.nativeOrder());
            colors = buffer.asFloatBuffer();
           
            colors.put( 1 );
            colors.put( 0 );
            colors.put( 0 );
            colors.put( 1 );
           
            colors.put( 0 );
            colors.put( 1 );
            colors.put( 0 );
            colors.put( 1 );
           
            colors.put( 0 );
            colors.put( 0 );
            colors.put( 1 );
            colors.put( 1 );
           
            colors.rewind();



Code: Select all
gl.glEnableClientState(GL10.GL_COLOR_ARRAY );
gl.glEnableClientState(GL10.GL_VERTEX_ARRAY );
gl.glVertexPointer(3, GL10.GL_FLOAT, 0, vertices);
gl.glViewport( 0, 0, activity.getViewportWidth(), activity.getViewportHeight() );           
gl.glColorPointer( 4, GL10.GL_FLOAT, 0, colors );
gl.glDrawArrays(GL10.GL_TRIANGLES, 0, 3);


could maybe post some code which draws some circle or so, to see if it works?
mrcoffee
Developer
Developer
 
Posts: 37
Joined: Mon Sep 20, 2010 8:10 am
Location: Germany

Re: testing on device gives error opengl es

Postby jonbonazza » Wed Oct 27, 2010 9:05 pm

Remove the vertices.rewind(); and colors.rewind(); lines and use vertices.position(0); and colors.position(0);

Also, put all of your float values into a single array and then use a single .put() statement to add the entire array. The way you have it now, you are putting multiple "arrays" the each contain only one value. This is likely a problem.
jonbonazza
Master Developer
Master Developer
 
Posts: 665
Joined: Thu Jul 15, 2010 2:58 pm
Location: WV USA

Top

Re: testing on device gives error opengl es

Postby mrcoffee » Mon Nov 08, 2010 11:16 am

thanks for help, it works
mrcoffee
Developer
Developer
 
Posts: 37
Joined: Mon Sep 20, 2010 8:10 am
Location: Germany

Top

Return to Android 2D/3D Graphics - OpenGL Problems

Who is online

Users browsing this forum: No registered users and 3 guests