有的机器上以下代码无法正确帮定纹理,把glTexImage2D换成
gluBuild2DMipmaps(GL_TEXTURE_2D, 3, resx, resy, GL_RGB, GL_UNSIGNED_BYTE, pBallImage->pixels);
就可以了,但速度奇慢,难道glTexImage2D不能正常使用帮定文理吗?请问glTexImage2D到底怎样使用下面代码怎样修改?glGenTextures(1,&TexId);
  glBindTexture(GL_TEXTURE_2D, TexId );
  // Update The Texture
  glTexImage2D(GL_TEXTURE_2D, 0, 3, resx, resy, 0, GL_RGB, GL_UNSIGNED_BYTE, pBallImage->pixels);
//  glTexSubImage2D (GL_TEXTURE_2D, 0, 0, 0, resx, resy, GL_RGB, GL_UNSIGNED_BYTE, pBallImage->pixels);
  //  glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, resx, resy,
//   GL_RGB, GL_UNSIGNED_BYTE, pBallImage->pixels);
  //¿ØÖÆÂ˲¨
  glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); // Set Texture Max Filter
  glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); // Set Texture Min Filter  glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);Draw();//绘制一个物体用前面的纹理包裹

解决方案 »

  1.   

    void glTexImage2D( GLenum target, GLint level, GLint components,
    GLsizei width, GLsizei height, GLint border,
    GLenum format, GLenum type, const GLvoid *pixels );
      target:纹理目标的类型
      level:表示多级分辨率的纹理图象的级数。若只有一种分辨率,level为0。
      components:是从1到4的整数,1:选择R;2:选择R A;3:选择R G B;
           4:选择R G B A;
      width:纹理的宽度
      height:是纹理的高度。
      border:边框的值
      format:映射格式,为GL_RGB时,表示图像数据由红、绿、蓝三色数据组成
      type:数据类型,为GL_UNSIGNED_BYTE 意味着组成图像的数据是无符号字节类型的
      pixels:图像数据的地址
    此函数用于创建纹理,此函数只适用于宽长均为64,128,256像素的Bmp图像以下是示例代码,你看一下:
    AUX_RGBImageRec *LoadBMP(char *Filename) // Loads A Bitmap Image
    {
    FILE *File=NULL; // File Handle if (!Filename) // Make Sure A Filename Was Given
    {
    return NULL; // If Not Return NULL
    } File=fopen(Filename,"r"); // Check To See If The File Exists if (File) // Does The File Exist?
    {
    fclose(File); // Close The Handle
    return auxDIBImageLoad(Filename); // Load The Bitmap And Return A Pointer
    } return NULL; // If Load Failed Return NULL
    }int LoadGLTextures()
    {
    int Status=FALSE;

    AUX_RGBImageRec *TextureImage[1];
    memset(TextureImage,0,sizeof(void *)*1);            // Set The Pointer To NULL // Load The Bitmap, Check For Errors, If Bitmap's Not Found Quit
    if (TextureImage[0]=LoadBMP("Data/NeHe.bmp"))
    {
    Status=TRUE; // Set The Status To TRUE glGenTextures(1, &texture[0]); // Create The Texture // Typical Texture Generation Using Data From The Bitmap
    glBindTexture(GL_TEXTURE_2D, texture[0]);
    glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[0]->sizeX, TextureImage[0]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data);
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
    } if (TextureImage[0]) // If Texture Exists
    {
    if (TextureImage[0]->data) // If Texture Image Exists
    {
    free(TextureImage[0]->data); // Free The Texture Image Memory
    } free(TextureImage[0]); // Free The Image Structure
    } return Status; // Return The Status
    }