commit dfc3f9664c932c14a418b8b296750d86041aeeba
parent e740e04468efd16f37bd85007ea3b4b25966661e
Author: William Casarin <jb55@jb55.com>
Date: Thu, 4 Nov 2021 08:50:49 -0700
visualize tex coords
Diffstat:
5 files changed, 27 insertions(+), 16 deletions(-)
diff --git a/etc/shaders/rogue/grid.v.glsl b/etc/shaders/rogue/grid.v.glsl
@@ -15,7 +15,7 @@ out shader_data {
void main()
{
- vec3 color = 0.4 + position / 32.0;
+ vec3 color = vec3(tex_coord.xy, 1.0);
data_out.tex_coord = tex_coord;
#include standard_vtxos.glsl
gl_Position = mvp * v4_pos;
diff --git a/etc/shaders/rogue/main.f.glsl b/etc/shaders/rogue/main.f.glsl
@@ -12,6 +12,7 @@ in shader_data {
void main() {
//vec4 v4_pos = vec4(vertex.position, 1.0);
- frag_color = texture(tileset, vertex.tex_coord);
+ //frag_color = texture(tileset, vertex.tex_coord);
+ frag_color = vec4(vertex.color, 1.0);
}
diff --git a/src/grid.c b/src/grid.c
@@ -32,7 +32,7 @@ static void make_grid(float *verts, float vert_capacity,
u32 *indices, float index_capacity,
float *normals, float normal_capacity,
float *colors, float color_capacity,
- float *coords, float coords_capacity,
+ float *tex_coords, float coords_capacity,
int width, int height, float cell_size)
{
int c = 0;
@@ -69,10 +69,15 @@ static void make_grid(float *verts, float vert_capacity,
for (i = 0; i < 2; i++) {
int nv = i*3;
+ int cv = i*2;
+
assert(iind+2+nv < index_capacity);
indices[iind+0+nv] = quad_indices[0+nv] + 4*c;
indices[iind+1+nv] = quad_indices[1+nv] + 4*c;
indices[iind+2+nv] = quad_indices[2+nv] + 4*c;
+
+ tex_coords[iind+0+cv] = quad_uvs[0+cv];
+ tex_coords[iind+1+cv] = quad_uvs[1+cv];
}
}
}
@@ -83,26 +88,29 @@ void make_grid_geom(struct geometry *geom, int width, int height, float cell_siz
struct make_geometry mkgeom;
init_make_geometry(&mkgeom);
- int size = 12 * width * height;
- int ind_size = 6 * width * height;
+ int wh = width * height;
+ int vert_size = 12 * wh;
+ int ind_size = 6 * wh;
+ int uv_size = 4 * wh;
- float verts[size]; // array_size(quad) 12 * w * h
- float colors[size]; // array_size(quad) 12 * w * h
- float normals[size]; // array_size(quad) 12 * w * h
+ float verts[vert_size]; // array_size(quad) 12 * w * h
+ float colors[vert_size]; // array_size(quad) 12 * w * h
+ float normals[vert_size]; // array_size(quad) 12 * w * h
+ float tex_coords[uv_size];
u32 indices[ind_size]; // array_size(quad) 6 * w * h
- make_grid(verts, size,
+ make_grid(verts, vert_size,
indices, ind_size,
- normals, size,
- colors, size,
- tex_coords, size,
+ normals, vert_size,
+ colors, vert_size,
+ tex_coords, uv_size,
width, height, cell_size);
mkgeom.indices = indices;
mkgeom.vertices = verts;
mkgeom.normals = normals;
mkgeom.colors = colors;
- mkgeom.tex_coords = quad_uvs;
+ mkgeom.tex_coords = tex_coords;
mkgeom.num_indices = ARRAY_SIZE(indices);
mkgeom.num_verts = ARRAY_SIZE(verts)/3;
diff --git a/src/shader.c b/src/shader.c
@@ -153,13 +153,14 @@ void init_gpu_program(struct gpu_program *program) {
memset(program, 0, sizeof(*program));
}
-void link_attribute(struct gpu_program *program, const char *name,
+gpu_addr link_attribute(struct gpu_program *program, const char *name,
enum vertex_attr attr)
{
program->vertex_attrs[attr] =
(gpu_addr)glGetAttribLocation(program->handle, name);
program->active_attributes |= 1 << attr;
check_gl();
+ return program->vertex_attrs[attr];
}
static inline struct lens *get_uniform_lens(struct gpu_program *program,
@@ -271,8 +272,8 @@ void create_attribute_bindings(struct gpu_program *program)
rtassert(0, "");
}
- debug("%s: linking %s to %d\n", program->name, name, attr);
- link_attribute(program, name, attr);
+ gpu_addr addr = link_attribute(program, name, attr);
+ debug("%s: linking %s to %d\n", program->name, name, addr);
}
}
diff --git a/src/texture.c b/src/texture.c
@@ -14,6 +14,7 @@ u32 create_cubemap(const char *faces[6]) {
u8 *data, *img_data;
size_t data_len;
+ glActiveTexture(GL_TEXTURE0);
glGenTextures(1, &tid);
glBindTexture(GL_TEXTURE_CUBE_MAP, tid);