mirror of https://github.com/sm64pc/sm64pc.git
Added n64Mode and some improvements
This commit is contained in:
parent
9f2dfbceae
commit
235a737d57
|
@ -74,6 +74,9 @@ using namespace std;
|
|||
SDL_Window* window = nullptr;
|
||||
ImGuiIO* io = nullptr;
|
||||
|
||||
#define SM64_WIDTH 320
|
||||
#define SM64_HEIGHT 240
|
||||
|
||||
#ifdef TARGET_SWITCH
|
||||
namespace MoonNX {
|
||||
SwkbdConfig kbd;
|
||||
|
@ -210,10 +213,10 @@ namespace MoonInternal {
|
|||
ImGuiWindowFlags window_flags = ImGuiWindowFlags_MenuBar | ImGuiWindowFlags_NoDocking;
|
||||
const ImGuiViewport* viewport = ImGui::GetMainViewport();
|
||||
ImGui::SetNextWindowPos(viewport->WorkPos);
|
||||
ImGui::SetNextWindowSize(viewport->WorkSize);
|
||||
ImGui::SetNextWindowSize(ImVec2(configWindow.w, configWindow.h));
|
||||
ImGui::SetNextWindowViewport(viewport->ID);
|
||||
window_flags |= ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoMove;
|
||||
window_flags |= ImGuiWindowFlags_NoBringToFrontOnFocus | ImGuiWindowFlags_NoNavFocus;
|
||||
window_flags |= ImGuiWindowFlags_NoBringToFrontOnFocus | ImGuiWindowFlags_NoNavFocus | ImGuiWindowFlags_NoResize;
|
||||
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0.0f, 0.0f));
|
||||
ImGui::Begin("Main - Deck", nullptr, window_flags);
|
||||
|
@ -244,24 +247,34 @@ namespace MoonInternal {
|
|||
if (ImGui::BeginMenu("View")) {
|
||||
ImGui::MenuItem("Moon64", NULL, &configImGui.moon64);
|
||||
ImGui::MenuItem("Textures", NULL, &configImGui.texture_debug);
|
||||
ImGui::MenuItem("N64 Mode", NULL, &configImGui.n64Mode);
|
||||
ImGui::EndMenu();
|
||||
}
|
||||
ImGui::EndMenuBar();
|
||||
}
|
||||
ImGui::End();
|
||||
|
||||
ImGui::SetNextWindowSize(ImVec2(configWindow.w, configWindow.h), ImGuiCond_FirstUseEver);
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0,0));
|
||||
ImGui::Begin("Game", NULL, ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove);
|
||||
ImGui::PushStyleColor(ImGuiCol_ChildBg, ImVec4(0.0f, 0.0f, 0.0f, 1.0f)); // Set window background to red
|
||||
ImGui::Begin("Game", NULL, ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove);
|
||||
ImGui::PopStyleVar();
|
||||
ImGui::PopStyleColor();
|
||||
|
||||
ImVec2 size = ImGui::GetContentRegionAvail();
|
||||
configWindow.internal_w = size.x;
|
||||
configWindow.internal_h = size.y;
|
||||
ImVec2 pos = ImVec2(0, 0);
|
||||
|
||||
configWindow.internal_w = configImGui.n64Mode ? SM64_WIDTH : size.x;
|
||||
configWindow.internal_h = configImGui.n64Mode ? SM64_HEIGHT : size.y;
|
||||
|
||||
if(configImGui.n64Mode) {
|
||||
configWindow.multiplier = 1.0f;
|
||||
int sw = size.y * SM64_WIDTH / SM64_HEIGHT;
|
||||
pos = ImVec2(size.x / 2 - sw / 2, 0);
|
||||
size = ImVec2(sw, size.y);
|
||||
}
|
||||
|
||||
int fbuf = stoi(MoonInternal::getEnvironmentVar("framebuffer"));
|
||||
// ImGui::Image((ImTextureID) fbuf, size);
|
||||
ImGui::ImageRotated((ImTextureID) fbuf, ImVec2(0, 0), size, 180.0f);
|
||||
ImGui::ImageRotated((ImTextureID) fbuf, pos, size, 180.0f);
|
||||
ImGui::End();
|
||||
ImGui::PopStyleVar();
|
||||
|
||||
if (configImGui.moon64){
|
||||
ImGui::PushStyleColor(ImGuiCol_Border, ImVec4(0, 0, 0, 0));
|
||||
|
@ -271,9 +284,12 @@ namespace MoonInternal {
|
|||
ImGui::Text("Status: %.3f ms/frame (%.1f FPS)", 1000.0f / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate);
|
||||
ImGui::Text("Version: " GIT_BRANCH " " GIT_HASH);
|
||||
ImGui::Text("Addons: %d\n", Moon::addons.size());
|
||||
ImGui::Text("Resolution: %.0fx%.0f\n", configWindow.w * configWindow.multiplier, configWindow.h * configWindow.multiplier);
|
||||
ImGui::Text("Internal Resolution:");
|
||||
ImGui::SliderFloat("Mul", &configWindow.multiplier, 0.0f, 10.0f);
|
||||
|
||||
if(!configImGui.n64Mode){
|
||||
ImGui::Text("Resolution: %.0fx%.0f\n", configWindow.w * configWindow.multiplier, configWindow.h * configWindow.multiplier);
|
||||
ImGui::Text("Internal Resolution:");
|
||||
ImGui::SliderFloat("Mul", &configWindow.multiplier, 0.0f, 4.0f);
|
||||
}
|
||||
ImGui::End();
|
||||
ImGui::PopStyleColor();
|
||||
}
|
||||
|
|
|
@ -35,7 +35,7 @@ namespace MoonInternal {
|
|||
#ifdef TARGET_SWITCH
|
||||
hidInitializeTouchScreen();
|
||||
#endif
|
||||
Moon::registerHookListener({.hookName = WINDOW_API_START_FRAME, .callback = [](HookCall call){
|
||||
Moon::registerHookListener({.hookName = WINDOW_API_START_FRAME, .callback = [&](HookCall call){
|
||||
#ifndef TARGET_SWITCH
|
||||
mstate = SDL_GetMouseState(&mouseX, &mouseY);
|
||||
#else
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
using namespace std;
|
||||
|
||||
map<string, vector<HookFunc*>> listeners;
|
||||
map<string, vector<HookFunc>> listeners;
|
||||
|
||||
namespace Moon {
|
||||
void registerHookListener(HookListener listener){
|
||||
|
@ -19,7 +19,7 @@ namespace MoonInternal {
|
|||
bool handleHook(HookCall call){
|
||||
string hookName = string(call.name);
|
||||
for(int l = 0; l < listeners[hookName].size(); l++){
|
||||
(*listeners[hookName][l])(call);
|
||||
(listeners[hookName][l])(call);
|
||||
}
|
||||
return call.cancelled;
|
||||
}
|
||||
|
|
|
@ -36,6 +36,7 @@ struct HookParameter {
|
|||
|
||||
#ifdef __cplusplus
|
||||
|
||||
#include <functional>
|
||||
#include <string>
|
||||
#include <map>
|
||||
|
||||
|
@ -46,10 +47,10 @@ struct HookCall {
|
|||
bool cancelled = false;
|
||||
};
|
||||
|
||||
typedef void HookFunc(HookCall call);
|
||||
typedef std::function<void(HookCall)> HookFunc;
|
||||
struct HookListener {
|
||||
std::string hookName;
|
||||
HookFunc *callback;
|
||||
HookFunc callback;
|
||||
int priority = 0;
|
||||
};
|
||||
|
||||
|
|
|
@ -55,7 +55,7 @@ namespace Moon {
|
|||
|
||||
TextureData* tex = textureMap.find(texturePath) != textureMap.end() ? textureMap.find(texturePath)->second : nullptr;
|
||||
// if(tex != nullptr)
|
||||
// if(!strcmp( (const char*) tex->texture_addr, "actors/mario/mario_metal.rgba16") || !strcmp( (const char*) tex->texture_addr, "actors/mario_cap/mario_cap_metal.rgba16"))
|
||||
// if(!strcmp( (const char*) tex->texture_addr, "textures/skyboxes/water.rgba16") || !strcmp( (const char*) tex->texture_addr, "actors/mario_cap/mario_cap_metal.rgba16"))
|
||||
// tex->texture_id = stoi(MoonInternal::getEnvironmentVar("framebuffer"));
|
||||
return tex;
|
||||
}
|
||||
|
|
|
@ -26,6 +26,8 @@ void moon_setup(char *state){
|
|||
MoonInternal::setupLanguageEngine(string(state));
|
||||
MoonInternal::setupIOModuleEngine(string(state));
|
||||
MoonInternal::setupImGuiModule(string(state));
|
||||
// MoonRenderer::setupSkyboxRenderer(string(state));
|
||||
// MoonInternal::setupSoundModule(string(state));
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
@ -0,0 +1,155 @@
|
|||
#ifdef UNUSED_FEAT
|
||||
#ifndef CAMERA_H
|
||||
#define CAMERA_H
|
||||
|
||||
#ifdef __MINGW32__
|
||||
# define FOR_WINDOWS 1
|
||||
#else
|
||||
# define FOR_WINDOWS 0
|
||||
#endif
|
||||
|
||||
#if FOR_WINDOWS || defined(OSX_BUILD)
|
||||
# define GLEW_STATIC
|
||||
# include <GL/glew.h>
|
||||
#endif
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
|
||||
#ifdef TARGET_SWITCH
|
||||
#include "glad/glad.h"
|
||||
#else
|
||||
#define GL_GLEXT_PROTOTYPES 1
|
||||
#ifdef USE_GLES
|
||||
# include <SDL2/SDL_opengles2.h>
|
||||
#else
|
||||
# include <SDL2/SDL_opengl.h>
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
#include <glm/gtc/matrix_transform.hpp>
|
||||
|
||||
#include <vector>
|
||||
|
||||
// Defines several possible options for camera movement. Used as abstraction to stay away from window-system specific input methods
|
||||
enum Camera_Movement {
|
||||
FORWARD,
|
||||
BACKWARD,
|
||||
LEFT,
|
||||
RIGHT
|
||||
};
|
||||
|
||||
// Default camera values
|
||||
const float YAW = -90.0f;
|
||||
const float PITCH = 0.0f;
|
||||
const float SPEED = 2.5f;
|
||||
const float SENSITIVITY = 0.1f;
|
||||
const float ZOOM = 45.0f;
|
||||
|
||||
|
||||
// An abstract camera class that processes input and calculates the corresponding Euler Angles, Vectors and Matrices for use in OpenGL
|
||||
class Camera
|
||||
{
|
||||
public:
|
||||
// camera Attributes
|
||||
glm::vec3 Position;
|
||||
glm::vec3 Front;
|
||||
glm::vec3 Up;
|
||||
glm::vec3 Right;
|
||||
glm::vec3 WorldUp;
|
||||
// euler Angles
|
||||
float Yaw;
|
||||
float Pitch;
|
||||
// camera options
|
||||
float MovementSpeed;
|
||||
float MouseSensitivity;
|
||||
float Zoom;
|
||||
|
||||
// constructor with vectors
|
||||
Camera(glm::vec3 position = glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3 up = glm::vec3(0.0f, 1.0f, 0.0f), float yaw = YAW, float pitch = PITCH) : Front(glm::vec3(0.0f, 0.0f, -1.0f)), MovementSpeed(SPEED), MouseSensitivity(SENSITIVITY), Zoom(ZOOM)
|
||||
{
|
||||
Position = position;
|
||||
WorldUp = up;
|
||||
Yaw = yaw;
|
||||
Pitch = pitch;
|
||||
updateCameraVectors();
|
||||
}
|
||||
// constructor with scalar values
|
||||
Camera(float posX, float posY, float posZ, float upX, float upY, float upZ, float yaw, float pitch) : Front(glm::vec3(0.0f, 0.0f, -1.0f)), MovementSpeed(SPEED), MouseSensitivity(SENSITIVITY), Zoom(ZOOM)
|
||||
{
|
||||
Position = glm::vec3(posX, posY, posZ);
|
||||
WorldUp = glm::vec3(upX, upY, upZ);
|
||||
Yaw = yaw;
|
||||
Pitch = pitch;
|
||||
updateCameraVectors();
|
||||
}
|
||||
|
||||
// returns the view matrix calculated using Euler Angles and the LookAt Matrix
|
||||
glm::mat4 GetViewMatrix()
|
||||
{
|
||||
return glm::lookAt(Position, Position + Front, Up);
|
||||
}
|
||||
|
||||
// processes input received from any keyboard-like input system. Accepts input parameter in the form of camera defined ENUM (to abstract it from windowing systems)
|
||||
void ProcessKeyboard(Camera_Movement direction, float deltaTime)
|
||||
{
|
||||
float velocity = MovementSpeed * deltaTime;
|
||||
if (direction == FORWARD)
|
||||
Position += Front * velocity;
|
||||
if (direction == BACKWARD)
|
||||
Position -= Front * velocity;
|
||||
if (direction == LEFT)
|
||||
Position -= Right * velocity;
|
||||
if (direction == RIGHT)
|
||||
Position += Right * velocity;
|
||||
}
|
||||
|
||||
// processes input received from a mouse input system. Expects the offset value in both the x and y direction.
|
||||
void ProcessMouseMovement(float xoffset, float yoffset, GLboolean constrainPitch = true)
|
||||
{
|
||||
xoffset *= MouseSensitivity;
|
||||
yoffset *= MouseSensitivity;
|
||||
|
||||
Yaw += xoffset;
|
||||
Pitch += yoffset;
|
||||
|
||||
// make sure that when pitch is out of bounds, screen doesn't get flipped
|
||||
if (constrainPitch)
|
||||
{
|
||||
if (Pitch > 89.0f)
|
||||
Pitch = 89.0f;
|
||||
if (Pitch < -89.0f)
|
||||
Pitch = -89.0f;
|
||||
}
|
||||
|
||||
// update Front, Right and Up Vectors using the updated Euler angles
|
||||
updateCameraVectors();
|
||||
}
|
||||
|
||||
// processes input received from a mouse scroll-wheel event. Only requires input on the vertical wheel-axis
|
||||
void ProcessMouseScroll(float yoffset)
|
||||
{
|
||||
Zoom -= (float)yoffset;
|
||||
if (Zoom < 1.0f)
|
||||
Zoom = 1.0f;
|
||||
if (Zoom > 45.0f)
|
||||
Zoom = 45.0f;
|
||||
}
|
||||
|
||||
private:
|
||||
// calculates the front vector from the Camera's (updated) Euler Angles
|
||||
void updateCameraVectors()
|
||||
{
|
||||
// calculate the new Front vector
|
||||
glm::vec3 front;
|
||||
front.x = cos(glm::radians(Yaw)) * cos(glm::radians(Pitch));
|
||||
front.y = sin(glm::radians(Pitch));
|
||||
front.z = sin(glm::radians(Yaw)) * cos(glm::radians(Pitch));
|
||||
Front = glm::normalize(front);
|
||||
// also re-calculate the Right and Up vector
|
||||
Right = glm::normalize(glm::cross(Front, WorldUp)); // normalize the vectors, because their length gets closer to 0 the more you look up or down which results in slower movement.
|
||||
Up = glm::normalize(glm::cross(Right, Front));
|
||||
}
|
||||
};
|
||||
#endif
|
||||
#endif
|
|
@ -0,0 +1,224 @@
|
|||
#ifdef UNUSED_FEAT
|
||||
#ifndef SHADER_H
|
||||
#define SHADER_H
|
||||
|
||||
#ifdef __MINGW32__
|
||||
# define FOR_WINDOWS 1
|
||||
#else
|
||||
# define FOR_WINDOWS 0
|
||||
#endif
|
||||
|
||||
#if FOR_WINDOWS || defined(OSX_BUILD)
|
||||
# define GLEW_STATIC
|
||||
# include <GL/glew.h>
|
||||
#endif
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
|
||||
#ifdef TARGET_SWITCH
|
||||
#include "glad/glad.h"
|
||||
#else
|
||||
#define GL_GLEXT_PROTOTYPES 1
|
||||
#ifdef USE_GLES
|
||||
# include <SDL2/SDL_opengles2.h>
|
||||
#else
|
||||
# include <SDL2/SDL_opengl.h>
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
|
||||
#include <string>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <iostream>
|
||||
|
||||
class Shader
|
||||
{
|
||||
public:
|
||||
unsigned int ID;
|
||||
const char* vertexPath;
|
||||
const char* fragmentPath;
|
||||
const char* geometryPath;
|
||||
// constructor generates the shader on the fly
|
||||
// ------------------------------------------------------------------------
|
||||
Shader(const char* vertexPath, const char* fragmentPath, const char* geometryPath = nullptr) {
|
||||
// 1. retrieve the vertex/fragment source code from filePath
|
||||
this->vertexPath = vertexPath;
|
||||
this->fragmentPath = fragmentPath;
|
||||
this->geometryPath = geometryPath;
|
||||
}
|
||||
|
||||
void load(){
|
||||
std::string vertexCode;
|
||||
std::string fragmentCode;
|
||||
std::string geometryCode;
|
||||
std::ifstream vShaderFile;
|
||||
std::ifstream fShaderFile;
|
||||
std::ifstream gShaderFile;
|
||||
// ensure ifstream objects can throw exceptions:
|
||||
vShaderFile.exceptions (std::ifstream::failbit | std::ifstream::badbit);
|
||||
fShaderFile.exceptions (std::ifstream::failbit | std::ifstream::badbit);
|
||||
gShaderFile.exceptions (std::ifstream::failbit | std::ifstream::badbit);
|
||||
try
|
||||
{
|
||||
// open files
|
||||
vShaderFile.open(vertexPath);
|
||||
fShaderFile.open(fragmentPath);
|
||||
std::stringstream vShaderStream, fShaderStream;
|
||||
// read file's buffer contents into streams
|
||||
vShaderStream << vShaderFile.rdbuf();
|
||||
fShaderStream << fShaderFile.rdbuf();
|
||||
// close file handlers
|
||||
vShaderFile.close();
|
||||
fShaderFile.close();
|
||||
// convert stream into string
|
||||
vertexCode = vShaderStream.str();
|
||||
fragmentCode = fShaderStream.str();
|
||||
// if geometry shader path is present, also load a geometry shader
|
||||
if(geometryPath != nullptr)
|
||||
{
|
||||
gShaderFile.open(geometryPath);
|
||||
std::stringstream gShaderStream;
|
||||
gShaderStream << gShaderFile.rdbuf();
|
||||
gShaderFile.close();
|
||||
geometryCode = gShaderStream.str();
|
||||
}
|
||||
}
|
||||
catch (std::ifstream::failure& e)
|
||||
{
|
||||
std::cout << "ERROR::SHADER::FILE_NOT_SUCCESFULLY_READ" << std::endl;
|
||||
}
|
||||
const char* vShaderCode = vertexCode.c_str();
|
||||
const char * fShaderCode = fragmentCode.c_str();
|
||||
// 2. compile shaders
|
||||
unsigned int vertex, fragment;
|
||||
// vertex shader
|
||||
vertex = glCreateShader(GL_VERTEX_SHADER);
|
||||
glShaderSource(vertex, 1, &vShaderCode, NULL);
|
||||
glCompileShader(vertex);
|
||||
checkCompileErrors(vertex, "VERTEX");
|
||||
// fragment Shader
|
||||
fragment = glCreateShader(GL_FRAGMENT_SHADER);
|
||||
glShaderSource(fragment, 1, &fShaderCode, NULL);
|
||||
glCompileShader(fragment);
|
||||
checkCompileErrors(fragment, "FRAGMENT");
|
||||
// if geometry shader is given, compile geometry shader
|
||||
unsigned int geometry;
|
||||
if(geometryPath != nullptr)
|
||||
{
|
||||
const char * gShaderCode = geometryCode.c_str();
|
||||
geometry = glCreateShader(GL_GEOMETRY_SHADER);
|
||||
glShaderSource(geometry, 1, &gShaderCode, NULL);
|
||||
glCompileShader(geometry);
|
||||
checkCompileErrors(geometry, "GEOMETRY");
|
||||
}
|
||||
// shader Program
|
||||
ID = glCreateProgram();
|
||||
glAttachShader(ID, vertex);
|
||||
glAttachShader(ID, fragment);
|
||||
if(geometryPath != nullptr)
|
||||
glAttachShader(ID, geometry);
|
||||
glLinkProgram(ID);
|
||||
checkCompileErrors(ID, "PROGRAM");
|
||||
// delete the shaders as they're linked into our program now and no longer necessery
|
||||
glDeleteShader(vertex);
|
||||
glDeleteShader(fragment);
|
||||
if(geometryPath != nullptr)
|
||||
glDeleteShader(geometry);
|
||||
}
|
||||
|
||||
// activate the shader
|
||||
// ------------------------------------------------------------------------
|
||||
void use()
|
||||
{
|
||||
glUseProgram(ID);
|
||||
}
|
||||
// utility uniform functions
|
||||
// ------------------------------------------------------------------------
|
||||
void setBool(const std::string &name, bool value) const
|
||||
{
|
||||
glUniform1i(glGetUniformLocation(ID, name.c_str()), (int)value);
|
||||
}
|
||||
// ------------------------------------------------------------------------
|
||||
void setInt(const std::string &name, int value) const
|
||||
{
|
||||
glUniform1i(glGetUniformLocation(ID, name.c_str()), value);
|
||||
}
|
||||
// ------------------------------------------------------------------------
|
||||
void setFloat(const std::string &name, float value) const
|
||||
{
|
||||
glUniform1f(glGetUniformLocation(ID, name.c_str()), value);
|
||||
}
|
||||
// ------------------------------------------------------------------------
|
||||
void setVec2(const std::string &name, const glm::vec2 &value) const
|
||||
{
|
||||
glUniform2fv(glGetUniformLocation(ID, name.c_str()), 1, &value[0]);
|
||||
}
|
||||
void setVec2(const std::string &name, float x, float y) const
|
||||
{
|
||||
glUniform2f(glGetUniformLocation(ID, name.c_str()), x, y);
|
||||
}
|
||||
// ------------------------------------------------------------------------
|
||||
void setVec3(const std::string &name, const glm::vec3 &value) const
|
||||
{
|
||||
glUniform3fv(glGetUniformLocation(ID, name.c_str()), 1, &value[0]);
|
||||
}
|
||||
void setVec3(const std::string &name, float x, float y, float z) const
|
||||
{
|
||||
glUniform3f(glGetUniformLocation(ID, name.c_str()), x, y, z);
|
||||
}
|
||||
// ------------------------------------------------------------------------
|
||||
void setVec4(const std::string &name, const glm::vec4 &value) const
|
||||
{
|
||||
glUniform4fv(glGetUniformLocation(ID, name.c_str()), 1, &value[0]);
|
||||
}
|
||||
void setVec4(const std::string &name, float x, float y, float z, float w)
|
||||
{
|
||||
glUniform4f(glGetUniformLocation(ID, name.c_str()), x, y, z, w);
|
||||
}
|
||||
// ------------------------------------------------------------------------
|
||||
void setMat2(const std::string &name, const glm::mat2 &mat) const
|
||||
{
|
||||
glUniformMatrix2fv(glGetUniformLocation(ID, name.c_str()), 1, GL_FALSE, &mat[0][0]);
|
||||
}
|
||||
// ------------------------------------------------------------------------
|
||||
void setMat3(const std::string &name, const glm::mat3 &mat) const
|
||||
{
|
||||
glUniformMatrix3fv(glGetUniformLocation(ID, name.c_str()), 1, GL_FALSE, &mat[0][0]);
|
||||
}
|
||||
// ------------------------------------------------------------------------
|
||||
void setMat4(const std::string &name, const glm::mat4 &mat) const
|
||||
{
|
||||
glUniformMatrix4fv(glGetUniformLocation(ID, name.c_str()), 1, GL_FALSE, &mat[0][0]);
|
||||
}
|
||||
|
||||
private:
|
||||
// utility function for checking shader compilation/linking errors.
|
||||
// ------------------------------------------------------------------------
|
||||
void checkCompileErrors(GLuint shader, std::string type)
|
||||
{
|
||||
GLint success;
|
||||
GLchar infoLog[1024];
|
||||
if(type != "PROGRAM")
|
||||
{
|
||||
glGetShaderiv(shader, GL_COMPILE_STATUS, &success);
|
||||
if(!success)
|
||||
{
|
||||
glGetShaderInfoLog(shader, 1024, NULL, infoLog);
|
||||
std::cout << "ERROR::SHADER_COMPILATION_ERROR of type: " << type << "\n" << infoLog << "\n -- --------------------------------------------------- -- " << std::endl;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
glGetProgramiv(shader, GL_LINK_STATUS, &success);
|
||||
if(!success)
|
||||
{
|
||||
glGetProgramInfoLog(shader, 1024, NULL, infoLog);
|
||||
std::cout << "ERROR::PROGRAM_LINKING_ERROR of type: " << type << "\n" << infoLog << "\n -- --------------------------------------------------- -- " << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
#endif
|
||||
#endif
|
|
@ -0,0 +1,11 @@
|
|||
#version 330 core
|
||||
out vec4 FragColor;
|
||||
|
||||
in vec2 TexCoords;
|
||||
|
||||
uniform sampler2D screenTexture;
|
||||
|
||||
void main() {
|
||||
vec3 col = texture(screenTexture, TexCoords).rgb;
|
||||
FragColor = vec4(col, 1.0);
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
#version 330 core
|
||||
layout (location = 0) in vec2 aPos;
|
||||
layout (location = 1) in vec2 aTexCoords;
|
||||
|
||||
out vec2 TexCoords;
|
||||
|
||||
void main() {
|
||||
TexCoords = aTexCoords;
|
||||
gl_Position = vec4(aPos.x, aPos.y, -1, 1.0);
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
#version 330 core
|
||||
out vec4 FragColor;
|
||||
|
||||
in vec2 TexCoords;
|
||||
|
||||
uniform sampler2D texture1;
|
||||
|
||||
void main() {
|
||||
FragColor = texture(texture1, TexCoords);
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
#version 330 core
|
||||
layout (location = 0) in vec3 aPos;
|
||||
layout (location = 1) in vec2 aTexCoords;
|
||||
|
||||
out vec2 TexCoords;
|
||||
|
||||
uniform mat4 model;
|
||||
uniform mat4 view;
|
||||
uniform mat4 projection;
|
||||
|
||||
void main()
|
||||
{
|
||||
TexCoords = aTexCoords;
|
||||
gl_Position = projection * view * model * vec4(aPos, 1.0);
|
||||
}
|
|
@ -0,0 +1,92 @@
|
|||
#ifdef UNUSED_FEAT
|
||||
#include "skybox.h"
|
||||
#include "moon/mod-engine/hooks/hook.h"
|
||||
|
||||
#ifdef __MINGW32__
|
||||
# define FOR_WINDOWS 1
|
||||
#else
|
||||
# define FOR_WINDOWS 0
|
||||
#endif
|
||||
|
||||
#if FOR_WINDOWS || defined(OSX_BUILD)
|
||||
# define GLEW_STATIC
|
||||
# include <GL/glew.h>
|
||||
#endif
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
|
||||
#ifdef TARGET_SWITCH
|
||||
#include "glad/glad.h"
|
||||
#else
|
||||
#define GL_GLEXT_PROTOTYPES 1
|
||||
#ifdef USE_GLES
|
||||
# include <SDL2/SDL_opengles2.h>
|
||||
#else
|
||||
# include <SDL2/SDL_opengl.h>
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#include "moon/utils/moon-env.h"
|
||||
#include "./shader.h"
|
||||
#include "./camera.h"
|
||||
#include "pc/configfile.h"
|
||||
|
||||
#include <string>
|
||||
using namespace std;
|
||||
|
||||
float quadVertices[] = {
|
||||
// positions // texture Coords
|
||||
5.0f, -0.5f, 5.0f, 2.0f, 0.0f,
|
||||
-5.0f, -0.5f, 5.0f, 0.0f, 0.0f,
|
||||
-5.0f, -0.5f, -5.0f, 0.0f, 2.0f,
|
||||
|
||||
5.0f, -0.5f, 5.0f, 2.0f, 0.0f,
|
||||
-5.0f, -0.5f, -5.0f, 0.0f, 2.0f,
|
||||
5.0f, -0.5f, -5.0f, 2.0f, 2.0f
|
||||
};
|
||||
|
||||
unsigned int quadVAO, quadVBO;
|
||||
Shader screen("src/moon/renderer/shaders/screen.vs", "src/moon/renderer/shaders/screen.fs");
|
||||
Shader screenShader("src/moon/renderer/shaders/framebuffer.vs", "src/moon/renderer/shaders/framebuffer.fs");
|
||||
Camera camera(glm::vec3(0.0f, 0.0f, 3.0f));
|
||||
|
||||
namespace MoonRenderer {
|
||||
void setupSkyboxRenderer(string status){
|
||||
if(status == "PreStartup"){
|
||||
Moon::registerHookListener({.hookName = GFX_INIT, .callback = [](HookCall call){
|
||||
glGenVertexArrays(1, &quadVAO);
|
||||
glGenBuffers(1, &quadVBO);
|
||||
glBindVertexArray(quadVAO);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, quadVBO);
|
||||
glBufferData(GL_ARRAY_BUFFER, sizeof(quadVertices), &quadVertices, GL_STATIC_DRAW);
|
||||
glEnableVertexAttribArray(0);
|
||||
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), (void*)0);
|
||||
glEnableVertexAttribArray(1);
|
||||
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), (void*)(2 * sizeof(float)));
|
||||
screen.load();
|
||||
screenShader.load();
|
||||
|
||||
screen.use();
|
||||
screen.setInt("texture1", 0);
|
||||
|
||||
screenShader.use();
|
||||
screenShader.setInt("screenTexture", stoi(MoonInternal::getEnvironmentVar("framebuffer")));
|
||||
}});
|
||||
Moon::registerHookListener({.hookName = GFX_PRE_START_FRAME, .callback = [](HookCall call){
|
||||
screen.use();
|
||||
glm::mat4 model = glm::mat4(1.0f);
|
||||
glm::mat4 view = camera.GetViewMatrix();
|
||||
glm::mat4 projection = glm::perspective(glm::radians(camera.Zoom), (float)configWindow.internal_w / (float)configWindow.internal_h, 0.1f, 100.0f);
|
||||
screen.setMat4("view", view);
|
||||
screen.setMat4("projection", projection);
|
||||
|
||||
screenShader.use();
|
||||
glBindVertexArray(quadVAO);
|
||||
glBindTexture(GL_TEXTURE_2D, stoi(MoonInternal::getEnvironmentVar("framebuffer")));
|
||||
glDrawArrays(GL_TRIANGLES, 0, 6);
|
||||
glUseProgram(0);
|
||||
}});
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
|
@ -0,0 +1,12 @@
|
|||
#ifdef UNUSED_FEAT
|
||||
#ifndef MoonSkyboxRenderer
|
||||
#define MoonSkyboxRenderer
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace MoonRenderer {
|
||||
void setupSkyboxRenderer(std::string status);
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
|
@ -0,0 +1,51 @@
|
|||
#ifdef UNUSED_FEAT
|
||||
#include "sound.h"
|
||||
#include "moon/mod-engine/hooks/hook.h"
|
||||
|
||||
#include "moon/utils/moon-env.h"
|
||||
#include "pc/configfile.h"
|
||||
#include "moon/libs/audeo/audeo/audeo.hpp"
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
using namespace std;
|
||||
|
||||
namespace MoonInternal {
|
||||
void setupSoundModule(string status){
|
||||
if(status == "PreStartup"){
|
||||
audeo::SoundSource source1;
|
||||
audeo::SoundSource source2;
|
||||
audeo::SoundSource source3;
|
||||
|
||||
Moon::registerHookListener({.hookName = WINDOW_API_INIT, .callback = [&](HookCall call){
|
||||
audeo::init();
|
||||
source1 = audeo::load_source("/home/alex/Videos/15.wav", audeo::AudioType::Effect);
|
||||
source2 = audeo::load_source("/home/alex/Videos/15.wav", audeo::AudioType::Effect);
|
||||
source3 = audeo::load_source("/home/alex/Videos/15.wav", audeo::AudioType::Effect);
|
||||
}});
|
||||
|
||||
Moon::registerHookListener({.hookName = WINDOW_API_HANDLE_EVENTS, .callback = [&](HookCall call){
|
||||
SDL_Event* ev = (SDL_Event*) call.baseArgs["event"];
|
||||
switch (ev->type){
|
||||
case SDL_KEYDOWN:
|
||||
if(ev->key.keysym.sym == SDLK_i){
|
||||
cout << "Playing owo" << endl;
|
||||
audeo::Sound effect = audeo::play_sound(source1);
|
||||
}
|
||||
if(ev->key.keysym.sym == SDLK_o){
|
||||
cout << "Playing owo" << endl;
|
||||
audeo::Sound effect = audeo::play_sound(source2);
|
||||
}
|
||||
if(ev->key.keysym.sym == SDLK_p){
|
||||
cout << "Playing owo" << endl;
|
||||
audeo::Sound effect = audeo::play_sound(source3);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}});
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
|
@ -0,0 +1,12 @@
|
|||
#ifdef UNUSED_FEAT
|
||||
#ifndef MoonSoundEngine
|
||||
#define MoonSoundEngine
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace MoonInternal {
|
||||
void setupSoundModule(std::string status);
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
|
@ -57,7 +57,8 @@ ConfigWindow configWindow = {
|
|||
|
||||
ImGuiConfig configImGui = {
|
||||
.moon64 = false,
|
||||
.texture_debug = false
|
||||
.texture_debug = false,
|
||||
.n64Mode = false
|
||||
};
|
||||
|
||||
unsigned int configLanguage = 0;
|
||||
|
@ -176,6 +177,7 @@ static const struct ConfigOption options[] = {
|
|||
|
||||
{.name = "moon64_win", .type = CONFIG_TYPE_BOOL, .boolValue = &configImGui.moon64},
|
||||
{.name = "texture_debug_win", .type = CONFIG_TYPE_BOOL, .boolValue = &configImGui.texture_debug},
|
||||
{.name = "n64Mode", .type = CONFIG_TYPE_BOOL, .boolValue = &configImGui.n64Mode}
|
||||
};
|
||||
|
||||
// Reads an entire line from a file (excluding the newline character) and returns an allocated string
|
||||
|
|
|
@ -24,6 +24,7 @@ typedef struct {
|
|||
typedef struct {
|
||||
bool moon64;
|
||||
bool texture_debug;
|
||||
bool n64Mode;
|
||||
} ImGuiConfig;
|
||||
|
||||
extern ConfigWindow configWindow;
|
||||
|
|
Loading…
Reference in New Issue