1

I'm creating my own mipmaps when creating textures, and as soon as I enable mipmaps via GL_LINEAR_MIPMAP_NEAREST (or anything MIPMAP), the textures are just a very dark, blurry mess. If I switch to GL_LINEAR, they're fine.

Here's how I'm creating the texture:

glGenTextures(1, &m_TextureId);
glBindTexture( GL_TEXTURE_2D, id );
int level = 0;

jobject mippedBitmap = srcBitmap;

while (width >= 2 && height >= 2) {
    jniEnv->CallStaticVoidMethod(s_GLUtilsClass, s_texImage2DMethodID,
                     GL_TEXTURE_2D, level, mippedBitmap, 0);

    width >>= 1;
    height >>= 1;
    level++;

    mippedBitmap = createScaledBitmap(jniEnv, srcBitmap, width, height, true);
}

I've omitted all Bitmap.recycle()/NewGlobalRef() calls for brevity. createScaledBitmap is obviously a JNI call to Bitmap.createScaledBitmap().

I also tried the other version of texImage2D that takes the format and type of the bitmap. I've verified that it's always RGBA.

EDIT: To elaborate on the textures - they're really almost black. I tried eraseColor() on the mips with bright colors, and they're still extremely dark.

genpfault
  • 51,148
  • 11
  • 85
  • 139
EboMike
  • 76,846
  • 14
  • 164
  • 167
  • Did you try using glGenerateMipmap? – kvark Feb 19 '11 at 20:48
  • @kvark: I'm a complete and utter schmuck. I didn't even know about that. Please write that as an answer so you can get your well-deserved 25 points :) – EboMike Feb 19 '11 at 22:50

3 Answers3

2

The code you're showing will not generate the lower mip levels (1x1 will be missing, e.g.), so your texture will be incomplete. That should make the rendering as if the texturing was not present at all. It's unclear from your description if this is what you're observing.

In all cases, you should provide the mipmaps all the way down to the 1x1 (and for non square textures, this requires some changes in the computation of the new texture size to keep passing 1, as in 4x1 -> 2x1 -> 1x1)

Bahbar
  • 17,760
  • 43
  • 62
  • You're the man! I didn't even think about that. Technically kvark's answer is even better in my case (you probably thought I knew about glGenerateMipmap but didn't use it because I wanted custom mips, but no), but adding the 1x1 level also fixed the issue. Big +1, wish I could accept two answers. – EboMike Feb 19 '11 at 22:52
2

glGenerateMipmap will do this task faster and much more convenient for you.

kvark
  • 5,291
  • 2
  • 24
  • 33
0

It may be the case that Bitmap.createScaledBitmap does not correct the gamma. Have a look at this thread for code to create gamma-corrected mipmaps

ryanm
  • 2,979
  • 18
  • 22
  • Good idea, but that wasn't it. The textures are VERY dark, almost black - it's not just like "they're a bit off due to gamma". Also, I tried filling them entirely with bright colors, and they still end up almost black. – EboMike Feb 19 '11 at 19:45