B4A Library OpenGL library

Here is a first stab at implementing an OpenGL library. The implementation is a subset of the full Android API but the actual functionality is pretty complete (I think!) as the omitted functions are mainly those that used scaled integer working, I have only implemented the equivalents that use floats.

However it is almost totally untested. I have got it to the point where it can draw a triangle on the screen but my total ignorance of OpenGL makes further progress challenging and I'm not really interested in doing graphics. As it can now draw on-screen most of the further functionality should be OK as it is a very thin wrapper of the OpenGL API. The hard part of integrating the GLSurfaceView with Basic4android and drawing on it is done.

The reason for posting it therefore is to see if there is any interest in it before I waste more time on it, and to see if there is an OpenGL expert out there who would collaborate on testing and debugging it - assuming anyone wants to use it at all!

As an aside I believe that the GLSurfaceView, being based on a standard View, can also be drawn on using the same methods as other Views as well as by the OpenGL renderer but I haven't tried that.

Note that the "demo" needs my Threading library.

EDIT :- Version 1.1 posted. See post #5 for details.

EDIT :- Version 1.2 posted. See post #10 for details.

EDIT :- Version 1.3 posted. See post #16 for details.

EDIT :- Version 1.4 posted. See post #21 for details.

EDIT :- Version 1.5 posted. See post #25 for details.

EDIT :- Version 1.6 posted. See post #35 for details.
EDIT :- Version 1.6 reposted with correct version number. See post #38 for details.

EDIT :- Version 1.7 posted. See post #39 for details.
 

Attachments

  • OpenGL1.7.zip
    51.3 KB · Views: 2,508
Last edited:

agraham

Expert
Licensed User
Longtime User
I found a problem : gltranslatex as no effect (x,y,z are integer)
gltranslatef work fine with integer or float

That must be a bug in Android :(, The code for calling gltranslatef and gltranslatex is so simple it can't be a bug in the library
B4X:
public void glTranslatef(float x, float y, float z)
{
   gl.glTranslatef(x, y, z);
}

public void glTranslatex(int x, int y, int z)
{
   gl.glTranslatex(x, y, z);
}
 

grobi71

Member
Licensed User
Longtime User
Hallo

first of all thanks for your help.

@scat your talking about 2D images and i am talking about 3D models that is
a little bit different. Else in your example you make your image transparent not the background.

i added my source if someone could look at it. I want to make the background (blue square) around the eye transparent. Sending it to the background is not what i want.

@agraham I changed intitiale to initialize2 with no effect

rgds
Harald
 

grobi71

Member
Licensed User
Longtime User
glwallpaperservice

Hallo agraham,

i have found this in the internet. It seems to be a library to make opengl available for live wallpapers. Is it possible to adapt it for B4A in the future with the extends like loading .model files ?

Grobi71
 

Attachments

  • markfguerra-GLWallpaperService-release-v0.9.1-4-g0e9fa7e(1).zip
    49.7 KB · Views: 325

grobi71

Member
Licensed User
Longtime User
ok.so i have to learn java and have to throw away b4a . Not
a good reference for it.

Harald
 

agraham

Expert
Licensed User
Longtime User
OK, go and throw your toys out of the pram and good riddance to you.

I am not employed by Anywhere software and I am not paid by Anywhere Software. I write software in my own time because I enjoy it and I give the results freely to the community. Why you think I should have some obligation to pander to your whim is beyond me.
 

grobi71

Member
Licensed User
Longtime User
hallo agraham,:sign0013:

i think you missunderstood because of my bad English. It's nothing against you. you made a hard and perfect work.:sign0098: I only want to say: if there is no possibility to adapt 3d objects in live wallpapers i have to learn JAVA to write my own lib for B4A or write my programs directly in JAVA.

So again: excuse me for this misunderstanding.

Best regards
Grobi71
 

grobi71

Member
Licensed User
Longtime User
Clinometer

Hallo Osi,

please have a look to this Thread:

Android Development Forum - Basic4android > Basic4android > Basic4android Share Your Creations new improved fun clinometer

What phone do you use?

regards
Grobi71
 

Osi

Member
Licensed User
Longtime User
I don't use a doid phone. The android SDK is a major minefield (not worth the resources).

I develop for the Kindle Fire only.
 

latch

Active Member
Licensed User
Longtime User
Transparent glsv.

I saw posts #107 #108 #116 and it looks like they were trying to get the glsv background transparent but it is not working for me. I got a textured quad to have transparency just fine but I need to see the canvas beneath through the glsv alpha channel.

B4X:
   Activity.Initialize("")
   
      glsv.Initialize2(glsv.RENDERMODE_WHEN_DIRTY, "glsv",0,0)
      
      Activity.AddView(glsv,200,48,420,420)
            canvas1.Initialize(Activity)
      Rect.Initialize(0, 0, 0, 0)
   Activity.Color=Colors.RGB(140,100,90)

Let me know if the this is not enough code to see what I'm doing wrong.(I'm using a bastardized version of Jim Brown's Nehedemo03 code and its a mess from experimentation and feature removal)
 
Last edited:

Jim Brown

Active Member
Licensed User
Longtime User
Hi Andrew

This is what Initialize2 does
Code:
public void Initialize2(BA ba, int RenderMode, String EventName, int depthSize, int stencilSize)
{
super.Initialize(ba, EventName);
((GLSurfaceView)getObject()).setEGLConfigChooser(8, 8, 8, 8, depthSize, stencilSize);
((GLSurfaceView)getObject()).getHolder( ).setFormat( PixelFormat.RGBA_8888 );
((GLSurfaceView)getObject()).setRenderer(new myRenderer(this, EventName));
setRenderMode(RenderMode);
}

I am trying to get a transparency to work for the GLSurfaceView but am having no luck yet. As was mentioned further back in this thread, and from what I have read in many Android+OpenGL articles now it seems that glSurfaceView.setZOrderOnTop(true) should be called. See this article for example:

How to set a transparent GLSurfaceView

I have tried glsv.BringToFront but I don't know if this is the same as setZOrderOnTop().
So, for testing purposes, do you know how I can call the 'setZOrderOnTop' command using reflection?[/B]
 
Last edited:

Jim Brown

Active Member
Licensed User
Longtime User
Thanks Andrew. Calling "setZOrderOnTop" did the trick. I now have a fully transparent GL surface view!
Best regards to you.
 

derez

Expert
Licensed User
Longtime User
Thank you Agraham and Jim Brown - the last two posts solved my problem as well :)
now I can fly my 3D UAV over the beach - see photo.
 

