本文介绍了SDL OpenGL png纹理加载:蓝色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在载入PNG纹理:

I'm loading a PNG texture with:

void Sprite::setTexture(string f) {
    SDL_Surface *image = IMG_Load(f.c_str());
    if (image == NULL) {
        this->texture = -1;
        return;
    }
    SDL_DisplayFormatAlpha(image);
    unsigned object(0);
    glGenTextures(1, &object);
    glBindTexture(GL_TEXTURE_2D, object);
    glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_CLAMP_TO_EDGE);
    glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_CLAMP_TO_EDGE);
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, image->w, image->h, 0, GL_RGBA, GL_UNSIGNED_BYTE, image->pixels);
    SDL_FreeSurface(image);
    this->texture = object;
}

唯一的问题是,而不是像这样

The only problem is that instead of being like this (seen in Photoshop):

它显示如下(在应用程序中看到):

it is shown like this (seen in the app):

出现什么问题?我试过和GL_RGBA打一点点,试图将它反转到GL_BGRA或更改为GL_RGBA8,GL_RGBA16 ...但没有改变(实际上GL_BGRA没有显示任何东西)。我需要alpha通道,即使在这个小的PNG的边界是半径为4px,所以图像角度是透明的。

What's wrong? I have tried playing a little bit with tha GL_RGBA and tried to invert it to GL_BGRA or change it to GL_RGBA8, GL_RGBA16... but nothing changed (actually GL_BGRA didn't show anything). I need the alpha channel, even in this little PNG the borders are radius at 4px and so the image angles are transparent.

我做错了什么?

What am I doing wrong?

推荐答案

它看起来像是你的频道颠倒了。从这里很难看出,如果你的alpha工作正常,但一些纹理 ARGB ,也许你应该试试!

It definitely looks like your channels are inverted. It's hard to see from here if your alpha is working properly, but some textures are ARGB, maybe you should try that!

实际上,为了验证您的数据,您应该检查您的

Actually, just to validate your data, you should check your

SDL_Surface *image

查看 image-> format-> Rmask Gmask Bmask Amask ,这样你就可以确定什么格式有。

And see what's image->format->Rmask Gmask Bmask and Amask, this way you can be sure what format your surface has.

这篇关于SDL OpenGL png纹理加载:蓝色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 13:17