#Separate texture for a vertex buffer

17 messages · Page 1 of 1 (latest)

wind latch
#

Is there a way to use a sprite as a texture for a vertex buffer without having to mark that sprite as a separate texture in the sprite editor?

earnest atlas
#

yeah

#

all kinds of ways

#

the easiest way is to get the UVs of the sprite and use those when building the vertex buffer

wind latch
earnest atlas
#

alright so you now how your sprites are all on a big ol texture right? like the texture is a sticker sheet and the sprites are stickers on it?

#

when we draw stuff to the screen, we use the whole sticker sheet not just the stickers, so to tell vertex buffers (which is how everything is drawn in gm) what sticker to use, we use UVs

#

the UVs are the individual coordinates of the sprites on the texture page

safe pineBOT
#

This function returns an array with the UV coordinates and other data for the texture of the sprite sub-image on the texture page. The function returns an array with the following 8 elements:

Arguments
sprite: The index of the sprite to use.
subimage: The sub-image of the sprite to use.

earnest atlas
#

if you check out this function, it returns the top left bottom and right UV values for a sprite

#

UVs always go from 0 to 1

#

so if the top left corner of a sprite is right in the middle of the texture, the UV coordinate of that coordinate is 0.5, 0.5

#

so when defining the top left corner of your vertex buffer, you have a vertex format that includes uvs, so it would look like:

vertex_texcoord(buffer, 0.5, 0.5);```for that vertex
wind latch
#

right now what I do for draw a 3D model is:

texture = sprite_get_texture(tex_sprite, 0);
vertex_submit(model, pr_trianglelist, texture);

earnest atlas
#

yes

earnest atlas
#

if you are importing the model, like as an OBJ