Android Question OpenGL 2.0 Library Demo newbie problems

John D.

Member
Licensed User
Longtime User
This is my first post here, I want to first say thank you to the developers for de-obfuscating Java. In the month I've spent trying to make heads or tails of it and trying to figure out why they designed it as they did and and trying to figure out the flow of execution .... I've found myself thinking that in order to get my little program written it might be easier for me to do something like what you've done. Now that I've found you and spent some time playing with B4A, you have my sincere thanks.

I bought a Nextbook 8 http://www.nextbookusa.com/productdetail.php?product_id=16
for the purpose of writing a program that will include some custom graphics.

On attempting to run the demo included with the OpenGL 2.0 library, I see some errors in logcat and the image doesn't render. There are some warnings in the compiler warning box on the logs tab;

Undeclared variable 'glerr'
Unused variable 'coords'
Sub 'QueuTest' not used
Sub 'QueutestGUI' not used
Sub 'ShowGLError' not used
Sub 'ShowOglImage' not used


The things I did to try to get it working;

Added the Threads library--

Included the 'main' file as instructed by the compiler warning box --

Added a line to the manifest requiring OpenGL ES 2 as described in the other thread about this library --

Uncommented the DebugFlags line in the program to see if I could find out more about what is going on.

Here is a logcat excerpt:

B4X:
>>>>>> AndroidRuntime START com.android.internal.os.RuntimeInit <<<<<<
CheckJNI is OFF
Trying to load lib libjavacore.so 0x0
Added shared lib libjavacore.so 0x0
Trying to load lib libnativehelper.so 0x0
Added shared lib libnativehelper.so 0x0
Loading ethernet jni class
Calling main entry com.android.commands.am.Am
START {act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=anywheresoftware.b4a.agraham.opengl2demo/.main u=0} from pid 26004
Shutting down VM
NOTE: attach of thread 'Binder_3' failed
GC_CONCURRENT freed 99K, 82% free 484K/2560K, paused 1ms+0ms, total 7ms
Turning on JNI app bug workarounds for target SDK version 4...
Start proc anywheresoftware.b4a.agraham.opengl2demo for activity anywheresoftware.b4a.agraham.opengl2demo/.main: pid=26015 uid=10080 gids={1028}
error opening trace file: No such file or directory (2)
setLightsOn(true)
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
loaded /system/lib/egl/libEGL_mali.so
loaded /system/lib/egl/libGLESv1_CM_mali.so
loaded /system/lib/egl/libGLESv2_mali.so


Note: class Landroid/opengl/GLWrapperBase; has 250 unimplemented (abstract) methods
Displayed anywheresoftware.b4a.agraham.opengl2demo/.main: +348ms


glGetString(7937) returns Mali-400 MP;
Created
Changed
glFrustumf(-0.66971797, 0.66971797, -0.41421357, 0.41421357, 1.0, 100.0);
called unimplemented OpenGL ES API


Permission denied: checkComponentPermission() owningUid=10005


Permission denied: checkComponentPermission() owningUid=10005


Permission denied: checkComponentPermission() owningUid=10005


Permission denied: checkComponentPermission() owningUid=10005
Permission denied: checkComponentPermission() owningUid=10005
Permission denied: checkComponentPermission() owningUid=10005
Permission denied: checkComponentPermission() owningUid=10005
Permission denied: checkComponentPermission() owningUid=10005
Permission denied: checkComponentPermission() owningUid=10005


Permission denied: checkComponentPermission() owningUid=10005
GC_CONCURRENT freed 603K, 9% free 7496K/8199K, paused 15ms+4ms, total 55ms


GC_FOR_ALLOC freed 166K, 4% free 6095K/6343K, paused 42ms, total 43ms


Grow heap (frag case) to 7.379MB for 1459216-byte allocation

Any clues you can give this clueless newbie will be much appreciated.

Thanks,

--John--
 

John D.

Member
Licensed User
Longtime User
Oops, I forgot to mention that. I did run it in release mode.

I do see the toast popups "Testing QueueEvent" and "Frame 60 shown" ....

Maybe it's my device. I did also utterly fail to get it to render the example at
http://developer.android.com/training/graphics/opengl/index.html

but some other examples from elsewhere on the web work. I can't figure out why.

--John--

Edit: Same behavior on another device, Samsung Skyrocket II. Perhaps I didn't install the libraries correctly or something?
 
Last edited:
Upvote 0

John D.

Member
Licensed User
Longtime User
I have another series of totally newbie questions;

I see in Activity_Resume that an array of floats is initialized, named coords.

This looks to me like it might be an array of vertices. (Is it?)

But I cannot see where it gets used anywhere.

In the draw call, all I see is the clear command and then the call to show the toast popups on the gui thread if certain conditions are met, along with error handling. Also it seems to be setting oglbmp to the results of a read, which baffles me. (Where does the bmp come from?)

