Compare commits
2 Commits
c412073c23
...
14b4e60d3a
| Author | SHA1 | Date | |
|---|---|---|---|
| 14b4e60d3a | |||
| fd35e93831 |
@@ -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();
|
||||||
|
|
||||||
|
|||||||
@@ -1,36 +1,26 @@
|
|||||||
#include <cstdint>
|
// 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"
|
||||||
#include "shared/logger.h"
|
#include "shared/logger.h"
|
||||||
|
#include "shared/window.h"
|
||||||
|
|
||||||
#include "ctx.h"
|
#include "ctx.h"
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
OatmealUtils::initLogging();
|
OatmealUtils::initLogging();
|
||||||
OatmealUtils::createLogger("window", nullptr);
|
|
||||||
OatmealUtils::createLogger("context", nullptr);
|
OatmealUtils::createLogger("context", nullptr);
|
||||||
|
|
||||||
OatmealUtils::get("window")->info("Initializing GLFW");
|
GLFWwindow *window = OatmealUtils::initWindow("Oatmeal - createContext", 800, 600);
|
||||||
glfwInit();
|
|
||||||
|
|
||||||
OatmealUtils::get("window")->info("Setting window hints");
|
|
||||||
glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
|
|
||||||
glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE);
|
|
||||||
|
|
||||||
OatmealUtils::get("window")->info("Create window");
|
|
||||||
GLFWwindow *window = glfwCreateWindow(800, 600, "Oatmeal - Basic GLFW window", nullptr, nullptr);
|
|
||||||
if (window == nullptr) {
|
|
||||||
const char *desc;
|
|
||||||
uint32_t code = glfwGetError(&desc);
|
|
||||||
OatmealUtils::get("window")->critical("Failed to create window: ({}) {}", code, desc);
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -39,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();
|
||||||
|
|
||||||
|
|||||||
@@ -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;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,48 +0,0 @@
|
|||||||
#include "logger.h"
|
|
||||||
#include <memory>
|
|
||||||
#include <spdlog/async_logger.h>
|
|
||||||
#include <spdlog/common.h>
|
|
||||||
#include "spdlog/async.h"
|
|
||||||
#include "spdlog/sinks/basic_file_sink.h"
|
|
||||||
#include "spdlog/sinks/stdout_color_sinks.h"
|
|
||||||
#include "spdlog/spdlog.h"
|
|
||||||
|
|
||||||
namespace OatmealUtils {
|
|
||||||
|
|
||||||
void initLogging() {
|
|
||||||
spdlog::init_thread_pool(8192, 1);
|
|
||||||
spdlog::flush_every(std::chrono::seconds(1));
|
|
||||||
}
|
|
||||||
|
|
||||||
void createLogger(const char *name, const char *filename) {
|
|
||||||
std::vector<spdlog::sink_ptr> sinks{};
|
|
||||||
|
|
||||||
const auto stdoutSink = std::make_shared<spdlog::sinks::stderr_color_sink_mt>();
|
|
||||||
stdoutSink->set_level(spdlog::level::debug);
|
|
||||||
stdoutSink->set_pattern("%^[%D %r %z] [%n] [%l] [thread %t] %v%$");
|
|
||||||
sinks.emplace_back(stdoutSink);
|
|
||||||
|
|
||||||
if (filename != nullptr) {
|
|
||||||
const auto fileSink = std::make_shared<spdlog::sinks::basic_file_sink_mt>(filename);
|
|
||||||
fileSink->set_level(spdlog::level::debug);
|
|
||||||
fileSink->set_pattern("%^[%D %r %z] [%n] [%l] [thread %t] %v%$");
|
|
||||||
sinks.emplace_back(fileSink);
|
|
||||||
}
|
|
||||||
|
|
||||||
const auto logger = std::make_shared<spdlog::async_logger>(
|
|
||||||
name, sinks.begin(), sinks.end(), spdlog::thread_pool(), spdlog::async_overflow_policy::block);
|
|
||||||
|
|
||||||
logger->flush_on(spdlog::level::warn);
|
|
||||||
#ifndef NDEBUG
|
|
||||||
logger->set_level(spdlog::level::debug);
|
|
||||||
#else
|
|
||||||
logger->set_level(spdlog::level::info);
|
|
||||||
#endif // !NDEBUG
|
|
||||||
|
|
||||||
spdlog::register_logger(logger);
|
|
||||||
}
|
|
||||||
|
|
||||||
void createLogger(std::string name, std::string filename) { createLogger(name.c_str(), filename.c_str()); }
|
|
||||||
std::shared_ptr<logger> get(const char *name) { return spdlog::get(name); }
|
|
||||||
std::shared_ptr<logger> get(std::string name) { return spdlog::get(name); }
|
|
||||||
} // namespace OatmealUtils
|
|
||||||
@@ -1,20 +1,57 @@
|
|||||||
#ifndef OATMEAL_LOGGER
|
#ifndef OATMEAL_UTILS_LOGGER
|
||||||
#define OATMEAL_LOGGER
|
#define OATMEAL_UTILS_LOGGER
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <spdlog/async_logger.h>
|
||||||
|
#include <spdlog/common.h>
|
||||||
#include <spdlog/spdlog.h>
|
#include <spdlog/spdlog.h>
|
||||||
|
#include "spdlog/async.h"
|
||||||
|
#include "spdlog/sinks/basic_file_sink.h"
|
||||||
|
#include "spdlog/sinks/stdout_color_sinks.h"
|
||||||
|
#include "spdlog/spdlog.h"
|
||||||
#include "string"
|
#include "string"
|
||||||
|
|
||||||
namespace OatmealUtils {
|
namespace OatmealUtils {
|
||||||
|
|
||||||
using logger = spdlog::logger;
|
using logger = spdlog::logger;
|
||||||
|
|
||||||
void initLogging();
|
inline void initLogging() {
|
||||||
void createLogger(const char *name, const char *filename);
|
spdlog::init_thread_pool(8192, 1);
|
||||||
void createLogger(std::string name, std::string filename);
|
spdlog::flush_every(std::chrono::seconds(1));
|
||||||
std::shared_ptr<logger> get(const char *name);
|
}
|
||||||
std::shared_ptr<logger> get(std::string name);
|
|
||||||
|
inline void createLogger(const char *name, const char *filename) {
|
||||||
|
std::vector<spdlog::sink_ptr> sinks{};
|
||||||
|
|
||||||
|
const auto stdoutSink = std::make_shared<spdlog::sinks::stderr_color_sink_mt>();
|
||||||
|
stdoutSink->set_level(spdlog::level::debug);
|
||||||
|
stdoutSink->set_pattern("%^[%D %r %z] [%n] [%l] [thread %t] %v%$");
|
||||||
|
sinks.emplace_back(stdoutSink);
|
||||||
|
|
||||||
|
if (filename != nullptr) {
|
||||||
|
const auto fileSink = std::make_shared<spdlog::sinks::basic_file_sink_mt>(filename);
|
||||||
|
fileSink->set_level(spdlog::level::debug);
|
||||||
|
fileSink->set_pattern("%^[%D %r %z] [%n] [%l] [thread %t] %v%$");
|
||||||
|
sinks.emplace_back(fileSink);
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto logger = std::make_shared<spdlog::async_logger>(
|
||||||
|
name, sinks.begin(), sinks.end(), spdlog::thread_pool(), spdlog::async_overflow_policy::block);
|
||||||
|
|
||||||
|
logger->flush_on(spdlog::level::warn);
|
||||||
|
#ifndef NDEBUG
|
||||||
|
logger->set_level(spdlog::level::debug);
|
||||||
|
#else
|
||||||
|
logger->set_level(spdlog::level::info);
|
||||||
|
#endif // !NDEBUG
|
||||||
|
|
||||||
|
spdlog::register_logger(logger);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void createLogger(std::string name, std::string filename) { createLogger(name.c_str(), filename.c_str()); }
|
||||||
|
inline std::shared_ptr<logger> getLogger(const char *name) { return spdlog::get(name); }
|
||||||
|
inline std::shared_ptr<logger> getLogger(std::string name) { return spdlog::get(name); }
|
||||||
|
|
||||||
} // namespace OatmealUtils
|
} // namespace OatmealUtils
|
||||||
|
|
||||||
#endif // !OATMEAL_LOGGER
|
#endif // !OATMEAL_UTILS_LOGGER
|
||||||
|
|||||||
24
examples/shared/shared/window.h
Normal file
24
examples/shared/shared/window.h
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
#include <cstdint>
|
||||||
|
#include <cstdlib>
|
||||||
|
#include "GLFW/glfw3.h"
|
||||||
|
#include "shared/logger.h"
|
||||||
|
|
||||||
|
namespace OatmealUtils {
|
||||||
|
inline GLFWwindow *initWindow(const char *title, uint32_t width, uint32_t height) {
|
||||||
|
OatmealUtils::createLogger("window", nullptr);
|
||||||
|
OatmealUtils::get("window")->debug("Initializing window backend");
|
||||||
|
glfwInit();
|
||||||
|
glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
|
||||||
|
glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE);
|
||||||
|
OatmealUtils::get("window")->debug("Creating window");
|
||||||
|
GLFWwindow *window = glfwCreateWindow(width, height, title, nullptr, nullptr);
|
||||||
|
if (window == nullptr) {
|
||||||
|
const char *desc;
|
||||||
|
uint32_t code = glfwGetError(&desc);
|
||||||
|
OatmealUtils::get("window")->critical("Failed to create window: ({}) {}", code, desc);
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
|
return window;
|
||||||
|
}
|
||||||
|
} // namespace OatmealUtils
|
||||||
29
examples/shared/window.h
Normal file
29
examples/shared/window.h
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
#ifndef OATMEAL_UTILS_WINDOW
|
||||||
|
#define OATMEAL_UTILS_WINDOW
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
|
#include "GLFW/glfw3.h"
|
||||||
|
#include "shared/logger.h"
|
||||||
|
|
||||||
|
namespace OatmealUtils {
|
||||||
|
inline GLFWwindow *initWindow(const char *title, uint32_t width, uint32_t height) {
|
||||||
|
OatmealUtils::initLogging();
|
||||||
|
OatmealUtils::createLogger("window", nullptr);
|
||||||
|
OatmealUtils::get("window")->debug("Initializing window backend");
|
||||||
|
glfwInit();
|
||||||
|
glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
|
||||||
|
glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE);
|
||||||
|
OatmealUtils::get("window")->debug("Creating window");
|
||||||
|
GLFWwindow *window = glfwCreateWindow(width, height, title, nullptr, nullptr);
|
||||||
|
if (window == nullptr) {
|
||||||
|
const char *desc;
|
||||||
|
uint32_t code = glfwGetError(&desc);
|
||||||
|
OatmealUtils::get("window")->critical("Failed to create window: ({}) {}", code, desc);
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
|
return window;
|
||||||
|
}
|
||||||
|
} // namespace OatmealUtils
|
||||||
|
|
||||||
|
#endif // !OATMEAL_UTILS_WINDOW
|
||||||
Reference in New Issue
Block a user