Getting smallest mipmap on ATI

I have a mipmapped RGB texture and I want to get the color of the smallest mipmap. The following works on NVidia and in software mode but not on an 8500. For example, I should get 157,147,128 but I always get 120,1,26. Is there a way to get the correct value on an ATI?

glBindTexture(GL_TEXTURE_2D, nTexture);
int nLevel = 0;
int nWidth, nHeight;
glGetTexLevelParameteriv(GL_TEXTURE_2D, nLevel, GL_TEXTURE_WIDTH, &nWidth);
glGetTexLevelParameteriv(GL_TEXTURE_2D, nLevel, GL_TEXTURE_HEIGHT, &nHeight);
while (nWidth > 1 | | nHeight > 1)
{
nLevel++;
glGetTexLevelParameteriv(GL_TEXTURE_2D, nLevel, GL_TEXTURE_WIDTH, &nWidth);
glGetTexLevelParameteriv(GL_TEXTURE_2D, nLevel, GL_TEXTURE_HEIGHT, &nHeight);
}
unsigned char pPixel[4];
glGetTexImage(GL_TEXTURE_2D, nLevel, GL_RGB, GL_UNSIGNED_BYTE, &pPixel);

You just need the width and height,
then in your while loop you just divide

if(width>1)
width/=2;
if(height>1)
height/=2;

Not sure why your code doesn’t work.

V-man

something like

maxXlevel = 0;
while(XSize>>=1) maxXlevel++;
maxYlevel = 0;
while(YSize>>=1) maxYlevel++;

maxlevel = min(maxXlevel,maxYlevel)

should basically work…

standard question: you have actual drivers?

Thanks for the suggestions. I will use those optimizations but nLevel is right it just gives wrong results.

I am using the latest official drivers.

James