• 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!

Legacy GM Explain pr_trianglestrip?

G

Guest User 1

Guest
I'm using primitives to draw the sides of an isometric cube. The documentation described a set of commands that made a rectangle. Thinking I understood this, I went and made the 3 polygons, but this didn't work. There is a corner missing from each polygon, and triangles appear to be being drawn on top of each-other.

Here is my code:
Code:
draw_primitive_begin( pr_trianglestrip ) ;
draw_vertex_colour( 16 ,  0 , $009900 , 1 ) ;
draw_vertex_colour( 32 ,  8 , $009900 , 1 ) ;
draw_vertex_colour( 16 , 16 , $009900 , 1 ) ;
draw_vertex_colour(  0 ,  8 , $009900 , 1 ) ;
draw_primitive_end() ;

draw_primitive_begin( pr_trianglestrip ) ;
draw_vertex_colour( 32 ,  8 , $663300 , 1 ) ;
draw_vertex_colour( 32 , 24 , $663300 , 1 ) ;
draw_vertex_colour( 16 , 32 , $663300 , 1 ) ;
draw_vertex_colour( 16 , 16 , $663300 , 1 ) ;
draw_primitive_end() ;

draw_primitive_begin( pr_trianglestrip ) ;
draw_vertex_colour(  0 ,  8 , $663300 , 0.8 ) ;
draw_vertex_colour( 16 , 16 , $663300 , 0.8 ) ;
draw_vertex_colour( 16 , 32 , $663300 , 0.8 ) ;
draw_vertex_colour(  0 , 24 , $663300 , 0.8 ) ;
draw_primitive_end() ;
While a fixed version would be nice, I'd much rather have an explanation as to how Game Maker draws the triangles based on the points given.

Thanks for any help.
 
C

CaffeineJunky

Guest
pr_trianglestrip will reuse the last two vertices as part of the next triangle.

For example, if I want to draw a square, I can define this using only four vertices, instead of six. However, this can be tricky if you are using backface culling, because you still need to have a counter-clockwise orientation for each one.
 
G

Guest User 1

Guest
pr_trianglestrip will reuse the last two vertices as part of the next triangle.

For example, if I want to draw a square, I can define this using only four vertices, instead of six. However, this can be tricky if you are using backface culling, because you still need to have a counter-clockwise orientation for each one.
This is helpful. Then if I'm using textures, are the last two values in the vertex function from 0 to 1? or are they pixel coordinates? For instance if I want the bottom right of a 32x32 texture, do I use 1, 1? Or 32, 32?
 
C

CaffeineJunky

Guest
The last two values I believe (and you can check the documentation) are numbers between 0 and 1. If you have a texture sheet that is 64x64, and you want to draw the top-right 32x32 square on the geometry, then you would use (0.5, 0), (0.5, 0.5), (1, 0), and (1, 0.5) for the last two parameters.
 
G

Guest User 1

Guest
Below I'm using a texture with the 0-1 value for the dimensions of a 32x32 sprite that is a radial gradient going from white in the middle to black around the edges. When I run the code, I get a black rhombus. Right shape, no texture. I tried adding in draw_set_colour(c_white) at the beginning as it does in the documentation, but then I get a white rhombus. What's happening?
Code:
draw_primitive_begin_texture( pr_trianglestrip , sprite0 ) ;
draw_vertex_texture( 32 ,  0 , 1 ,  0 ) ;
draw_vertex_texture( 64 , 16 , 1 , 1 ) ;
draw_vertex_texture(  0 , 16 ,  0 ,  0 ) ;
draw_vertex_texture( 32 , 32 ,  0 , 1 ) ;
draw_primitive_end() ;
 
C

CaffeineJunky

Guest
You might need to use sprite_get_texture or background_get_texture. See the page in the documentation for draw_primitive_begin_texture.
 
Top