开发者

glTexImage2D and problem with loading image

I'm using Corona (to load images) / C++ / Glut.

I have strange problem with loading texture. I know that problem is with glTexImage2D, but it's strange , everything is OK when image is 850 x 249 or 850 x 251 or 850 x 252. But when it's 850 x 250 I get an error after compiling :

Unhandled exception at 0x024bfee9 in [...].exe: 0xC0000005: Access violation reading location 0x0265c001.

I'm using :

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

What's going on ?

edit

glTexImage2D and problem with loading image

edit2 - code

Loading texture code :

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->getWidt开发者_如何转开发h() "   <<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;
}

I use it this way :

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