[SOLVED]glGenTexture returning 0

Tutorials concerning the OpenGL® ES cross-platform API for full-function 2D and 3D graphics on the Google-Android platform.

[SOLVED]glGenTexture returning 0

Postby Shaka » Sat Dec 05, 2009 2:10 pm

Hi!

Is it only possible to use glGenTextures in the GLSurfaceView's onSurfaceChanged event? I tried calling it when the drawing had commenced but then it only returns 0.
Last edited by Shaka on Wed Dec 09, 2009 6:55 pm, edited 1 time in total.
Shaka
Developer
Developer
 
Posts: 44
Joined: Fri Aug 28, 2009 3:01 pm

Top

Postby hardcoras » Sat Dec 05, 2009 9:58 pm

glGenTextures can not return anything because return type is void. (public abstract void glGenTextures(int n, IntBuffer textures) - from http://developer.android.com/reference/javax/microedition/khronos/opengles/GL10.html#glGenTextures%28int,%20java.nio.IntBuffer%29).

You can use glGenTextures in onSurfaceChanged() or onDrawFrame() methods because gl instance is already created.
hardcoras
Experienced Developer
Experienced Developer
 
Posts: 62
Joined: Sat Nov 14, 2009 2:31 pm
Location: Lithunia

Postby Shaka » Sun Dec 06, 2009 7:34 am

hardcoras: Thanks for the reply. What I meant with "returns" was that the structure glGenTexture fills only contains 0.
I tried running it inside onDrawFrame and got the same result. Any sugestions?
Shaka
Developer
Developer
 
Posts: 44
Joined: Fri Aug 28, 2009 3:01 pm

Postby hardcoras » Sun Dec 06, 2009 1:59 pm

I've just wrote the code to test glGenTExtures:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public class MyActivity extends Activity {
  2.     @Override
  3.     public void onCreate(Bundle savedInstanceState) {
  4.         super.onCreate(savedInstanceState);
  5.         GLSurfaceView view = new GLSurfaceView(this);
  6.         setContentView(view);
  7.         view.setRenderer(new GLSurfaceView.Renderer() {
  8.             public void onSurfaceCreated(GL10 gl, EGLConfig config) {
  9.             }
  10.  
  11.             public void onSurfaceChanged(GL10 gl, int width, int height) {
  12.                 int total = 5;
  13.                 int[] buffer  = new int[total];
  14.                 gl.glGenTextures(total, buffer, 0);
  15.                 for (int i=0; i<total; i++) Log.v("glGenTextures", i+"="+buffer[i]);
  16.             }
  17.  
  18.             public void onDrawFrame(GL10 gl) {
  19.             }
  20.         });
  21.     }
  22. }
Parsed in 0.032 seconds, using GeSHi 1.0.8.4


Everything looks fine. The results are:
Code: Select all
12-06 14:52:52.741: VERBOSE/glGenTextures(787): 0=1
12-06 14:52:52.741: VERBOSE/glGenTextures(787): 1=2
12-06 14:52:52.751: VERBOSE/glGenTextures(787): 2=3
12-06 14:52:52.761: VERBOSE/glGenTextures(787): 3=4
12-06 14:52:52.761: VERBOSE/glGenTextures(787): 4=5


Maybe there is something wrong with your code?
hardcoras
Experienced Developer
Experienced Developer
 
Posts: 62
Joined: Sat Nov 14, 2009 2:31 pm
Location: Lithunia

Postby Shaka » Mon Dec 07, 2009 6:29 am

Well, that's what I meant, I can only get it to work in onSurfaceChanged.
I think I know what the problem is though, I'm calling the texture creation method from another thread, and by doing that I probably don't have an active context associated with that thread. Does anyone know if you can set the context to use somehow? Like when using OpenGL ES on iPhone you can call something like "setcurrentcontext" when making calls from another thread to the rendering thread.
Shaka
Developer
Developer
 
Posts: 44
Joined: Fri Aug 28, 2009 3:01 pm

Postby hardcoras » Mon Dec 07, 2009 12:47 pm

Yes you are right. You can not call gl functions from another thread because only GL render thread holds gl context. You should try to call all methods from GL render thread or use queueEvent() method.

http://developer.android.com/reference/ ... g.Runnable)
hardcoras
Experienced Developer
Experienced Developer
 
Posts: 62
Joined: Sat Nov 14, 2009 2:31 pm
Location: Lithunia

Top

Postby Shaka » Mon Dec 07, 2009 1:10 pm

hardcoras wrote:Yes you are right. You can not call gl functions from another thread because only GL render thread holds gl context. You should try to call all methods from GL render thread or use queueEvent() method.

http://developer.android.com/reference/ ... g.Runnable)


Thanks man, appreciated. Will try it when I get home from work :)
Shaka
Developer
Developer
 
Posts: 44
Joined: Fri Aug 28, 2009 3:01 pm

Postby Shaka » Wed Dec 09, 2009 6:55 pm

Works like a charm now :D
Thanks for the help hardcoras!
Shaka
Developer
Developer
 
Posts: 44
Joined: Fri Aug 28, 2009 3:01 pm

Top

Return to Android 2D/3D Graphics - OpenGL Tutorials

Who is online

Users browsing this forum: No registered users and 3 guests