Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » [A5] How to draw triangle list outlines only

Credits go to Edgar Reynaldo and MikiZX for helping out!
This thread is locked; no one can reply to it. rss feed Print
[A5] How to draw triangle list outlines only
BitCruncher
Member #11,279
August 2009
avatar

Hi all,

Is there a way to call al_draw_vertex_buffer() with ALLEGRO_PRIM_TRIANGLE_LIST so that it will draw the vertex list as triangles but not fill them?

MikiZX
Member #17,092
June 2019

I am a noob so cannot really help directly - only some thoughts:

You will likely need to create a separate index buffer (using your existing vertex buffer of vertices) for this and then draw this new index buffer using al_draw_indexed_buffer and ALLEGRO_PRIM_LINE_LIST.
Indexed buffer is a list of indices pointing to the vertices in your vertex buffer and those indices, in this example - in pairs, define the lines to be drawn.

If you are using OpenGL, you might have another option (though I have not tested this).
This would be to include :
#include <allegro5/allegro.h>
#include <allegro5/allegro_opengl.h>

and then execute:

// draw the wireframe
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
// draw the same polygons again

// restore default polygon mode
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);

Possibly you will want to do this as well:
// offset the wireframe
glEnable(GL_POLYGON_OFFSET_LINE);
glPolygonOffset(-1,-1);
// draw your stuff here
glDisable(GL_POLYGON_OFFSET_LINE);

Polygon mode used here:
https://github.com/liballeg/allegro5/blob/master/examples/ex_glext.c

Though, as mentioned I am new to Allegro5 so likely someone who knows much more will post a better way.

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

BitCruncher
Member #11,279
August 2009
avatar

I haven't had time to test this, but it seems right, so +1. Thanks.

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Elias
Member #358
May 2000

I have a debug option in my game to switch everything to wireframe - I do it inside of my pixel shader. When the wireframe uniform is set to true it will only draw the outline of each triangle instead of filling it. The advantage is that you do not change anything in your actual drawing code at all (except maybe adding barycentric coordinate attributes), and it's easy to adjust the look of the wireframe.

Just google for "wireframe glsl shader" and you will find plenty, for example this one: https://github.com/rreusser/glsl-solid-wireframe

--
"Either help out or stop whining" - Evert

Go to: