afegit executable path a les rutes
This commit is contained in:
@@ -1,5 +1,8 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <filesystem>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
// Nombre de la aplicación
|
// Nombre de la aplicación
|
||||||
constexpr const char* APP_NAME = "Shadertoy";
|
constexpr const char* APP_NAME = "Shadertoy";
|
||||||
|
|
||||||
@@ -7,11 +10,55 @@ constexpr const char* APP_NAME = "Shadertoy";
|
|||||||
constexpr int WINDOW_WIDTH = 800;
|
constexpr int WINDOW_WIDTH = 800;
|
||||||
constexpr int WINDOW_HEIGHT = 800;
|
constexpr int WINDOW_HEIGHT = 800;
|
||||||
|
|
||||||
// Rutas
|
// Includes específicos por plataforma para obtener la ruta del ejecutable
|
||||||
#ifdef MACOS_BUNDLE
|
#ifdef _WIN32
|
||||||
constexpr const char* SHADERS_FOLDER = "../Resources/shaders";
|
#include <windows.h>
|
||||||
constexpr const char* DEFAULT_SHADER = "../Resources/shaders/test.frag.glsl";
|
#elif defined(__APPLE__)
|
||||||
|
#include <limits.h>
|
||||||
|
#include <mach-o/dyld.h>
|
||||||
#else
|
#else
|
||||||
constexpr const char* SHADERS_FOLDER = "shaders";
|
#include <limits.h>
|
||||||
constexpr const char* DEFAULT_SHADER = "shaders/test.frag.glsl";
|
#include <unistd.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// Función auxiliar para obtener la ruta del directorio del ejecutable
|
||||||
|
inline std::string getExecutableDirectory() {
|
||||||
|
#ifdef _WIN32
|
||||||
|
char buffer[MAX_PATH];
|
||||||
|
GetModuleFileNameA(NULL, buffer, MAX_PATH);
|
||||||
|
std::filesystem::path exe_path(buffer);
|
||||||
|
return exe_path.parent_path().string();
|
||||||
|
#elif defined(__APPLE__)
|
||||||
|
char buffer[PATH_MAX];
|
||||||
|
uint32_t size = sizeof(buffer);
|
||||||
|
if (_NSGetExecutablePath(buffer, &size) == 0) {
|
||||||
|
std::filesystem::path exe_path(buffer);
|
||||||
|
return exe_path.parent_path().string();
|
||||||
|
}
|
||||||
|
return ".";
|
||||||
|
#else
|
||||||
|
// Linux y otros Unix
|
||||||
|
char buffer[PATH_MAX];
|
||||||
|
ssize_t len = readlink("/proc/self/exe", buffer, sizeof(buffer) - 1);
|
||||||
|
if (len != -1) {
|
||||||
|
buffer[len] = '\0';
|
||||||
|
std::filesystem::path exe_path(buffer);
|
||||||
|
return exe_path.parent_path().string();
|
||||||
|
}
|
||||||
|
return ".";
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
// Función auxiliar para obtener la ruta del directorio de recursos
|
||||||
|
inline std::string getResourcesDirectory() {
|
||||||
|
std::string exe_dir = getExecutableDirectory();
|
||||||
|
|
||||||
|
#ifdef MACOS_BUNDLE
|
||||||
|
// En macOS Bundle: ejecutable está en Contents/MacOS/, recursos en Contents/Resources/
|
||||||
|
std::filesystem::path resources_path = std::filesystem::path(exe_dir) / ".." / "Resources";
|
||||||
|
return resources_path.string();
|
||||||
|
#else
|
||||||
|
// En desarrollo o releases normales: recursos están junto al ejecutable
|
||||||
|
return exe_dir;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|||||||
11
src/main.cpp
11
src/main.cpp
@@ -283,7 +283,7 @@ int main(int argc, char** argv) {
|
|||||||
if (a == "-F" || a == "--fullscreen") { fullscreenFlag = true; continue; }
|
if (a == "-F" || a == "--fullscreen") { fullscreenFlag = true; continue; }
|
||||||
if (shaderPath.empty()) shaderPath = a;
|
if (shaderPath.empty()) shaderPath = a;
|
||||||
}
|
}
|
||||||
if (shaderPath.empty()) shaderPath = DEFAULT_SHADER;
|
if (shaderPath.empty()) shaderPath = "test.frag.glsl";
|
||||||
Options_video.fullscreen = fullscreenFlag;
|
Options_video.fullscreen = fullscreenFlag;
|
||||||
|
|
||||||
// Inicializar SDL3
|
// Inicializar SDL3
|
||||||
@@ -326,12 +326,15 @@ int main(int argc, char** argv) {
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Obtener directorio de recursos
|
||||||
|
std::string resources_dir = getResourcesDirectory();
|
||||||
|
|
||||||
// Determinar carpeta de shaders
|
// Determinar carpeta de shaders
|
||||||
std::filesystem::path shaderFile(shaderPath);
|
std::filesystem::path shaderFile(shaderPath);
|
||||||
if (shaderFile.has_parent_path()) {
|
if (shaderFile.has_parent_path()) {
|
||||||
shaders_directory_ = shaderFile.parent_path();
|
shaders_directory_ = shaderFile.parent_path();
|
||||||
} else {
|
} else {
|
||||||
shaders_directory_ = SHADERS_FOLDER;
|
shaders_directory_ = std::filesystem::path(resources_dir) / "shaders";
|
||||||
}
|
}
|
||||||
|
|
||||||
// Escanear carpeta de shaders
|
// Escanear carpeta de shaders
|
||||||
@@ -358,9 +361,9 @@ int main(int argc, char** argv) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Si no se encuentra, intentar con DEFAULT_SHADER
|
// Si no se encuentra, intentar con shader por defecto (test.frag.glsl)
|
||||||
if (!found_shader) {
|
if (!found_shader) {
|
||||||
std::filesystem::path default_path(DEFAULT_SHADER);
|
std::filesystem::path default_path = std::filesystem::path(resources_dir) / "shaders" / "test.frag.glsl";
|
||||||
for (size_t i = 0; i < shader_list_.size(); ++i) {
|
for (size_t i = 0; i < shader_list_.size(); ++i) {
|
||||||
if (shader_list_[i] == default_path) {
|
if (shader_list_[i] == default_path) {
|
||||||
initial_index = i;
|
initial_index = i;
|
||||||
|
|||||||
Reference in New Issue
Block a user