Begin merge of Backend_Init/Backend_CreateWindow

OpenGL3+OpenGLES2 backend done so far
This commit is contained in:
Clownacy 2020-01-22 22:19:55 +00:00
parent 3baba6a727
commit 6dac8254e2
5 changed files with 129 additions and 147 deletions

View file

@ -14,8 +14,7 @@ typedef enum FontPixelMode
typedef struct Backend_Surface Backend_Surface;
typedef struct Backend_Glyph Backend_Glyph;
SDL_Window* Backend_CreateWindow(const char *title, int width, int height);
Backend_Surface* Backend_Init(SDL_Window *window);
Backend_Surface* Backend_Init(const char *title, int width, int height, BOOL fullscreen);
void Backend_Deinit(void);
void Backend_DrawScreen(void);
Backend_Surface* Backend_CreateSurface(unsigned int width, unsigned int height);

View file

@ -17,6 +17,8 @@
#include "../../WindowsWrapper.h"
#include "../../Resource.h"
#define TOTAL_VBOS 2
#define ATTRIBUTE_INPUT_VERTEX_COORDINATES 1
@ -412,7 +414,7 @@ static void FlushVertexBuffer(void)
current_vertex_buffer_slot = 0;
}
SDL_Window* Backend_CreateWindow(const char *title, int width, int height)
Backend_Surface* Backend_Init(const char *title, int width, int height, BOOL fullscreen)
{
#ifdef USE_OPENGLES2
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES);
@ -426,12 +428,21 @@ SDL_Window* Backend_CreateWindow(const char *title, int width, int height)
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2);
#endif
return SDL_CreateWindow(title, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, width, height, SDL_WINDOW_OPENGL);
}
window = SDL_CreateWindow(title, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, width, height, SDL_WINDOW_OPENGL);
Backend_Surface* Backend_Init(SDL_Window *p_window)
if (window != NULL)
{
window = p_window;
#ifndef _WIN32 // On Windows, we use native icons instead (so we can give the taskbar and window separate icons, like the original EXE does)
size_t resource_size;
const unsigned char *resource_data = FindResource("ICON_MINI", "ICON", &resource_size);
SDL_RWops *rwops = SDL_RWFromConstMem(resource_data, resource_size);
SDL_Surface *icon_surface = SDL_LoadBMP_RW(rwops, 1);
SDL_SetWindowIcon(window, icon_surface);
SDL_FreeSurface(icon_surface);
#endif
if (fullscreen)
SDL_SetWindowFullscreen(window, SDL_WINDOW_FULLSCREEN);
int window_width, window_height;
SDL_GetWindowSize(window, &window_width, &window_height);
@ -548,6 +559,9 @@ Backend_Surface* Backend_Init(SDL_Window *p_window)
SDL_GL_DeleteContext(context);
}
SDL_DestroyWindow(window);
}
return NULL;
}
@ -568,6 +582,7 @@ void Backend_Deinit(void)
glDeleteVertexArrays(1, &vertex_array_id);
#endif
SDL_GL_DeleteContext(context);
SDL_DestroyWindow(window);
}
void Backend_DrawScreen(void)

View file

@ -84,7 +84,7 @@ BOOL Flip_SystemTask(void)
return TRUE;
}
SDL_Window* CreateWindow(const char *title, int width, int height)
BOOL StartDirectDraw(const char *title, int width, int height, int lMagnification)
{
#ifndef NDEBUG
puts("Available SDL2 video drivers:");
@ -95,11 +95,6 @@ SDL_Window* CreateWindow(const char *title, int width, int height)
printf("Selected SDL2 video driver: %s\n", SDL_GetCurrentVideoDriver());
#endif
return Backend_CreateWindow(title, width, height);
}
BOOL StartDirectDraw(SDL_Window *window, int lMagnification)
{
memset(surface_metadata, 0, sizeof(surface_metadata));
switch (lMagnification)
@ -117,11 +112,10 @@ BOOL StartDirectDraw(SDL_Window *window, int lMagnification)
case 2:
magnification = 2;
fullscreen = TRUE;
SDL_SetWindowFullscreen(window, SDL_WINDOW_FULLSCREEN);
break;
}
framebuffer = Backend_Init(window);
framebuffer = Backend_Init(title, width, height, fullscreen);
if (framebuffer == NULL)
return FALSE;

View file

