Drawing A Vertex Buffer As An Outline

Is it possible to draw a shape built from vertices, say, a circle, as an outline similar to draw_circle(x,y,outline) where outline = true without using a shader? I can't seem to locate a solution. If I render the vertices using pr_linestrip the lines connecting to the radial vertex are also drawn (as they should be).

The following code works to draw an outline but it uses draw_primitive_begin() and its related functions, an approach which is undesirable in this case.

GML:
var _steps = 20;
var _xx = 50;
var _yy = 50;
var _radius = 30;
draw_primitive_begin(pr_linestrip);
//draw_vertex_color(_xx, _yy,c_white,1.0);
for(var i = 0; i <= _steps; ++i;)
    {
    draw_vertex_color(_xx + lengthdir_x(_radius, 360 * i / _steps), _yy + lengthdir_y(_radius, 360 * i / _steps), c_white,1.0);

    //For a psychedelic experience, comment out the above draw_vertex call and uncomment the below draw_vertex call. Also, change the draw_primitive_begin() render method to pr_trianglefan
    //To make it look like a crazy, magic vortex, uncomment the initial draw_vertex_color(_xx, _yy,c_white,1.0) call.
    //Do this at your own risk. lol
    //draw_vertex_color(_xx + lengthdir_x(_radius, 360 * i / _steps), _yy + lengthdir_y(_radius, 360 * i / _steps), make_color_rgb(random(255),random(255),random(255)),1.0);
    }
draw_primitive_end();
Might there be a way to use pr_linestrip to render a line between only two vertices in a vertex buffer?
 

Binsk

Member
You can render a vertex buffer w/ pr_linestrip just like draw_primitive_* functions.

If you are asking to skip vertices in the buffer when executing this then no, there is no built-in way to do it. I would say just built a separate vertex buffer with the undesired vertices removed. You can copy a vertex buffer to a regular buffer and back as needed so it is fairly easy to modify and rebuild so long as you know the data for each vertex (so you know how many bytes to delete). Either do that or build two copies when you initially make the buffer, one copy w/o the extra vertices.
 
You can render a vertex buffer w/ pr_linestrip just like draw_primitive_* functions.

If you are asking to skip vertices in the buffer when executing this then no, there is no built-in way to do it. I would say just built a separate vertex buffer with the undesired vertices removed. You can copy a vertex buffer to a regular buffer and back as needed so it is fairly easy to modify and rebuild so long as you know the data for each vertex (so you know how many bytes to delete). Either do that or build two copies when you initially make the buffer, one copy w/o the extra vertices.
Interesting. So, vertices can be rendered using vertex_submit() even if they do not consist of a full triangle? I haven't pulled individual vertices from a vertex buffer as I have not had a need to do so. Can you point me in the direction of a tutorial for how to pull vertices from a vertex buffer into a normal buffer and then into a new vertex buffer?

Also, did you try the psychedelic experience in my above code. It's wacky!
 

Simon Gust

Member
Interesting. So, vertices can be rendered using vertex_submit() even if they do not consist of a full triangle? I haven't pulled individual vertices from a vertex buffer as I have not had a need to do so. Can you point me in the direction of a tutorial for how to pull vertices from a vertex buffer into a normal buffer and then into a new vertex buffer?

Also, did you try the psychedelic experience in my above code. It's wacky!
There are functions for that, called buffer_create_from_vertex_buffer() and vertex_create_buffer_from_buffer() or by recreating the vertex buffer manually if you want to delete or add vertices.
A linestrip should be represented in the buffer the same way your vertex format suggests it.
With only vertex_format_add_position (only vertices), it would like like this
Code:
x1 = buffer_read(buffer, buffer_f32);
y1 = buffer_read(buffer, buffer_f32);

x2 = buffer_read(buffer, buffer_f32);
y2 = buffer_read(buffer, buffer_f32);

x3.... 
and so on
in this case, every vertex has a size of 8 (bytes).

if the format contains also color to each vertex, then they would be set inbetween them
Code:
x1 = buffer_read(buffer, buffer_f32);
y1 = buffer_read(buffer, buffer_f32);
c1 = buffer_read(buffer, buffer_u32);

x2 = buffer_read(buffer, buffer_f32);
y2 = buffer_read(buffer, buffer_f32);
c2 = buffer_read(buffer, buffer_u32);

x3....
with c holding the color together with an alpha value and the total size of a vertex being 12 bytes.
 
Top