diff --git a/ion/src/sdl/windows/Makefile b/ion/src/sdl/windows/Makefile new file mode 100644 index 000000000..e683a5bb8 --- /dev/null +++ b/ion/src/sdl/windows/Makefile @@ -0,0 +1,6 @@ +src += $(addprefix ion/src/sdl/windows/, \ + images.cpp \ + resources.rc \ +) + +LDFLAGS += -lgdiplus diff --git a/ion/src/sdl/windows/images.cpp b/ion/src/sdl/windows/images.cpp new file mode 100644 index 000000000..6316d722f --- /dev/null +++ b/ion/src/sdl/windows/images.cpp @@ -0,0 +1,92 @@ +#include +#include +#include +#include +#include +#include + +HRESULT CreateStreamOnResource(const char * name, LPSTREAM * stream) { + assert(name != nullptr); + assert(stream != nullptr); + HINSTANCE hInstance = GetModuleHandle(0); + *stream = NULL; + HRSRC hC = FindResource(hInstance, name, RT_RCDATA); + if (!hC) { + SDL_Log("Could not find resource %s", name); + return E_INVALIDARG; + } + // This is not really a HGLOBAL http://msdn.microsoft.com/en-us/library/windows/desktop/ms648046(v=vs.85).aspx + HGLOBAL hG = LoadResource(hInstance, hC); + if (!hG) { + SDL_Log("Could not load resource %s", name); + return E_INVALIDARG; + } + void* bytes = LockResource(hG); + ULONG size = SizeofResource(hInstance, hC); + // Create a new empty stream. + HRESULT hr = CreateStreamOnHGlobal(NULL, TRUE, stream); + if (SUCCEEDED(hr)) { + ULONG written; + // Copy the resource into it. + hr = (*stream)->Write(bytes, size, &written); + } + return hr; +} + +extern "C" SDL_Texture * loadImage(SDL_Renderer * renderer, const char * identifier) { +//SDL_LogCritical(SDL_LOG_CATEGORY_APPLICATION, "Loading image"); + SDL_Log("chabite"); + + Gdiplus::GdiplusStartupInput gdiplusStartupInput; + ULONG_PTR gdiplusToken; + Gdiplus::GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, nullptr); + + LPSTREAM stream; + const char * resname = MAKEINTRESOURCE(300); + CreateStreamOnResource(resname, &stream); +#if 0 + IPicture * picture = nullptr; + OleLoadPicture( + stream, + 0, + false, + IID_IPicture, + (void**)&picture + ); +#endif + + Gdiplus::Bitmap * image = Gdiplus::Bitmap::FromStream(stream); + + SDL_Log("Gdiplus::Bitmap is %p", image); + + int w = (int)image->GetWidth(); + int h = (int)image->GetHeight(); + Gdiplus::Rect rc(0, 0, w, h); + + SDL_Log("Gdiplus::Bitmap is %dx%d", w,h); + + Gdiplus::BitmapData * bitmapData = new Gdiplus::BitmapData; + image->LockBits(&rc, Gdiplus::ImageLockModeRead, PixelFormat32bppARGB, bitmapData); + + SDL_Texture * texture = SDL_CreateTexture( + renderer, + SDL_PIXELFORMAT_ARGB8888, + SDL_TEXTUREACCESS_STATIC, + w, + h + ); + + SDL_UpdateTexture( + texture, + NULL, + bitmapData->Scan0, + 4 * w + ); + + image->UnlockBits(bitmapData); + delete bitmapData; + delete image; + Gdiplus::GdiplusShutdown(gdiplusToken); + + return texture; +} diff --git a/ion/src/sdl/windows/resources.rc b/ion/src/sdl/windows/resources.rc new file mode 100644 index 000000000..024eb2d13 --- /dev/null +++ b/ion/src/sdl/windows/resources.rc @@ -0,0 +1,25 @@ +300 RCDATA "../assets/background.jpg" + +1 VERSIONINFO +FILEVERSION 1,0,0,0 +PRODUCTVERSION 1,0,0,0 +BEGIN + BLOCK "StringFileInfo" + BEGIN + BLOCK "040904E4" + BEGIN + VALUE "CompanyName", "NumWorks" + VALUE "FileDescription", "Graphing calculator simulator" + VALUE "FileVersion", "1.0" + VALUE "InternalName", "epsilon" + VALUE "LegalCopyright", "NumWorks" + VALUE "OriginalFilename", "epsilon.exe" + VALUE "ProductName", "Epsilon" + VALUE "ProductVersion", "1.0" + END + END + BLOCK "VarFileInfo" + BEGIN + VALUE "Translation", 0x409, 1252 + END +END diff --git a/scripts/platform.sdl.windows.mak b/scripts/platform.sdl.windows.mak new file mode 100644 index 000000000..40320cd9d --- /dev/null +++ b/scripts/platform.sdl.windows.mak @@ -0,0 +1,2 @@ +TOOLCHAIN ?= windows +EXE = exe diff --git a/scripts/targets.sdl.windows.mak b/scripts/targets.sdl.windows.mak new file mode 100644 index 000000000..51f8c7518 --- /dev/null +++ b/scripts/targets.sdl.windows.mak @@ -0,0 +1,4 @@ +$(eval $(call rule_for, \ + WINDRES, %.o, %.rc, \ + $$(WINDRES) $$< -O coff -o $$@ \ +)) diff --git a/scripts/toolchain.windows.mak b/scripts/toolchain.windows.mak new file mode 100644 index 000000000..3973705de --- /dev/null +++ b/scripts/toolchain.windows.mak @@ -0,0 +1,10 @@ +CC = x86_64-w64-mingw32-gcc +CXX = x86_64-w64-mingw32-g++ +LD = x86_64-w64-mingw32-g++ +EXE = exe + +SFLAGS += -D_USE_MATH_DEFINES +#LDFLAGS += -static -mwindows +LDFLAGS += -static + +WINDRES = x86_64-w64-mingw32-windres