Compare commits

...

2 Commits

Author SHA1 Message Date
f6fbcc0d89 update to tip SDL3 2024-09-14 10:34:02 +10:00
bc4d13c54b fix compiler flags 2024-09-14 10:30:27 +10:00
2 changed files with 17 additions and 17 deletions

View File

@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION "3.5" FATAL_ERROR) cmake_minimum_required(VERSION "3.15" FATAL_ERROR)
project(Lesson10 LANGUAGES C) project(Lesson10 LANGUAGES C)
find_package(SDL3 REQUIRED CONFIG) find_package(SDL3 REQUIRED CONFIG)
@@ -9,8 +9,8 @@ set_target_properties(Lesson10 PROPERTIES
C_STANDARD 99 C_STANDARD 99
WIN32_EXECUTABLE ON) WIN32_EXECUTABLE ON)
target_link_libraries(Lesson10 SDL3::SDL3 OpenGL::GL) target_link_libraries(Lesson10 SDL3::SDL3 OpenGL::GL)
target_compile_options(Lesson10 PRIVATE $<$<CXX_COMPILER_ID:GNU>:-Wall -Wextra -pedantic>) target_compile_options(Lesson10 PRIVATE $<$<C_COMPILER_ID:GNU,Clang,AppleClang>:-Wall -Wextra -pedantic>)
target_compile_definitions(Lesson10 PRIVATE $<$<CXX_COMPILER_ID:MSVC>:_CRT_SECURE_NO_WARNINGS>) target_compile_definitions(Lesson10 PRIVATE $<$<C_COMPILER_ID:MSVC>:_CRT_SECURE_NO_WARNINGS>)
if (CMAKE_SYSTEM_NAME STREQUAL "Darwin") if (CMAKE_SYSTEM_NAME STREQUAL "Darwin")
get_property(SDL3_IMPORTED_LOCATION TARGET SDL3::SDL3 PROPERTY IMPORTED_LOCATION) get_property(SDL3_IMPORTED_LOCATION TARGET SDL3::SDL3 PROPERTY IMPORTED_LOCATION)

View File

