I'm currently working on an openGL launcher and it's all working pretty well so far. However, I ran into a little problem I can't figure out.
Here's the renderer:
Using java Syntax Highlighting
- public class LauncherRenderer implements GLSurfaceView.Renderer
- {
- static int screenSize[] = new int[2];
- static float virtualSize[] = new float[2];
- shortcutTile shortcut[] = new shortcutTile[150];
- ScreenDynamics dynamics;
- public static ArrayList<AppInfo> appInfos;
- long start = 0;
- long current = 0;
- int frames = 0;
- float screenY = 0;
- float yPadding = 0;
- float xPadding = 0;
- float tileSpacingX = 0;
- float tileSpacingY = 0;
- final int nAppsX = 4;
- final int nAppsY = 5;
- @Override
- public void onDrawFrame(GL10 gl)
- {
- getFPS(true);
- gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
- gl.glLoadIdentity();
- screenY = dynamics.getCurrentYCoord();
- gl.glTranslatef(0, screenY, 0);
- gl.glTranslatef(xPadding, yPadding, -1);
- int x = 0;
- for (int i = 0; i < appInfos.size(); i++)
- {
- if (x == 400)
- {
- gl.glTranslatef(-tileSpacingX*nAppsX, tileSpacingY , 0);
- x = 0;
- }
- gl.glBindTexture(GL10.GL_TEXTURE_2D, appInfos.get(i).texID);
- shortcut[i].draw(gl);
- gl.glTranslatef(tileSpacingX, 0, 0);
- x += 100f;
- }
- frames++;
- }
- @Override
- public void onSurfaceChanged(GL10 gl, int w, int h)
- {
- gl.glMatrixMode(GL10.GL_PROJECTION);
- float ratio = (float) w / (float) h;
- screenSize[0] = w;
- screenSize[1] = h;
- virtualSize[0] = 400;
- virtualSize[1] = (float) 400.0f / (float) ratio;
- gl.glOrthof(0.0f, virtualSize[0], virtualSize[1], 0.0f, 0.01f, 100.0f);
- gl.glViewport(0, 0, screenSize[0], screenSize[1]);
- tileSpacingX = (virtualSize[0]/nAppsX);
- tileSpacingY = (virtualSize[1]/nAppsY);
- xPadding = (tileSpacingX-70)/2;
- yPadding = (tileSpacingY-70)/2;
- dynamics.setLimits((int) ((int) (Math.ceil(appInfos.size()/nAppsX)*tileSpacingY)-virtualSize[1]+tileSpacingY), 0);
- gl.glMatrixMode(GL10.GL_MODELVIEW);
- }
- @Override
- public void onSurfaceCreated(GL10 gl, EGLConfig config)
- {
- start = System.currentTimeMillis();
- dynamics = new ScreenDynamics();
- gl.glClearColor(0f, 0f, 0f, 1.0f);
- gl.glEnable(GL10.GL_CULL_FACE);
- gl.glFrontFace(GL10.GL_CCW);
- gl.glCullFace(GL10.GL_BACK);
- gl.glEnable(GL10.GL_TEXTURE_2D);
- gl.glShadeModel(GL10.GL_SMOOTH);
- gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);
- gl.glEnable(GL10.GL_BLEND);
- for (int i = 0; i < appInfos.size() && i < 150; i++)
- {
- appInfos.get(i).texID = loadTexture(gl, appInfos.get(i).icon);
- shortcut[i] = new shortcutTile();
- }
- }
- private static int newTextureID(GL10 gl)
- {
- int[] temp = new int[1];
- gl.glGenTextures(1, temp, 0);
- return temp[0];
- }
- private int loadTexture(GL10 gl, Drawable drawable)
- {
- int id = newTextureID(gl);
- Bitmap temp = ((BitmapDrawable) drawable).getBitmap();
- Matrix flip = new Matrix();
- float scaleWidth = ((float) 64) / temp.getWidth();
- float scaleHeight = ((float) 64) / temp.getHeight();
- flip.postRotate(270);
- flip.postScale(scaleWidth, -scaleHeight);
- Bitmap bmp = Bitmap.createBitmap(temp, 0, 0, temp.getWidth(), temp.getHeight(), flip, true);
- temp.recycle();
- gl.glBindTexture(GL10.GL_TEXTURE_2D, id);
- gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_LINEAR);
- gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR);
- gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_S, GL10.GL_REPEAT);
- gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_T, GL10.GL_REPEAT);
- GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bmp, 0);
- bmp.recycle();
- return id;
- }
- // GETTERS AND SETTERS FOLLOWING, IRRELEVANT
Parsed in 0.043 seconds, using GeSHi 1.0.8.4
and here's my activity:
Using java Syntax Highlighting
- public class LauncherGL extends Activity
- {
- private LauncherView _LauncherView;
- private LauncherRenderer renderer;
- static WallpaperManager wallmanager;
- @Override
- public void onCreate(Bundle savedInstanceState)
- {
- super.onCreate(savedInstanceState);
- _LauncherView = new LauncherView(this);
- renderer = _LauncherView.getRenderer();
- setContentView(_LauncherView);
- getAllPackages();
- }
- @Override
- protected void onPause()
- {
- super.onPause();
- _LauncherView.onPause();
- }
- @Override
- protected void onResume()
- {
- super.onResume();
- _LauncherView.onResume();
- }
- // IRRELEVANT STUFF FOLLOWING
Parsed in 0.032 seconds, using GeSHi 1.0.8.4
Now first of all, I'm using a small method to transform a drawable to an openGL texture I modified from the internet. One of the bitmaps called temp gets recycled, and causes problems when resuming (attempt to use recycled bitmap error). Besides just leaving it out, what would be the solution to this?
Now the main problem is that when I resume the activity (just forgetting about recycling the bitmap described above) my squares -are- drawn, but without a texture, the squares are simply transparent, showing the background beneath them. I can make the textures appear by launching the activity again without navigating away from it first, or calling "setContentView(_LauncherView);" from onResume()
I really hope that someone could help me with this, as it's the only thing holding me back at the moment.
Thank you very much,
Quipeace

.

