• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

draw_vertex_texture, repeated triangle texture

BMatjasic

Member
Hello everyone,

Recently I've been messing around with vertexes and I wonder, how would I be able to apply a repeated texture on a triangle, because I've been pretty unsuccessful with xtex and ytex arguments... The way I currently draw it is:

Code:
DrawTerrain();

draw_primitive_begin_texture(pr_trianglestrip, background_get_texture(background0));

for(var i=0; i < ds_list_size(Points); i++) {
    

    if((i+1)%2 == 0) {
    draw_set_color(c_white);
        var pointMap = ds_list_find_value(Points, i-1);
        var px = ds_map_find_value(pointMap, "x");
        var py = ds_map_find_value(pointMap, "y");
        
        var pointMap1 = ds_list_find_value(Points, i);
        var px1 = ds_map_find_value(pointMap, "x");
        
        draw_vertex_texture(px, py,1,1);
        draw_vertex_texture(px1, py, 1, 1);
        draw_vertex_texture(px, room_height, 1,1);
        
      
    }
}
draw_primitive_end();
And the outcoming result is:



QUESTION:

How would I be able to repetable apply smooth texture over those triangles?

PS: I've commented code for bottom triangles just for the easier preview
 

Joe Ellis

Member
Code:
draw_vertex_texture(px, py,px/(background_get_width(background0)),py/(background_get_height(background0)));
this is basically what you need

Also look at this thread I made, It'll explain everything you need to know about tex coordinates

https://forum.yoyogames.com/index.p...retched-torn-model-textures.12677/#post-83831

https://forum.yoyogames.com/index.php?threads/tiled-animated-textures.12765/#post-83930

basically the texture coords range from 0 to 1

0 is the left/top and 1 is the right/bottom

so if you want it spreading over a triangle you need to set furthest left vertex texture coord to be at 0

and the furthest right vertex to be 1

and if you want it tiling and repeating change the 1 to a higher number, 2 will make it repeat twice and 3 will make it repeat thrice etc.

you can also map it to the vertices' coords by dividing the vertex coord by the texture width (this is what you'll want if your making a 2d game)

eg. v1tx=v1x/128
v1ty=v1y/128

or
v1tx=v1x/(background_get_width(tex1))
v1ty=v1y/(background_get_height(tex1))
 

BMatjasic

Member
Well, it didin't exactly worked as I've planned, I've changed the code and read both articles which I've found very usefull, but the solution isn't what I've been looking for.. I've also unsuccessfully tried many other ways...

 

Joe Ellis

Member
Right, I think the problem is probably that you havent got texture repeat set to true.

All you need to do is put texture_set_repeat(1) in the create event.

Also on the background you need to check Used for 3D.

Looking at your code there might be something going wrong with the actual geometry aswell, is that slope supposed to be solid white? Cus the zig-zag thing means your only making 1 triangle at each step, you need to make 2 triangles at a time, 1 being the mirror of the other one, filling the gap.

Also you're best learning how to use vertex buffers aswell cus they increase performance infinitely and are alot simpler to use once you know how.

Having a loop in your draw event working through a ds_ is really gonna slow your game down, and is completely unnecessary, you only need to do this once in the create event while creating the vertex buffer, then in the draw event all you need is one line: vertex_submit(vbuff1,pr_trianglelist,texture)


All you need to do is replace the draw_vertex_texture with vertex_position_3d and vertex_texcoord

Code:
DrawTerrain();

draw_primitive_begin_texture(pr_trianglestrip, background_get_texture(background0));

for(var i=0; i < ds_list_size(Points); i++) {
    

    if((i+1)%2 == 0) {
    draw_set_color(c_white);
        var pointMap = ds_list_find_value(Points, i-1);
        var px = ds_map_find_value(pointMap, "x");
        var py = ds_map_find_value(pointMap, "y");
        
        var pointMap1 = ds_list_find_value(Points, i);
        var px1 = ds_map_find_value(pointMap, "x");
        
        vertex_position_3d(p1x,p1y,0)
        vertex_texcoord(p1x/width,p1y/height)
        vertex_position_3d(p2x,p2y,0)
        vertex_texcoord(p2x/width,p2y/height)
        vertex_position_3d(p3x,p3y,0)
        vertex_texcoord(p3x/width,p3y/height)
        vertex_position_3d(p3x,p3y,0)
        vertex_texcoord(p3x/width,p3y/height)
        vertex_position_3d(p4x,p4y,0)
        vertex_texcoord(p4x/width,p4y/height)
        vertex_position_3d(p1x,p1y,0)
        vertex_texcoord(p1x/width,p1y/height)
    }
}
draw_primitive_end();
Also heres an example from one of my projects:

Code:
///Update Tile Buffer
if ca=0
{
ca=1
}
vertex_begin(b,f1)
n=0
do
{
if ds_list_find_value(cl,n+1)=ttex
{
cx=ds_list_find_value(cl,n+2)
cy=ds_list_find_value(cl,n+3)
cz=ds_list_find_value(cl,n+4)
vertex_position_3d(b,cx,cy,cz)
vertex_texcoord(b,0,0)
vertex_colour(b,c_white,ca)
vertex_position_3d(b,cx+gs,cy,cz)
vertex_texcoord(b,1,0)
vertex_colour(b,c_white,ca)
vertex_position_3d(b,cx+gs,cy+gs,cz)
vertex_texcoord(b,1,1)
vertex_colour(b,c_white,ca)
vertex_position_3d(b,cx+gs,cy+gs,cz)
vertex_texcoord(b,1,1)
vertex_colour(b,c_white,ca)
vertex_position_3d(b,cx,cy+gs,cz)
vertex_texcoord(b,0,1)
vertex_colour(b,c_white,ca)
vertex_position_3d(b,cx,cy,cz)
vertex_texcoord(b,0,0)
vertex_colour(b,c_white,ca)
}
n+=5
}
until ds_list_find_value(cl,n)=undefined
vertex_end(b)
vertex_freeze(b)
I'm not gonna bother explaining what every bit is, but you'll probably get the jist from it
 
Top