Attachments

  • Screenshot.png
    Screenshot.png
    93.9 KB · Views: 394
Last edited:

alfcen

Well-Known Member
Licensed User
Longtime User
This worked for my phone, too. A big thank-you, Andrew.
 

Attachments

  • glsv.jpg
    glsv.jpg
    80.4 KB · Views: 338

alienhunter

Active Member
Licensed User
Longtime User
gl_lines

:sign0087:

since i am new here , just want to ask if this is posible

drawing 3d lines ?

i have seen a lot of examples with shapes but none with lines

please see picture

vb6 code
how i am doing it now :
Obj = gluNewQuadric 'create new quadric object
gluQuadricNormals Obj, qnSmooth

glNewList World_Axis, lstCompile
glBegin GL_LINES
glColor3f 0, 0, 1: glVertex3f 0, 0, 0
glColor3f 0, 0, 1: glVertex3f 0.03, 0, 0
glEnd
glBegin GL_LINES
glColor3f 0, 0, 1: glVertex3f 0, 0, 0
glColor3f 0, 0, 1: glVertex3f 0, 0.03, 0
glEnd
glBegin GL_LINES
glColor3f 0, 1, 0: glVertex3f 0, 0, 0
glColor3f 0, 1, 0: glVertex3f 0, 0, 0.03
glEnd
and so on ....

thanks Alfred
 

Attachments

  • open gl.jpg
    open gl.jpg
    32 KB · Views: 315

alienhunter

Active Member
Licensed User
Longtime User
got it how ..:BangHead:

great software
just spent some hours reading and a bit trying

:sign0089::sign0161::sign0151:
 

Attachments

  • lines.png
    lines.png
    16.7 KB · Views: 297
  • gl_1.jpg
    gl_1.jpg
    28.2 KB · Views: 291
Last edited:

tan22

New Member
Problem with gesturing and OpenGL

Hi All,

I've been having a bit of trouble getting this code to work properly. What I'm doing is rendering some objects on the screen and allowing the user to rotate the view using gestures.

This works fine if I make slow gestures, but if I make any fast movements my code will crash. Odd thing is, it crashes in different ways each time.

I have tested out Jim's OpenGLObjectTest example as the functionality is nearly identical (gesture and rotate). I've found that it has the same issue, although much less frequently (took me a little while to actually get it to crash). I'm guessing this is because the objects I am rendering are a bit more complicated. (the less I render the less frequently it will crash).

Below is one of the logs from the app crashing

B4X:
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
main_glsv_draw (B4A line: 144)
End Sub
java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer
   at anywheresoftware.b4a.debug.Debug.PopSubsStack(Debug.java:163)
   at basic.android.openglobjecttest.main._glsv_draw(main.java:724)
   at java.lang.reflect.Method.invokeNative(Native Method)
   at java.lang.reflect.Method.invoke(Method.java:491)
   at anywheresoftware.b4a.BA.raiseEvent2(BA.java:167)
   at anywheresoftware.b4a.BA.raiseEvent2(BA.java:155)
   at anywheresoftware.b4a.BA.raiseEvent(BA.java:151)
   at anywheresoftware.b4a.agraham.opengl.GLWrapper$GLSurfaceViewWrapper$myRenderer.onDrawFrame(GLWrapper.java:2227)
   at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1454)
   at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1198)
java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer
java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()


   at android.os.Handler.<init>(Handler.java:121)
   at android.app.Dialog.<init>(Dialog.java:100)
   at android.app.AlertDialog.<init>(AlertDialog.java:96)
   at android.app.AlertDialog$Builder.create(AlertDialog.java:891)
   at anywheresoftware.b4a.BA.raiseEvent2(BA.java:204)
   at anywheresoftware.b4a.BA.raiseEvent2(BA.java:155)
   at anywheresoftware.b4a.BA.raiseEvent(BA.java:151)
   at anywheresoftware.b4a.agraham.opengl.GLWrapper$GLSurfaceViewWrapper$myRenderer.onDrawFrame(GLWrapper.java:2227)
   at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1454)
   at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1198)
** Activity (main) Pause, UserClosed = true **

Does anyone have a clue as to why this might be happening? Any help would be greatly appreciated.

Thanks!
 
Top