Erik Leppen
Member
Hi all, I have another question about vertex buffers (that I couldn't find in the manual).
I have a vertex format using position (xy) and color (ca) and I want to use it to draw a line segment (as a minimal example):
This all works well.
Now, I want to reuse the vertexbuffer, but change the color, i.e. have different colors for different draws of the same vertex buffer.
So I thought: remove the color information from the vertex buffer (and format), and it will use the current active color (set by draw_set_color). Sounds sensible to me
So, create a format with only xy and remove the vertex_color calls, but add draw_set_color before the draw call.
But it doesn't work. I don't see it on screen. Why? I provide the vertex position, I have a color anda alpha set, which should be enough information.
Why does this not work? And how can I make it work, that is: how to store vertex position (xy) data in a vertex buffer and then draw the same vertex buffer multiple times with a different color each time?
I have a vertex format using position (xy) and color (ca) and I want to use it to draw a line segment (as a minimal example):
GML:
vertex_format_begin();
vertex_format_add_position();
vertex_format_add_color();
global.vf_xy_ca = vertex_format_end();
var vbuff = vertex_create_buffer();
vertex_begin(vbuff, global.vf_xy_ca);
vertex_position(vbuff, 100, 100); vertex_color(vbuff, c_red, 1);
vertex_position(vbuff, 200, 150); vertex_color(vbuff, c_red, 1);
vertex_end(vbuff);
vertex_freeze(vbuff);
vertex_submit(vbuff, pr_linelist, -1);
vertex_delete_buffer(vbuff);
Now, I want to reuse the vertexbuffer, but change the color, i.e. have different colors for different draws of the same vertex buffer.
So I thought: remove the color information from the vertex buffer (and format), and it will use the current active color (set by draw_set_color). Sounds sensible to me
So, create a format with only xy and remove the vertex_color calls, but add draw_set_color before the draw call.
GML:
vertex_format_begin();
vertex_format_add_position();
global.vf_xy = vertex_format_end();
var vbuff = vertex_create_buffer();
vertex_begin(vbuff, global.vf_xy);
vertex_position(vbuff, 100, 200);
vertex_position(vbuff, 200, 250);
vertex_end(vbuff);
vertex_freeze(vbuff);
draw_set_color(c_yellow); draw_set_alpha(1);
vertex_submit(vbuff, pr_linelist, -1);
vertex_delete_buffer(vbuff);
Why does this not work? And how can I make it work, that is: how to store vertex position (xy) data in a vertex buffer and then draw the same vertex buffer multiple times with a different color each time?