[ion/sdl] Add a Windows version

This commit is contained in:
Romain Goyet
2019-03-07 23:01:45 +01:00
parent 2ac9f3efbd
commit acb6c65e35
6 changed files with 139 additions and 0 deletions

View File

@@ -0,0 +1,6 @@
src += $(addprefix ion/src/sdl/windows/, \
images.cpp \
resources.rc \
)
LDFLAGS += -lgdiplus

View File

@@ -0,0 +1,92 @@
#include <SDL.h>
#include <windows.h>
#include <olectl.h>
#include <assert.h>
#include <gdiplus.h>
#include <stdio.h>
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;
}

View File

@@ -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

View File

@@ -0,0 +1,2 @@
TOOLCHAIN ?= windows
EXE = exe

View File

@@ -0,0 +1,4 @@
$(eval $(call rule_for, \
WINDRES, %.o, %.rc, \
$$(WINDRES) $$< -O coff -o $$@ \
))

View File

@@ -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