本文介绍了OpenGL中的Mipmapping的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

要使Mipmap正常工作,我遇到很多麻烦.我正在使用OpenGL 1.1,并且没有glu,因此我正在使用以下纹理初始化代码:

I'm having a lot of trouble getting mipmaps to work. I'm using OpenGL 1.1, and I don't have glu, so I'm using the following texture initiation code:


  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]);

变量:


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

tex是一个数组,其中保存纹理mipmap像素数组的列表.正确处理了mipmap(我分别对其进行了测试). mipmaps是将原始图像缩小为1x1像素纹理的mipmap的数量(原始纹理为256x256-因此在代码中为8). widthheight是原始纹理的尺寸(256x256).

tex is an array that holds the list of the texture mipmap pixel arrays. The mipmaps are processed correctly (I tested them individually). 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). width and height are the dimensions of the original texture (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.

其他详细信息:总计,我将启用GL_DEPTH_TEST,GL_TEXTURE_2D,GL_LIGHTING,GL_CULL_FACE,GL_FOG(以及GL_LIGHT0,GL_LIGHT1可能没有什么不同).另外,如果可能与Mesa 3D的OpenGL(Mesa版本4.0转换为OpenGL版本1.3)有关,我将使用它.

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).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.

问题是,当我将GL_NEAREST_MIPMAP_NEAREST更改为GL_NEAREST时,纹理工作正常(不使用mipmap).因此,我看不到其他任何代码-至少我想不到其他任何代码.

The issue is, the texture works fine (not using mipmaps) the moment I change GL_NEAREST_MIPMAP_NEAREST to GL_NEAREST. So, I can't see how it could be any other code - at least I can't think of anything else it might be.

推荐答案

mipmaps的值为8.您的图像为256x256.因此,您应该具有9个级别的mipmapping(256、128、64、32、16、8、4、2、1).如果丢失了,您将失去质感.

The value of mipmaps is 8. Your image is 256x256. Therefore, you should have 9 levels of mipmapping (256,128,64,32,16,8,4,2,1). If one is missing, you'll lose your texture.

这篇关于OpenGL中的Mipmapping的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 02:50