Extract graphic class
This commit is contained in:
@@ -4,6 +4,7 @@ import derelict.sdl2.image;
|
|||||||
import derelict.opengl3.gl;
|
import derelict.opengl3.gl;
|
||||||
import derelict.opengl3.gl3;
|
import derelict.opengl3.gl3;
|
||||||
import otya.smilebasic.petitcomputer;
|
import otya.smilebasic.petitcomputer;
|
||||||
|
import std.string;
|
||||||
|
|
||||||
enum DrawType
|
enum DrawType
|
||||||
{
|
{
|
||||||
@@ -76,6 +77,74 @@ class Graphic
|
|||||||
//nnnue
|
//nnnue
|
||||||
paint.buffer = new uint[width * height];
|
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];
|
bool[2] visibles = [true, true];
|
||||||
private int[2] showPage = [0, 1];
|
private int[2] showPage = [0, 1];
|
||||||
|
|||||||
@@ -120,7 +120,7 @@ class GraphicPage
|
|||||||
glBindTexture(GL_TEXTURE_2D, glTexture);
|
glBindTexture(GL_TEXTURE_2D, glTexture);
|
||||||
glGenRenderbuffersEXT(1, &render);
|
glGenRenderbuffersEXT(1, &render);
|
||||||
glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, 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);
|
glGenFramebuffersEXT(1, &buffer);
|
||||||
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, buffer);
|
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, buffer);
|
||||||
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, glTexture, 0);
|
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);
|
return SDL_Color(r >> 5 << 5, g >> 5 << 5, b >> 5 << 5, a == 255 ? 255 : 0);
|
||||||
}
|
}
|
||||||
Button button;
|
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
|
struct Point
|
||||||
{
|
{
|
||||||
int x, y;
|
int x, y;
|
||||||
@@ -547,16 +479,16 @@ class PetitComputer
|
|||||||
{
|
{
|
||||||
DerelictSDL2.load();
|
DerelictSDL2.load();
|
||||||
DerelictSDL2Image.load();
|
DerelictSDL2Image.load();
|
||||||
console.GRPF = createGRPF(fontFile);
|
console.GRPF = graphic.createGRPF(fontFile);
|
||||||
graphic.GRP = new GraphicPage[6];
|
graphic.GRP = new GraphicPage[6];
|
||||||
for(int i = 0; i < 4; i++)
|
for(int i = 0; i < 4; i++)
|
||||||
{
|
{
|
||||||
graphic.GRP[i] = createEmptyPage();
|
graphic.GRP[i] = graphic.createEmptyPage();
|
||||||
}
|
}
|
||||||
sprite.sppage = 4;
|
sprite.sppage = 4;
|
||||||
graphic.GRP[4] = createGRPF(spriteFile);
|
graphic.GRP[4] = graphic.createGRPF(spriteFile);
|
||||||
bgpage = 5;
|
bgpage = 5;
|
||||||
graphic.GRP[5] = createGRPF(BGFile);
|
graphic.GRP[5] = graphic.createGRPF(BGFile);
|
||||||
SDL_Init(SDL_INIT_VIDEO);
|
SDL_Init(SDL_INIT_VIDEO);
|
||||||
|
|
||||||
DerelictGL.load();
|
DerelictGL.load();
|
||||||
|
|||||||
Reference in New Issue
Block a user