Is there a way to pass context into onDrawFrame(GL10 gl)?

987 views Asked by At

I am designing a game in Open GLES on Android in Java.

Obviously I am using lots of textures and soon I will run out of memory.

I am quite new to Android and Java, but I figured that the easiest way to go round this problem is to destroy the objects with bitmaps, which I don't need at the moment, let the garbage collector reclaim the memory which they occupied, then re-create those objects at the late stage when I again need the respective textures.

Something like this:

background = null;

then when I need the textures in background object:

background = new Background(context);

seems pretty straighforward, except that is, that the context (which I need for my class background to function, as it loads the textures from it via BitmapFactory) is not passed into onDrawFrame(GL10 gl) function where my main game loop is and where I need it!

If I try to add context as a second parameter after GL10 gl, I get an error - this does not seem to be possible.

Does anybody know how to pass context into onDrawFrame, or other way how to clear the context objects from memory and then reinstate them again?

1

There are 1 answers

3
Reuben Scratton On

You must be drawing to a SurfaceView, or a GLSurfaceView... which is obviously a type of View, and therefore has a getContext() method.