glTexImage2D和加载图像的问题

时间:2011-07-06 10:27:45

标签: c++ opengl-es corona

我正在使用Corona(加载图片)/ C ++ / Glut。

加载纹理时遇到奇怪的问题。我知道问题出在glTexImage2D上,但很奇怪,当图像 850 x 249 850 x 251 850 x 252 时一切正常。但是当它 850 x 250 时,编译后出错:

  

0x024bfee9处的未处理异常   [...]。exe:0xC0000005:访问   违规阅读地点0x0265c001。

我正在使用:

glTexImage2D(GL_TEXTURE_2D, 0, TextureFormat, TextureImage->getWidth(), TextureImage->getHeight(), 0, TextureFormat, GL_UNSIGNED_BYTE, TextureImage->getPixels());

发生了什么事?

修改

getpixels

edit2 - 代码

加载纹理代码:

GLuint LoadTexture(char *_filename)
{
    cout<<"loading image start"<<endl;
    GLuint ttemp=0;
    // Load texture

    cout<<"1"<<endl;
    corona::Image *TextureImage = corona::OpenImage(_filename);

    cout<<"2"<<endl;
    if (TextureImage)
    {
        glGenTextures(1, &ttemp);
        glBindTexture(GL_TEXTURE_2D, ttemp);

        // get the format of image
        GLuint TextureFormat;

        switch (TextureImage->getFormat())
        {
            case corona::PF_B8G8R8A8:
                TextureImage = ConvertImage(TextureImage, corona::PF_R8G8B8A8);
                TextureFormat = GL_RGBA; break;

            case corona::PF_R8G8B8A8:
                TextureFormat = GL_RGBA; break;

            case corona::PF_B8G8R8:
                TextureImage = ConvertImage(TextureImage, corona::PF_R8G8B8);
                TextureFormat = GL_RGB; break;

            case corona::PF_R8G8B8:
                TextureFormat = GL_RGB; break;

            case corona::PF_I8: // for example gif - convert to RGB
                TextureImage = ConvertImage(TextureImage, corona::PF_R8G8B8);
                TextureFormat = GL_RGB; break;
        }

        // Flip image
        FlipImage(TextureImage, corona::CA_X);

        // Generate The Texture
        cout<<"3"<<endl;
        cout<<"-"<<endl;

        cout<<"TextureFormat "              <<TextureFormat<<endl;
        cout<<"TextureImage->getWidth() "   <<TextureImage->getWidth()<<endl;
        cout<<"TextureImage->getHeight() "  <<TextureImage->getHeight()<<endl;
        cout<<"TextureImage->getPixels() "  <<TextureImage->getPixels()<<endl;


        cout<<"-"<<endl;

        glTexImage2D(GL_TEXTURE_2D, 0, TextureFormat, TextureImage->getWidth(), TextureImage->getHeight(), 0, TextureFormat, GL_UNSIGNED_BYTE, TextureImage->getPixels());

        cout<<"4"<<endl;
        //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); // Linear Filtering
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);  // Linear Filtering
        cout<<"5"<<endl;
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
        cout<<"6"<<endl;
        delete TextureImage;
        cout<<"7"<<endl;
    }
    cout<<"8"<<endl;
    return ttemp;
}

我这样使用它:

GLuint texttest;
texttest= LoadTexture("test.png");

0 个答案:

没有答案