@@ -125,7 +125,7 @@ static void SetupWorld(APPSTATE *state)
static bool FlipSurface(SDL_Surface *surface) static bool FlipSurface(SDL_Surface *surface)
{ {
if (!surface || SDL_LockSurface(surface) < 0) if (!surface || !SDL_LockSurface(surface))
{ {
return false; return false;
} }
@@ -307,12 +307,12 @@ static void KillGLWindow(APPSTATE *state)
// Release and delete rendering context // Release and delete rendering context
if (state->ctx) if (state->ctx)
{ {
if (SDL_GL_MakeCurrent(state->win, NULL)) if (SDL_GL_MakeCurrent(state->win, NULL) == SDL_FALSE)
{ {
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_INFORMATION, "SHUTDOWN ERROR", "Release Of RC Failed.", NULL); SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_INFORMATION, "SHUTDOWN ERROR", "Release Of RC Failed.", NULL);
} }
SDL_GL_DeleteContext(state->ctx); SDL_GL_DestroyContext(state->ctx);
state->ctx = NULL; state->ctx = NULL;
} }
@@ -341,7 +341,7 @@ static bool CreateGLWindow(APPSTATE *state, char *title, int width, int height,
// Try entering fullscreen mode if requested // Try entering fullscreen mode if requested
if (fullscreenflag) if (fullscreenflag)
{ {
if (SDL_SetWindowFullscreen(state->win, SDL_TRUE) < 0) if (!SDL_SetWindowFullscreen(state->win, SDL_TRUE))
{ {
// If mode switching fails, ask the user to quit or use to windowed mode // If mode switching fails, ask the user to quit or use to windowed mode
int bttnid = ShowYesNoMessageBox(state->win, BTTN_YES, "NeHe GL", int bttnid = ShowYesNoMessageBox(state->win, BTTN_YES, "NeHe GL",
@@ -378,7 +378,7 @@ static bool CreateGLWindow(APPSTATE *state, char *title, int width, int height,
return false; return false;
} }
if (SDL_GL_MakeCurrent(state->win, state->ctx)) // Activate the rendering context if (!SDL_GL_MakeCurrent(state->win, state->ctx)) // Activate the rendering context
{ {
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "ERROR", "Can't Activate The GL Rendering Context.", NULL); SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "ERROR", "Can't Activate The GL Rendering Context.", NULL);
return false; return false;
@@ -397,7 +397,7 @@ static bool CreateGLWindow(APPSTATE *state, char *title, int width, int height,
return true; return true;
} }
int SDL_AppEvent(void *appstate, const SDL_Event *event) SDL_AppResult SDL_AppEvent(void *appstate, SDL_Event *event)
{ {
APPSTATE *state = (APPSTATE *)appstate; APPSTATE *state = (APPSTATE *)appstate;
switch (event->type) switch (event->type)
@@ -406,15 +406,15 @@ int SDL_AppEvent(void *appstate, const SDL_Event *event)
return SDL_APP_SUCCESS; return SDL_APP_SUCCESS;
case SDL_EVENT_KEY_DOWN: case SDL_EVENT_KEY_DOWN:
if (event->key.keysym.sym == SDLK_ESCAPE) // Quit on escape key if (event->key.key == SDLK_ESCAPE) // Quit on escape key
{ {
return SDL_APP_SUCCESS; return SDL_APP_SUCCESS;
} }
if (!event->key.repeat) // Was a key just pressed? if (!event->key.repeat) // Was a key just pressed?
{ {
switch (event->key.keysym.sym) switch (event->key.key)
{ {
case SDLK_b: // B = Toggle blending case SDLK_B: // B = Toggle blending
state->blend = !state->blend; state->blend = !state->blend;
if (!state->blend) if (!state->blend)
{ {
@@ -428,7 +428,7 @@ int SDL_AppEvent(void *appstate, const SDL_Event *event)
} }
break; break;
case SDLK_f: // F = Cycle texture filtering case SDLK_F: // F = Cycle texture filtering
state->filter += 1; state->filter += 1;
if (state->filter > 2) if (state->filter > 2)
{ {
@@ -462,14 +462,14 @@ int SDL_AppEvent(void *appstate, const SDL_Event *event)
return SDL_APP_CONTINUE; return SDL_APP_CONTINUE;
} }
int SDL_AppIterate(void *appstate) SDL_AppResult SDL_AppIterate(void *appstate)
{ {
APPSTATE *state = (APPSTATE *)appstate; APPSTATE *state = (APPSTATE *)appstate;
DrawGLScene(state); // Draw the scene DrawGLScene(state); // Draw the scene
SDL_GL_SwapWindow(state->win); // Swap buffers (double buffering) SDL_GL_SwapWindow(state->win); // Swap buffers (double buffering)
// Handle keyboard input // Handle keyboard input
const Uint8 *keys = SDL_GetKeyboardState(NULL); const SDL_bool *keys = SDL_GetKeyboardState(NULL);
if (keys[SDL_SCANCODE_PAGEUP]) if (keys[SDL_SCANCODE_PAGEUP])
{ {
@@ -538,9 +538,9 @@ int SDL_AppIterate(void *appstate)
return SDL_APP_CONTINUE; return SDL_APP_CONTINUE;
} }
int SDL_AppInit(void **appstate, int argc, char *argv[]) SDL_AppResult SDL_AppInit(void **appstate, int argc, char *argv[])
{ {
if (SDL_Init(SDL_INIT_VIDEO) < 0) if (SDL_Init(SDL_INIT_VIDEO) == SDL_FALSE)
{ {
return SDL_APP_FAILURE; return SDL_APP_FAILURE;
} }