I don't see where the shaders are set up ... (are there defaults? All my reading seems to indicate they are required ...)

I can't see where the variable eyeangle gets used anywhere. Shouldn't this be a vector for a transformation or something?

Please excuse my ignorance.... boy am I ever lost here.
 
Upvote 0

agraham

Expert
Licensed User
Longtime User
I'm afraid that I just make the libraries work so other people can use them, I don't always, as in this case, know how to use them!. As I remarked in the first post.
The included "demo" is not really a demo at all and does little more than test the device OpenGL capability and initialise a drawing surface. It needs someone more interested in graphics than I to take it further.
So don't try to read much into that demo as it does nothing graphically. What it shows is
1) Using a timer to request a redraw every 100 mS
2) The general structure in Sub glsv_Draw of how to capture any errors or exceptions and pass them to the main thread..
3) How to capture an OpenGL frame and display it on the main thread.
 
Upvote 0

John D.

Member
Licensed User
Longtime User
Andy,

Can you clarify something for me, please?

In the reference for the GLSurfaceView at http://developer.android.com/reference/android/opengl/GLSurfaceView.html,
it says;

Initializing GLSurfaceView
All you have to do to initialize a GLSurfaceView is call setRenderer(Renderer).....

Setting a Renderer
Finally, you must call setRenderer(GLSurfaceView.Renderer) to register a GLSurfaceView.Renderer. The renderer is responsible for doing the actual OpenGL rendering.
And in your documentation at http://www.b4x.com/android/help/opengl2.html#gl2_gl_renderer
it says;

RenderMode AsInt
//snip

....
This method can only be called after setRenderer(Renderer)

My problem is that I can't find any reference to this method (or for that matter how to set up the renderer, which is (usually) declared as a class in Java in every example I can find).

I'm sure I am missing something simple, can you point it out to me please?

Thanks,

--John--
 
Last edited:
Upvote 0

agraham

Expert
Licensed User
Longtime User
Upvote 0

John D.

Member
Licensed User
Longtime User
I have another dumb question ....

onDrawFrame(GL10 gl)

shouldn't this be (GL1 Unused) ??

Found elsewhere on the web:
You may have noticed that the GL10 instance passed in is referred to as glUnused. We don’t use this when drawing using OpenGL ES 2; instead, we use the static methods of the class GLES20. The GL10 parameter is only there because the same interface is used for OpenGL ES 1.x.

Or maybe it doesn't matter? Thanks for clarifying ....

--John--

Edit -- never mind. Seems cosmetic only ( usage: glsv_Draw(gl As GL2) )
 
Last edited:
Upvote 0

John D.

Member
Licensed User
Longtime User
Thanks, Andy. Maybe that's a clue to something new that I've been worrying over.

I've been playing with the example GDO posted back in March. (Thanks, GDO, for blazing this trail!)

I've got the rotating triangles going around very smoothly (the trick is to use smaller jumps and draw more often), but the log shows repeated garbage collection, once every few seconds. His example of using Vertex Buffer Objects seems to follow all the caveats for not allocating and releasing objects continuously. The GC continues when the example is pared down to nothing but the single triangle running off a statically loaded VBO. So I spent all night trying to figure out what is being allocated and released on every draw cycle. Of course, being new to Java and Android .... I couldn't find it.

So -- is it really creating a new GL2 instance on every frame? And if so, is this the desired behavior?

Is there a tool that can be used to find out what is generating and releasing resources to trigger such constant garbage collection?

Why do I always make everything so hard for myself?

(No need to address that last question...)

Thanks,

--John--
 
Upvote 0

agraham

Expert
Licensed User
Longtime User
A garbage collection every few seconds is nothing to worry about, especially as you probably don't know how much, if any, is being collected anyway. You are in a managed environment, if you haven't run out of memory don't worry about garbage collection.

It really is creating a new GL2 instance every frame because it needs to, or at least because that was the neatest way of creating access to the GL10 that onDraw was passed and which a couple of methods need. However that overhead is insignificant compared to the rest of what will be happening to draw the frame.
 
Upvote 0

John D.

Member
Licensed User
Longtime User
Andy,

I am head on against a wall. I can now draw at will using VBO's, but all my attempts at using any matrix transform render a black screen. I can pass a uniform into the shader and get a handle back. I've tried using examples from at least a dozen tutorials around the web. Where I'd like to end up is being able to pan and zoom some rendered lines. If I could get one example of a simple line drawn, then transformed in any way (static would be just fine), I could move on. I have some examples that work in Eclipse (and many that don't, in particular Google's own tutorial), but I have not been able to translate them to B4A with any success. Everything comes up black screen. Do you have any hints to offer? (I don't have any context to guide me, I might be putting things in the wrong places, for instance, I don't know which code talks to which thread or how to tell the difference and so on...)

Thanks,
--John--
 
Last edited:
Upvote 0
Top