This commit is contained in:
2024-01-01 18:59:12 -05:00
parent 879fb026ff
commit 3d3a783d73
9 changed files with 52 additions and 368 deletions

View File

@@ -19,7 +19,6 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
# Enable Package Managers
include(cmake/CPM.cmake)
include(cmake/sdl.cmake)
include(cmake/glm.cmake)
file(GLOB_RECURSE HEADERS "include/*")
@@ -42,7 +41,7 @@ CPMAddPackage(
CPMAddPackage(
NAME ReWindowLibrary
URL https://git.redacted.cc/Redacted/ReWindow/archive/vA0.3.zip
URL https://git.redacted.cc/Redacted/ReWindow/archive/vA0.8.1.zip
)
if(ReWindowLibrary_ADDED)
@@ -50,15 +49,11 @@ if(ReWindowLibrary_ADDED)
add_library(ReWindow SHARED IMPORTED)
set_target_properties(ReWindow PROPERTIES IMPORTED_LOCATION "${ReWindowLibrary_LIBRARIES}")
endif()
find_package(SDL2 REQUIRED)
include_directories(${SDL2_INCLUDE_DIRS})
include_directories(${REWINDOW_INCLUDE_DIRS})
#find_package(SDL2_image REQUIRED)
#include_directories(${SDL2_IMAGE_INCLUDE_DIRS})
find_package(OpenGL REQUIRED)
include_directories({$OPENGL_INCLUDE_DIRS})
find_package(glm REQUIRED)
find_package(ReWindowLibrary REQUIRED)
target_link_libraries(SDL3D PUBLIC glm::glm SDL2::SDL2 ReWindowLibrary ${OPENGL_LIBRARIES})
target_link_libraries(SDL3D PUBLIC glm::glm ReWindowLibrary X11 ${OPENGL_LIBRARIES})
add_executable(SDL3D_Demo "include/demo/main.cpp")
target_link_libraries(SDL3D_Demo PUBLIC SDL3D ReWindowLibrary)
target_link_libraries(SDL3D_Demo PUBLIC SDL3D X11 ReWindowLibrary)

View File

@@ -1,163 +0,0 @@
# Locate SDL2 library
# This module defines
# SDL2_LIBRARY, the name of the library to link against
# SDL2_FOUND, if false, do not try to link to SDL2
# SDL2_INCLUDE_DIR, where to find SDL.h
#
# This module responds to the the flag:
# SDL2_BUILDING_LIBRARY
# If this is defined, then no SDL2main will be linked in because
# only applications need main().
# Otherwise, it is assumed you are building an application and this
# module will attempt to locate and set the the proper link flags
# as part of the returned SDL2_LIBRARY variable.
#
# Don't forget to include SDLmain.h and SDLmain.m your project for the
# OS X framework based version. (Other versions link to -lSDL2main which
# this module will try to find on your behalf.) Also for OS X, this
# module will automatically add the -framework Cocoa on your behalf.
#
#
# Additional Note: If you see an empty SDL2_LIBRARY_TEMP in your configuration
# and no SDL2_LIBRARY, it means CMake did not find your SDL2 library
# (SDL2.dll, libsdl2.so, SDL2.framework, etc).
# Set SDL2_LIBRARY_TEMP to point to your SDL2 library, and configure again.
# Similarly, if you see an empty SDL2MAIN_LIBRARY, you should set this value
# as appropriate. These values are used to generate the final SDL2_LIBRARY
# variable, but when these values are unset, SDL2_LIBRARY does not get created.
#
#
# $SDL2DIR is an environment variable that would
# correspond to the ./configure --prefix=$SDL2DIR
# used in building SDL2.
# l.e.galup 9-20-02
#
# Modified by Eric Wing.
# Added code to assist with automated building by using environmental variables
# and providing a more controlled/consistent search behavior.
# Added new modifications to recognize OS X frameworks and
# additional Unix paths (FreeBSD, etc).
# Also corrected the header search path to follow "proper" SDL guidelines.
# Added a search for SDL2main which is needed by some platforms.
# Added a search for threads which is needed by some platforms.
# Added needed compile switches for MinGW.
#
# On OSX, this will prefer the Framework version (if found) over others.
# People will have to manually change the cache values of
# SDL2_LIBRARY to override this selection or set the CMake environment
# CMAKE_INCLUDE_PATH to modify the search paths.
#
# Note that the header path has changed from SDL2/SDL.h to just SDL.h
# This needed to change because "proper" SDL convention
# is #include "SDL.h", not <SDL2/SDL.h>. This is done for portability
# reasons because not all systems place things in SDL2/ (see FreeBSD).
#=============================================================================
# Copyright 2003-2009 Kitware, Inc.
#
# Distributed under the OSI-approved BSD License (the "License");
# see accompanying file Copyright.txt for details.
#
# This software is distributed WITHOUT ANY WARRANTY; without even the
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the License for more information.
#=============================================================================
# (To distribute this file outside of CMake, substitute the full
# License text for the above reference.)
SET(SDL2_SEARCH_PATHS
~/Library/Frameworks
/Library/Frameworks
/usr/local
/usr
/sw # Fink
/opt/local # DarwinPorts
/opt/csw # Blastwave
/opt
)
FIND_PATH(SDL2_INCLUDE_DIR SDL.h
HINTS
$ENV{SDL2DIR}
PATH_SUFFIXES include/SDL2 include
PATHS ${SDL2_SEARCH_PATHS}
)
FIND_LIBRARY(SDL2_LIBRARY_TEMP
NAMES SDL2
HINTS
$ENV{SDL2DIR}
PATH_SUFFIXES lib64 lib
PATHS ${SDL2_SEARCH_PATHS}
)
IF(NOT SDL2_BUILDING_LIBRARY)
IF(NOT ${SDL2_INCLUDE_DIR} MATCHES ".framework")
# Non-OS X framework versions expect you to also dynamically link to
# SDL2main. This is mainly for Windows and OS X. Other (Unix) platforms
# seem to provide SDL2main for compatibility even though they don't
# necessarily need it.
FIND_LIBRARY(SDL2MAIN_LIBRARY
NAMES SDL2main
HINTS
$ENV{SDL2DIR}
PATH_SUFFIXES lib64 lib
PATHS ${SDL2_SEARCH_PATHS}
)
ENDIF(NOT ${SDL2_INCLUDE_DIR} MATCHES ".framework")
ENDIF(NOT SDL2_BUILDING_LIBRARY)
# SDL2 may require threads on your system.
# The Apple build may not need an explicit flag because one of the
# frameworks may already provide it.
# But for non-OSX systems, I will use the CMake Threads package.
IF(NOT APPLE)
FIND_PACKAGE(Threads)
ENDIF(NOT APPLE)
# MinGW needs an additional library, mwindows
# It's total link flags should look like -lmingw32 -lSDL2main -lSDL2 -lmwindows
# (Actually on second look, I think it only needs one of the m* libraries.)
IF(MINGW)
SET(MINGW32_LIBRARY mingw32 CACHE STRING "mwindows for MinGW")
ENDIF(MINGW)
IF(SDL2_LIBRARY_TEMP)
# For SDL2main
IF(NOT SDL2_BUILDING_LIBRARY)
IF(SDL2MAIN_LIBRARY)
SET(SDL2_LIBRARY_TEMP ${SDL2MAIN_LIBRARY} ${SDL2_LIBRARY_TEMP})
ENDIF(SDL2MAIN_LIBRARY)
ENDIF(NOT SDL2_BUILDING_LIBRARY)
# For OS X, SDL2 uses Cocoa as a backend so it must link to Cocoa.
# CMake doesn't display the -framework Cocoa string in the UI even
# though it actually is there if I modify a pre-used variable.
# I think it has something to do with the CACHE STRING.
# So I use a temporary variable until the end so I can set the
# "real" variable in one-shot.
IF(APPLE)
SET(SDL2_LIBRARY_TEMP ${SDL2_LIBRARY_TEMP} "-framework Cocoa")
ENDIF(APPLE)
# For threads, as mentioned Apple doesn't need this.
# In fact, there seems to be a problem if I used the Threads package
# and try using this line, so I'm just skipping it entirely for OS X.
IF(NOT APPLE)
SET(SDL2_LIBRARY_TEMP ${SDL2_LIBRARY_TEMP} ${CMAKE_THREAD_LIBS_INIT})
ENDIF(NOT APPLE)
# For MinGW library
IF(MINGW)
SET(SDL2_LIBRARY_TEMP ${MINGW32_LIBRARY} ${SDL2_LIBRARY_TEMP})
ENDIF(MINGW)
# Set the final string here so the GUI reflects the final state.
SET(SDL2_LIBRARY ${SDL2_LIBRARY_TEMP} CACHE STRING "Where the SDL2 Library can be found")
# Set the temp variable to INTERNAL so it is not seen in the CMake GUI
SET(SDL2_LIBRARY_TEMP "${SDL2_LIBRARY_TEMP}" CACHE INTERNAL "")
ENDIF(SDL2_LIBRARY_TEMP)
INCLUDE(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(SDL2 REQUIRED_VARS SDL2_LIBRARY SDL2_INCLUDE_DIR)

View File

@@ -1,92 +0,0 @@
include(cmake/CPM.cmake)
if(NOT DEFINED EMSCRIPTEN)
SET(BUILD_SHARED_LIBS OFF CACHE BOOL "BUILD_SHARED_LIBS" FORCE)
SET(BUILD_STATIC_LIBS ON CACHE BOOL "BUILD_STATIC_LIBS" FORCE)
SET(POSITION_INDEPENDENT_CODE ON CACHE BOOL "POSITION_INDEPENDENT_CODE" FORCE)
# SDL2
string(TIMESTAMP BEFORE "%s")
CPMAddPackage(
NAME SDL2
GITHUB_REPOSITORY libsdl-org/SDL
GIT_TAG release-2.26.2
OPTIONS
"SDL2_DISABLE_INSTALL ON"
"SDL_SHARED OFF"
"SDL_STATIC ON"
"SDL_STATIC_PIC ON"
"SDL_WERROR OFF"
)
find_package(SDL2 REQUIRED)
file(GLOB SDL2_HEADERS "${SDL2_SOURCE_DIR}/include/*.h")
# Create a target that copies headers at build time, when they change
add_custom_target(sdl_copy_headers_in_build_dir
COMMAND ${CMAKE_COMMAND} -E copy_directory "${SDL2_SOURCE_DIR}/include" "${CMAKE_BINARY_DIR}/SDLHeaders/SDL2"
DEPENDS ${SDL2_HEADERS})
# Make SDL depend from it
add_dependencies(SDL2-static sdl_copy_headers_in_build_dir)
# And add the directory where headers have been copied as an interface include dir
target_include_directories(SDL2-static INTERFACE "${CMAKE_BINARY_DIR}/SDLHeaders")
set (SDL2_INCLUDE_DIR ${SDL2_SOURCE_DIR}/include)
include_directories(${SDL2_INCLUDE_DIR})
string(TIMESTAMP AFTER "%s")
math(EXPR DELTASDL "${AFTER} - ${BEFORE}")
MESSAGE(STATUS "SDL2 TIME: ${DELTASDL}s")
## SDL_ttf
#string(TIMESTAMP BEFORE "%s")
#CPMAddPackage(GITHUB_REPOSITORY libsdl-org/SDL_ttf
# GIT_TAG release-2.20.1
# OPTIONS
# "SDL2TTF_INSTALL OFF"
# "SDL2TTF_BUILD_SHARED_LIBS OFF"
# "SDL2TTF_VENDORED ON"
# "SDL2TTF_SAMPLES OFF"
#) # vendor is required for mingw builds
#find_package(SDL_ttf REQUIRED)
#include_directories(${SDL_ttf_SOURCE_DIR})
#string(TIMESTAMP AFTER "%s")
#math(EXPR DELTASDL_ttf "${AFTER} - ${BEFORE}")
#MESSAGE(STATUS "SDL_ttf TIME: ${DELTASDL_ttf}s")
# SDL_image
string(TIMESTAMP BEFORE "%s")
CPMAddPackage(GITHUB_REPOSITORY libsdl-org/SDL_image
GIT_TAG release-2.6.2
OPTIONS
"SDL2IMAGE_INSTALL OFF"
"SDL2IMAGE_SAMPLES OFF"
"SDL2IMAGE_VENDORED ON"
"SDL2IMAGE_BUILD_SHARED_LIBS OFF"
"GIT_SUBMODULES_RECURSE ON"
)
find_package(SDL_image REQUIRED)
include_directories(${SDL_image_SOURCE_DIR})
string(TIMESTAMP AFTER "%s")
math(EXPR DELTASDL_image "${AFTER} - ${BEFORE}")
MESSAGE(STATUS "SDL_image TIME: ${DELTASDL_image}s")
#
### SDL_mixer
#string(TIMESTAMP BEFORE "%s")
#CPMAddPackage(GITHUB_REPOSITORY libsdl-org/SDL_mixer
# GIT_TAG release-2.6.2
# OPTIONS
# "SDL2MIXER_INSTALL OFF"
# "SDL2MIXER_VENDORED ON"
# "SDL2MIXER_SAMPLES OFF"
# "SDL2MIXER_BUILD_SHARED_LIBS OFF"
#)
#find_package(SDL_mixer REQUIRED)
#include_directories(${SDL_mixer_SOURCE_DIR}/include)
#string(TIMESTAMP AFTER "%s")
#math(EXPR DELTASDL_mixer "${AFTER} - ${BEFORE}")
#MESSAGE(STATUS "SDL_mixer TIME: ${DELTASDL_mixer}s")
ENDIF()

View File

@@ -16,16 +16,20 @@ class GameApp : public App
{
};
void test() {
std::cout << "test" << std::endl;
}
class glDemoGameApp : public GameApp
{
public:
void Run() override
{
engine->loadConfig();
std::thread renderThread(render_loop);
renderThread.join();
gameTick();
//engine->loadConfig();
//engine->initVideo();
engine->window->render = render_loop();
std::thread game_tick(gameTick);
game_tick.join();
engine->window->pollEvents();
}
};

View File

@@ -4,7 +4,6 @@
#include <cstring>
#include <iostream>
#include <fstream>
#include <SDL2/SDL.h>
#include <GL/gl.h>
#include <rewindow/types/window.h>
enum class GAMESTATE: uint8_t {
@@ -17,12 +16,9 @@ enum class GAMESTATE: uint8_t {
class Engine {
public:
RWindow window1;
RWindow* window;
GAMESTATE gameState = GAMESTATE::NORMAL;
bool debug = true;
SDL_Window *window = nullptr;
uint16_t windowWidth;
uint16_t windowHeight;
bool fullscreen;
uint64_t tickCount = 0;
float tickDelta = NULL;
@@ -30,12 +26,9 @@ public:
float frameDelta = NULL;
uint16_t minimumTickDelta = 15625;
GLenum glError = GL_NO_ERROR;
SDL_GLContext glContext = nullptr;
float nearPlane = 0.01f;
float farPlane = 100.0f;
float fov;
Uint8* keyState = nullptr;
SDL_Event event;
[[nodiscard]] float framerate() const;
void takeScreenshot() const;
void quit() const;

View File

@@ -1,47 +1,11 @@
#pragma once
#include <chrono>
#include <SDL_events.h>
#include <thread>
#include <engine/engine.h>
#include <types/camera.h>
#include <types/skybox.h>
#include <types/entityList.h>
void process_sdl_events() {
while (SDL_PollEvent(&engine->event)) {
// TODO: Consider switch statements as opposed to ifs
// This adds control flow in the form of "break" statement.
// Which will save checking every single event type unnecessarily
// IMO premature optimization
// I personally dislike deciphering switch statements aswell
if (engine->event.type == SDL_QUIT) {engine->quit();}
if (engine->event.type == SDL_DROPFILE) {}
// Window Events
if (engine->event.type == SDL_WINDOWEVENT) {
auto window_ev = engine->event.window;
auto ev_type = window_ev.event;
if (ev_type == SDL_WINDOWEVENT_FOCUS_LOST) {}
if (ev_type == SDL_WINDOWEVENT_FOCUS_GAINED) {}
if (ev_type == SDL_WINDOWEVENT_CLOSE) {}
if (ev_type == SDL_WINDOWEVENT_SHOWN) {}
if (ev_type == SDL_WINDOWEVENT_HIDDEN) {}
if (ev_type == SDL_WINDOWEVENT_EXPOSED) {}
if (ev_type == SDL_WINDOWEVENT_MOVED) {}
if (ev_type == SDL_WINDOWEVENT_RESIZED) {}
if (ev_type == SDL_WINDOWEVENT_SIZE_CHANGED) {}
if (ev_type == SDL_WINDOWEVENT_MINIMIZED) {}
if (ev_type == SDL_WINDOWEVENT_MAXIMIZED) {}
if (ev_type == SDL_WINDOWEVENT_RESTORED) {}
if (ev_type == SDL_WINDOWEVENT_ENTER) {}
if (ev_type == SDL_WINDOWEVENT_LEAVE) {}
}
}
}
void pre_render() {
// NO
if(engine->frameCount == 0) {
@@ -61,8 +25,6 @@ void pre_render() {
storeEntity(player);
}
engine->frameCount++;
process_sdl_events();
engine->keyState = const_cast<Uint8 *>(SDL_GetKeyboardState(nullptr));
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
getCamera()->pre_render();
getPlayer()->pre_render();
@@ -79,7 +41,8 @@ void render() {
}
void post_render() {
SDL_GL_SwapWindow(engine->window);
//I need to wrap this.
RWindow::glSwapBuffers();
getCamera()->post_render();
//Resets all of the transformations for the next frame.
@@ -87,8 +50,7 @@ void post_render() {
glPushMatrix();
}
[[noreturn]] void render_loop() {
while (true) {
void* render_loop() {
auto start = std::chrono::high_resolution_clock::now();
pre_render();
render();
@@ -103,5 +65,4 @@ void post_render() {
dT = 1000;
}
engine->frameDelta = dT / 1000000;
}
}

View File

@@ -45,17 +45,17 @@ public:
void update();
void pre_render() {
if (engine->keyState[SDL_SCANCODE_0] == 1) {
if (engine->window->keyDown(SCANCODE::ZERO)) {
this->takingScreenshot = true;
}
if (engine->keyState[SDL_SCANCODE_1] == 1)
if (engine->window->keyDown(SCANCODE::ONE))
this->cameraMode = CameraMode::FREECAM;
if (engine->keyState[SDL_SCANCODE_2] == 1)
if (engine->window->keyDown(SCANCODE::TWO))
this->cameraMode = CameraMode::THIRD_PERSON;
if (engine->keyState[SDL_SCANCODE_3] == 1)
if (engine->window->keyDown(SCANCODE::THREE))
this->cameraMode = CameraMode::SCRIPTED_MOVE;
if (cameraMode == CameraMode::SCRIPTED_MOVE) {
@@ -76,37 +76,37 @@ public:
//getPlayer()->thirdPersonCameraPoints();
if (cameraMode == CameraMode::FREECAM) {
if (engine->keyState[SDL_SCANCODE_S] == 1) {
if (engine->window->keyDown(SCANCODE::S)) {
move(bAngle(),2);
}
if (engine->keyState[SDL_SCANCODE_W] == 1) {
if (engine->window->keyDown(SCANCODE::W)) {
move(fAngle(),2);
}
if (engine->keyState[SDL_SCANCODE_A] == 1) {
if (engine->window->keyDown(SCANCODE::A)) {
move(lAngle(), 2);
}
if (engine->keyState[SDL_SCANCODE_D] == 1) {
if (engine->window->keyDown(SCANCODE::D)) {
move(rAngle(),2);
}
if (engine->keyState[SDL_SCANCODE_SPACE] == 1) {
if (engine->window->keyDown(SCANCODE::SPACE)) {
this->position.y += 5*engine->frameDelta;
}
if (engine->keyState[SDL_SCANCODE_LSHIFT] == 1) {
if (engine->window->keyDown(SCANCODE::LEFT_SHIFT)) {
this->position.y -= 5*engine->frameDelta;
}
if (engine->keyState[SDL_SCANCODE_LEFT] == 1) {
if (engine->window->keyDown(SCANCODE::LEFT)) {
this->angle.yaw +=75.0f*engine->frameDelta;
}
if (engine->keyState[SDL_SCANCODE_RIGHT] == 1) {
if (engine->window->keyDown(SCANCODE::RIGHT)) {
this->angle.yaw -=75.0f*engine->frameDelta;
}
if (engine->keyState[SDL_SCANCODE_UP] == 1) {
if (engine->window->keyDown(SCANCODE::UP)) {
this->angle.pitch -=75.0f*engine->frameDelta;
}
if (engine->keyState[SDL_SCANCODE_DOWN] == 1) {
if (engine->window->keyDown(SCANCODE::DOWN)) {
this->angle.pitch +=75.0f*engine->frameDelta;
}
}

View File

@@ -1,6 +1,5 @@
#pragma once
#include <SDL_opengl.h>
#include "entityList.h"
#include "moby.h"
#include "camera.h"

View File

@@ -3,12 +3,10 @@
#include <GL/gl.h>
#include <GL/glu.h>
#include <sstream>
#include <chrono>
#include <thread>
void Engine::quit() const {
SDL_DestroyWindow(this->window);
SDL_Quit();
window->destroyWindow();
exit(0);
}
@@ -24,7 +22,7 @@ void Engine::initGL()
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
//glOrtho(-1.0f, 1.0f, -1.0f, 1.0f, -0.5f, 0.5f);
gluPerspective(this->fov, this->windowWidth / this->windowHeight, this->nearPlane, this->farPlane);
gluPerspective(this->fov, window->getSize()[0] / window->getSize()[1], this->nearPlane, this->farPlane);
this->glError = glGetError();
if (glError != GL_NO_ERROR) {
@@ -39,7 +37,7 @@ void Engine::initGL()
exit (1);
}
glClearColor(0.f, 0.f, 0.f, 1.f);
glViewport(0,0,this->windowWidth,this->windowHeight);
glViewport(0,0,window->getSize()[0],window->getSize()[1]);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LESS);
glDepthMask(GL_TRUE);
@@ -50,35 +48,24 @@ void Engine::initGL()
void Engine::initVideo()
{
Uint32 sdl_initializer_flags = SDL_INIT_VIDEO;// | SDL_INIT_AUDIO;
// Start SDL, check for errors
if (SDL_Init(sdl_initializer_flags) < 0) {
std::cerr << "SDL_Error: " << SDL_GetError() << std::endl;
exit(1);
}
window->init(RenderingAPI::OPENGL,"title",144,144);
//window->setFlag(RWindowFlags::RESIZABLE, false);
//window->pollEvents();
// Create the window, set resizable, check for errors
SDL_GL_SetAttribute( SDL_GL_CONTEXT_MAJOR_VERSION, 1);
SDL_GL_SetAttribute( SDL_GL_CONTEXT_MINOR_VERSION, 4);
SDL_GL_SetSwapInterval(0);
if (engine->fullscreen)
this->window = SDL_CreateWindow("SDL3D", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, this->windowWidth, this->windowHeight, SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN | SDL_WINDOW_FULLSCREEN);
if (!engine->fullscreen)
this->window = SDL_CreateWindow("SDL3D", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, this->windowWidth, this->windowHeight, SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN);
SDL_SetWindowResizable(this->window,SDL_FALSE);
this->glContext = SDL_GL_CreateContext(window);
//SDL_GL_SetAttribute( SDL_GL_CONTEXT_MAJOR_VERSION, 1);
//SDL_GL_SetAttribute( SDL_GL_CONTEXT_MINOR_VERSION, 4);
//if (engine->fullscreen)
//this->window = SDL_CreateWindow("SDL3D", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, this->windowWidth, this->windowHeight, SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN | SDL_WINDOW_FULLSCREEN);
//if (!engine->fullscreen)
//this->window = SDL_CreateWindow("SDL3D", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, this->windowWidth, this->windowHeight, SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN);
//SDL_SetWindowResizable(this->window,SDL_FALSE);
//this->glContext = SDL_GL_CreateContext(window);
if (Engine::getGLVersion() < 1.4f) {
std::cerr << "Driver OpenGL version: " << Engine::getGLVersion() << std::endl;
std::cerr << "OpenGL >= 1.4 is required." << std::endl;
exit(1);
}
if (this->window == nullptr) {
std::cerr << "SDL_Error: " << SDL_GetError() << std::endl;
exit(1);
}
//if (Engine::getGLVersion() < 1.4f) {
//std::cerr << "Driver OpenGL version: " << Engine::getGLVersion() << std::endl;
//std::cerr << "OpenGL >= 1.4 is required." << std::endl;
//exit(1);
//}
}
void Engine::debugInfo() const
@@ -131,7 +118,7 @@ void Engine::loadConfig() {
std::string prefix;
stream >> prefix;
if (prefix == "Resolution:")
stream >> windowWidth >> windowHeight;
//stream >> window->getSize()[0] >> window->getSize()[1];
if (prefix == "Fullscreen:")
stream >> fullscreen;
if (prefix == "Debug:")
@@ -141,14 +128,14 @@ void Engine::loadConfig() {
}
//If we have a window already.
if (window != nullptr) {
SDL_DestroyWindow(this->window);
//window->destroyWindow();
//Some window managers won't handle destroying and remaking the window with zero delay very well.
std::this_thread::sleep_for(std::chrono::milliseconds(500));
initVideo();
initGL();
}
std::cout << "Fullscreen: " << fullscreen << std::endl;
std::cout << "Resolution: " << windowWidth << "x" << windowHeight << std::endl;
std::cout << "Resolution: " << window->getSize()[0] << "x" << window->getSize()[1] << std::endl;
std::cout << "Camera FOV: " << fov << std::endl;
std::cout << "Debug: " << debug << std::endl;
}