mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-18 16:27:34 +01:00
63 lines
1.4 KiB
Plaintext
63 lines
1.4 KiB
Plaintext
#include "../shared/platform.h"
|
|
#include <SDL.h>
|
|
#include <UIKit/UIKit.h>
|
|
|
|
namespace Ion {
|
|
namespace Simulator {
|
|
namespace Platform {
|
|
|
|
SDL_Texture * loadImage(SDL_Renderer * renderer, const char * identifier) {
|
|
CGImageRef cgImage = [[UIImage imageNamed:[NSString stringWithUTF8String:identifier]] CGImage];
|
|
if (cgImage == NULL) {
|
|
return NULL;
|
|
}
|
|
size_t width = CGImageGetWidth(cgImage);
|
|
size_t height = CGImageGetHeight(cgImage);
|
|
|
|
|
|
size_t bytesPerPixel = 4;
|
|
size_t bytesPerRow = bytesPerPixel * width;
|
|
size_t bitsPerComponent = 8;
|
|
|
|
size_t size = height * width * bytesPerPixel;
|
|
void * bitmapData = malloc(size);
|
|
memset(bitmapData, 0, size);
|
|
|
|
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
|
|
CGContextRef context = CGBitmapContextCreate(
|
|
bitmapData, width, height,
|
|
bitsPerComponent, bytesPerRow, colorSpace,
|
|
kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big
|
|
);
|
|
|
|
CGContextDrawImage(context, CGRectMake(0, 0, width, height), cgImage);
|
|
|
|
CGContextRelease(context);
|
|
CGColorSpaceRelease(colorSpace);
|
|
|
|
SDL_Texture * texture = SDL_CreateTexture(
|
|
renderer,
|
|
SDL_PIXELFORMAT_ABGR8888,
|
|
SDL_TEXTUREACCESS_STATIC,
|
|
width,
|
|
height
|
|
);
|
|
|
|
SDL_UpdateTexture(
|
|
texture,
|
|
NULL,
|
|
bitmapData,
|
|
bytesPerPixel * width
|
|
);
|
|
|
|
SDL_SetTextureBlendMode(texture, SDL_BLENDMODE_BLEND);
|
|
|
|
free(bitmapData);
|
|
|
|
return texture;
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|