summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 0ece348)
raw | patch | inline | side by side (parent: 0ece348)
author | DeaDDooMER <deaddoomer@deadsoftware.ru> | |
Wed, 1 Apr 2020 05:55:23 +0000 (09:55 +0400) | ||
committer | DeaDDooMER <deaddoomer@deadsoftware.ru> | |
Wed, 1 Apr 2020 05:55:23 +0000 (09:55 +0400) |
src/gl/render.c | patch | blob | history | |
src/render.h | patch | blob | history | |
src/sdl2/main.c | patch | blob | history | |
src/soft/render.c | patch | blob | history | |
src/soft/vga.c | patch | blob | history | |
src/soft/vga.h | patch | blob | history |
diff --git a/src/gl/render.c b/src/gl/render.c
index 41670016fa3872969e352ea937bf684c5ba987cb..73ce92a4390892e76009478be58d04f916003c08 100644 (file)
--- a/src/gl/render.c
+++ b/src/gl/render.c
}
}
-void R_init (void) {
- int res = 0;
+void R_set_videomode (int w, int h, int fullscreen) {
+ assert(w > 0);
+ assert(h > 0);
+ int was = Y_videomode_setted();
int flags = SYSTEM_USE_OPENGL;
if (fullscreen) {
flags |= SYSTEM_USE_FULLSCREEN;
}
- logo("R_init: intialize opengl render\n");
- int was = Y_videomode_setted();
- if (SCRW <= 0 || SCRH <= 0) {
- ERR_failinit("Invalid screen size %ix%i\n", SCRW, SCRH);
- }
- if (was == 0) {
- R_init_playpal(); // only onece
- }
- res = Y_set_videomode(SCRW, SCRH, flags);
+ int res = Y_set_videomode(w, h, flags);
if (res == 0) {
- ERR_failinit("Unable to set video mode\n");
+ if (was == 0) {
+ ERR_failinit("Unable to set video mode\n");
+ }
+ } else {
+ SCRW = w;
+ SCRH = h;
}
+}
+
+void R_toggle_fullscreen (void) {
+ Y_set_fullscreen(!Y_get_fullscreen());
+ fullscreen = Y_get_fullscreen();
+}
+
+void R_init (void) {
+ logo("R_init: intialize opengl render\n");
+ R_init_playpal();
+ R_set_videomode(SCRW, SCRH, fullscreen);
root = R_cache_new();
assert(root);
R_alloc();
void R_done (void) {
R_cache_free(root, 1);
Y_unset_videomode();
+ root = NULL;
}
void R_setgamma (int g) {
return gamma;
}
-void R_toggle_fullscreen (void) {
- Y_set_fullscreen(!Y_get_fullscreen());
- fullscreen = Y_get_fullscreen();
- R_alloc();
-}
-
void R_get_name (int n, char s[8]) {
assert(n >= 0 && n < 256);
if (walp[n].res == -1) {
diff --git a/src/render.h b/src/render.h
index 71d4365f659451e0b2ae2d329fdd72548e9c6eec..49040173a7521b8b04ec8e70f93966b7a4b487b2 100644 (file)
--- a/src/render.h
+++ b/src/render.h
void R_setgamma (int g);
int R_getgamma (void);
void R_toggle_fullscreen (void);
+void R_set_videomode (int w, int h, int fullscreen);
void R_get_name (int n, char s[8]);
int R_get_special_id (int n);
diff --git a/src/sdl2/main.c b/src/sdl2/main.c
index 42fda3e41c0910050f60518392a46825b3193f0a..dd5b8d43b2d16947a79291f66e1dc57d9fa9c38f 100644 (file)
--- a/src/sdl2/main.c
+++ b/src/sdl2/main.c
static int Y_set_videomode_opengl (int w, int h, int fullscreen) {
assert(w > 0);
assert(h > 0);
- Uint32 flags = SDL_WINDOW_HIDDEN | SDL_WINDOW_OPENGL;
+ Uint32 flags = SDL_WINDOW_RESIZABLE | SDL_WINDOW_OPENGL;
flags |= fullscreen ? SDL_WINDOW_FULLSCREEN : 0;
// TODO set context version and type
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 1);
window = win;
context = ctx;
SDL_GL_MakeCurrent(window, context);
- SDL_ShowWindow(window);
} else {
SDL_DestroyWindow(win);
win = NULL;
assert(h > 0);
int x = SDL_WINDOWPOS_CENTERED;
int y = SDL_WINDOWPOS_CENTERED;
- Uint32 flags = SDL_WINDOW_HIDDEN | SDL_WINDOW_OPENGL;
+ Uint32 flags = SDL_WINDOW_RESIZABLE;
flags |= fullscreen ? SDL_WINDOW_FULLSCREEN : 0;
SDL_Window *win = SDL_CreateWindow(TITLE_STR, x, y, w, h, flags);
if (win != NULL) {
Y_unset_videomode();
window = win;
surf = s;
- SDL_ShowWindow(window);
} else {
SDL_DestroyWindow(win);
win = NULL;
return win != NULL;
}
+static int Y_resize_window (int w, int h, int fullscreen) {
+ assert(w > 0);
+ assert(h > 0);
+ assert(window != NULL);
+ if (surf != NULL) {
+ SDL_Surface *s = SDL_CreateRGBSurface(0, w, h, 8, 0, 0, 0, 0);
+ if (s != NULL) {
+ SDL_SetPaletteColors(s->format->palette, surf->format->palette->colors, 0, surf->format->palette->ncolors);
+ SDL_FreeSurface(surf);
+ surf = s;
+ }
+ }
+ SDL_SetWindowSize(window, w, h);
+ Y_set_fullscreen(fullscreen);
+ return 1;
+}
+
int Y_set_videomode (int w, int h, int flags) {
assert(w > 0);
assert(h > 0);
int fullscreen = (flags & SYSTEM_USE_FULLSCREEN) != 0;
if (flags & SYSTEM_USE_OPENGL) {
- return Y_set_videomode_opengl(w, h, fullscreen);
+ if (window != NULL && context != NULL) {
+ return Y_resize_window(w, h, fullscreen);
+ } else {
+ return Y_set_videomode_opengl(w, h, fullscreen);
+ }
} else {
- return Y_set_videomode_software(w, h, fullscreen);
+ if (window != NULL && surf != NULL) {
+ return Y_resize_window(w, h, fullscreen);
+ } else {
+ return Y_set_videomode_software(w, h, fullscreen);
+ }
}
}
}
}
+static void window_event_handler (SDL_WindowEvent *ev) {
+ switch (ev->event) {
+ case SDL_WINDOWEVENT_RESIZED:
+ if (window != NULL && ev->windowID == SDL_GetWindowID(window)) {
+ R_set_videomode(ev->data1, ev->data2, Y_get_fullscreen());
+ }
+ break;
+ case SDL_WINDOWEVENT_CLOSE:
+ ERR_quit();
+ break;
+ }
+}
+
static void poll_events (void (*h)(int key, int down)) {
int key;
SDL_Event ev;
case SDL_QUIT:
ERR_quit();
break;
+ case SDL_WINDOWEVENT:
+ window_event_handler(&ev.window);
+ break;
case SDL_KEYDOWN:
case SDL_KEYUP:
key = sdl_to_key(ev.key.keysym.scancode);
diff --git a/src/soft/render.c b/src/soft/render.c
index 224d926f679b30e7ea15c2b331914f6a49f3cff2..aaaea63749ccb2f9d8c947794fa4dd212601cb53 100644 (file)
--- a/src/soft/render.c
+++ b/src/soft/render.c
#include "game.h"
#include "sound.h"
#include "music.h"
+#include "system.h"
// game
static vgaimg *scrnh[3]; // TITLEPIC INTERPIC ENDPIC
return gammaa;
}
+void R_set_videomode (int w, int h, int fullscreen) {
+ assert(w > 0);
+ assert(h > 0);
+ int was = Y_videomode_setted();
+ int res = Y_set_videomode(w, h, fullscreen ? SYSTEM_USE_FULLSCREEN : 0);
+ if (res == 0) {
+ if (was == 0) {
+ ERR_failinit("Unable to set video mode");
+ }
+ } else {
+ SCRW = w;
+ SCRH = h;
+ Y_get_buffer(&buffer, &buf_w, &buf_h, &pitch);
+ }
+}
+
void R_toggle_fullscreen (void) {
- fullscreen = !fullscreen;
- V_toggle();
+ Y_set_fullscreen(!Y_get_fullscreen());
+ fullscreen = Y_get_fullscreen();
}
void R_init () {
int i;
+ logo("R_init: initialize software render\n");
F_loadres(F_getresid("PLAYPAL"), main_pal, 0, 768);
for (i = 0; i < 256; ++i) {
bright[i] = ((int) main_pal[i][0] + main_pal[i][1] + main_pal[i][2]) * 8 / (63 * 3);
}
F_loadres(F_getresid("MIXMAP"), mixmap, 0, 0x10000);
F_loadres(F_getresid("COLORMAP"), clrmap, 0, 256*12);
- logo("V_init: настройка видео\n");
- if (V_init() != 0) {
- ERR_failinit("Не могу установить видеорежим VGA");
- }
+ R_set_videomode(SCRW, SCRH, fullscreen);
R_setgamma(gammaa);
V_setrect(0, SCRW, 0, SCRH);
-// V_setscr(scrbuf);
V_clr(0, SCRW, 0, SCRH, 0);
R_alloc();
}
void R_done (void) {
- V_done();
+ buffer = NULL;
+ buf_w = 0;
+ buf_h = 0;
+ pitch = 0;
+ Y_unset_videomode();
}
diff --git a/src/soft/vga.c b/src/soft/vga.c
index ef97ca7afa9103bae141e77173ba343e3c84290d..d9c77e1e8dea01a24339a990bd5f0da209f503bc 100644 (file)
--- a/src/soft/vga.c
+++ b/src/soft/vga.c
byte mixmap[256][256];
byte clrmap[256*12];
-static byte *buffer;
-static int buf_w, buf_h, pitch;
+byte *buffer;
+int buf_w, buf_h, pitch;
static int offx, offy;
static int cx1, cx2, cy1, cy2;
static byte flametab[16] = {
return V_getvgaimg(F_getresid(name));
}
-short V_init (void) {
- int flags = fullscreen ? SYSTEM_USE_FULLSCREEN : 0;
- int res = Y_set_videomode(SCRW, SCRH, flags);
- if (res == 0) {
- ERR_failinit("Unable to set video mode");
- }
- Y_get_buffer(&buffer, &buf_w, &buf_h, &pitch);
- return 0;
-}
-
-void V_done (void) {
- buffer = NULL;
- buf_w = 0;
- buf_h = 0;
- pitch = 0;
- Y_unset_videomode();
-}
-
static void draw_rect (int x, int y, int w, int h, int c) {
int i;
int x0 = max(x, cx1);
for (cy=y; cy<y+h; cy++)
mappixel(cx,cy,cmap);
}
-
-void V_toggle (void) {
- fullscreen = Y_set_fullscreen(!Y_get_fullscreen());
-}
diff --git a/src/soft/vga.h b/src/soft/vga.h
index ecc633446b0660bf48a3613823100cea22b0e533..dc91d2b90d343fae503973b9e89c58660ec62719 100644 (file)
--- a/src/soft/vga.h
+++ b/src/soft/vga.h
extern int SCRH;
extern char fullscreen;
+extern byte *buffer;
+extern int buf_w, buf_h, pitch;
+
extern byte bright[256];
extern byte mixmap[256][256];
extern byte clrmap[256*12];
vgaimg *V_getvgaimg (int id);
vgaimg *V_loadvgaimg (char *name);
-// переключение в режим VGA 320x200,256 цветов
-// возвращает 0, если все о'кей
-short V_init (void);
-
-// переключение в текстовый режим
-void V_done (void);
-
// ждать обратного хода луча развертки
void V_wait (void);
void V_remap_rect (int x, int y, int w, int h, byte *cmap);
-void V_toggle (void);
void V_rotspr (int x, int y, vgaimg* i, int d);
void V_center (int f);
void V_offset (int ox, int oy);