Begin merge of Backend_Init/Backend_CreateWindow
OpenGL3+OpenGLES2 backend done so far
This commit is contained in:
parent
3baba6a727
commit
6dac8254e2
5 changed files with 129 additions and 147 deletions
|
@ -14,8 +14,7 @@ typedef enum FontPixelMode
|
||||||
typedef struct Backend_Surface Backend_Surface;
|
typedef struct Backend_Surface Backend_Surface;
|
||||||
typedef struct Backend_Glyph Backend_Glyph;
|
typedef struct Backend_Glyph Backend_Glyph;
|
||||||
|
|
||||||
SDL_Window* Backend_CreateWindow(const char *title, int width, int height);
|
Backend_Surface* Backend_Init(const char *title, int width, int height, BOOL fullscreen);
|
||||||
Backend_Surface* Backend_Init(SDL_Window *window);
|
|
||||||
void Backend_Deinit(void);
|
void Backend_Deinit(void);
|
||||||
void Backend_DrawScreen(void);
|
void Backend_DrawScreen(void);
|
||||||
Backend_Surface* Backend_CreateSurface(unsigned int width, unsigned int height);
|
Backend_Surface* Backend_CreateSurface(unsigned int width, unsigned int height);
|
||||||
|
|
|
@ -17,6 +17,8 @@
|
||||||
|
|
||||||
#include "../../WindowsWrapper.h"
|
#include "../../WindowsWrapper.h"
|
||||||
|
|
||||||
|
#include "../../Resource.h"
|
||||||
|
|
||||||
#define TOTAL_VBOS 2
|
#define TOTAL_VBOS 2
|
||||||
|
|
||||||
#define ATTRIBUTE_INPUT_VERTEX_COORDINATES 1
|
#define ATTRIBUTE_INPUT_VERTEX_COORDINATES 1
|
||||||
|
@ -412,7 +414,7 @@ static void FlushVertexBuffer(void)
|
||||||
current_vertex_buffer_slot = 0;
|
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
|
#ifdef USE_OPENGLES2
|
||||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES);
|
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);
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2);
|
||||||
#endif
|
#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;
|
int window_width, window_height;
|
||||||
SDL_GetWindowSize(window, &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_GL_DeleteContext(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SDL_DestroyWindow(window);
|
||||||
|
}
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -568,6 +582,7 @@ void Backend_Deinit(void)
|
||||||
glDeleteVertexArrays(1, &vertex_array_id);
|
glDeleteVertexArrays(1, &vertex_array_id);
|
||||||
#endif
|
#endif
|
||||||
SDL_GL_DeleteContext(context);
|
SDL_GL_DeleteContext(context);
|
||||||
|
SDL_DestroyWindow(window);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Backend_DrawScreen(void)
|
void Backend_DrawScreen(void)
|
||||||
|
|
10
src/Draw.cpp
10
src/Draw.cpp
|
@ -84,7 +84,7 @@ BOOL Flip_SystemTask(void)
|
||||||
return TRUE;
|
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
|
#ifndef NDEBUG
|
||||||
puts("Available SDL2 video drivers:");
|
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());
|
printf("Selected SDL2 video driver: %s\n", SDL_GetCurrentVideoDriver());
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return Backend_CreateWindow(title, width, height);
|
|
||||||
}
|
|
||||||
|
|
||||||
BOOL StartDirectDraw(SDL_Window *window, int lMagnification)
|
|
||||||
{
|
|
||||||
memset(surface_metadata, 0, sizeof(surface_metadata));
|
memset(surface_metadata, 0, sizeof(surface_metadata));
|
||||||
|
|
||||||
switch (lMagnification)
|
switch (lMagnification)
|
||||||
|
@ -117,11 +112,10 @@ BOOL StartDirectDraw(SDL_Window *window, int lMagnification)
|
||||||
case 2:
|
case 2:
|
||||||
magnification = 2;
|
magnification = 2;
|
||||||
fullscreen = TRUE;
|
fullscreen = TRUE;
|
||||||
SDL_SetWindowFullscreen(window, SDL_WINDOW_FULLSCREEN);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
framebuffer = Backend_Init(window);
|
framebuffer = Backend_Init(title, width, height, fullscreen);
|
||||||
|
|
||||||
if (framebuffer == NULL)
|
if (framebuffer == NULL)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
|
@ -51,8 +51,7 @@ typedef enum SurfaceID
|
||||||
} SurfaceID;
|
} SurfaceID;
|
||||||
|
|
||||||
BOOL Flip_SystemTask(void);
|
BOOL Flip_SystemTask(void);
|
||||||
SDL_Window* CreateWindow(const char *title, int width, int height);
|
BOOL StartDirectDraw(const char *title, int width, int height, int lMagnification);
|
||||||
BOOL StartDirectDraw(SDL_Window *window, int lMagnification);
|
|
||||||
void EndDirectDraw(void);
|
void EndDirectDraw(void);
|
||||||
void ReleaseSurface(SurfaceID s);
|
void ReleaseSurface(SurfaceID s);
|
||||||
BOOL MakeSurface_Resource(const char *name, SurfaceID surf_no);
|
BOOL MakeSurface_Resource(const char *name, SurfaceID surf_no);
|
||||||
|
|
45
src/Main.cpp
45
src/Main.cpp
|
@ -193,15 +193,13 @@ int main(int argc, char *argv[])
|
||||||
|
|
||||||
RECT unused_rect = {0, 0, WINDOW_WIDTH, WINDOW_HEIGHT};
|
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, "0");
|
||||||
SDL_SetHint(SDL_HINT_WINDOWS_INTRESOURCE_ICON_SMALL, "1");
|
SDL_SetHint(SDL_HINT_WINDOWS_INTRESOURCE_ICON_SMALL, "1");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
SDL_InitSubSystem(SDL_INIT_VIDEO);
|
SDL_InitSubSystem(SDL_INIT_VIDEO);
|
||||||
|
|
||||||
SDL_Window *window;
|
|
||||||
|
|
||||||
switch (conf.display_mode)
|
switch (conf.display_mode)
|
||||||
{
|
{
|
||||||
case 1:
|
case 1:
|
||||||
|
@ -218,28 +216,23 @@ int main(int argc, char *argv[])
|
||||||
windowHeight = WINDOW_HEIGHT * 2;
|
windowHeight = WINDOW_HEIGHT * 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
window = CreateWindow(lpWindowName, windowWidth, windowHeight);
|
|
||||||
|
|
||||||
if (window == NULL)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
#ifdef FIX_BUGS
|
#ifdef FIX_BUGS
|
||||||
if (conf.display_mode == 1)
|
if (conf.display_mode == 1)
|
||||||
{
|
{
|
||||||
if (!StartDirectDraw(window, 0))
|
if (!StartDirectDraw(lpWindowName, windowWidth, windowHeight, 0))
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (!StartDirectDraw(window, 1))
|
if (!StartDirectDraw(lpWindowName, windowWidth, windowHeight, 1))
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
// Doesn't handle StartDirectDraw failing
|
// Doesn't handle StartDirectDraw failing
|
||||||
if (conf.display_mode == 1)
|
if (conf.display_mode == 1)
|
||||||
StartDirectDraw(window, 0);
|
StartDirectDraw(lpWindowName, windowWidth, windowHeight, 0);
|
||||||
else
|
else
|
||||||
StartDirectDraw(window, 1);
|
StartDirectDraw(lpWindowName, windowWidth, windowHeight, 1);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
@ -251,17 +244,12 @@ int main(int argc, char *argv[])
|
||||||
windowWidth = WINDOW_WIDTH * 2;
|
windowWidth = WINDOW_WIDTH * 2;
|
||||||
windowHeight = WINDOW_HEIGHT * 2;
|
windowHeight = WINDOW_HEIGHT * 2;
|
||||||
|
|
||||||
window = CreateWindow(lpWindowName, windowWidth, windowHeight);
|
|
||||||
|
|
||||||
if (window == NULL)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
#ifdef FIX_BUGS
|
#ifdef FIX_BUGS
|
||||||
if (!StartDirectDraw(window, 2))
|
if (!StartDirectDraw(lpWindowName, windowWidth, windowHeight, 2))
|
||||||
return 0;
|
return 0;
|
||||||
#else
|
#else
|
||||||
// Doesn't handle StartDirectDraw failing
|
// Doesn't handle StartDirectDraw failing
|
||||||
StartDirectDraw(window, 2);
|
StartDirectDraw(lpWindowName, windowWidth, windowHeight, 2);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
bFullscreen = TRUE;
|
bFullscreen = TRUE;
|
||||||
|
@ -274,21 +262,10 @@ int main(int argc, char *argv[])
|
||||||
SDL_EventState(SDL_DROPFILE, SDL_ENABLE);
|
SDL_EventState(SDL_DROPFILE, SDL_ENABLE);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Set up the window icon and cursor
|
// Set up the cursor
|
||||||
const unsigned char *resource_data;
|
|
||||||
size_t resource_size;
|
size_t resource_size;
|
||||||
SDL_RWops *rwops;
|
const unsigned char *resource_data = FindResource("CURSOR_NORMAL", "CURSOR", &resource_size);
|
||||||
|
SDL_RWops *rwops = SDL_RWFromConstMem(resource_data, resource_size);
|
||||||
#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);
|
|
||||||
SDL_Surface *cursor_surface = SDL_LoadBMP_RW(rwops, 1);
|
SDL_Surface *cursor_surface = SDL_LoadBMP_RW(rwops, 1);
|
||||||
SDL_SetColorKey(cursor_surface, SDL_TRUE, SDL_MapRGB(cursor_surface->format, 0xFF, 0, 0xFF));
|
SDL_SetColorKey(cursor_surface, SDL_TRUE, SDL_MapRGB(cursor_surface->format, 0xFF, 0, 0xFF));
|
||||||
SDL_Cursor *cursor = SDL_CreateColorCursor(cursor_surface, 0, 0);
|
SDL_Cursor *cursor = SDL_CreateColorCursor(cursor_surface, 0, 0);
|
||||||
|
@ -315,7 +292,6 @@ int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
SDL_FreeCursor(cursor);
|
SDL_FreeCursor(cursor);
|
||||||
SDL_FreeSurface(cursor_surface);
|
SDL_FreeSurface(cursor_surface);
|
||||||
SDL_DestroyWindow(window);
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -343,7 +319,6 @@ int main(int argc, char *argv[])
|
||||||
|
|
||||||
SDL_FreeCursor(cursor);
|
SDL_FreeCursor(cursor);
|
||||||
SDL_FreeSurface(cursor_surface);
|
SDL_FreeSurface(cursor_surface);
|
||||||
SDL_DestroyWindow(window);
|
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue