|
如下是一段OpenGL 自动生成Mipmap的代码:- Image image;
- typedef GLuint TextureID;
- TextureID texID;
- GLint max_texture_max_anisotropy = 0;
- //load a image
- image = load_image("image.jpg");//asume a jpg file
- glGenTextures(1,&texID);
- glBindTexture(GL_TEXTURE_2D,texID);
- glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIP_LINEAR);
- glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_CLAMP);
- glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_CLAMP);
- glGetTexParameteri(GL_TEXTURE_2D,GL_MAX_TEXTURE_MAX_ANISOTROPY,&max_texture_max_anisotropy);
- glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAX_ANISOTROPY,max_texture_max_anisotropy);
- glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAX_LEVEL,8);//these two parameters control the range of mipmap
- glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_BASE_LEVEL,0);//to generate
- #if USE_GLU_BUILD_MIPMAP
- gluBuild2DMipmaps(GL_TEXTURE_2D,image.getFormat(),image.getWidth(),image.getHeight(),image.getFormat(),image.getType(),image.getData());
- #else
- glTexParameteri(GL_TEXTURE_2D,GL_GENERATE_MIPMAP,GL_TRUE);
- glTexImage2D(GL_TEXTURE_2D,0,image.getFormat(),image.getWidth(),image.getHeight(),0,image.getFormat(),image.getType(),image.getData());
- glTexParameteri(GL_TEXTURE_2D,GL_GENERATE_MIPMAP,GL_FALSE);
- #endif
复制代码 在osg之中自动生成Mipmap(不是我们生成好后再一层一层设置的那种)是怎么完成的呀?还有GL_TEXTURE_BASE_LEVEL,GL_TEXTURE_MAX_LEVEL这两个参数是怎么设置的? |
|