GL_TEXTURE_RECTANGLE_ARB

妖精的绣舞 提交于 2019-12-04 20:11:27

GL_ARB_texture_rectangle extension uses dimension-dependent texture coordinates. Use [0..W]x[0..H] range for texture coordinates, instead of normalized coordinates range [0..1]x[0..1].

For example, to draw a full image on a quad;

glTexCoord2f(0, 0);                     glVertex3f(...); // top-left
glTexCoord2f(0, imageHeight);           glVertex3f(...); // bottom-left
glTexCoord2f(imageWidth, imageHeight);  glVertex3f(...); // bottom-right
glTexCoord2f(imageWidth, 0);            glVertex3f(...); // top-right

Note that there are several limitations using GL_ARB_texture_rectangle extension.

  1. Mipmap filtering is not supported.
  2. Texture border is not supported.
  3. GL_REPEAT wrap mode is not supported.
  4. Palette texture is not supported.
  5. texture coods are addressed by [0..w]x[0..h].

Luckily, OpenGL provides GL_ARB_texture_non_power_of_two extension as well to resolve the above limitations, while it is still supporting NPOT (Non Power Of Two) textures.

The biggest advantages of GL_ARB_texture_non_power_of_two are;

  1. GL_ARB_texture_non_power_of_two uses the conventional normalized texture coords, [0..1]x[0..1].

  2. It does NOT require an additional texture target token, GL_TEXTURE_RECTANGLE_ARB for glEnable(), glTexImage*D(), glBindTexture(), etc. That is, you can still use GL_TEXTURE_2D as usual for NPOT textures.

Using texture rectangles, the texture coordinates are absolute pixel positions. In your case your texture coordinates would be 0,0 2,0 2,2 0,2

It's working now, see next:

GLubyte Texture[16] =
{
0,0xFF,0,0xFF, 0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF, 0,0,0,0
};
GLuint Nom;
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );   //Efface le framebuffer et le depthbuffer
glMatrixMode(GL_MODELVIEW);     //Un petit gluLookAt()...
glLoadIdentity();//load identity matrix
glTranslatef(0.0f,0.0f,-4.0f);//move forward 4 units
angle  = 0.1 * glutGet ( GLUT_ELAPSED_TIME );
glRotatef(angle,0,2,2);
glEnable(GL_TEXTURE_2D);
glEnable (GL_TEXTURE_RECTANGLE_ARB);
glPixelStorei(GL_UNPACK_ROW_LENGTH, 2);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glGenTextures(1,&Nom);  //Génère un n° de texture
glBindTexture(GL_TEXTURE_2D,Nom);   //Sélectionne ce n°
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 4, 4, 0, GL_RGB,GL_UNSIGNED_BYTE, Texture);
glTexParameterf(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); // GL_CLAMP_TO_EDGE
glTexParameterf(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); // GL_CLAMP_TO_EDGE
glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGBA8, 2, 2, 0, GL_BGRA_EXT, GL_UNSIGNED_INT_8_8_8_8_REV, Texture);
glBegin(GL_QUADS);
glTexCoord2i(0,0);glVertex3i(-1,-1,-1);
glTexCoord2i(2,0);glVertex3i(+1,-1,-1);
glTexCoord2i(2,2);glVertex3i(+1,+1,-1);
glTexCoord2i(0,2);glVertex3i(-1,+1,-1);
//1 face
glTexCoord2i(0,0);glVertex3i(-1,-1,+1);
glTexCoord2i(2,0);glVertex3i(+1,-1,+1);
glTexCoord2i(2,2);glVertex3i(+1,+1,+1);
glTexCoord2i(0,2);glVertex3i(-1,+1,+1);
//2 faces
glTexCoord2i(0,0);glVertex3i(+1,-1,-1);
glTexCoord2i(2,0);glVertex3i(+1,-1,+1);
glTexCoord2i(2,2);glVertex3i(+1,+1,+1);
glTexCoord2i(0,2);glVertex3i(+1,+1,-1);
//3 faces
glTexCoord2i(0,0);glVertex3i(-1,-1,-1);
glTexCoord2i(2,0);glVertex3i(-1,-1,+1);
glTexCoord2i(2,2);glVertex3i(-1,+1,+1);
glTexCoord2i(0,2);glVertex3i(-1,+1,-1);
glEnd();
glDisable(GL_TEXTURE_2D);
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!