Example #1
0
void GLSprite::Init(CSprite* sprite)
{
    fail_ = true;

    // Hack for mapeditor
    bool force_no_fail = false;
    if (GetGLWidget() == nullptr)
    {
        force_no_fail = true;
    }

    GLint maxTexSize;
    glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxTexSize);
    if ((sprite->w > maxTexSize || sprite->h > maxTexSize) && !force_no_fail)
    {
        SYSTEM_STREAM << "OpenGL texture load fail: texture too big, maximal allowed size is " << maxTexSize << std::endl;
        return;
    }

    sdl_sprite_ = sprite;
    w_ = sprite->w;
    h_ = sprite->h;

    gl_sprites_.resize(sprite->numFrameH);
    for (int i = 0; i < sprite->numFrameH; ++i)
        gl_sprites_[i].resize(sprite->numFrameW);

    GLuint glFormat_text = GL_RGBA;
    GLuint glFormat_surf = GL_BGRA;

    for (int i = 0; i < sprite->numFrameH; ++i)
    {
        glGenTextures(gl_sprites_[i].size(), &(gl_sprites_[i][0]));
        for (int j = 0; j < sprite->numFrameW; ++j)
        {
            //SYSTEM_STREAM << i << " " << j << std::endl;

            glBindTexture(GL_TEXTURE_2D, gl_sprites_[i][j]);

            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);

            glTexImage2D(GL_TEXTURE_2D, 0, glFormat_text, sprite->w, sprite->h, 0, glFormat_surf, GL_UNSIGNED_BYTE, 
               sprite->frames[j * sprite->numFrameH + i]->pixels);

            //SYSTEM_STREAM << gl_sprites_[i][j] << std::endl;

            if (glGetError())
                SYSTEM_STREAM << glGetError() << std::endl; 
            if (sprite->frames[j * sprite->numFrameH + i] == nullptr || sprite->frames[j * sprite->numFrameH + i]->pixels == nullptr)
                SYSTEM_STREAM << "nullptr pixels" << std::endl;
            //SYSTEM_STREAM << sprite->frames[j * sprite->numFrameH + i] << std::endl;
        }
    }

    fail_ = false;
}
Example #2
0
void Screen::Swap()
{
    GetGLWidget()->swapBuffers();
}
Example #3
0
void Screen::ResetScreen(int x, int y, int bpp, Uint32 flags)
{
    GetGLWidget()->resize(x, y);
}
Example #4
0
void Screen::PerformSizeUpdate()
{
    glViewport(0, 0, GetGLWidget()->width(), GetGLWidget()->height());
}
Example #5
0
int Screen::h()
{
    return GetGLWidget()->height();
}
Example #6
0
int Screen::w()
{
    return GetGLWidget()->width();
}
Example #7
0
void Screen::ResetScreen(int x, int y)
{
    GetGLWidget()->resize(x, y);
}