@ -51,8 +51,7 @@ typedef enum SurfaceID
} SurfaceID;
BOOL Flip_SystemTask(void);
SDL_Window* CreateWindow(const char *title, int width, int height);
BOOL StartDirectDraw(SDL_Window *window, int lMagnification);
BOOL StartDirectDraw(const char *title, int width, int height, int lMagnification);
void EndDirectDraw(void);
void ReleaseSurface(SurfaceID s);
BOOL MakeSurface_Resource(const char *name, SurfaceID surf_no);

View file

@ -193,15 +193,13 @@ int main(int argc, char *argv[])
RECT unused_rect = {0, 0, WINDOW_WIDTH, WINDOW_HEIGHT};
#ifdef _WIN32
#ifdef _WIN32 // On Windows, we use native icons instead (so we can give the taskbar and window separate icons, like the original EXE does)
SDL_SetHint(SDL_HINT_WINDOWS_INTRESOURCE_ICON, "0");
SDL_SetHint(SDL_HINT_WINDOWS_INTRESOURCE_ICON_SMALL, "1");
#endif
SDL_InitSubSystem(SDL_INIT_VIDEO);
SDL_Window *window;
switch (conf.display_mode)
{
case 1:
@ -218,28 +216,23 @@ int main(int argc, char *argv[])
windowHeight = WINDOW_HEIGHT * 2;
}
window = CreateWindow(lpWindowName, windowWidth, windowHeight);
if (window == NULL)
return 0;
#ifdef FIX_BUGS
if (conf.display_mode == 1)
{
if (!StartDirectDraw(window, 0))
if (!StartDirectDraw(lpWindowName, windowWidth, windowHeight, 0))
return 0;
}
else
{
if (!StartDirectDraw(window, 1))
if (!StartDirectDraw(lpWindowName, windowWidth, windowHeight, 1))
return 0;
}
#else
// Doesn't handle StartDirectDraw failing
if (conf.display_mode == 1)
StartDirectDraw(window, 0);
StartDirectDraw(lpWindowName, windowWidth, windowHeight, 0);
else
StartDirectDraw(window, 1);
StartDirectDraw(lpWindowName, windowWidth, windowHeight, 1);
#endif
break;
@ -251,17 +244,12 @@ int main(int argc, char *argv[])
windowWidth = WINDOW_WIDTH * 2;
windowHeight = WINDOW_HEIGHT * 2;
window = CreateWindow(lpWindowName, windowWidth, windowHeight);
if (window == NULL)
return 0;
#ifdef FIX_BUGS
if (!StartDirectDraw(window, 2))
if (!StartDirectDraw(lpWindowName, windowWidth, windowHeight, 2))
return 0;
#else
// Doesn't handle StartDirectDraw failing
StartDirectDraw(window, 2);
StartDirectDraw(lpWindowName, windowWidth, windowHeight, 2);
#endif
bFullscreen = TRUE;
@ -274,21 +262,10 @@ int main(int argc, char *argv[])
SDL_EventState(SDL_DROPFILE, SDL_ENABLE);
#endif
// Set up the window icon and cursor
const unsigned char *resource_data;
// Set up the cursor
size_t resource_size;
SDL_RWops *rwops;
#ifndef _WIN32 // On Windows, we use native icons instead (so we can give the taskbar and window separate icons, like the original EXE does)
resource_data = FindResource("ICON_MINI", "ICON", &resource_size);
rwops = SDL_RWFromConstMem(resource_data, resource_size);
SDL_Surface *icon_surface = SDL_LoadBMP_RW(rwops, 1);
SDL_SetWindowIcon(window, icon_surface);
SDL_FreeSurface(icon_surface);
#endif
resource_data = FindResource("CURSOR_NORMAL", "CURSOR", &resource_size);
rwops = SDL_RWFromConstMem(resource_data, resource_size);
const unsigned char *resource_data = FindResource("CURSOR_NORMAL", "CURSOR", &resource_size);
SDL_RWops *rwops = SDL_RWFromConstMem(resource_data, resource_size);
SDL_Surface *cursor_surface = SDL_LoadBMP_RW(rwops, 1);
SDL_SetColorKey(cursor_surface, SDL_TRUE, SDL_MapRGB(cursor_surface->format, 0xFF, 0, 0xFF));
SDL_Cursor *cursor = SDL_CreateColorCursor(cursor_surface, 0, 0);
@ -315,7 +292,6 @@ int main(int argc, char *argv[])
{
SDL_FreeCursor(cursor);
SDL_FreeSurface(cursor_surface);
SDL_DestroyWindow(window);
return 1;
}
@ -343,7 +319,6 @@ int main(int argc, char *argv[])
SDL_FreeCursor(cursor);
SDL_FreeSurface(cursor_surface);
SDL_DestroyWindow(window);
return 1;
}