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

    :sign0098:
    There may be other corrections to the library needed as you go further but we are off to a good start and any further problems will hopefully only be with individual methods.
     
  2. GDO

    GDO Member Licensed User

    Hi,

    Could you please add something like that :

    "...In order to make your OpenGL ES application respond to touch events, you must implement the onTouchEvent() method in your GLSurfaceView class..."

    Now I can draw a triangle, I want to move it ...

    :)

    Thanks.
     
  3. agraham

    agraham Expert Licensed User

    This potentially opens up a whole can of worms :( UI events are raised on the main application thread but the renderer events Draw, SurfaceChanged and SurfaceCreated run on a separate rendering thread. I need to think about this.

    So that I can read it do you have the link for that quote you gave above?

    What did you want to do in a Touch event? Changing global variables to be picked up by the Draw event would be OK but you might have to implement some resource locking or system of flags so the cross thread access from both the main and rendering threads to those variables doesn't cause problems. I don't think that you can call OpenGL functions outside of those rendering events, though I might be wrong. Even so those calls should only be made on the rendering thread.

    One way of handling events that is "ready-rolled" would be to put a transparent Panel on top of the GLSurfaceView.
     
  4. GDO

    GDO Member Licensed User

  5. GDO

    GDO Member Licensed User

    It's OK for me with the panel.
    Bye.
     
  6. GDO

    GDO Member Licensed User

    Hello,

    My triangle is now moving and I got new problem.

    It seems to me that Opengl2 is not hardware accelerated.
    I added, into the manifest, hardware Accelerated (application level), minSdk=9 and targetSdk=11 but it is not accelerated on my 2 real devices (Galaxy Notes and Asus Transformer TF300).

    Is there something like "double bufered" inside your library to enable ?

    Thanks.
     
  7. agraham

    agraham Expert Licensed User

    No. As far as I know there is nothing more to be exposed. You can check for hardware acceleration with this code
    Code:
    Dim r As Reflector
    Dim hw As Boolean
    r.Target = glsv
    hw = r.RunMethod(
    "isHardwareAccelerated")
    Msgbox(hw, "HardwareAccelerated")
     
  8. agraham

    agraham Expert Licensed User

    I got the reflection code above reporting hardware acceleration on my Xoom by putting
    Code:
    SetApplicationAttribute(android:hardwareAccelerated, "true")
    in the Manifest Editor. I was already compiling with "...\android-13\android.jar" in my android.jar path.

    EDIT :- the minSdkVersion and targetSdkVersion don't seem to matter. I've set both to 4 and I still get hardware acceleration reported.
     
    Last edited: Mar 13, 2013
  9. GDO

    GDO Member Licensed User

    Hi,

    hardware Accelerated is OK BUT it seems that opengl2 doesn't use double buffers.

    I don't kow why ...
     
  10. agraham

    agraham Expert Licensed User

    From what I can see from Googling GLSurfaceView automatically double-buffers. See the second post here screen flickering in GLSurfaceView - android-discuss for a description of how it works. Are you not completely redrawing each frame? This can cause flicker as described in that link.
     
  11. GDO

    GDO Member Licensed User

    Yes I read it, too but what I see on my device, makes me think there is a trouble with double-buffers.

    In my OnDraw event, I clear color and depth, draw my rotating triangle and that's all.

    And on my device from, time to time, you can see the new triangle (this one is ok) AND a piece of the old one (not OK) as if the screen was not clear before the drawing.
     
  12. agraham

    agraham Expert Licensed User

    If you post your project I'll try it on my Xoom if you want.
     
  13. GDO

    GDO Member Licensed User

    Don't forget I am a newbie ...
     

    Attached Files:

  14. agraham

    agraham Expert Licensed User

    I have been playing with various combinations of speed and colours for about an hour now. I see the effect but I wonder if it is an artefact of persistence of vision.

    If you speed it up by setting the Timer interval to 10mS then you see lots of triangle points.

    If you slow it down by setting the timer to 1000mS and set the background to black or white then you don't really notice any effect but when the background is gray it obvious but, to me, only on the red and the blue points but not on the green point of the large triangle. If you make the small triangle white or green I see no effect but if it is blue then I see it.
     
  15. GDO

    GDO Member Licensed User

    Yes, I wonder too.

    I don't know if the trouble is about my display devices.
    But I tried other demo (not in b4a and from better programmer than I am) which run fine on my display devices.

    I'll try to make a better demo and see if the problem is still there.

    Thanks.
     
  16. GDO

    GDO Member Licensed User

    Hello,

    I am playing with textures but nothing is working ...
    I have 3 questions/remarks about the library

    1- gActiveTexture should be glActiveTexture
    2-glCompressedTexImage2D and glCompressedTexSubImage2D are defined with java.nio.Buffer

    and the most important point,

    3- with glTexImage2D (target As Int, level As Int, bitmap As android.graphics.Bitmap, border As Int), how do you manage the missing parameters (internalFormat, width, height, format and type) ?

    from here : glTexImage2D - OpenGL 4 Reference Pages


    Thank you
     
  17. Informatix

    Informatix Expert Licensed User

  18. agraham

    agraham Expert Licensed User

    Oops!, sorry I will fix it.
    Like those other method that I left needing a Buffer, those fall into the class of needing someone who knows what they are doing to tell me what type you want to use. So what types of arrays do you want pass?
    As Informatix has pointed out Android uses OpenGl ES. There is a class in Android called GLUtils of which the documentations says "Utility class to help bridging OpenGL ES and Android APIs.". With my prevailing ignorance all things OpenGL I exposed
    Code:
    texImage2D(int target, int level, int internalformat, Bitmap bitmap, int type, int border)
    and
    texSubImage2D(int target, int level, int xoffset, int yoffset, 
    Bitmap bitmap)
    and again was waiting feedback from anyone trying to use them to see if any more of the GLUtils methods were needed. This library does nothing clever at all - that's a bit beyond me! It's a very thin wrapper to expose the API calls to Basic4android so there should be almost a one to one correspondence between this library methods and those in the Android API documentation
     
  19. GDO

    GDO Member Licensed User

    Hello,

    1- ;-)

    2- glCompressedTexImage2D and glCompressedTexSubImage2D
    I am not using them, for now, but I'll ask you for modifications as soon as possible, if you don't mind.

    3- You're right, Android + Opengl ES is not Opengl.
    I have to read the doc more carrefully.

    I can now see my texture on my square.

    Thank you for your help.
     
  20. GDO

    GDO Member Licensed User

    Hello,

    1-
    I can test my programs on 3 devices (Samsung Galaxy Notes, Nexus 7 and Asus Transformer TF300).

    My first program (colored triangle with OGL2) runs OK on the 3 devices .
    My second program (square with one texture OGL2) doesn't run on my Asus but runs OK on the 2 others devices.

    Do you know if there is something special to do with OGL2 and Asus ?
    Could you, please, try my program ?

    2-
    Could you add this, in Matrix2 :
    // Create a camera view matrix
    Matrix.setLookAtM(mVMatrix, 0, 0, 0, -3, 0f, 0f, 0f, 0f, 1.0f, 0.0f);
    ( from OpenGL | Android Developers )

    Thank you.
     

    Attached Files:

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