comparison src/dmsimple.c @ 2043:cbb3463fea2a

Initial dabbling for SDL2 migration of the SW rendering / dmsimple.
author Matti Hamalainen <ccr@tnsp.org>
date Fri, 30 Nov 2018 06:56:38 +0200
parents 93d1050eac99
children 78a0f44aa8b5
comparison
equal deleted inserted replaced
2042:45d9db50d996 2043:cbb3463fea2a
100 int dx = 60, 100 int dx = 60,
101 dh = 20, 101 dh = 20,
102 dw = engine.screen->w - (2 * dx), 102 dw = engine.screen->w - (2 * dx),
103 dy = (engine.screen->h - dh) / 2; 103 dy = (engine.screen->h - dh) / 2;
104 104
105 if (SDL_MUSTLOCK(engine.screen) != 0 && SDL_LockSurface(engine.screen) != 0)
106 return DMERR_INIT_FAIL;
107
108 // Draw the progress bar 105 // Draw the progress bar
109 dmClearSurface(engine.screen, dmMapRGBA(engine.screen, 0,0,0,0)); 106 dmClearSurface(engine.screen, dmMapRGBA(engine.screen, 0,0,0,0));
110 dmFillRect(engine.screen, dx, dy, dx+dw, dy+dh, dmMapRGB(engine.screen, 255,255,255)); 107 dmFillRect(engine.screen, dx, dy, dx+dw, dy+dh, dmMapRGB(engine.screen, 255,255,255));
111 dmFillRect(engine.screen, dx+1, dy+1, dx+dw-1, dy+dh-1, dmMapRGB(engine.screen, 0,0,0)); 108 dmFillRect(engine.screen, dx+1, dy+1, dx+dw-1, dy+dh-1, dmMapRGB(engine.screen, 0,0,0));
112 109
118 dy + dh - 3, 115 dy + dh - 3,
119 dmMapRGB(engine.screen, 200,200,200)); 116 dmMapRGB(engine.screen, 200,200,200));
120 } 117 }
121 118
122 // Flip screen 119 // Flip screen
123 if (SDL_MUSTLOCK(engine.screen) != 0) 120 SDL_Surface dst;
124 SDL_UnlockSurface(engine.screen); 121 SDL_LockTexture(engine.texture, NULL, &dst.pixels, &dst.pitch);
125 122
126 SDL_Flip(engine.screen); 123 for (int yc = 0; yc < engine.screen->h; yc++)
124 {
125 memcpy(dst.pixels + dst.pitch * yc,
126 engine.screen->pixels + engine.screen->pitch * yc,
127 dst.pitch);
128 }
129
130 SDL_UnlockTexture(engine.texture);
131
132 SDL_SetRenderDrawColor(engine.renderer, 0, 0, 0, 255);
133 SDL_RenderClear(engine.renderer);
134 SDL_RenderCopy(engine.renderer, engine.texture, NULL, NULL);
135 SDL_RenderPresent(engine.renderer);
136
127 return DMERR_OK; 137 return DMERR_OK;
128 } 138 }
129 139
130 140
131 static int engineLoadResources() 141 static int engineLoadResources()
151 static BOOL engineGenInitializeVideo(int width, int height, int depth, Uint32 flags) 161 static BOOL engineGenInitializeVideo(int width, int height, int depth, Uint32 flags)
152 { 162 {
153 dmPrint(1, "Initializing SDL video %d x %d x %dbpp, flags=0x%08x\n", 163 dmPrint(1, "Initializing SDL video %d x %d x %dbpp, flags=0x%08x\n",
154 width, height, depth, flags); 164 width, height, depth, flags);
155 165
156 SDL_WM_SetCaption(dmProgDesc, dmProgName); 166 SDL_SetWindowTitle(engine.window, dmProgDesc);
157 167
158 return TRUE; 168 return TRUE;
159 } 169 }
160 170
161 171