Browse Source

make everything pretend positive y is down, then flip with the camera matrix

feature/replace-renderer
Martin Dørum 3 years ago
parent
commit
eabd356117
2 changed files with 14 additions and 10 deletions
  1. 12
    8
      libcygnet/src/Renderer.cc
  2. 2
    2
      libcygnet/src/shaders.cc

+ 12
- 8
libcygnet/src/Renderer.cc View File

static constexpr float cw = (float)SwanCommon::CHUNK_WIDTH; static constexpr float cw = (float)SwanCommon::CHUNK_WIDTH;
static constexpr GLfloat vertexes[] = { static constexpr GLfloat vertexes[] = {
0.0f, 0.0f, // pos 0: top left 0.0f, 0.0f, // pos 0: top left
0.0f, -ch , // pos 1: bottom left
cw, -ch, // pos 2: bottom right
cw, -ch, // pos 2: bottom right
0.0f, ch , // pos 1: bottom left
cw, ch, // pos 2: bottom right
cw, ch, // pos 2: bottom right
cw, 0.0f, // pos 3: top right cw, 0.0f, // pos 3: top right
0.0f, 0.0f, // pos 0: top left 0.0f, 0.0f, // pos 0: top left
}; };


static constexpr GLfloat vertexes[] = { static constexpr GLfloat vertexes[] = {
0.0f, 0.0f, // pos 0: top left 0.0f, 0.0f, // pos 0: top left
0.0f, -1.0f, // pos 1: bottom left
1.0f, -1.0f, // pos 2: bottom right
1.0f, -1.0f, // pos 2: bottom right
0.0f, 1.0f, // pos 1: bottom left
1.0f, 1.0f, // pos 2: bottom right
1.0f, 1.0f, // pos 2: bottom right
1.0f, 0.0f, // pos 3: top right 1.0f, 0.0f, // pos 3: top right
0.0f, 0.0f, // pos 0: top left 0.0f, 0.0f, // pos 0: top left
}; };


void Renderer::draw(const RenderCamera &cam) { void Renderer::draw(const RenderCamera &cam) {
Mat3gf camMat; Mat3gf camMat;

// Make the matrix translate to { -camX, -camY }, fix up the aspect ratio,
// flip the Y axis so that positive Y direction is down, and scale according to zoom.
float ratio = (float)cam.size.y / (float)cam.size.x; float ratio = (float)cam.size.y / (float)cam.size.x;
camMat.translate(cam.pos.scale(-ratio, 1) * cam.zoom); // TODO: Change something to make this -cam.pos
camMat.scale({ cam.zoom * ratio, cam.zoom });
camMat.translate(cam.pos.scale(-ratio, 1) * cam.zoom);
camMat.scale({ cam.zoom * ratio, -cam.zoom });

auto &chunkProg = state_->chunkProg; auto &chunkProg = state_->chunkProg;
auto &spriteProg = state_->spriteProg; auto &spriteProg = state_->spriteProg;



+ 2
- 2
libcygnet/src/shaders.cc View File

void main() { void main() {
vec3 pos = camera * transform * vec3(vertex, 1); vec3 pos = camera * transform * vec3(vertex, 1);
gl_Position = vec4(pos.xy, 0, 1); gl_Position = vec4(pos.xy, 0, 1);
v_texCoord = vec2(vertex.x, -vertex.y);
v_texCoord = vec2(vertex.x, vertex.y);
} }
)glsl"; )glsl";


void main() { void main() {
vec3 pos = camera * vec3(pos + vertex, 1); vec3 pos = camera * vec3(pos + vertex, 1);
gl_Position = vec4(pos.xy, 0, 1); gl_Position = vec4(pos.xy, 0, 1);
v_tileCoord = vec2(vertex.x, -vertex.y);
v_tileCoord = vec2(vertex.x, vertex.y);
} }
)glsl"; )glsl";



Loading…
Cancel
Save