a shallow game will never be good, it takes depth

This commit is contained in:
zlago 2025-11-17 20:56:24 +01:00
parent 5e3b3c2bf9
commit d69c8e3a5e
6 changed files with 21 additions and 18 deletions

View File

@ -9,7 +9,7 @@
#include "rect-pack.h"
#include "batch.h"
#include <glad/gles2.h>
#include "glad/gles2.h"
#include "main.h++"

View File

@ -3,13 +3,14 @@
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <glad/gles2.h>
#include <stddef.h>
#include "glad/gles2.h"
#include "batch.h"
struct batch {
struct vertices { // 8 bytes
int16_t x, y; // 4 bytes
struct vertices { // 10 bytes
int16_t x, y, z; // 6 bytes
uint16_t s, t; // 4 bytes
// must subtract 1 after multiplying
} (*vertices)[4];
@ -38,17 +39,17 @@ struct batch {
static void batch_insert(struct vertices v[4], GLuint texture);
void batch_blit_flippable(int x, int y, struct texture *tex, struct crop *crop) {
void batch_blit_flippable(int x, int y, int z, struct texture *tex, struct crop *crop) {
if (crop->w < 0) {
x -= crop->w;
}
if (crop->h < 0) {
y -= crop->h;
}
batch_blit(x, y, tex, crop);
batch_blit(x, y, z, tex, crop);
}
void batch_blit(int x, int y, struct texture *tex, struct crop *crop) {
void batch_blit(int x, int y, int z, struct texture *tex, struct crop *crop) {
unsigned s1, s2, t1, t2;
if (tex->flipped) {
s1 = tex->x + crop->y;
@ -63,7 +64,7 @@ void batch_blit(int x, int y, struct texture *tex, struct crop *crop) {
}
struct vertices vi = {
.x = x, .y = y,
.x = x, .y = y, .z = z,
.s = s1 * tex->size,
.t = t1 * tex->size,
};
@ -126,8 +127,8 @@ void batch_flush(void) {
glUseProgram(batch.program);
glVertexAttribPointer(batch.aVertCoord, 2, GL_SHORT, GL_FALSE, sizeof (struct vertices), (void *) 0);
glVertexAttribPointer(batch.aTexCoord, 2, GL_UNSIGNED_SHORT, GL_TRUE, sizeof (struct vertices), (void *) 4);
glVertexAttribPointer(batch.aVertCoord, 3, GL_SHORT, GL_FALSE, sizeof (struct vertices), (void *) offsetof (struct vertices, x));
glVertexAttribPointer(batch.aTexCoord, 2, GL_UNSIGNED_SHORT, GL_TRUE, sizeof (struct vertices), (void *) offsetof (struct vertices, s));
glEnableVertexAttribArray(batch.aVertCoord);
glEnableVertexAttribArray(batch.aTexCoord);

View File

@ -7,7 +7,7 @@ extern "C" {
#include <limits.h>
#include <stdint.h>
#include <stdbool.h>
#include <glad/gles2.h>
#include "glad/gles2.h"
struct texture {
GLuint texture;
@ -21,8 +21,8 @@ struct crop {
int w, h;
};
void batch_blit(int x, int y, struct texture *tex, struct crop *crop);
void batch_blit_flippable(int x, int y, struct texture *tex, struct crop *crop);
void batch_blit(int x, int y, int z, struct texture *tex, struct crop *crop);
void batch_blit_flippable(int x, int y, int z, struct texture *tex, struct crop *crop);
void batch_flush(void);

View File

@ -1,4 +1,4 @@
#include <glad/gles2.h>
#include "glad/gles2.h"
#include <SDL3/SDL.h>
#define SDL_MAIN_USE_CALLBACKS 1
#include <SDL3/SDL_main.h>
@ -157,9 +157,10 @@ SDL_AppResult SDL_AppIterate(void *) {
glViewport(0, 0, WINDOW_VIRTUAL, WINDOW_VIRTUAL);
glClearColor(0.0, 0.0, 0.0, 0.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glEnable(GL_DEPTH_TEST);
struct crop c = {0, 0, 64, 64};
batch_blit(-32, -32, &textures.at("turret"), &c);
batch_blit(-32, -32, 0, &textures.at("turret"), &c);
batch_flush();
glBindFramebuffer(GL_FRAMEBUFFER, 0);
@ -185,6 +186,7 @@ SDL_AppResult SDL_AppIterate(void *) {
}
glClearColor(0.0, 0.0, 0.0, 0.0);
glClear(GL_COLOR_BUFFER_BIT);
glDisable(GL_DEPTH_TEST);
glBindBuffer(GL_ARRAY_BUFFER, fb.vbo);
glUseProgram(fb.program);

View File

@ -1,6 +1,6 @@
#pragma once
#include <glad/gles2.h>
#include "glad/gles2.h"
#include <SDL3/SDL.h>
#include <unordered_map>

View File

@ -10,12 +10,12 @@ varying vec2 vTexCoord;
%%
attribute vec2 aVertCoord;
attribute vec3 aVertCoord;
attribute vec2 aTexCoord;
void main(void) {
vTexCoord = aTexCoord;
gl_Position = vec4(aVertCoord * vec2(1.0 / 64.0), 0.0, 1.0);
gl_Position = vec4(aVertCoord * (1.0 / 64.0), 1.0);
}
##