-
Notifications
You must be signed in to change notification settings - Fork 584
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
469 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
SDL | ||
build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
cmake_minimum_required(VERSION 3.16) | ||
|
||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/$<CONFIGURATION>") | ||
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/$<CONFIGURATION>") | ||
set(CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}" CACHE INTERNAL "") | ||
|
||
# CMAKE Modules | ||
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") | ||
|
||
project(nuklear_sdl3_renderer) | ||
|
||
set(EXECUTABLE_NAME ${PROJECT_NAME}) | ||
|
||
# The SDL java code is hardcoded to load libmain.so on android, so we need to change EXECUTABLE_NAME | ||
if (ANDROID) | ||
set(EXECUTABLE_NAME main) | ||
add_library(${EXECUTABLE_NAME} SHARED) | ||
else() | ||
add_executable(${EXECUTABLE_NAME}) | ||
endif() | ||
|
||
# Add your sources to the target | ||
target_sources(${EXECUTABLE_NAME} PRIVATE main.c) | ||
|
||
find_package(SDL3 REQUIRED) | ||
|
||
target_link_libraries(${EXECUTABLE_NAME} PUBLIC SDL3::SDL3) | ||
|
||
# Nuklear Include Directory | ||
target_include_directories(${EXECUTABLE_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../..) | ||
|
||
# on Visual Studio, set our app as the default project | ||
set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT "${EXECUTABLE_NAME}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
include(FetchContent) | ||
FetchContent_Declare( | ||
SDL3 | ||
GIT_REPOSITORY https://github.com/libsdl-org/SDL.git | ||
GIT_TAG eb3fc06 | ||
#GIT_SHALLOW 1 | ||
) | ||
FetchContent_MakeAvailable(SDL3) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
#define SDL_MAIN_USE_CALLBACKS | ||
#include <SDL3/SDL.h> | ||
#include <SDL3/SDL_main.h> | ||
|
||
#define NK_SDL_RENDERER_IMPLEMENTATION | ||
#include "nuklear_sdl3_renderer.h" | ||
|
||
typedef struct AppContext { | ||
SDL_Window* window; | ||
SDL_Renderer* renderer; | ||
} AppContext; | ||
|
||
SDL_AppResult SDL_Fail(){ | ||
SDL_LogError(SDL_LOG_CATEGORY_CUSTOM, "Error %s", SDL_GetError()); | ||
return SDL_APP_FAILURE; | ||
} | ||
|
||
SDL_AppResult SDL_AppInit(void** appstate, int argc, char* argv[]) { | ||
if (!SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTS)) { | ||
return SDL_Fail(); | ||
} | ||
|
||
AppContext* appContext = (AppContext*)SDL_malloc(sizeof(AppContext)); | ||
if (appContext == NULL) { | ||
return SDL_Fail(); | ||
} | ||
|
||
if (!SDL_CreateWindowAndRenderer("Nuklear: SDL3 Renderer", 1200, 800, SDL_WINDOW_RESIZABLE, &appContext->window, &appContext->renderer)) { | ||
SDL_free(appContext); | ||
return SDL_Fail(); | ||
} | ||
|
||
*appstate = appContext; | ||
|
||
return SDL_APP_CONTINUE; | ||
} | ||
|
||
SDL_AppResult SDL_AppEvent(void *appstate, SDL_Event* event) { | ||
AppContext* app = (AppContext*)appstate; | ||
|
||
switch (event->type) { | ||
case SDL_EVENT_QUIT: | ||
return SDL_APP_SUCCESS; | ||
} | ||
|
||
nk_sdl_handle_event(event); | ||
|
||
return SDL_APP_CONTINUE; | ||
} | ||
|
||
SDL_AppResult SDL_AppIterate(void *appstate) { | ||
AppContext* app = (AppContext*)appstate; | ||
|
||
SDL_SetRenderDrawColor(app->renderer, 255, 0, 255, SDL_ALPHA_OPAQUE); | ||
SDL_RenderClear(app->renderer); | ||
SDL_RenderPresent(app->renderer); | ||
|
||
return SDL_APP_CONTINUE; | ||
} | ||
|
||
void SDL_AppQuit(void* appstate, SDL_AppResult result) { | ||
AppContext* app = (AppContext*)appstate; | ||
|
||
if (app) { | ||
SDL_DestroyRenderer(app->renderer); | ||
SDL_DestroyWindow(app->window); | ||
SDL_free(app); | ||
} | ||
|
||
SDL_Quit(); | ||
} |
Oops, something went wrong.