Search code examples
androidopengl-eslive-wallpapersamsung-mobile

Android OpenGL ES Textures Showing On Black screen on Some Samsung devices


I recently worked on a live wallpaper application. In that i found out my Android live wallpaper has an odd issue. I use my HTC Wildfire S, Samsung Galaxy tab, Motorola Droid Millstone, Samsung galaxy pop to test my wallpaper along with the emulator and all is working fine, but on Samsung handsets (Samsung Galaxy S II and Samsung Galaxy Player have the symptom) the screen just stays Black for initial launch. But once we move to settings screen and return to preview its working fine.After a little debugging with those handsets I was able to find out that the wallpaper loads correctly, but the textures aren't just showing up. I tried searching about the problem, but didn't found anything helpful.

I bind a texture form the native code. In that am using the OPEN GL library to bind wallpaper . My opengl library intiation is like following

 glEnable(GL_TEXTURE_2D);
  glGenTextures(1, &textureConverted);
  glBindTexture(GL_TEXTURE_2D,textureConverted);
  //...and bind it to our array
  __android_log_print(ANDROID_LOG_DEBUG,
              "NDK initOpenGL()",
              "binded texture"
              );
  glTexParameterf(GL_TEXTURE_2D, 
          GL_TEXTURE_MIN_FILTER, 
          GL_NEAREST);
  glTexParameterf(GL_TEXTURE_2D, 
          GL_TEXTURE_MAG_FILTER, 
          GL_NEAREST);
  //Different possible texture parameters, e.g. GL10.GL_CLAMP_TO_EDGE
  glTexParameterf(GL_TEXTURE_2D, 
          GL_TEXTURE_WRAP_S, 
          GL_CLAMP_TO_EDGE);
  //GL_REPEAT);
  glTexParameterf(GL_TEXTURE_2D, 
          GL_TEXTURE_WRAP_T, 
          GL_CLAMP_TO_EDGE);
  //GL_REPEAT);
  glTexImage2D(GL_TEXTURE_2D,       /* target */
           0,           /* level */
           GL_RGBA,         /* internal format */
           textureWidth,        /* width */
           textureHeight,       /* height */
           0,           /* border */
           GL_RGBA,         /* format */
           GL_UNSIGNED_BYTE,/* type */
           NULL);
  //setup simple shading
  glShadeModel(GL_FLAT);
  //check_gl_error("glShademo_comdel");
  glColor4x(0x10000, 0x10000, 0x10000, 0x10000);

and in my drawFunction

 glClear(GL_COLOR_BUFFER_BIT);
  int max;
  glGetIntegerv(GL_MAX_TEXTURE_SIZE, &max);
    __android_log_print(ANDROID_LOG_DEBUG,
              "NDK drawFrame()",
              "GL_MAX_TEXTURE_SIZE: %d",
        max);
  glBindTexture(GL_TEXTURE_2D,textureConverted);
  int rect[4] = {0, textureHeight, textureWidth, nTextureHeight};
  glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_CROP_RECT_OES, rect);

  glTexSubImage2D(GL_TEXTURE_2D, /* target */
          0,        /* level */
          0,    /* xoffset */
          0,    /* yoffset */
          textureWidth,
          textureHeight,
          GL_RGBA,  /* format */
          GL_UNSIGNED_BYTE, /* type */
          pFrameConverted->data[0]);
  glDrawTexiOES(0, 0, 0, drawWidth, drawHeight); //drawWidth is th screenwidth and drawheight is the screenheight

Why doesn't this work on Samsung phones?


Solution

  • i fix this issue. It is all in the initiation of the opengl library. when i add glViewport(0, 0, screenWidth, screenHeight); this line of code, the bug was fixed. Now my opengl application renders all the devices. thank you guys.