diff options
Diffstat (limited to 'gfx')
-rw-r--r-- | gfx/camera_controller.h | 8 | ||||
-rw-r--r-- | gfx/followCameraController.h | 3 | ||||
-rw-r--r-- | gfx/gl/glSource.cpp | 2 | ||||
-rw-r--r-- | gfx/gl/glSource.h | 1 | ||||
-rw-r--r-- | gfx/gl/shader.cpp | 3 | ||||
-rw-r--r-- | gfx/gl/shader.h | 2 | ||||
-rw-r--r-- | gfx/gl/uiShader.cpp | 4 | ||||
-rw-r--r-- | gfx/gl/uiShader.h | 3 | ||||
-rw-r--r-- | gfx/inputHandler.h | 18 | ||||
-rw-r--r-- | gfx/manualCameraController.cpp | 67 | ||||
-rw-r--r-- | gfx/manualCameraController.h | 29 | ||||
-rw-r--r-- | gfx/window.cpp | 32 | ||||
-rw-r--r-- | gfx/window.h | 29 |
13 files changed, 15 insertions, 186 deletions
diff --git a/gfx/camera_controller.h b/gfx/camera_controller.h index 926c93b..e6fc16d 100644 --- a/gfx/camera_controller.h +++ b/gfx/camera_controller.h @@ -1,12 +1,16 @@ #ifndef CAMERA_CONTROLLER_H #define CAMERA_CONTROLLER_H -#include <game/worldobject.h> +#include <special_members.hpp> class Camera; -class CameraController : public WorldObject { +class CameraController { public: + CameraController() = default; + virtual ~CameraController() = default; + DEFAULT_MOVE_COPY(CameraController); + virtual void updateCamera(Camera *) const = 0; }; diff --git a/gfx/followCameraController.h b/gfx/followCameraController.h index ef2000d..cfe70c2 100644 --- a/gfx/followCameraController.h +++ b/gfx/followCameraController.h @@ -1,7 +1,6 @@ #ifndef FOLLOW_CAMERA_CONTROLLER_H #define FOLLOW_CAMERA_CONTROLLER_H -#include "game/worldobject.h" #include <game/vehicles/vehicle.h> #include <gfx/camera_controller.h> @@ -12,8 +11,6 @@ public: enum class Mode { Pan, Ride, ISO }; explicit FollowCameraController(VehicleWPtr, Mode = Mode::Pan); - void tick(TickDuration) override { } - void updateCamera(Camera * camera) const override; private: diff --git a/gfx/gl/glSource.cpp b/gfx/gl/glSource.cpp index 13686ae..49773d0 100644 --- a/gfx/gl/glSource.cpp +++ b/gfx/gl/glSource.cpp @@ -1,5 +1,7 @@ #include "glSource.h" #include <array> +#include <stdexcept> +#include <string> GLsource::ShaderRef GLsource::compile() const diff --git a/gfx/gl/glSource.h b/gfx/gl/glSource.h index 53c221b..e44c5a2 100644 --- a/gfx/gl/glSource.h +++ b/gfx/gl/glSource.h @@ -3,6 +3,7 @@ #include <GL/glew.h> #include <glRef.hpp> +#include <string_view> struct GLsource { using ShaderRef = glRef<GLuint, __glewCreateShader, __glewDeleteShader>; diff --git a/gfx/gl/shader.cpp b/gfx/gl/shader.cpp index 03e7899..a196e07 100644 --- a/gfx/gl/shader.cpp +++ b/gfx/gl/shader.cpp @@ -2,6 +2,7 @@ #include "gfx/gl/glSource.h"
#include <array>
#include <cstddef>
+#include <gfx/gl/programHandle.h>
#include <gfx/gl/shaders/fs-basicShader.h>
#include <gfx/gl/shaders/fs-landmassShader.h>
#include <gfx/gl/shaders/fs-waterShader.h>
@@ -13,8 +14,6 @@ #include <glm/gtx/transform.hpp>
#include <location.hpp>
#include <maths.h>
-#include <stdexcept>
-#include <string>
Shader::ProgramHandle::ProgramHandle(GLuint vs, GLuint fs) : ProgramHandleBase {vs, fs}
{
diff --git a/gfx/gl/shader.h b/gfx/gl/shader.h index 249b2f4..7df7a07 100644 --- a/gfx/gl/shader.h +++ b/gfx/gl/shader.h @@ -4,9 +4,7 @@ #include "programHandle.h"
#include <GL/glew.h>
#include <array>
-#include <glRef.hpp>
#include <glm/glm.hpp>
-#include <string_view>
class Location;
diff --git a/gfx/gl/uiShader.cpp b/gfx/gl/uiShader.cpp index 2fbb0d4..b3fee14 100644 --- a/gfx/gl/uiShader.cpp +++ b/gfx/gl/uiShader.cpp @@ -1,8 +1,10 @@ #include "uiShader.h" +#include <gfx/gl/glSource.h> +#include <gfx/gl/programHandle.h> #include <gfx/gl/shaders/fs-uiShader.h> #include <gfx/gl/shaders/vs-uiShader.h> +#include <glm/glm.hpp> #include <glm/gtc/type_ptr.hpp> -#include <glm/gtx/transform.hpp> UIShader::UIShader(size_t width, size_t height) : program {uiShader_vs.compile(), uiShader_fs.compile()} { diff --git a/gfx/gl/uiShader.h b/gfx/gl/uiShader.h index ff0e96d..b251136 100644 --- a/gfx/gl/uiShader.h +++ b/gfx/gl/uiShader.h @@ -2,7 +2,8 @@ #define UISHADER_H #include "programHandle.h" -#include <cstdint> +#include <GL/glew.h> +#include <cstddef> class UIShader { public: diff --git a/gfx/inputHandler.h b/gfx/inputHandler.h deleted file mode 100644 index 5b426c7..0000000 --- a/gfx/inputHandler.h +++ /dev/null @@ -1,18 +0,0 @@ -#ifndef INPUT_HANDLER_H -#define INPUT_HANDLER_H - -#include <special_members.hpp> - -union SDL_Event; - -class InputHandler { -public: - InputHandler() = default; - virtual ~InputHandler() = default; - - DEFAULT_MOVE_COPY(InputHandler); - - virtual bool handleInput(SDL_Event &) = 0; -}; - -#endif diff --git a/gfx/manualCameraController.cpp b/gfx/manualCameraController.cpp deleted file mode 100644 index cacf6ac..0000000 --- a/gfx/manualCameraController.cpp +++ /dev/null @@ -1,67 +0,0 @@ -#include "manualCameraController.h" -#include <algorithm> -#include <cmath> -#include <gfx/gl/camera.h> -#include <maths.h> - -bool -ManualCameraController::handleInput(SDL_Event & e) -{ - switch (e.type) { - case SDL_KEYDOWN: - switch (e.key.keysym.sym) { - case SDLK_LCTRL: - case SDLK_RCTRL: - ctrl = true; - return true; - } - break; - case SDL_KEYUP: - switch (e.key.keysym.sym) { - case SDLK_LCTRL: - case SDLK_RCTRL: - ctrl = false; - return true; - } - break; - case SDL_MOUSEBUTTONDOWN: - switch (e.button.button) { - case SDL_BUTTON_RIGHT: - SDL_SetRelativeMouseMode(SDL_TRUE); - mrb = true; - return true; - } - break; - case SDL_MOUSEBUTTONUP: - switch (e.button.button) { - case SDL_BUTTON_RIGHT: - SDL_SetRelativeMouseMode(SDL_FALSE); - mrb = false; - return true; - } - break; - case SDL_MOUSEMOTION: - if (mrb) { - if (ctrl) { - direction -= 0.01F * static_cast<float>(e.motion.xrel); - pitch = std::clamp(pitch - 0.01F * static_cast<float>(e.motion.yrel), 0.1F, half_pi); - } - else { - focus += rotate_flat(-direction) * glm::vec2 {-e.motion.xrel, e.motion.yrel}; - } - } - return true; - case SDL_MOUSEWHEEL: - dist = std::clamp(dist - static_cast<float>(e.wheel.y) * 4.F, 5.F, 200.F); - break; - } - return false; -} - -void -ManualCameraController::updateCamera(Camera * camera) const -{ - camera->forward = glm::normalize(sincosf(direction) ^ -sin(pitch)); - camera->pos = !focus + up * 3.F - (camera->forward * std::pow(dist, 1.3F)); - camera->up = up; -} diff --git a/gfx/manualCameraController.h b/gfx/manualCameraController.h deleted file mode 100644 index f2141a4..0000000 --- a/gfx/manualCameraController.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef MANUAL_CAMERA_CONTROLLER_H -#define MANUAL_CAMERA_CONTROLLER_H - -#include "game/worldobject.h" -#include "inputHandler.h" -#include <SDL2/SDL.h> -#include <gfx/camera_controller.h> -#include <glm/glm.hpp> -#include <maths.h> - -class Camera; - -class ManualCameraController : public CameraController, public InputHandler { -public: - explicit ManualCameraController(glm::vec2 f) : focus {f} { } - - bool handleInput(SDL_Event & e) override; - - void tick(TickDuration) override { } - - void updateCamera(Camera * camera) const override; - -private: - bool ctrl {false}, mrb {false}; - glm::vec2 focus; - float direction {quarter_pi}; - float dist {40}, pitch {quarter_pi}; -}; -#endif diff --git a/gfx/window.cpp b/gfx/window.cpp deleted file mode 100644 index dd300a7..0000000 --- a/gfx/window.cpp +++ /dev/null @@ -1,32 +0,0 @@ -#include "window.h"
-#include <GL/glew.h>
-#include <stdexcept>
-
-Window::Window(int width, int height, const std::string & title) :
- m_window {title.c_str(), static_cast<int>(SDL_WINDOWPOS_CENTERED), static_cast<int>(SDL_WINDOWPOS_CENTERED), width,
- height, static_cast<Uint32>(SDL_WINDOW_OPENGL)},
- m_glContext {m_window}
-{
- if (glewInit() != GLEW_OK) {
- throw std::runtime_error {"Glew failed to initialize!"};
- }
-
- glEnable(GL_DEPTH_TEST);
- glEnable(GL_CULL_FACE);
- glCullFace(GL_BACK);
- glEnable(GL_BLEND);
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
-}
-
-void
-Window::Clear(float r, float g, float b, float a) const
-{
- glClearColor(r, g, b, a);
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
-}
-
-void
-Window::SwapBuffers() const
-{
- SDL_GL_SwapWindow(m_window);
-}
diff --git a/gfx/window.h b/gfx/window.h deleted file mode 100644 index 252ccaa..0000000 --- a/gfx/window.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef DISPLAY_INCLUDED_H
-#define DISPLAY_INCLUDED_H
-
-#include "ptr.hpp"
-#include <SDL2/SDL.h>
-#include <special_members.hpp>
-#include <string>
-#include <type_traits>
-
-class Window {
-public:
- Window(int width, int height, const std::string & title);
- ~Window() = default;
-
- NO_COPY(Window);
- NO_MOVE(Window);
-
- void Clear(float r, float g, float b, float a) const;
- void SwapBuffers() const;
-
-private:
- using GL_Context = std::remove_pointer_t<SDL_GLContext>;
- using SDL_WindowPtr = wrapped_ptrt<SDL_Window, SDL_CreateWindow, SDL_DestroyWindow>;
- using SDL_GLContextPtr = wrapped_ptrt<GL_Context, SDL_GL_CreateContext, SDL_GL_DeleteContext>;
- SDL_WindowPtr m_window;
- SDL_GLContextPtr m_glContext;
-};
-
-#endif
|