B4A Library OpenGL 2.0 library

Discussion in 'Additional libraries, classes and official updates' started by agraham, May 20, 2011.

  1. agraham

    agraham Expert Licensed User

    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.
     

    Attached Files:

    Last edited: Sep 29, 2019
    feland likes this.
  2. Erel

    Erel Administrator Staff Member Licensed User

  3. NeoTechni

    NeoTechni Well-Known Member Licensed User

    I get a blank screen on my device, Xperia Play

    i get, Testing Queue event, and 60 frames shown
     
  4. agraham

    agraham Expert Licensed User

    That's correct. Didn't you read
    The demo is an empty version of the OpenGL 1.0 demo.
     
  5. NeoTechni

    NeoTechni Well-Known Member Licensed User

    Ah, expected it to what the first one did. my bad.
     
  6. NeoTechni

    NeoTechni Well-Known Member Licensed User

    Could you find the API needed to poll the states of hardware buttons?
    We cant make realtime games using just the keypress event...
     
  7. agraham

    agraham Expert Licensed User

    I don't see that the question has anything to do with OpenGL. :confused: OpenGl has no API to interact with other views.
     
  8. GDO

    GDO Member Licensed User

    glBufferData (target As Int, size As Int, data As java.nio.Buffer, usage As Int)

    Hello,

    Could you please tell me how to define data as java.nio.Buffer ?

    Thank you
     
  9. agraham

    agraham Expert Licensed User

    I know nothing about OpenGL but I exposed as much of Android's OpenGL capability as I could in the OpenGL and OpenGL2 libraries in the hope that someone with OpenGL experience could help me get them working properly. This happened with the OpenGL library, thanks to Jim Brown and others. Unfortunately however in the twenty months since no-one, until now, has shown any interest in using this library. Either that or it's working perfectly well for them! :)

    In this library glBufferData, glBufferSubData, glCompressedTexImage2D and glCompressedTexSubImage2D all want a java.nio.Buffer. Buffer is the superclass of a set of typed buffers, ByteBuffer, IntBuffer, FloatBuffer etc.

    Some of the OpenGL methods require a specific type of buffer and in this case I have made the method I exposed accept the required type of array and converted the array to a buffer of the required type.

    I think that the reason the calls above specify the base Buffer type of parameter is that they can then accept various types of typed buffers depending on the required use, about which I could not find any information. I left these methods exposed using the Buffer type in the hope that an OpenGL expert would tell me what is required for these methods and I could then provide variations of the methods that accept arrays of the required types.
     
  10. GDO

    GDO Member Licensed User

    Hi,
    An array of GL_FLOAT (FLOAT) will be a good beginning.
    Could you, please ?
     
  11. GDO

    GDO Member Licensed User

    an array of FLOAT.
     
  12. agraham

    agraham Expert Licensed User

    Version 1.1 now posted replaces glBufferData() and glBufferSubData with glBufferDataF, glBufferSubDataF, glBufferDataI, and glBufferSubDataI. The methods suffixed "F" accept a float array of data and the methods suffixed "I" accept an int array.
     
  13. GDO

    GDO Member Licensed User

    Hi,
    Thanks for the new version.
    I am trying to use Opengl es 2 but it seems to me that something is wrong with glVertexAttribPointer.

    You define it like that : glVertexAttribPointer (
    indx As Int,
    size As Int,
    normalized As Boolean,
    stride As Int,
    ptr() As Float)

    but it should be (I think) like that :void glVertexAttribPointer(
    GLuint index,
    GLint size,
    GLenum type,
    GLboolean normalized,
    GLsizei stride,
    const GLvoid * pointer);

    GLenum type is missing and
    const GLvoid * pointer (often 0) is not possible with ptr() As Float

    Am I right ?

    Thank you for your help.
     
  14. agraham

    agraham Expert Licensed User

    The Android definition of glVertexAttribPointer is
    Code:
    public void  glVertexAttribPointer(int indx, int size, int type, boolean normalized, int stride, Buffer ptr)
    Because Basic4android cannot cope with buffers I implemented it to accept a float array and pass a FloatBuffer
    Code:
    public void glVertexAttribPointer(int indx, int size, boolean normalized, int stride, float[] ptr)
       {
          ByteBuffer pbb = ByteBuffer.allocateDirect(ptr.length * 
    4);
          pbb.order(ByteOrder.nativeOrder());
          FloatBuffer pfb = pbb.asFloatBuffer();
          pfb.put(ptr);
          pfb.position(
    0);
          GLES20.glVertexAttribPointer(indx, size, GL_FLOAT, 
    false0, pfb);
       
    }
    It looks like passing "false" rather passing the normalised argument is a bug.

    As Java doesn't allow pointer manipulation you can't pass 0 like in C. You could try either Null or a zero length array.
     
    Last edited: Mar 7, 2013
  15. GDO

    GDO Member Licensed User

    Hello,
    It seems to me that "int offset" is defined, too :
    Added in API level 9
    public static void glVertexAttribPointer (int indx, int size, int type, boolean normalized, int stride, int offset)

    For now, nothing is working, for me, with "Buffer ptr" :

    in API level 8
    public static void glVertexAttribPointer (int indx, int size, int type, boolean normalized, int stride, Buffer ptr)

    Could you change/add glVertexAttribPointer with "int offset", please.
     
  16. agraham

    agraham Expert Licensed User

    In version 1.2 now posted the previous version of glVertexAttribPointer is corrected and named glVertexAttribPointerF

    Code:
    public void glVertexAttribPointerF(int indx, int size, boolean normalized, int stride, float[] ptr)
       {
          ByteBuffer pbb = ByteBuffer.allocateDirect(ptr.length * 
    4);
          pbb.order(ByteOrder.nativeOrder());
          FloatBuffer pfb = pbb.asFloatBuffer();
          pfb.put(ptr);
          pfb.position(
    0);
          GLES20.glVertexAttribPointer(indx, size, GL_FLOAT, normalized, stride, pfb);
       
    }
    A new glVertexAttribPointer method is added.
    Code:
    public void glVertexAttribPointer(int indx, int size, int type, boolean normalized, int stride, int offset)
       {
          GLES20.glVertexAttribPointer(indx, size, 
    type, normalized, stride, offset);
       
    }
     
    MarkusR likes this.
  17. GDO

    GDO Member Licensed User

    Thank you for the change.

    There is a problem with buffer :

    main_v7 (java line: 317)
    java.lang.IllegalArgumentException: remaining() < size


    at android.opengl.GLES20.glBufferData(Native Method)
    at anywheresoftware.b4a.agraham.opengl2.GLWrapper2.glBufferDataF(GLWrapper2.java:470)


    at gdo.opengl2.main._v7(main.java:317)
    at gdo.opengl2.main._glsv_surfacecreated(main.java:477)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:507)
    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.opengl2.GLWrapper2$GLSurfaceViewWrapper2$myRenderer.onSurfaceCreated(GLWrapper2.java:1668)
    at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1348)
    at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1118)
    java.lang.IllegalArgumentException: remaining() < size



    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:101)
    at android.app.AlertDialog.<init>(AlertDialog.java:63)
    at android.app.AlertDialog.<init>(AlertDialog.java:59)
    at android.app.AlertDialog$Builder.create(AlertDialog.java:786)
    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.opengl2.GLWrapper2$GLSurfaceViewWrapper2$myRenderer.onSurfaceCreated(GLWrapper2.java:1668)
    at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1348)
    at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1118)
    ** Activity (main) Pause, UserClosed = true **


    Thanks
     
  18. agraham

    agraham Expert Licensed User

    What value are you passing in for size? I supect it is a byte count and needs to be data.length * 4.
     
  19. GDO

    GDO Member Licensed User

    It's : gl.GL_FLOAT * 3*3

    gl.glBufferDataF(gl.GL_ARRAY_BUFFER, gl.GL_FLOAT * 3*3, triVertices, gl.GL_STATIC_DRAW)

    where triVertices is Dim triVertices(9) As Float
     
  20. GDO

    GDO Member Licensed User

    ooops !

    gl.GL_FLOAT is not correct !

    I change it by 4.

    Sorry.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice