examples - comments
Some checks failed
Build / Build (push) Failing after 2m8s

This commit is contained in:
2026-04-12 23:42:15 -04:00
parent fd35e93831
commit 14b4e60d3a
4 changed files with 47 additions and 14 deletions

View File

@@ -1,33 +1,55 @@
// basicGLFWWindow
// While I've got a basic initWindow() function in shared/window.h, I mostly just wanted to give an example of how to
// create a window with glfw without it. You can always figure out from the window.h file as well, but it is nice and
// easy to just look here instead, as you're probably already here anyways.
// Oatmeal does ship with GLFW linked as public, so you should be able to just link with it in your CMakeLists.txt file
// without having to add it yourself.
// - Firewire
#include <cstdint> #include <cstdint>
#include <cstdlib> #include <cstdlib>
#include "GLFW/glfw3.h" #include "GLFW/glfw3.h"
#include "shared/logger.h" #include "shared/logger.h"
int main() { int main() {
// Init and create the logger
OatmealUtils::initLogging(); OatmealUtils::initLogging();
OatmealUtils::createLogger("window", nullptr); OatmealUtils::createLogger("window", nullptr);
OatmealUtils::get("window")->info("Initializing GLFW"); // Initialize the GLFW backend
OatmealUtils::getLogger("window")->info("Initializing GLFW");
glfwInit(); glfwInit();
OatmealUtils::get("window")->info("Setting window hints"); // GLFW works on hints for configuration.
// Since oatmeal is entirely vulkan based and GLFW creates an opengl context by default, we need to tell it not to.
// At the time of writing (very very early indev) there is no resizable window support, so thats turned off here as
// well.
OatmealUtils::getLogger("window")->info("Setting window hints");
glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API); glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE); glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE);
OatmealUtils::get("window")->info("Create window"); // Create the window, running a small error check just in case it failed for whatever reason; and if it did, grab
// the error from glfw and print it out.
OatmealUtils::getLogger("window")->info("Create window");
GLFWwindow *window = glfwCreateWindow(800, 600, "Oatmeal - Basic GLFW window", nullptr, nullptr); GLFWwindow *window = glfwCreateWindow(800, 600, "Oatmeal - Basic GLFW window", nullptr, nullptr);
if (window == nullptr) { if (window == nullptr) {
const char *desc; const char *desc;
uint32_t code = glfwGetError(&desc); uint32_t code = glfwGetError(&desc);
OatmealUtils::get("window")->critical("Failed to create window: ({}) {}", code, desc); OatmealUtils::getLogger("window")->critical("Failed to create window: ({}) {}", code, desc);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
// This here is whats known as the main application loop. Everything with graphics/games/whatever runs in a loop,
// updating values as needed before it starts over again. The time it takes to run that loop is known at the
// frametime, and how many times you can run that loop per second is the FPS (sorta)
// Since we are just creating a window and have no way of updating it yet, we can just poll for any events and
// continue.
while (!glfwWindowShouldClose(window)) { while (!glfwWindowShouldClose(window)) {
glfwPollEvents(); glfwPollEvents();
} }
OatmealUtils::get("window")->info("Cleaning up"); // Cleanup the window and terminate the glfw backend
OatmealUtils::getLogger("window")->info("Cleaning up");
glfwDestroyWindow(window); glfwDestroyWindow(window);
glfwTerminate(); glfwTerminate();

View File

@@ -1,3 +1,8 @@
// createContext
// Still in progress, although I'm 95% sure this wont get changed.
// Come back later!
// - Firewire
#include <cstdlib> #include <cstdlib>
#include <exception> #include <exception>
#include "GLFW/glfw3.h" #include "GLFW/glfw3.h"
@@ -15,7 +20,7 @@ int main() {
try { try {
Oatmeal::ctx ctx(window); Oatmeal::ctx ctx(window);
} catch (const std::exception &e) { } catch (const std::exception &e) {
OatmealUtils::get("context")->critical("{}", e.what()); OatmealUtils::getLogger("context")->critical("{}", e.what());
return EXIT_FAILURE; return EXIT_FAILURE;
} }
@@ -24,7 +29,7 @@ int main() {
glfwPollEvents(); glfwPollEvents();
} }
OatmealUtils::get("window")->info("Cleaning up"); OatmealUtils::getLogger("window")->info("Cleaning up");
glfwDestroyWindow(window); glfwDestroyWindow(window);
glfwTerminate(); glfwTerminate();

View File

@@ -1,3 +1,9 @@
// Logging
// This program is just to test out/show any new features I add to the shared/logging.h file.
// It is mostly a wrapper around spdlog, nothing fancy at all.
// The code should be self explanatory enough so I'm not going to bother commenting everything out.
// - Firewire
#include <cstdint> #include <cstdint>
#include "shared/logger.h" #include "shared/logger.h"
@@ -5,13 +11,13 @@ int main() {
OatmealUtils::initLogging(); OatmealUtils::initLogging();
OatmealUtils::createLogger("logger", nullptr); OatmealUtils::createLogger("logger", nullptr);
OatmealUtils::get("logger")->debug("This is a debug message!"); OatmealUtils::getLogger("logger")->debug("This is a debug message!");
OatmealUtils::get("logger")->info("This is an info message!"); OatmealUtils::getLogger("logger")->info("This is an info message!");
OatmealUtils::get("logger")->warn("This is a warning message!"); OatmealUtils::getLogger("logger")->warn("This is a warning message!");
OatmealUtils::get("logger")->critical("This is a critical message!"); OatmealUtils::getLogger("logger")->critical("This is a critical message!");
uint32_t a = 5; uint32_t a = 5;
std::string b = "Test string arg!"; std::string b = "Test string arg!";
OatmealUtils::get("logger")->info("String arg: {} uint32_t args: {}", b, a); OatmealUtils::getLogger("logger")->info("String arg: {} uint32_t args: {}", b, a);
return 0; return 0;
} }

View File

@@ -49,8 +49,8 @@ namespace OatmealUtils {
} }
inline void createLogger(std::string name, std::string filename) { createLogger(name.c_str(), filename.c_str()); } inline void createLogger(std::string name, std::string filename) { createLogger(name.c_str(), filename.c_str()); }
inline std::shared_ptr<logger> get(const char *name) { return spdlog::get(name); } inline std::shared_ptr<logger> getLogger(const char *name) { return spdlog::get(name); }
inline std::shared_ptr<logger> get(std::string name) { return spdlog::get(name); } inline std::shared_ptr<logger> getLogger(std::string name) { return spdlog::get(name); }
} // namespace OatmealUtils } // namespace OatmealUtils