16
Graphics / Re: Drawing Vertex Array with big Texture
« on: January 26, 2024, 11:39:00 am »
If you're willing to get your hands dirty with some OpenGL the Array Texture would help here (and would also be a nice addition to SFML, but that's another matter
)
For example, if you have individual textures, as Hapax says, each containing an atlas of a single frame, you can load each one of these into a slot in the texture array - resulting in a single texture bind/single vertex array for all the frames.
In the first case where all characters are on the same frame, you can simply set the current frame index in the shader:
Animating characters individually is a little more work, however can be done by setting the frame index of a character in its vertex data:
In the latter case you could even combine the coordinates in the vertex shader if you don't mind losing the flat qualifier. It's a relatively large chunk of work to set up, however it results in a single vertex array and a single texture object for your text, and if encapsulated would be a nice addition to any library
![Wink ;)](https://www.sfml-dev.org/forums/Smileys/default/wink.gif)
For example, if you have individual textures, as Hapax says, each containing an atlas of a single frame, you can load each one of these into a slot in the texture array - resulting in a single texture bind/single vertex array for all the frames.
In the first case where all characters are on the same frame, you can simply set the current frame index in the shader:
Code: [Select]
uniform sampler2DArray u_texture;
uniform float u_frameIndex;
in vec2 v_texCoord;
out vec4 o_colour;
void main()
{
o_colour = texture(u_texture, vec3(v_texCoord, u_frameIndex));
}
Animating characters individually is a little more work, however can be done by setting the frame index of a character in its vertex data:
Code: [Select]
//vertex shader
in vec2 a_position;
in vec2 a_texCoord;
in float a_frameIndex;
out vec2 v_texCoord;
flat out float v_frameIndex;
void main()
{
gl_Position = //usual stuff here
v_texCoord = a_texCoord;
v_frameIndex = a_frameIndex;
}
//then in the fragment shader we do as before, only the frame index comes from the vertex shader, not a uniform:
uniform sampler2DArray u_texture;
in vec2 v_texCoord;
flat in float u_frameIndex;
out vec4 o_colour;
void main()
{
o_colour = texture(u_texture, vec3(v_texCoord, u_frameIndex));
}
In the latter case you could even combine the coordinates in the vertex shader if you don't mind losing the flat qualifier. It's a relatively large chunk of work to set up, however it results in a single vertex array and a single texture object for your text, and if encapsulated would be a nice addition to any library
![Smiley :)](https://www.sfml-dev.org/forums/Smileys/default/smiley.gif)