예제 #1
0
파일: Texture.cpp 프로젝트: psde/gosu
Gosu::Bitmap Gosu::Texture::toBitmap(unsigned x, unsigned y, unsigned width, unsigned height) const
{
#ifdef GOSU_IS_IPHONE
    throw std::logic_error("Texture::toBitmap not supported on iOS");
#else
    Gosu::Bitmap fullTexture;
    fullTexture.resize(size(), size());
    glBindTexture(GL_TEXTURE_2D, name);
    glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, fullTexture.data());
    Gosu::Bitmap bitmap;
    bitmap.resize(width, height);
    bitmap.insert(fullTexture, -int(x), -int(y));
    
    return bitmap;
#endif
}
예제 #2
0
파일: BitmapIO.cpp 프로젝트: johan--/gosu
void Gosu::loadImageFile(Gosu::Bitmap& bitmap, Reader input)
{
    stbi_io_callbacks callbacks;
    callbacks.read = readCallback;
    callbacks.skip = skipCallback;
    callbacks.eof = eofCallback;
    int x, y, n;
    stbi_uc* bytes = stbi_load_from_callbacks(&callbacks, &input, &x, &y, &n, STBI_rgb_alpha);

    if (bytes == 0) {
        // TODO - stbi_failure_reason is not thread safe. Everything here should be wrapped in a mutex.
        throw std::runtime_error("Cannot load image: " + std::string(stbi_failure_reason()));
    }

    bitmap.resize(x, y);
    std::memcpy(bitmap.data(), bytes, x * y * sizeof(Gosu::Color));

    stbi_image_free(bytes);
}