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 "rect-pack.h"
#include "batch.h" #include "batch.h"
#include <glad/gles2.h> #include "glad/gles2.h"
#include "main.h++" #include "main.h++"

View File

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

View File

@ -7,7 +7,7 @@ extern "C" {
#include <limits.h> #include <limits.h>
#include <stdint.h> #include <stdint.h>
#include <stdbool.h> #include <stdbool.h>
#include <glad/gles2.h> #include "glad/gles2.h"
struct texture { struct texture {
GLuint texture; GLuint texture;
@ -21,8 +21,8 @@ struct crop {
int w, h; int w, h;
}; };
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);
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);
void batch_flush(void); void batch_flush(void);

View File

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

View File

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

View File

@ -10,12 +10,12 @@ varying vec2 vTexCoord;
%% %%
attribute vec2 aVertCoord; attribute vec3 aVertCoord;
attribute vec2 aTexCoord; attribute vec2 aTexCoord;
void main(void) { void main(void) {
vTexCoord = aTexCoord; 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);
} }
## ##