finished embeddable/none platforms and the example

This commit is contained in:
IoIxD 2024-08-30 15:08:38 -07:00
commit c13252e512
2 changed files with 132 additions and 53 deletions

View file

@ -118,15 +118,16 @@ elseif (NOT SUPPORT_GESTURES_SYSTEM)
list(REMOVE_ITEM example_sources ${CMAKE_CURRENT_SOURCE_DIR}/core/core_basic_screen_manager.c)
list(REMOVE_ITEM example_sources ${CMAKE_CURRENT_SOURCE_DIR}/core/core_input_gestures_web.c)
list(REMOVE_ITEM example_sources ${CMAKE_CURRENT_SOURCE_DIR}/core/core_input_gestures.c)
elseif ("${PLATFORM}" STREQUAL "None" OR "${PLATFORM}" STREQUAL "Offscreen")
# for some reason i get an error when trying to compile this one from any platform? oh well we'll just stick it here
list(REMOVE_ITEM example_sources ${CMAKE_CURRENT_SOURCE_DIR}/others/raylib_opengl_interop.c)
endif ()
# The core_override one is only for Embeddable/Blank platforms
if (NOT ${PLATFORM} MATCHES "None" AND NOT ${PLATFORM} MATCHES "Embeddable")
list(REMOVE_ITEM example_sources ${CMAKE_CURRENT_SOURCE_DIR}/core/core_override.c)
endif()
# The rlgl_standalone example only targets desktop, without shared libraries.
if (BUILD_SHARED_LIBS OR NOT ${PLATFORM} MATCHES "Desktop")
list(REMOVE_ITEM example_sources ${CMAKE_CURRENT_SOURCE_DIR}/others/rlgl_standalone.c)
endif()
include_directories(BEFORE SYSTEM others/external/include)

View file

@ -0,0 +1,157 @@
/*******************************************************************************************
*
* raylib [core] example - Ascii rendering
*
* Example originally created with raylib 5.5, last time updated with raylib 5.5
*
* Example contributed by Gavin Parker (@IoIxD) and reviewed by Ramon Santamaria (@raysan5)
*
* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified,
* BSD-like license that allows static linking with closed source software
*
* Copyright (c) 2023 Gavin Parker (@IoIxD)
*
********************************************************************************************/
#include "raylib.h"
#include "rcore.h"
#include "GLFW/glfw3.h" // Windows/Context and inputs management
#include <stdio.h> // Required for: printf()
#include "rlgl.h"
#include "raymath.h"
const int screenWidth = 800;
const int screenHeight = 450;
GLFWwindow *window;
void CustomSetWindowTitle(const char *title)
{
GetCore()->Window.title = title;
glfwSetWindowTitle(window, title);
}
double CustomGetTime(void) {
return glfwGetTime();
}
bool CustomWindowShouldClose(void) {
if (GetCore()->Window.ready) return GetCore()->Window.shouldClose;
else return true;
}
int CustomInitPlatform(void) {
if (!glfwInit())
{
printf("GLFW3: Can not initialize GLFW\n");
return 1;
}
else printf("GLFW3: GLFW initialized successfully\n");
glfwWindowHint(GLFW_SAMPLES, 4);
glfwWindowHint(GLFW_DEPTH_BITS, 16);
// WARNING: OpenGL 3.3 Core profile only
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
//glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GL_TRUE);
#if defined(__APPLE__)
glfwWindowHint( GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE );
#endif
window = glfwCreateWindow(screenWidth, screenHeight, "rlgl standalone", NULL, NULL);
if (!window)
{
glfwTerminate();
return 2;
}
else printf("GLFW3: Window created successfully\n");
//glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE);
glfwSetWindowSize(window, GetCore()->Window.screen.width, GetCore()->Window.screen.height);
glfwSetWindowPos(window, 200, 200);
glfwMakeContextCurrent(window);
glfwSwapInterval(0);
// Load OpenGL 3.3 supported extensions
rlLoadExtensions(glfwGetProcAddress);
//--------------------------------------------------------
// Initialize OpenGL context (states and resources)
rlglInit(screenWidth, screenHeight);
// Initialize viewport and internal projection/modelview matrices
rlViewport(0, 0, screenWidth, screenHeight);
rlMatrixMode(RL_PROJECTION); // Switch to PROJECTION matrix
rlLoadIdentity(); // Reset current matrix (PROJECTION)
rlOrtho(0, screenWidth, screenHeight, 0, 0.0f, 1.0f); // Orthographic projection with top-left corner at (0,0)
rlMatrixMode(RL_MODELVIEW); // Switch back to MODELVIEW matrix
rlLoadIdentity(); // Reset current matrix (MODELVIEW)
GetCore()->Window.ready = true;
return 0;
}
void CustomClosePlatform(void) {
glfwDestroyWindow(window); // Close window
glfwTerminate(); // Free GLFW3 resources
}
//------------------------------------------------------------------------------------
// Program main entry point
//------------------------------------------------------------------------------------
int main(void)
{
union OverridableFunctionPointer funcs[4];
funcs[0].InitPlatform = CustomInitPlatform;
OverrideInternalFunction("InitPlatform",&funcs[0]);
funcs[1].ClosePlatform = CustomClosePlatform;
OverrideInternalFunction("ClosePlatform",&funcs[1]);
funcs[2].WindowShouldClose = CustomWindowShouldClose;
OverrideInternalFunction("WindowShouldClose",&funcs[2]);
funcs[3].GetTime = CustomGetTime;
OverrideInternalFunction("GetTime",&funcs[3]);
funcs[4].SetWindowTitle = CustomSetWindowTitle;
OverrideInternalFunction("SetWindowTitle",&funcs[4]);
InitWindow(screenWidth,screenHeight,"Test");
Color col = WHITE;
SetTargetFPS(5);
//--------------------------------------------------------------------------------------
// Main game loop
while(!WindowShouldClose()) {
BeginDrawing();
ClearBackground(col);
EndDrawing();
col.r = GetRandomValue(0,255);
col.g = GetRandomValue(0,255);
col.b = GetRandomValue(0,255);
glfwSwapBuffers(window);
glfwPollEvents();
GetCore()->Window.shouldClose = glfwWindowShouldClose(window);
}
//CustomClosePlatform();
return 0;
}