views:

69

answers:

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?

+1  A: 

Apparently the problem is that you're (or I am, as the case may be) not calling glColor() with all full color channels first. This seems like a bug in the implementation I'm working with (Android, NDK), as the default Color should be (1, 1, 1, 1). Yet calling glColor4f(1, 1, 1, 1) is enough to fix things.

(I have no other calls to glColor in my program. Not sure if there's any other way to update the current color, but the textures render correctly using the default color and drawing them with glEnableClientState(GL_TEXTURE_COORD_ARRAY) / glDrawArrays() )

Clayton Hughes
If anyone can explain why this ought to be the case and is not a bug, I'd be glad to award them for answering the question.
Clayton Hughes
+1 sir. I wish I had read this answer a few days ago instead of now, after independently reaching the exact same conclusion.
rq