简体   繁体   English

OpenGL中的Mipmapping

[英]Mipmapping in OpenGL

I'm having a lot of trouble getting mipmaps to work. 使mipmap正常工作非常麻烦。 I'm using OpenGL 1.1, and I don't have glu, so I'm using the following texture initiation code: 我正在使用OpenGL 1.1,并且没有glu,因此我正在使用以下纹理初始化代码:

glGenTextures(1,&texname);
  glBindTexture(GL_TEXTURE_2D,texname);
  glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_REPEAT);
  glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_REPEAT);
  glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
  glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST_MIPMAP_NEAREST);
  w=width;h=height;
  for(int i=0;i<mipmaps;i++,w/=2,h/=2)
    glTexImage2D(GL_TEXTURE_2D,i,GL_RGBA8,w,h,0,GL_RGBA,GL_UNSIGNED_BYTE,tex[i]);

Variables: 变量:

// data types:
unsigned long int *tex[20];
int mipmaps, width, height, w, h;
GLuint texname;

tex is an array that holds the list of the texture mipmap pixel arrays. tex是一个数组,其中包含纹理mipmap像素数组的列表。 The mipmaps are processed correctly (I tested them individually). 正确处理了mipmap(我分别对其进行了测试)。 mipmaps is the number of mipmaps that reduce down the original image to a 1x1 pixel texture (the original texture is 256x256 - so at this point in the code it's 8). mipmaps是将原始图像缩小为1x1像素纹理的mipmap的数量(原始纹理为256x256-因此在代码中为8)。 width and height are the dimensions of the original texture (256x256). widthheight是原始纹理的尺寸(256x256)。

The result is that it doesn't even use a texture. 结果是它甚至不使用纹理。 Everything just appears flat grays (gray due to the lighting). 一切都显示为浅灰色(由于光照而呈灰色)。

Is there something I'm forgetting? 有什么我要忘记的吗? I've checked this reference , and I can't find any conflicts. 我已经检查了此参考资料 ,但找不到任何冲突。

Other details: In total, I'm enabling GL_DEPTH_TEST, GL_TEXTURE_2D, GL_LIGHTING, GL_CULL_FACE, GL_FOG (and GL_LIGHT0, GL_LIGHT1 which probably don't make a difference). 其他详细信息:总的来说,我将启用GL_DEPTH_TEST,GL_TEXTURE_2D,GL_LIGHTING,GL_CULL_FACE,GL_FOG(以及GL_LIGHT0,GL_LIGHT1可能没有什么不同)。 Also, I am using Mesa 3D's implementation of OpenGL (Mesa version 4.0 which translates to OpenGL version 1.3) if that might have anything to do with it. 另外,如果可能与Mesa 3D的OpenGL(Mesa 4.0版转换为OpenGL 1.3版)一起使用,则可以使用它。

EDIT: 编辑:

The issue is, the texture works fine (not using mipmaps) the moment I change GL_NEAREST_MIPMAP_NEAREST to GL_NEAREST. 问题是,当我将GL_NEAREST_MIPMAP_NEAREST更改为GL_NEAREST时,纹理工作正常(不使用mipmap)。 So, I can't see how it could be any other code - at least I can't think of anything else it might be. 因此,我看不到其他任何代码-至少我想不到其他任何代码。

The value of mipmaps is 8. Your image is 256x256. mipmaps的值为8。您的图像为256x256。 Therefore, you should have 9 levels of mipmapping (256,128,64,32,16,8,4,2,1). 因此,您应该具有9个级别的mipmapping(256、128、64、32、16、8、4、2、1)。 If one is missing, you'll lose your texture. 如果丢失了,您将失去质感。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM