GLSurfaceView.onSurfaceCreated not called in time

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

GLSurfaceView.onSurfaceCreated not called in time

Postby mvdgaag » Wed Jun 09, 2010 10:09 pm

Hi all,

I'm new to java programming and threads, but have some experience with c++ and opengl, so I guess this is an easy one to answer.

I load my textures in a TextureManager class that is owned by the Renderer I attach to the GLSurfaceView.
In the onSurfaceCreated method of the Renderer class I load my textures and in my main Activity I create objects that require textures.

Now the creation of these objects in the main Activity seems to happen before onSurfaceCreated is called.
Is there an easy way to wait for my surface to be created? Or maybe a simpler/better design that avoids this problem all together?

Thanks a lot!

Maarten
mvdgaag
Junior Developer
Junior Developer
 
Posts: 10
Joined: Wed Jun 09, 2010 10:02 pm

Top

Re: GLSurfaceView.onSurfaceCreated not called in time

Postby luugiathuy » Thu Jun 10, 2010 3:44 am

Hi,

I also encounter this problem and on the way try to solve it.

Hope that someone can help us =)
luugiathuy
Junior Developer
Junior Developer
 
Posts: 10
Joined: Tue Jun 01, 2010 3:16 am

Re: GLSurfaceView.onSurfaceCreated not called in time

Postby mvdgaag » Thu Jun 10, 2010 9:48 pm

I solved it by now.

I have a separate class to store Texture objects. When an object requires a texture, it requests it from the TextureManager that passes a reference to an instance of this Texture class.

The actual texture and openGL handle to the texture are filled in into the instances of the Texture classes by the TextureManager in the OnSurfaceCreated method. You don't need the openGL handle anyways before you draw.

Hope this helps

edit: only problem now is that my texture is all black (i have GL_LIGHTING) turned off.
oh and I draw on the simulator using glDrawTexfOES.
mvdgaag
Junior Developer
Junior Developer
 
Posts: 10
Joined: Wed Jun 09, 2010 10:02 pm

Re: GLSurfaceView.onSurfaceCreated not called in time

Postby luugiathuy » Fri Jun 11, 2010 1:35 pm

I'll try your solution. Thank you

I thought that we can delay the onDrawFrame() and creating objects until finished loading all the textures.
luugiathuy
Junior Developer
Junior Developer
 
Posts: 10
Joined: Tue Jun 01, 2010 3:16 am

Re: GLSurfaceView.onSurfaceCreated not called in time

Postby mvdgaag » Fri Jun 11, 2010 2:28 pm

Hi, luugiathuy. That might work, but my solution allows you to create any object that contains a texture at any time.
mvdgaag
Junior Developer
Junior Developer
 
Posts: 10
Joined: Wed Jun 09, 2010 10:02 pm

Top

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

Who is online

Users browsing this forum: No registered users and 8 guests