#include "sf_frotz.h"
-static SDL_Rect blitrect = {0,0,0,0};
static char banner[256];
static int isfullscreen;
static ulong *sbuffer = NULL;
static int sbpitch; // in longs
static int dirty = 0;
-static int bitsperpixel = 32;
-static int RBswap = 0;
static int ewidth, eheight;
-static SDL_Surface *screen, *off = NULL;
-static int mustlockscreen = 0;
+static SDL_Renderer *renderer = NULL;
+static SDL_Texture *texture = NULL;
int m_timerinterval = 100;
static void sf_quitconf();
}
static void myGrefresh(){
- if (off) {
- if (mustlockscreen) SDL_LockSurface(screen);
- SDL_BlitSurface(off,NULL,screen,&blitrect);
- if (mustlockscreen) SDL_UnlockSurface(screen);
- }
- SDL_UpdateRect(screen,0,0,0,0);
+ SDL_UpdateTexture(texture, NULL, sbuffer, sbpitch * sizeof(ulong));
+ SDL_RenderClear(renderer);
+ SDL_RenderCopy(renderer, texture, NULL, NULL);
+ SDL_RenderPresent(renderer);
}
void sf_wpixel( int x, int y, ulong c)
extern char stripped_story_name[];
void sf_initvideo( int W, int H, int full)
- {
- int desired_bpp, needoff, reqW, reqH;
- Uint32 video_flags;
- SDL_PixelFormat *format;
- Uint32 initflags = SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE | SDL_INIT_TIMER |
- SDL_INIT_AUDIO;
+{
+ int reqW, reqH;
+ Uint32 video_flags, pixfmt;
+ SDL_Window *win;
+ Uint32 initflags = SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE | SDL_INIT_TIMER
+ | SDL_INIT_AUDIO;
sprintf(banner, "SDL Frotz v%s - %s (z%d)",
frotz_version, f_setup.story_name, h_version);
- desired_bpp = 32;
- video_flags = 0;
-
- if ( SDL_Init(initflags) < 0 ) {
- os_fatal("Couldn't initialize SDL: %s", SDL_GetError());
- }
+ video_flags = 0;
- CLEANREG(cleanvideo);
+ if ( SDL_Init(initflags) < 0 ) {
+ os_fatal("Couldn't initialize SDL: %s", SDL_GetError());
+ }
- isfullscreen = full;
- if (full) video_flags = SDL_FULLSCREEN;
- reqW = W; reqH = H;
- if (full)
- {
- if (m_reqW == -1)
- {
- const SDL_VideoInfo * v = SDL_GetVideoInfo();
- if (v) { m_reqW = v->current_w; m_reqH = v->current_h;}
- }
- if (m_reqW > reqW) reqW = m_reqW;
- if (m_reqH > reqH) reqH = m_reqH;
- }
- screen = SDL_SetVideoMode( reqW, reqH, desired_bpp, video_flags);
- if ( screen == NULL ) {
- os_fatal("Couldn't set %dx%dx%d video mode: %s",
- reqW, reqH, desired_bpp, SDL_GetError());
- }
- SDL_WM_SetCaption(banner,NULL);
- bitsperpixel = 32;
-
- mustlockscreen = SDL_MUSTLOCK(screen);
- format = screen->format;
-
- needoff = (mustlockscreen) || (screen->w != W) || (screen->h != H) ||
- (format->BitsPerPixel != 24) ||
- (screen->pitch != 3*W);
-
- RBswap = 0;
- if (!needoff) {
- needoff = check(format->Rmask,format->Gmask,format->Bmask);
- if ((needoff == -1)){
- RBswap = 1;
- needoff = 0;
- }
+ CLEANREG(cleanvideo);
+
+ isfullscreen = full;
+ reqW = W; reqH = H;
+ if (full) {
+ if (m_reqW == -1) {
+ video_flags = SDL_WINDOW_FULLSCREEN_DESKTOP;
+ reqW = reqH = 0;
+ } else {
+ video_flags = SDL_WINDOW_FULLSCREEN;
+ if (m_reqW > reqW) reqW = m_reqW;
+ if (m_reqH > reqH) reqH = m_reqH;
+ }
+ }
+ if ((win = SDL_CreateWindow(
+ banner, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
+ reqW, reqH, video_flags)))
+ renderer = SDL_CreateRenderer(win, -1, 0);
else
- needoff = 1;
+ renderer = NULL;
+ if (renderer == NULL ) {
+ os_fatal("Couldn't create %dx%d window: %s",
+ reqW, reqH, SDL_GetError());
+ }
+ if (reqW != W || reqH != H) {
+ SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "linear");
+ if (SDL_RenderSetLogicalSize(renderer, W, H))
+ os_fatal("Failed to set logical rendering size to %dx%d: %s",
+ W, H, SDL_GetError());
}
-// printf("setvideo: gm %dx%d rq %dx%d(f%d) got %dx%d needoff %d\n", W,H,reqW,reqH,full,screen->w,screen->h,needoff);
+ pixfmt = SDL_MasksToPixelFormatEnum(32, 0xff, 0xff00, 0xff0000, 0);
+ if (!(texture = SDL_CreateTexture(renderer, pixfmt,
+ SDL_TEXTUREACCESS_STREAMING, W, H)))
+ os_fatal("Failed to create texture: %s", SDL_GetError());
+
+// printf("setvideo: gm %dx%d rq %dx%d(f%d)\n",W,H,reqW,reqH,full);
- if (needoff) {
sbuffer = calloc(W*H,sizeof(ulong));
- if (!sbuffer){
- os_fatal("Could not create gc");
- }
- off = SDL_CreateRGBSurfaceFrom(sbuffer,
- W,H,32,4*W,0xff,0xff00,0xff0000,0);
-// off = SDL_CreateRGBSurfaceFrom(sbuffer,
-// W,H,32,4*screen->w,0xff,0xff00,0xff0000,0);
- if (!off){
- os_fatal("Could not create offscreen surface");
- }
- }
- else {
- sbuffer = (ulong *)screen->pixels;
- }
+ if (!sbuffer)
+ os_fatal("Could not create gc");
- blitrect.w = W; blitrect.h = H;
- blitrect.x = (screen->w - W)/2;
- blitrect.y = (screen->h - H)/2;
- SDL_EnableUNICODE(1);
- SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);
+ // SDL_EnableUNICODE(1);
+ // SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);
- SDL_AddTimer(SFdticks,mytimer,NULL);
+ SDL_AddTimer(SFdticks,mytimer,NULL);
- xmin = ymin = 0;
- xmax = ewidth = W;
- ymax = eheight = H;
- sbpitch = W;
- dirty = 1;
- }
+ xmin = ymin = 0;
+ xmax = ewidth = W;
+ ymax = eheight = H;
+ sbpitch = W;
+ dirty = 1;
+}
/*
* os_draw_picture
int mouse_button;
static int numAltQ = 0;
+static void set_mouse_xy(int x, int y)
+{
+ //TODO Scale to logical coordinates.
+ mouse_x = x + 1;
+ mouse_y = y + 1;
+}
+
static zword goodzkey( SDL_Event *e, int allowed)
{
- zword c;
+ SDL_Keycode c;
if (e->type == SDL_QUIT)
{
sf_quitconf();
if (true) //(e->button.button == SDL_BUTTON_LEFT)
{
mouse_button = e->button.button;
- mouse_x = e->button.x+1-blitrect.x;
- mouse_y = e->button.y+1-blitrect.y;
+ set_mouse_xy(e->button.x, e->button.y);
return ZC_SINGLE_CLICK;
}
return 0;
case SDLK_TAB: return (allowed ? VK_TAB : 0);
case SDLK_PAGEUP: return (allowed ? VK_PAGE_UP : 0);
case SDLK_PAGEDOWN: return (allowed ? VK_PAGE_DOWN : 0);
- case SDLK_KP0: return ZC_NUMPAD_MIN+0;
- case SDLK_KP1: return ZC_NUMPAD_MIN+1;
- case SDLK_KP2: return ZC_NUMPAD_MIN+2;
- case SDLK_KP3: return ZC_NUMPAD_MIN+3;
- case SDLK_KP4: return ZC_NUMPAD_MIN+4;
- case SDLK_KP5: return ZC_NUMPAD_MIN+5;
- case SDLK_KP6: return ZC_NUMPAD_MIN+6;
- case SDLK_KP7: return ZC_NUMPAD_MIN+7;
- case SDLK_KP8: return ZC_NUMPAD_MIN+8;
- case SDLK_KP9: return ZC_NUMPAD_MIN+9;
+ case SDLK_KP_0: return ZC_NUMPAD_MIN+0;
+ case SDLK_KP_1: return ZC_NUMPAD_MIN+1;
+ case SDLK_KP_2: return ZC_NUMPAD_MIN+2;
+ case SDLK_KP_3: return ZC_NUMPAD_MIN+3;
+ case SDLK_KP_4: return ZC_NUMPAD_MIN+4;
+ case SDLK_KP_5: return ZC_NUMPAD_MIN+5;
+ case SDLK_KP_6: return ZC_NUMPAD_MIN+6;
+ case SDLK_KP_7: return ZC_NUMPAD_MIN+7;
+ case SDLK_KP_8: return ZC_NUMPAD_MIN+8;
+ case SDLK_KP_9: return ZC_NUMPAD_MIN+9;
case SDLK_F1: return ZC_FKEY_MIN+0;
case SDLK_F2: return ZC_FKEY_MIN+1;
case SDLK_F3: return ZC_FKEY_MIN+2;
case SDLK_F10: return ZC_FKEY_MIN+9;
case SDLK_F11: return ZC_FKEY_MIN+10;
case SDLK_F12: return ZC_FKEY_MIN+11;
- default: break;
}
- c = e->key.keysym.unicode;
- if ((c >= 32 && c <= 126) || (c >= 160)) return c;
+ c = e->key.keysym.sym;
+ if (c >= 32 && c <= 126)
+ return c;
return 0;
}
// Get the mouse position
SDL_PumpEvents();
c = SDL_GetMouseState(&x,&y);
- mouse_x = x+1-blitrect.x;
- mouse_y = y+1-blitrect.y;
+ set_mouse_xy(x, y);
// Get the last selected menu item
// menu_selected = theWnd->GetMenuClick();
//printf("%04x\n",c);
}
}
-void os_check_events(void)
- {
- SDL_Event event;
- SDL_PumpEvents();
- if (SDL_PeepEvents(&event,1,SDL_GETEVENT,SDL_QUITMASK))
- sf_quitconf();
- }
-