Compare commits
3 Commits
9eae2aa785
...
22b62dd46b
| Author | SHA1 | Date | |
|---|---|---|---|
| 22b62dd46b | |||
| aaa847b4be | |||
| 618e032284 |
3
.gitignore
vendored
3
.gitignore
vendored
@@ -1,3 +1,4 @@
|
||||
.vscode/*
|
||||
dilemmaker
|
||||
build/*
|
||||
build/*
|
||||
*.exe
|
||||
|
||||
@@ -7,6 +7,7 @@ namespace draw
|
||||
{
|
||||
SDL_Window *sdl_window {nullptr}; // La finestra de SDL
|
||||
SDL_Renderer *sdl_renderer {nullptr}; // El renderer de SDL
|
||||
SDL_Texture *sdl_texture {nullptr}; // La textura a la que ho renderitze tot
|
||||
SDL_Texture *sdl_source {nullptr};
|
||||
|
||||
void init(const char *titol, const uint16_t width, const uint16_t height)
|
||||
@@ -22,9 +23,17 @@ namespace draw
|
||||
SDL_LogError(SDL_LOG_CATEGORY_VIDEO, "ERROR (draw::init): Failed to initialize renderer!\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
sdl_texture = SDL_CreateTexture(sdl_renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_TARGET, width, height);
|
||||
//SDL_SetRenderDrawBlendMode(sdl_renderer, SDL_BLENDMODE_BLEND);
|
||||
}
|
||||
|
||||
void resizeSystemTexture(const uint16_t width, const uint16_t height)
|
||||
{
|
||||
SDL_DestroyTexture(sdl_texture);
|
||||
sdl_texture = SDL_CreateTexture(sdl_renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_TARGET, width, height);
|
||||
}
|
||||
|
||||
void quit()
|
||||
{
|
||||
SDL_DestroyRenderer(sdl_renderer);
|
||||
@@ -58,7 +67,14 @@ namespace draw
|
||||
int sdl_pitch;
|
||||
|
||||
SDL_LockTexture(surf, NULL, (void **)&sdl_pixels, &sdl_pitch);
|
||||
for (uint32_t i = 0; i < w*h; ++i) sdl_pixels[i] = transparent==pixels[i] ? 0x00000000 : pal[pixels[i]] | 0xff000000;
|
||||
int i=0;
|
||||
for (int y=0; y<h; ++y) {
|
||||
for (int x=0; x<w; ++x) {
|
||||
sdl_pixels[x+y*(sdl_pitch/4)] = transparent==pixels[i] ? 0x00000000 : pal[pixels[i]] | 0xff000000;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
//for (uint32_t i = 0; i < w*h; ++i) sdl_pixels[i] = transparent==pixels[i] ? 0x00000000 : pal[pixels[i]] | 0xff000000;
|
||||
SDL_UnlockTexture(surf);
|
||||
|
||||
free(pal);
|
||||
@@ -75,7 +91,7 @@ namespace draw
|
||||
|
||||
void setDestination(SDL_Texture *surf)
|
||||
{
|
||||
SDL_SetRenderTarget(sdl_renderer, surf);
|
||||
SDL_SetRenderTarget(sdl_renderer, surf ? surf : sdl_texture);
|
||||
}
|
||||
|
||||
void setSource(SDL_Texture *surf)
|
||||
@@ -178,7 +194,10 @@ namespace draw
|
||||
// Refresca la pantalla
|
||||
void render()
|
||||
{
|
||||
SDL_SetRenderTarget(sdl_renderer, nullptr);
|
||||
SDL_RenderTexture(sdl_renderer, sdl_texture, nullptr, nullptr);
|
||||
SDL_RenderPresent(sdl_renderer);
|
||||
SDL_SetRenderTarget(sdl_renderer, sdl_texture);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ namespace draw
|
||||
enum flip { none, horizontal, vertical, both };
|
||||
|
||||
void init(const char *titol, const uint16_t width, const uint16_t height);
|
||||
void resizeSystemTexture(const uint16_t width, const uint16_t height);
|
||||
void quit();
|
||||
|
||||
SDL_Texture *createSurface(const uint16_t w, const uint16_t h);
|
||||
|
||||
@@ -24,13 +24,11 @@ namespace font
|
||||
bool eof = false;
|
||||
while (true) {
|
||||
if (*p=='#') while (*p!=0 && *p!=10) p++;
|
||||
if (*p==0) break;
|
||||
p++;
|
||||
if (*p==0) break; while (*p==10 || *p==13) p++;
|
||||
spaces[pos++] = (*p)-48;
|
||||
if (pos==127) break;
|
||||
p++;
|
||||
if (*p==0) break;
|
||||
p++;
|
||||
if (*p==0) break; while (*p==10 || *p==13) p++;
|
||||
}
|
||||
free(buffer);
|
||||
|
||||
|
||||
@@ -114,6 +114,10 @@ int main(int argc, char *argv[])
|
||||
{
|
||||
game::windowHasFocus = false;
|
||||
}
|
||||
if (e.type == SDL_EVENT_WINDOW_RESIZED)
|
||||
{
|
||||
draw::resizeSystemTexture(e.window.data1, e.window.data2);
|
||||
}
|
||||
}
|
||||
|
||||
if (SDL_GetTicks()-current_ticks >= game::ticks_per_frame)
|
||||
|
||||
Reference in New Issue
Block a user