1

I'm not sure I'm using glDrawTex_OES correctly. In fact, I'm sure I'm not because I'm getting a black rectangle on the screen rather than the intended texture.

To get the silly points out of the way: Yes, the GL Extension string contains the OES_draw_texture token. Yes, the texture is loaded into memory/etc. correctly: it displays just fine if I map it to a polygon.

From reading the various bits of documentation I can find for it, it looks like I need to "configur[e] the texture crop rectangle ... via TexParameteriv() with pname equal to TEXTURE_CROP_RECT_OES". According to this post in the khronos forums (best documentation google can find for me), the values for that are "Ucr, Vcr, Wcr, Hcr. That is, left/bottom/width/height"

Here's the render code:

void SetUpCamera( int windowWidth, int windowHeight, bool ortho ) // only called once
{
  glViewport( 0, 0, windowWidth, windowHeight );
  glMatrixMode( GL_PROJECTION );
  glLoadIdentity();

  if( ortho )
  {
    float aspect = (float)windowWidth / (float)windowHeight;
    float halfHeight = 32;
    glOrthof( -halfHeight*aspect, halfHeight*aspect, -halfHeight, halfHeight, 1.0f, 100.0f );
  }
  else
  {
    mygluPerspective( 45.0f, (float)windowWidth / (float)windowHeight, 1.0f, 100.0f ); // I don't _actually_ have glu, but that's irrelevant--this does what you'd expect.
  }
}

void DrawTexture( int windowWidth, int windowHeight, int texID )
{
  // Clear back/depth buffer
  glClearColor( 1, 1, 1, 1 );
  glClearDepth( 1.0f );
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

  // Next 2 lines probably not necessary, but, you know, sanity check:
  glMatrixMode( GL_MODELVIEW );
  glLoadIdentity();

  // set up texture
  glBindTexture( GL_TEXTURE_2D, texID ); // texID is the glGenTexture result for a 64x64 2D RGB_8 texture - nothing crazy.
  GLint coords [] = {0, 0, 64, 64};
  glTexParameteriv( GL_TEXTURE_2D, GL_TEXTURE_CROP_RECT_OES, coords );

  // blit? =(
  glDrawTexiOES( windowWidth / 2 - 32, windowHeight - 70, 10, 64, 64 );
}

Am I missing something obvious? Doing anything just plain dumb?

4

1 回答 1

2

显然问题是你(或者我,视情况而定)没有首先调用所有全彩色通道的 glColor() 。这似乎是我正在使用的实现(Android,NDK)中的一个错误,因为默认颜色应该是(1、1、1、1)。然而调用 glColor4f(1, 1, 1, 1) 就足以解决问题。

(我的程序中没有对 glColor 的其他调用。不确定是否有任何其他方法可以更新当前颜色,但纹理使用默认颜色正确渲染并使用 glEnableClientState(GL_TEXTURE_COORD_ARRAY) / glDrawArrays() 绘制它们)

于 2010-07-06T14:32:24.343 回答