Skip to content

Instantly share code, notes, and snippets.

@azaika
Created April 2, 2017 13:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save azaika/0916daf30d811aa6ceda810134f21865 to your computer and use it in GitHub Desktop.
Save azaika/0916daf30d811aa6ceda810134f21865 to your computer and use it in GitHub Desktop.
Siv3DでDxLibのLoadDivGraph関数っぽいやつ
#include <Siv3D.hpp>
// image を大きさ size の画像に分割
Array<Texture> makeDividedTexture(const Image& image, const Size& size) {
// 分割数
const Size numDiv{ image.size.x / size.x, image.size.y / size.y };
Array<Texture> result;
result.reserve(numDiv.x * numDiv.y);
for (auto&& p : step(numDiv))
result.emplace_back(image.clipped(size * p, size));
// RVO で消える
return result;
}
void Main() {
auto&& textures = makeDividedTexture(Image(L"Example/Earth.jpg"), { 256, 256 });
int currentIdx = 0;
while (System::Update()) {
// 左クリックで画像推移
if (Input::MouseL.clicked)
++currentIdx;
if (currentIdx >= textures.size())
currentIdx = 0;
textures[currentIdx].drawAt(Window::Center());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment