前几天,用自己的一张图片,把HeHe里纹理(lesson 6)代码稍微改了一下,只是为了了解纹理映射的步骤,
但是结果很是意外,图片始终是被拉伸了,如下图:
一直以为是纹理坐标问题,后来才知道是图片问题。我的图片尺寸是90*90不是2的幂,
下面是nehe官方的原话:
The texture size must be a power of two (1,2,4,8,16,32,64,128,256 and so on up to 2048 or 4096 depending a little on the hardware), though you don need to have a square texture 128x512 is perfectly valid, on nvidia cards above GF6xxx the power of two limit has been removed, however most cards still have this limit so it's best to stick with it.
来自:http://nehe.gamedev.net/wiki/NewLesson5.ashx
void glTexImage2D( GLenum target,
GLint level,
GLint internalformat,
GLsizei width,
GLsizei height,
GLint border,
GLenum format,
GLenum type,
const GLvoid *pixels )
opengl中这个函数,支持的图片尺寸为:(2的m次幂)2m + 2*border
border只能是0,1。
可以手动的改图片的size,也可以利用opengl自带的函数修改图片size:
GLint gluScaleImage( GLenum format,
GLsizei wIn,
GLsizei hIn,
GLenum typeIn,
const void *dataIn,
GLsizei wOut,
GLsizei hOut,
GLenum typeOut,
GLvoid* dataOut )
在opengl2.0中则取消了纹理单元必须是2的整数次方的限制。