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,533
Last edited:

alfcen

Well-Known Member
Licensed User
Longtime User
Hello Andrew

Perhaps it is next to impossible, nevertheless, is there any means of saving a glsv View to a bitmap, thus to an output stream and a file?

I do not screw up my expectations to too high altitudes, though.

Cheers
Robert
 

alfcen

Well-Known Member
Licensed User
Longtime User
Thanks a lot, Andrew, that was the right hint!
Sorry, if I bothered, just didn't find it in the jungle of functions in Help.
 

Smee

Well-Known Member
Licensed User
Longtime User
:sign0188::sign0087:

You guys are truly awesome. I have just read thru the previous 11 pages and got a headache.
Thanks for your work Andrew on creating the library and thanks to all the others for the encouragement to Andrew.

There will be a demand for this stuff.

I have been researching for 2 days on page flip software or how it could be integrated. It is however beyond my skill set. I am hoping that someone here could develop an example from which i could learn.

I have found this
[Moof:Bar]: Implementing iBooks page curling using a conical deformation algorithm

And there is code here to do the page turning but i am unable to do the translation from the programming language

https://github.com/harism/android_page_curl

there are also a load of examples of page turning examples on youtube

Once again ppl well done on your work, and i hope we are able to see a port of page flipping code


:sign0188:
 

alwaysbusy

Expert
Licensed User
Longtime User
New Initialize for transparent backgound

Hi agraham,

Is it possible to add an new Initialize (Initialize3?)

This one should make the background transparent. (order of gl commands seems to be important)

B4X:
glview.setEGLConfigChooser(8,8,8,8,16,0);

glview.setRenderer(new MyRenderer(this));
glview.getHolder().setFormat([B]PixelFormat.TRANSLUCENT[/B]);

[B]glview.setZOrderOnTop(true)[/B];

Thanks in advance!
 

agraham

Expert
Licensed User
Longtime User
This is what Initialize2 does
B4X:
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);
}
According to the docs for PixelFormat.TRANSLUCENT it "chooses a format that supports translucency (many alpha bits) " which PixelFormat.RGBA_8888 does and is probably the one that would be chosen anyway.

Why do you need setZOrderOnTop?
 

alwaysbusy

Expert
Licensed User
Longtime User
Thanks agraham,

Works like a charm. I thought setZOrderOnTop(true) was needed to make it transparent (according to some websites, but it looks like they were having the same problem as me).

In my code the GLSurfaceView always was under the panel. But, when I add the GLSurfaceView first and then the panel, it works great.
 

Mikie

Member
Licensed User
Longtime User
OpenGL vs OpenGL2

What is the difference between OpenGL1.7 and OpenGL2_1.0? Should we have both of them installed?
 

scrat

Active Member
Licensed User
Longtime User
Hello agraham

I try your very well opengl 1.7 library.
The library works well on Arm platform but on android X86 the texture color is reverted (red are bleu)

It is possible to expose the "format" parameter in gltexImage2d to be set either GL_RGB(A) or GL_BGR(A)

Thanks


Ps: sorry my english is bad
 

agraham

Expert
Licensed User
Longtime User
Neither the GL_BGR nor the GL_BGRA constants are defined in the Android OpenGL library so I have no idea what values you would use. If you can guess the values you could try using my Reflection library to invoke it but I guess that Android might not support it. If you get a "not found" error then one or more of the args may not be of Int type. To make sure assign them from an Int variable.
B4X:
Dim Obj1 As Reflector
Dim args(6) As Object
Dim types(6) As String
args(0) = target 
args(1) = level 
args(2) = bmpinternalformat 
args(3) = myBitmap  
args(4) = bmptype 
args(5) = border 
types(0) = "I"   
types(1) = "I"   
types(2) = "I"   
types(3) = "android.graphics.Bitmap"
types(4) = "I"   
types(5) = "I"   
Obj1.RunStaticMethod("android.opengl.GLUtils", "texImage2D", args, types)
You could also try the PixelsABGRtoARGB method in my Jpeg library to swap the R and B values.
B4X:
Dim jpg As Jpeg
jpg.SetPixelsFromBmp(bmp)
jpg.PixelsABGRtoARGB
bmp = jpg.GetBmpFromPixels
 
Last edited:

NeoTechni

Well-Known Member
Licensed User
Longtime User
So my 2D app is running a bit slow and I'd like to switch to OpenGL to speed it up.

My requirements are as follows:
-Use of a custom font file (I'm sure OpenGL allows this)
-Use of the Webview control, while allowing images with transparency
-Use of PNG and GIF textures with transparency (8 bit in PNG's case, 1 bit in GIF's)
-Drawing primitives (Rectangles, lines, and maybe pie segments?)

Are these possible?
 

grobi71

Member
Licensed User
Longtime User
transparent background

Hallo agraham,

thank you for your hard work. i have a little problem:

i use opengl lib 1.7 and want to set the color around the Object to transparent

gl.glClearColor(r,g,b,A) set the backgroundcolor but without Alpha if i set

gl.glClearColor(0,0,0,0) the background is set to black not transparent
gl.glClearColor(0,0,0,1) the background is also black

do you have any suggestions ?

best regards
Harald (Grobi71)
 

scrat

Active Member
Licensed User
Longtime User
Hello

@Agraham
With new version of android x86 (ICS version 1/1/2012) color is now correct Blue and Red are not swapped. sorry for the inconvenience

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


@grobi71
No problem with alphachanel and initialize() and texture for me.
 

grobi71

Member
Licensed User
Longtime User
Background transparent

Hallo agraham,

i used your test app. Now i changed Initialize to Initialize2 as
Dim glsv As GLSurfaceView

glsv.Initialize2(glsv.RENDERMODE_WHEN_DIRTY, "glsv", 16, 0)

Sub glsv_Draw(gl As GL1)
If GLSurfaceChanged=True Then
GLMaterial_Reload(obj1.Material,gl)
GLSurfaceChanged=False
End If
gl.glClearColor(1,1,1,0)
gl.glClear(Bit.Or(gl.GL_COLOR_BUFFER_BIT, gl.GL_DEPTH_BUFFER_BIT))
' cube - textured
gl.glLoadIdentity : gl.glScalef(0.5,0.5,0.5)
gl.glTranslatef(0.0,0.0,distZ)
gl.glRotatef(rotX,1,0,0) : gl.glRotatef(rotY,0,1,0)
GLObject_Draw(obj1,gl)
End Sub

with the same effect

@scrat Do you have a simple example ?

rgds
Harald (Grobi71)
 

scrat

Active Member
Licensed User
Longtime User
Attached a small exemple

Line 70 you can change gl.glColor4f(1,1,1,1) to gl.glColor4f(1,1,1,0.2) and see
 

Attachments

  • compass.zip
    57.5 KB · Views: 375
Top