Skip to content

Commit

Permalink
Update winsys.cpp, CMakeLists.txt
Browse files Browse the repository at this point in the history
  • Loading branch information
stephengtuggy committed Apr 29, 2024
1 parent cacd549 commit 34a199c
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 9 deletions.
5 changes: 4 additions & 1 deletion engine/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ SET(SIZEOF_VOID_P CMAKE_SIZEOF_VOID_P)
# CHECK_TYPE_SIZE("void*" SIZEOF_VOID_P) #BUILTIN_TYPES_ONLY)
# cmake_pop_check_state()

SET(CMAKE_FIND_FRAMEWORK "LAST")

#Find Math
INCLUDE(CheckSymbolExists)
Expand Down Expand Up @@ -397,6 +398,7 @@ ENDIF (USE_SYSTEM_BOOST)
IF (NOT DISABLE_CLIENT) ##########

#Find GL
SET(CMAKE_FIND_FRAMEWORK "FIRST")
FIND_PACKAGE(OpenGL REQUIRED)
IF (OPENGL_FOUND AND OPENGL_GLU_FOUND)
SET(TST_INCLUDES ${TST_INCLUDES} ${OPENGL_INCLUDE_DIR})
Expand Down Expand Up @@ -434,6 +436,7 @@ IF (NOT DISABLE_CLIENT) ##########
ENDIF (GLUT_FOUND)

UNSET(OPENGL_LIBRARY_DIR)
SET(CMAKE_FIND_FRAMEWORK "LAST")

#Find OpenAL
FIND_PACKAGE(OpenAL REQUIRED)
Expand Down Expand Up @@ -1154,7 +1157,7 @@ SET(VEGASTRIKE_SOURCES
SET(TST_LIBS vegastrike-engine_com vegastrike-OPcollide ${TST_LIBS})

IF (NOT DISABLE_CLIENT)
ADD_EXECUTABLE(vegastrike-engine ${VEGASTRIKE_SOURCES})
ADD_EXECUTABLE(vegastrike-engine WIN32 MACOSX_BUNDLE ${VEGASTRIKE_SOURCES})

#TARGET_COMPILE_FEATURES(vegastrike-engine PUBLIC cxx_std_11)
IF (NEED_LINKING_AGAINST_LIBM)
Expand Down
50 changes: 42 additions & 8 deletions engine/src/gldrv/winsys.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,8 @@ void winsys_set_passive_motion_func(winsys_motion_func_t func) {
* \date Modified: 2000-10-19
*/
void winsys_swap_buffers() {
// SDL_Window* current_window = SDL_GL_GetCurrentWindow();
SDL_GL_SwapWindow(window);
SDL_Window* current_window = SDL_GL_GetCurrentWindow();
SDL_GL_SwapWindow(current_window);
}

/*---------------------------------------------------------------------------*/
Expand All @@ -177,8 +177,8 @@ void winsys_swap_buffers() {
* \date Modified: 2000-10-19
*/
void winsys_warp_pointer(int x, int y) {
// SDL_Window* current_window = SDL_GL_GetCurrentWindow();
SDL_WarpMouseInWindow(window, x, y);
SDL_Window* current_window = SDL_GL_GetCurrentWindow();
SDL_WarpMouseInWindow(current_window, x, y);
}

/*---------------------------------------------------------------------------*/
Expand Down Expand Up @@ -246,13 +246,47 @@ static bool setup_sdl_video_mode() {

SDL_GL_GetDrawableSize(window, &width, &height);

auto context = SDL_GL_CreateContext(window);
SDL_GLContext context = SDL_GL_CreateContext(window);
if (!context) {
std::cerr << "No GL context\n" << std::flush;
VS_LOG_FLUSH_EXIT(fatal, "No GL context", 1);
}

VS_LOG_AND_FLUSH(important_info, (boost::format("GL Vendor: %1%") % glGetString(GL_VENDOR)));
VS_LOG_AND_FLUSH(important_info, (boost::format("GL Renderer: %1%") % glGetString(GL_RENDERER)));
VS_LOG_AND_FLUSH(important_info, (boost::format("GL Version: %1%") % glGetString(GL_VERSION)));

SDL_GL_MakeCurrent(window, context);

screen = SDL_GetWindowSurface(window); //SDL_CreateRenderer(window, -1, video_flags);
if (!screen) {
VS_LOG_FLUSH_EXIT(fatal, (boost::format("Couldn't initialize video: %1%") % SDL_GetError()), 1);

// for (int counter = 0; window == nullptr && counter < 2; ++counter) {
// for (int bpd = 4; bpd > 1; --bpd) {
// SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, bpd * 8);
// if ((screen = SDL_SetVideoMode(width, height, bpp, video_flags))
// == NULL) {
// VS_LOG_AND_FLUSH(error,
// (boost::format("Couldn't initialize video bpp %1% depth %2%: %3%")
// % bpp
// % (bpd * 8)
// % SDL_GetError()));
// } else {
// break;
// }
// }
// if (screen == NULL) {
// SDL_GL_SetAttribute(SDL_GL_RED_SIZE, otherattributes);
// SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, otherattributes);
// SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, otherattributes);
// gl_options.color_depth = bpp = otherbpp;
// }
// }
// if (screen == NULL) {
// VS_LOG_AND_FLUSH(fatal, "FAILED to initialize video");
// VSExit(1);
// }
}

std::string version = (const char *) glGetString(GL_RENDERER);
Expand Down Expand Up @@ -292,8 +326,7 @@ static bool setup_sdl_video_mode() {
void winsys_init(int *argc, char **argv, char const *window_title, char const *icon_title) {
keepRunning = true;

//SDL_INIT_AUDIO|
Uint32 sdl_flags = SDL_INIT_VIDEO | SDL_INIT_JOYSTICK;
Uint32 sdl_flags = SDL_INIT_AUDIO | SDL_INIT_VIDEO | SDL_INIT_JOYSTICK | SDL_INIT_EVENTS | SDL_INIT_TIMER;
g_game.x_resolution = game_options()->x_resolution;
g_game.y_resolution = game_options()->y_resolution;
gl_options.fullscreen = game_options()->fullscreen;
Expand Down Expand Up @@ -471,9 +504,10 @@ void winsys_process_events() {
(*display_func)();
} else if (idle_func) {
(*idle_func)();
/* Delay for 1 ms. This allows the other threads to do some
/* Delay for a bit. This allows the other threads to do some
* work (otherwise the audio thread gets starved). */
}
// SDL_GL_SwapWindow(window);
SDL_Delay(1);
}
winsys_cleanup();
Expand Down

0 comments on commit 34a199c

Please sign in to comment.