B4A Library OpenGL 2.0 library

Android 2.2 and later support OpenGL 2.0 ES as well as OpenGL 1.0 ES. Having produced an OpenGL library for 1.0 I thought I may as well do one for 2.0 as well so here it is!

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.

Note that the demo needs my Threading library.

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

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

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

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

EDIT:- Version 1.5 posted. See post #83 for details.
User @walterf25 has added two methods to the the library to create version 1.5. The new jar and xml are posted below in OpenGL2_v1.5_lib.zip. I have left version 1.4 as the zip for that contains a somewhat trivial demo program. Just use the new v1.5 libs and ignore the v1.4 ones.
 

Attachments

  • OpenGL2_1.4.zip
    43.7 KB · Views: 1,453
  • OpenGL2_v1.5_lib.zip
    38.2 KB · Views: 635
Last edited:

GDO

Member
Licensed User
Longtime User
Hello,

I don't know what is wrong but gl.Version always return 1.2 and all functions needed by opengl es 2 (1.5 , I suppose) are logged like that :

called unimplemented OpenGL ES API

My AVD is 4.1 and android.jar is from android-17

What can I do ?
 

GDO

Member
Licensed User
Longtime User
Many ...

gl.glGenBuffers
gl.glBindBuffer
gl.glBufferDataF

and all the functions with shader (glCreateShader, glShaderSource, etc ...)
 

GDO

Member
Licensed User
Longtime User
In the documention there is GL1 :

Events:
Click
LongClick
Draw(gl As GL1) 'The view wants to be drawn using the supplied GL10
SurfaceChanged(gl As GL1, width As Int, height As Int) 'Called when the surface has changed size.
SurfaceCreated(gl As GL1) 'Called when the surface is created or recreated.

Is it an error in the documentation or in the code?
 

agraham

Expert
Licensed User
Longtime User
You can try putting this in your manifest that should check at runtime if OpenGL 2 is present.
<uses-feature android:glEsVersion="0x00020000" android:required="true" />
Can your post your project (File -> Export as Zip) and I will see if I can see anything in the logs when it fails. However if some of the functions succeed but others fail I presently have no idea what the problem could be.
 

GDO

Member
Licensed User
Longtime User
Hi,
I had already changed the manifest and it was not ok with the emulator.
I tried with the real device and it is not ok.

I changed my program (little program) to add more log("...") and now it is clear that the only functions that are OK are defined inside your libraries opengl 2 AND opengl 1.

The functions that are only defined in the opengl 2 library are not working.

I think the EGL_CONTEXT is not initialized for opengl 2 but for opengl 1 but I don't know why.

Thanks

Log :


** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
mCBPickerDialog enter case. MSG_DISMISS_DIALOG
Hide Clipboard dialog at Starting input: finished by someone else... !
mCBPickerDialog enter case. MSG_DISMISS_DIALOG
id=290 Removed main idx=4 Map Size=5
id=291(2) createSurface 0x32944 (800x1280),1 flag=0, main
id=290 Removed main idx=-2 Map Size=6
id=292(3) createSurface 0x44efc (800x1134),1 flag=0, SurfaceView
loaded /system/lib/egl/libEGL_mali.so
loaded /system/lib/egl/libGLESv1_CM_mali.so
loaded /system/lib/egl/libGLESv2_mali.so
Device driver API match
Device driver API version: 10
User space API version: 10
mali: REVISION=Linux-r2p4-02rel0 BUILD_DATE=Fri May 4 10:32:42 KST 2012
Displayed shortComponentName: +310ms
Hide Clipboard dialog at Starting input: finished by someone else... !
mCBPickerDialog enter case. MSG_DISMISS_DIALOG


Created

Create Triangle
glGenBuffers
glBindBuffer
glBufferDataF
glBindBuffer


Shader

glCreateProgram
called unimplemented OpenGL ES API

glCreateShader
called unimplemented OpenGL ES API

