Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/233.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android glDrawTex_OES的问题_Android_Opengl Es_Textures_Android Ndk_Texture2d - Fatal编程技术网

Android glDrawTex_OES的问题

Android glDrawTex_OES的问题,android,opengl-es,textures,android-ndk,texture2d,Android,Opengl Es,Textures,Android Ndk,Texture2d,我不确定我是否正确使用了glDrawTex。事实上,我肯定我没有,因为我在屏幕上得到的是一个黑色矩形,而不是预期的纹理 为了避免这些愚蠢的点:是的,GL扩展字符串包含OES\u draw\u纹理标记。是的,纹理已加载到内存/等中。正确:如果我将其映射到多边形,它将显示得很好 从为它读取的各种位来看,似乎我需要“配置纹理裁剪矩形…通过TexParameteriv(),pname等于texture_crop_RECT_OES”。根据khronos论坛(谷歌能为我找到的最佳文档)中的数据,其值为“Uc

我不确定我是否正确使用了glDrawTex。事实上,我肯定我没有,因为我在屏幕上得到的是一个黑色矩形,而不是预期的纹理

为了避免这些愚蠢的点:是的,GL扩展字符串包含OES\u draw\u纹理标记。是的,纹理已加载到内存/等中。正确:如果我将其映射到多边形,它将显示得很好

从为它读取的各种位来看,似乎我需要“配置纹理裁剪矩形…通过TexParameteriv(),pname等于texture_crop_RECT_OES”。根据khronos论坛(谷歌能为我找到的最佳文档)中的数据,其值为“Ucr、Vcr、Wcr、Hcr,即左/下/宽/高”

以下是渲染代码:

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 );
}

我错过了什么明显的东西吗?做任何简单的蠢事?

显然,问题是你(或者我,视情况而定)没有先用所有全彩频道调用glColor()。这看起来像是我正在使用的实现(Android,NDK)中的一个bug,作为默认颜色(1,1,1,1)。然而,调用glColor4f(1,1,1,1)就足以解决问题


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

如果有人能解释为什么会出现这种情况,并且不是错误,我很高兴奖励他们回答这个问题。我希望我几天前读过这个答案,而不是现在,在独立得出完全相同的结论之后。