@@ -4,6 +4,7 @@ core_mod = shared_library('mod', | |||
'src/entities/PlayerEntity.cc', | |||
'src/entities/ItemStackEntity.cc', | |||
name_prefix: '', | |||
name_suffix: 'so', | |||
install: true, | |||
install_dir: 'core.mod', | |||
dependencies: [libswan, libperlinnoise]) |
@@ -4,11 +4,13 @@ | |||
#include "entities/PlayerEntity.h" | |||
#include "entities/ItemStackEntity.h" | |||
#include <functional> | |||
class CoreMod: public Swan::Mod { | |||
public: | |||
CoreMod(Swan::World &world): Swan::Mod("core") { | |||
breakListener_ = world.evtTileBreak_.subscribe( | |||
std::bind_front(&CoreMod::onTileBreak, this)); | |||
[=](auto ...args) { return onTileBreak(args...); }); | |||
registerSprite("entity/player-running"); | |||
registerSprite("entity/player-still"); |
@@ -20,14 +20,15 @@ public: | |||
void clear(Color color = {}); | |||
void flip(); | |||
void onResize(int w, int h); | |||
SwanCommon::Vec2i size() { return { w_, h_ }; } | |||
SwanCommon::Vec2i size() { return size_; } | |||
double pixelRatio() { return ratio_; } | |||
SDL_Window *sdlWindow(); | |||
private: | |||
std::unique_ptr<WindowState> state_; | |||
int w_; | |||
int h_; | |||
SwanCommon::Vec2i size_; | |||
double ratio_; | |||
}; | |||
} |
@@ -1 +1,2 @@ | |||
#include <SDL_opengles2.h> | |||
#include <GL/glew.h> | |||
#include <SDL_opengl.h> |
@@ -8,6 +8,6 @@ libcygnet = declare_dependency( | |||
'src/TileAtlas.cc', | |||
'src/util.cc', | |||
'src/Window.cc', | |||
dependencies: [common, libtracy, libthreads, libsdl2, libgles2], | |||
dependencies: [common, libtracy, libthreads, libsdl2, libgl, libglew], | |||
install: true, | |||
include_directories: 'include/cygnet')) |
@@ -589,6 +589,7 @@ RenderChunk Renderer::createChunk( | |||
GL_TEXTURE_2D, 0, GL_LUMINANCE_ALPHA, | |||
SwanCommon::CHUNK_WIDTH, SwanCommon::CHUNK_HEIGHT, | |||
0, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, tiles); | |||
glCheck(); | |||
} else if constexpr (std::endian::native == std::endian::big) { | |||
uint8_t buf[SwanCommon::CHUNK_WIDTH * SwanCommon::CHUNK_HEIGHT * 2]; | |||
for (size_t y = 0; y < SwanCommon::CHUNK_HEIGHT; ++y) { | |||
@@ -604,9 +605,9 @@ RenderChunk Renderer::createChunk( | |||
GL_TEXTURE_2D, 0, GL_LUMINANCE_ALPHA, | |||
SwanCommon::CHUNK_WIDTH, SwanCommon::CHUNK_HEIGHT, | |||
0, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, buf); | |||
glCheck(); | |||
} | |||
glCheck(); | |||
return chunk; | |||
} | |||
@@ -1,6 +1,7 @@ | |||
#include "Window.h" | |||
#include <SDL.h> | |||
#include <iostream> | |||
#include "gl.h" | |||
#include "util.h" | |||
@@ -13,8 +14,8 @@ struct WindowState { | |||
}; | |||
Window::Window(const char *name, int w, int h): | |||
state_(std::make_unique<WindowState>()), w_(w), h_(h) { | |||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES); | |||
state_(std::make_unique<WindowState>()) { | |||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_COMPATIBILITY); | |||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2); | |||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0); | |||
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); | |||
@@ -33,6 +34,10 @@ Window::Window(const char *name, int w, int h): | |||
glCheck(); | |||
makeCurrent(); | |||
glewInit(); | |||
std::cerr << "OpenGL Version: " << glGetString(GL_VERSION) << '\n'; | |||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); | |||
glEnable(GL_BLEND); | |||
glCheck(); | |||
@@ -62,13 +67,13 @@ void Window::flip() { | |||
} | |||
void Window::onResize(int w, int h) { | |||
w_ = w; | |||
h_ = h; | |||
int dw, dh; | |||
SDL_GL_GetDrawableSize(state_->window, &dw, &dh); | |||
glViewport(0, 0, dw, dh); | |||
glCheck(); | |||
size_ = {dw, dh}; | |||
ratio_ = (double)dw / (double)w; | |||
} | |||
SDL_Window *Window::sdlWindow() { |
@@ -3,7 +3,6 @@ | |||
namespace Cygnet::Shaders { | |||
const char *chunkVx = R"glsl( | |||
precision mediump float; | |||
uniform mat3 camera; | |||
uniform vec2 pos; | |||
attribute vec2 vertex; | |||
@@ -17,7 +16,6 @@ const char *chunkVx = R"glsl( | |||
)glsl"; | |||
const char *chunkFr = R"glsl( | |||
precision mediump float; | |||
#define TILE_SIZE 32.0 | |||
#define CHUNK_WIDTH 64 | |||
#define CHUNK_HEIGHT 64 | |||
@@ -44,7 +42,6 @@ const char *chunkFr = R"glsl( | |||
)glsl"; | |||
const char *chunkShadowVx = R"glsl( | |||
precision mediump float; | |||
#define CHUNK_WIDTH 64 | |||
#define CHUNK_HEIGHT 64 | |||
@@ -61,8 +58,6 @@ const char *chunkShadowVx = R"glsl( | |||
)glsl"; | |||
const char *chunkShadowFr = R"glsl( | |||
precision mediump float; | |||
varying vec2 v_texCoord; | |||
uniform sampler2D tex; | |||
@@ -73,7 +68,6 @@ const char *chunkShadowFr = R"glsl( | |||
)glsl"; | |||
const char *tileVx = R"glsl( | |||
precision mediump float; | |||
uniform mat3 camera; | |||
uniform mat3 transform; | |||
attribute vec2 vertex; | |||
@@ -87,7 +81,6 @@ const char *tileVx = R"glsl( | |||
)glsl"; | |||
const char *tileFr = R"glsl( | |||
precision mediump float; | |||
#define TILE_SIZE 32.0 | |||
varying vec2 v_tileCoord; | |||
@@ -109,7 +102,6 @@ const char *tileFr = R"glsl( | |||
)glsl"; | |||
const char *spriteVx = R"glsl( | |||
precision mediump float; | |||
#define TILE_SIZE 32.0 | |||
uniform mat3 camera; | |||
@@ -136,7 +128,6 @@ const char *spriteVx = R"glsl( | |||
)glsl"; | |||
const char *spriteFr = R"glsl( | |||
precision mediump float; | |||
varying vec2 v_texCoord; | |||
uniform sampler2D tex; | |||
@@ -146,7 +137,6 @@ const char *spriteFr = R"glsl( | |||
)glsl"; | |||
const char *rectVx = R"glsl( | |||
precision mediump float; | |||
uniform mat3 camera; | |||
uniform vec2 pos; | |||
uniform vec2 size; | |||
@@ -161,7 +151,6 @@ const char *rectVx = R"glsl( | |||
)glsl"; | |||
const char *rectFr = R"glsl( | |||
precision mediump float; | |||
#define THICKNESS 0.02 | |||
varying vec2 v_coord; | |||
@@ -175,7 +164,6 @@ const char *rectFr = R"glsl( | |||
)glsl"; | |||
const char *blendVx = R"glsl( | |||
precision mediump float; | |||
attribute vec2 vertex; | |||
attribute vec2 texCoord; | |||
varying vec2 v_texCoord; | |||
@@ -187,7 +175,6 @@ const char *blendVx = R"glsl( | |||
)glsl"; | |||
const char *blendFr = R"glsl( | |||
precision mediump float; | |||
varying vec2 v_texCoord; | |||
uniform sampler2D tex; | |||
@@ -3,7 +3,11 @@ project('swan', 'cpp', | |||
libdl = meson.get_compiler('cpp').find_library('dl') | |||
libz = meson.get_compiler('cpp').find_library('z') | |||
libgles2 = meson.get_compiler('cpp').find_library('GLESv2') | |||
libglew = dependency('glew') | |||
libgl = dependency('OpenGL') | |||
#libgl = meson.get_compiler('cpp').find_library('GLESv2') | |||
libsdl2 = dependency('sdl2') | |||
libsdl2_image = dependency('SDL2_image') | |||
libthreads = dependency('threads') |
@@ -5,8 +5,8 @@ | |||
#include <chrono> | |||
#include <ratio> | |||
#include <SDL2/SDL.h> | |||
#include <SDL2/SDL_image.h> | |||
#include <SDL.h> | |||
#include <SDL_image.h> | |||
#include <string.h> | |||
#include <imgui.h> | |||
#include <imgui_sdl.h> | |||
@@ -146,21 +146,29 @@ int main(int argc, char **argv) { | |||
imguiIO.MousePos.x = (float)evt.motion.x; | |||
imguiIO.MousePos.y = (float)evt.motion.y; | |||
if (!imguiIO.WantCaptureMouse) */ | |||
game.onMouseMove(evt.motion.x, evt.motion.y); | |||
game.onMouseMove( | |||
evt.motion.x * window.pixelRatio(), | |||
evt.motion.y * window.pixelRatio()); | |||
break; | |||
case SDL_MOUSEBUTTONDOWN: | |||
/* | |||
imguiIO.MouseDown[sdlButtonToImGuiButton(evt.button.button)] = true; | |||
if (!imguiIO.WantCaptureMouse) */ | |||
game.onMouseDown(evt.button.x, evt.button.y, evt.button.button); | |||
game.onMouseDown( | |||
evt.button.x * window.pixelRatio(), | |||
evt.button.y * window.pixelRatio(), | |||
evt.button.button); | |||
break; | |||
case SDL_MOUSEBUTTONUP: | |||
/* | |||
imguiIO.MouseDown[sdlButtonToImGuiButton(evt.button.button)] = false; | |||
if (!imguiIO.WantCaptureMouse) */ | |||
game.onMouseUp(evt.button.x, evt.button.y, evt.button.button); | |||
game.onMouseUp( | |||
evt.button.x * window.pixelRatio(), | |||
evt.button.y * window.pixelRatio(), | |||
evt.button.button); | |||
break; | |||
case SDL_MOUSEWHEEL: |