glShaderSource
called unimplemented OpenGL ES API

glCompileShader
called unimplemented OpenGL ES API

glCompileShader
called unimplemented OpenGL ES API

glAttachShader
called unimplemented OpenGL ES API

glBindAttribLocation
called unimplemented OpenGL ES API

glLinkProgram
called unimplemented OpenGL ES API

Changed
Clear

UseProgram
called unimplemented OpenGL ES API

BindBuffer

VertexAttribPointer
called unimplemented OpenGL ES API

EnableVertexAttribArray
called unimplemented OpenGL ES API

VertexAttrib3f
called unimplemented OpenGL ES API

DrawArrays

DisableVertexAttribArray
called unimplemented OpenGL ES API

BindBuffer

UseProgram
called unimplemented OpenGL ES API
 

GDO

Member
Licensed User
Longtime User
I read that opengl 2 is now supported with emulator but of course I will only test with a real device.

Thank you for your help.
 

GDO

Member
Licensed User
Longtime User
Hello,
Yes I used GLSurfaceView2.Initialize2 (I use your demo and try to add the display of a triangle).

Now, with GLSurfaceView2.Initialize, all the errors disappeared but I can not see my triangle (on a real device).

I don't know, for now, what I have to change in my code to make it work with Initialize.

What I needed was RGBA_8888 and a 16 bits depth buffer (Initialize2 was perfect).

I'll be back ...

;-)

Once again, thank you for your help.
 

agraham

Expert
Licensed User
Longtime User
I missed setting GLSurfaceView.setEGLContextClientVersion(2) in Initialize2 which is why I suggested trying Initialize which does have it. I'll post an update with Initialize2 corrected tomorrow as it's getting a bit late here now (17:30) and it's my turn to cook dinner tonight. :(
 

agraham

Expert
Licensed User
Longtime User
Version 1.3 now posted has some new Initialize methods to let you control the configuration better.

Initialize3 uses the default settings for OpenGL2

The following partial initializers can be used sequentially in place of Initialize, Initialize2 or Initialize3 to create a custom initialisation.

InitializeGL - must be called and called first to set up OpenGL 2
InitializeConfig - if called should be called second to initialise the EGLConfigChooser
InitializeHolder - if called should be called third to initialise the pixel format
InitializeRender - must be called and called last to set up the Renderer
 

GDO

Member
Licensed User
Longtime User
Hi,

glsv.Initialize2(glsv.RENDERMODE_WHEN_DIRTY, "glsv", 16, 0)
or
glsv.Initialize3(glsv.RENDERMODE_WHEN_DIRTY, "glsv")
seems OK

but
glsv..InitializeGL2("glsv")
glsv.InitializeConfig(8, 8, 8, 8, 16, 0)
glsv..InitializeHolder(glsv.PixelFormat.RGBA_8888)
glsv.InitializeRender(glsv.RENDERMODE_WHEN_DIRTY)
are KO

InitializeGL not defined (I suppose it's InitializeGL2)
InitializeHolder not defined
 

agraham

Expert
Licensed User
Longtime User
Sorry :( I changed the name but the original one stuck in my mind when I wrote that post. I also made a stupid oversight in the code that I have now fixed. Download version 1.3 again and it should work. Notice that you need the int value of PixelFormat that you can get from the link in the help.
B4X:
glsv.InitializeGL2("glsv")
glsv.InitializeConfig(8, 8, 8, 8, 16, 0)
glsv.InitializeFormat(1) ' 1 is the int value of PixelFormat.RGBA_8888
glsv.InitializeRender(glsv.RENDERMODE_WHEN_DIRTY)
 

GDO

Member
Licensed User
Longtime User
Hi,
Now,everything looks fine in your library.
But my triangle display is not OK.
I am looking what's wrong in my code...
Thanks
 

GDO

Member
Licensed User
Longtime User
Hello,

It was a log way to go but I can now see my triangle !

Thank you for your help.
 
Top