Skip to content

Commit

Permalink
library: fix vertex2d_xy y direction
Browse files Browse the repository at this point in the history
  • Loading branch information
Adamcake committed Nov 27, 2024
1 parent 27fca45 commit 8532e98
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
17 changes: 13 additions & 4 deletions src/library/doc.texi
Original file line number Diff line number Diff line change
Expand Up @@ -1925,7 +1925,8 @@ or smaller than that area, proportionally.
@subsection vertexxy

Given an index of a vertex in a batch, returns its X and Y position on
the screen, in pixel coordinates.
the screen, in pixel coordinates. As with all pixel coordinates in the
Bolt API, this is relative to the top-left pixel of the screen.

@node batch2d-vertexatlasxy
@subsection vertexatlasxy
Expand All @@ -1943,7 +1944,13 @@ its associated image in the batch's texture atlas, in pixel coordinates.
@subsection vertexuv

Given an index of a vertex in a batch, returns the vertex's associated
"UV" coordinates.
"UV" coordinates. The values will be floating-point numbers in the range
0.0 - 1.0.

Unlike with 3D render events, these UVs are relative to the entire
texture atlas, not to the sub-image. However they may fall outside the
bounds of the sub-image, in which case they're usually expected to wrap
around within it.

The values will be floating-point numbers in the range 0.0 - 1.0. They
are relative to image in the texture atlas.
Expand Down Expand Up @@ -2202,8 +2209,10 @@ local x, y, w, h = event:atlasxywh(meta)

Given a vertex number, returns the vertex's associated "UV" coordinates.

The values will be floating-point numbers in the range 0.0 - 1.0. They
are relative to image in the texture atlas.
The values will be floating-point numbers, usually in the range 0.0 -
1.0. They are relative to image in the texture atlas. They may fall
outside the image (and therefore outside the range 0.0 - 1.0), in which
case they're expected to wrap around within the image.

@node render3d-vertexcolour
@subsection vertexcolour
Expand Down
9 changes: 6 additions & 3 deletions src/library/gl.c
Original file line number Diff line number Diff line change
Expand Up @@ -1445,13 +1445,14 @@ void _bolt_gl_onDrawElements(GLenum mode, GLsizei count, GLenum type, const void
vertex_userdata.atlas_size = &attributes[c->bound_program->loc_aTextureUVAtlasExtents];
vertex_userdata.tex_uv = &attributes[c->bound_program->loc_aTextureUV];
vertex_userdata.colour = &attributes[c->bound_program->loc_aVertexColour];
vertex_userdata.screen_height = roundf(2.0 / projection_matrix[5]);

struct GLPluginTextureUserData tex_userdata;
tex_userdata.tex = tex;

struct RenderBatch2D batch;
batch.screen_width = roundf(2.0 / projection_matrix[0]);
batch.screen_height = roundf(2.0 / projection_matrix[5]);
batch.screen_height = vertex_userdata.screen_height;
batch.index_count = count;
batch.vertices_per_icon = 6;
batch.is_minimap = tex_target && tex_target->is_minimap_tex_small;
Expand Down Expand Up @@ -1687,11 +1688,13 @@ void _bolt_gl_onViewport(GLint x, GLint y, GLsizei width, GLsizei height) {

static void _bolt_gl_plugin_drawelements_vertex2d_xy(size_t index, void* userdata, int32_t* out) {
struct GLPluginDrawElementsVertex2DUserData* data = userdata;
if (!_bolt_get_attr_binding_int(data->c, data->position, data->indices[index], 2, out)) {
if (_bolt_get_attr_binding_int(data->c, data->position, data->indices[index], 2, out)) {
out[1] = (int32_t)data->screen_height - (out[1] + 1);
} else {
float pos[2];
_bolt_get_attr_binding(data->c, data->position, data->indices[index], 2, pos);
out[0] = (int32_t)roundf(pos[0]);
out[1] = (int32_t)roundf(pos[1]);
out[1] = (int32_t)data->screen_height - ((int32_t)roundf(pos[1]) + 1);
}
}

Expand Down
1 change: 1 addition & 0 deletions src/library/gl.h
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,7 @@ struct GLPluginDrawElementsVertex2DUserData {
struct GLAttrBinding* atlas_size;
struct GLAttrBinding* tex_uv;
struct GLAttrBinding* colour;
uint32_t screen_height;
};

struct GLPluginDrawElementsVertex3DUserData {
Expand Down

0 comments on commit 8532e98

Please sign in to comment.