diff --git a/SMILEBASIC/graphic.d b/SMILEBASIC/graphic.d index 1e5d3ac..4af9ac5 100644 --- a/SMILEBASIC/graphic.d +++ b/SMILEBASIC/graphic.d @@ -4,6 +4,7 @@ import derelict.sdl2.image; import derelict.opengl3.gl; import derelict.opengl3.gl3; import otya.smilebasic.petitcomputer; +import std.string; enum DrawType { @@ -76,6 +77,74 @@ class Graphic //nnnue paint.buffer = new uint[width * height]; } + GraphicPage createGRPF(string file) + { + SDL_RWops* stream = SDL_RWFromFile(toStringz(file), toStringz("rb")); + auto src = IMG_Load_RW(stream, 0); + SDL_Surface* surface = SDL_CreateRGBSurface(0, src.w, src.h, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000);//0xff000000, 0x00ff0000, 0x0000ff00, 0xFF); + SDL_Rect rect; + rect.x = 0; + rect.y = 0; + rect.w = src.w; + rect.h = src.h; + // SDL_SetSurfaceBlendMode(surface, SDL_BLENDMODE_BLEND); + // SDL_SetSurfaceBlendMode(src, SDL_BLENDMODE_BLEND); + + ubyte sr, sg, sb, sa; + SDL_GetRGBA((cast(uint*)src.pixels)[0], src.format, &sr, &sg, &sb, &sa); + auto color = SDL_MapRGBA(surface.format, sr, sg, sb, sa); + SDL_SetColorKey(src, SDL_TRUE, (cast(uint*)src.pixels)[0]); + //SDL_SetColorKey(surface, SDL_TRUE, color); + int i = SDL_BlitSurface(src, &rect, surface, &rect); + auto srcpixels = (cast(uint*)src.pixels); + auto pixels = (cast(uint*)surface.pixels); + auto aaa = surface.format.Amask; + //surface.format.Amask = 0xFF; + for(int x = 0; x < src.w; x++) + { + for(int y = 0; y < src.h; y++) + { + ubyte r, g, b, a; + SDL_GetRGBA(*pixels, surface.format, &r, &g, &b, &a); + if(r == sr && g == sg && b == sb) + { + r = 0; + g = 0; + b = 0; + a = 0; + *pixels = 0; + *pixels = SDL_MapRGBA(surface.format, r, g, b, a); + } + pixels++; + } + } + SDL_RWclose(stream); + SDL_FreeSurface(src); + return new GraphicPage(surface); + } + GraphicPage createEmptyPage() + { + auto surface = SDL_CreateRGBSurface(0, width, height, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000); + auto pixels = (cast(uint*)surface.pixels); + for(int x = 0; x < surface.w; x++) + { + for(int y = 0; y < surface.h; y++) + { + ubyte r, g, b, a; + SDL_GetRGBA(*pixels, surface.format, &r, &g, &b, &a); + { + r = 0; + g = 0; + b = 0; + a = 0; + *pixels = 0; + *pixels = SDL_MapRGBA(surface.format, r, g, b, a); + } + pixels++; + } + } + return new GraphicPage(surface); + } bool[2] visibles = [true, true]; private int[2] showPage = [0, 1]; diff --git a/SMILEBASIC/petitcomputer.d b/SMILEBASIC/petitcomputer.d index 0d0293a..238373a 100644 --- a/SMILEBASIC/petitcomputer.d +++ b/SMILEBASIC/petitcomputer.d @@ -120,7 +120,7 @@ class GraphicPage glBindTexture(GL_TEXTURE_2D, glTexture); glGenRenderbuffersEXT(1, &render); glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, render); - glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT24, 512, 512); + glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT24, surface.w, surface.h); glGenFramebuffersEXT(1, &buffer); glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, buffer); glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, glTexture, 0); @@ -199,74 +199,6 @@ class PetitComputer return SDL_Color(r >> 5 << 5, g >> 5 << 5, b >> 5 << 5, a == 255 ? 255 : 0); } Button button; - GraphicPage createGRPF(string file) - { - SDL_RWops* stream = SDL_RWFromFile(toStringz(file), toStringz("rb")); - auto src = IMG_Load_RW(stream, 0); - SDL_Surface* surface = SDL_CreateRGBSurface(0, src.w, src.h, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000);//0xff000000, 0x00ff0000, 0x0000ff00, 0xFF); - SDL_Rect rect; - rect.x = 0; - rect.y = 0; - rect.w = src.w; - rect.h = src.h; - // SDL_SetSurfaceBlendMode(surface, SDL_BLENDMODE_BLEND); - // SDL_SetSurfaceBlendMode(src, SDL_BLENDMODE_BLEND); - - ubyte sr, sg, sb, sa; - SDL_GetRGBA((cast(uint*)src.pixels)[0], src.format, &sr, &sg, &sb, &sa); - auto color = SDL_MapRGBA(surface.format, sr, sg, sb, sa); - SDL_SetColorKey(src, SDL_TRUE, (cast(uint*)src.pixels)[0]); - //SDL_SetColorKey(surface, SDL_TRUE, color); - int i = SDL_BlitSurface(src, &rect, surface, &rect); - auto srcpixels = (cast(uint*)src.pixels); - auto pixels = (cast(uint*)surface.pixels); - auto aaa = surface.format.Amask; - //surface.format.Amask = 0xFF; - for(int x = 0; x < src.w; x++) - { - for(int y = 0; y < src.h; y++) - { - ubyte r, g, b, a; - SDL_GetRGBA(*pixels, surface.format, &r, &g, &b, &a); - if(r == sr && g == sg && b == sb) - { - r = 0; - g = 0; - b = 0; - a = 0; - *pixels = 0; - *pixels = SDL_MapRGBA(surface.format, r, g, b, a); - } - pixels++; - } - } - SDL_RWclose(stream); - SDL_FreeSurface(src); - return new GraphicPage(surface); - } - GraphicPage createEmptyPage() - { - auto surface = SDL_CreateRGBSurface(0, 512, 512, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000); - auto pixels = (cast(uint*)surface.pixels); - for(int x = 0; x < surface.w; x++) - { - for(int y = 0; y < surface.h; y++) - { - ubyte r, g, b, a; - SDL_GetRGBA(*pixels, surface.format, &r, &g, &b, &a); - { - r = 0; - g = 0; - b = 0; - a = 0; - *pixels = 0; - *pixels = SDL_MapRGBA(surface.format, r, g, b, a); - } - pixels++; - } - } - return new GraphicPage(surface); - } struct Point { int x, y; @@ -547,16 +479,16 @@ class PetitComputer { DerelictSDL2.load(); DerelictSDL2Image.load(); - console.GRPF = createGRPF(fontFile); + console.GRPF = graphic.createGRPF(fontFile); graphic.GRP = new GraphicPage[6]; for(int i = 0; i < 4; i++) { - graphic.GRP[i] = createEmptyPage(); + graphic.GRP[i] = graphic.createEmptyPage(); } sprite.sppage = 4; - graphic.GRP[4] = createGRPF(spriteFile); + graphic.GRP[4] = graphic.createGRPF(spriteFile); bgpage = 5; - graphic.GRP[5] = createGRPF(BGFile); + graphic.GRP[5] = graphic.createGRPF(BGFile); SDL_Init(SDL_INIT_VIDEO); DerelictGL.load();