May 20, 2011 Replies: 90 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 OpenGL2_1.4.zip 43.7 KB · Views: 2,046 OpenGL2_v1.5_lib.zip OpenGL2_v1.5_lib.zip 38.2 KB · Views: 1,254 Last edited: Sep 29, 2019 Click to expand...
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.
agraham Expert Licensed User Longtime User Mar 11, 2013 #41 GDO said: I can now see my triangle ! Click to expand... :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.
GDO said: I can now see my triangle ! Click to expand... :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.
G GDO Member Licensed User Longtime User Mar 11, 2013 #42 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.
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.
agraham Expert Licensed User Longtime User Mar 11, 2013 #43 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.
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.
G GDO Member Licensed User Longtime User Mar 12, 2013 #44 Hello, The quote is from here : Responding to Touch Events | Android Developers But I think you're right with this : "...put a transparent Panel on top of the GLSurfaceView..." I'll try. Thank you.
Hello, The quote is from here : Responding to Touch Events | Android Developers But I think you're right with this : "...put a transparent Panel on top of the GLSurfaceView..." I'll try. Thank you.
G GDO Member Licensed User Longtime User Mar 13, 2013 #46 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.
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.
agraham Expert Licensed User Longtime User Mar 13, 2013 #47 No. As far as I know there is nothing more to be exposed. You can check for hardware acceleration with this code Code: Copy Dim r As Reflector Dim hw As Boolean r.Target = glsv hw = r.RunMethod("isHardwareAccelerated") Msgbox(hw, "HardwareAccelerated")
No. As far as I know there is nothing more to be exposed. You can check for hardware acceleration with this code Code: Copy Dim r As Reflector Dim hw As Boolean r.Target = glsv hw = r.RunMethod("isHardwareAccelerated") Msgbox(hw, "HardwareAccelerated")
agraham Expert Licensed User Longtime User Mar 13, 2013 #48 I got the reflection code above reporting hardware acceleration on my Xoom by putting Code: Copy 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
I got the reflection code above reporting hardware acceleration on my Xoom by putting Code: Copy 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.
G GDO Member Licensed User Longtime User Mar 13, 2013 #49 Hi, hardware Accelerated is OK BUT it seems that opengl2 doesn't use double buffers. I don't kow why ...
Hi, hardware Accelerated is OK BUT it seems that opengl2 doesn't use double buffers. I don't kow why ...
agraham Expert Licensed User Longtime User Mar 13, 2013 #50 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.
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.
G GDO Member Licensed User Longtime User Mar 13, 2013 #51 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.
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.
agraham Expert Licensed User Longtime User Mar 13, 2013 #52 If you post your project I'll try it on my Xoom if you want.
G GDO Member Licensed User Longtime User Mar 13, 2013 #53 Don't forget I am a newbie ... Attachments OGL2-TRSTt.zip OGL2-TRSTt.zip 4.3 KB · Views: 685
agraham Expert Licensed User Longtime User Mar 13, 2013 #54 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.
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.
G GDO Member Licensed User Longtime User Mar 13, 2013 #55 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.
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.
G GDO Member Licensed User Longtime User Mar 19, 2013 #56 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
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
Informatix Expert Licensed User Longtime User Mar 19, 2013 #57 GDO said: from here : glTexImage2D - OpenGL 4 Reference Pages Click to expand... I don't think you should rely on this documentation (Android uses a special version of OpenGL called OpenGL ES). Here's the Android doc: Android OpenGL
GDO said: from here : glTexImage2D - OpenGL 4 Reference Pages Click to expand... I don't think you should rely on this documentation (Android uses a special version of OpenGL called OpenGL ES). Here's the Android doc: Android OpenGL
agraham Expert Licensed User Longtime User Mar 19, 2013 #58 gActiveTexture should be glActiveTexture Click to expand... Oops!, sorry I will fix it. GDO said: 2-glCompressedTexImage2D and glCompressedTexSubImage2D are defined with java.nio.Buffer Click to expand... 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? 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) ? Click to expand... 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: Copy 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
gActiveTexture should be glActiveTexture Click to expand... Oops!, sorry I will fix it. GDO said: 2-glCompressedTexImage2D and glCompressedTexSubImage2D are defined with java.nio.Buffer Click to expand... 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? 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) ? Click to expand... 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: Copy 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
G GDO Member Licensed User Longtime User Mar 20, 2013 #59 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.
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.
G GDO Member Licensed User Longtime User Mar 22, 2013 #60 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. Attachments OGL2Bitmap.zip OGL2Bitmap.zip 40.9 KB · Views: 673
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.