Using QImage with OpenGL

前端 未结 3 1506
一整个雨季
一整个雨季 2020-12-09 21:19

I\'ve very recently picked up Qt and am using it with OpenGL The thing though is that when moving my SDL code to Qt and changing the texture code to use QImage it stops work

3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-09 21:33

    This is my solution for conversion from Qt to GL This also can work in reverse with little changes; Cheers -- Daimon

    void Image::Convert32bitARGBtoRGBA()
    {
        if(!isQtImage()) return;
        QImage& q = *(m_data->image);
        U32 count=0, max=(U32)(q.height()*q.width());
        U32* p = (U32*)(q.bits());
        U32 n;
        while( count>24) & 0x000000ff);
                    // p[count] = RGBA
            count++;
        }
    }
    
    void Image::Convert32bitRGBAtoARGB()
    {
        if(!isQtImage()) return;
        QImage& q = *(m_data->image);
        U32 count=0, max=(U32)(q.height()*q.width());
        U32* p = (U32*)(q.bits());
        U32 n;
        while( count>8)  & 0x000000ff) |
                    ((n>>8)  & 0x0000ff00) |
                    ((n>>8)  & 0x00ff0000) |
                    ((n<<24) & 0xff000000);
                    // p[count] = ARGB
            count++;
        }
    }
    

提交回复
热议问题