Legacy GMIs it possible to.. (with surfaces? draw brackgrounds..)

S

Sam L

Guest
For a top down game, my walls are lines that can have any angle or length, resulting in layouts such as this, for example :

(These lines are made of a 1x2 sprite (2 pixels) that are stretched on the side with xscale, and oriented with image_angle)

Now, if I want to fill the interior with a texture, and the exterior with another, can it be done? I don't know much about surfaces, but they only seem to be possible in square/rectangle shapes, or am I wrong? Can surfaces have such complex layouts? Or is there another way to fill this with a texture?

Last edited by a moderator:

jo-thijs

Member
Hi and welcome to the GMC!

Can we assume the lines will properly define a single closed figure without holes, protrubing lines or self intersections?

In that case, yes it's definitely possible, but it can be pretty hard.
You can use primitives to draw the texture inside the given figure,
but you will need to divide your figure in triangles for that to work.

I would have to either research or think for a while how to tackle this problem myself,
but these links could get you started on that:
https://en.wikipedia.org/wiki/Polygon_triangulation
https://www.cs.ucsb.edu/~suri/cs235/Triangulation.pdf

S

Sam L

Guest
Yeah it will always end up a closed figure.
As for 'protrubing lines', I'm not sure I understand, but pretty sure it's a nope.

I'll check this out thanks a lot! I really want this to work I'll let you know when I got significant progress.

S

Sam L

Guest
Edit :

I wasn't ready but I might start tackling this.
Just to know where I'm going : when I figure out the triangulation, what happens then?

I just don't know anything about primitives, but I'll be able to.. use the triangle coordinates to... place a bunch of triangle-shaped primitives? Is 'pr_trianglestrip' what I'm looking for?

And then apply.. textures or colour.. to this triangle strip?

I mean, the hard part mostly is the triangulation beforehand, right?

Last edited by a moderator:

jo-thijs

Member
The hard part is the triangulation, yes.
Primitives allow you to draw a bunch of triangles, lines or points and applying textures to those triangles, lines and points.
To make the triangulation easier (I'm not even sure if it would be possible otherwise), pr_trianglelist would be better than pr_trianglestrip.

The code could look like this:
Code:
``````Create/Step event:
// triangulation code that stores triangle coordinates like this:
// i = 0;
// coord[i + 0] = x1;
// coord[i + 1] = y1;
// coord[i + 2] = x2;
// coord[i + 3] = y2;
// coord[i + 4] = x3;
// coord[i + 5] = y3;
// i += 6;
// next triangle ...

Draw event:
var t = sprite_get_texture(SPRITE, IMAGE);
var w = texture_get_width(t);
var h = texture_get_height(t);

var l = 0; // left side of hidden image
var r = room_width; // right side of hidden image
var u = 0; // top side of hidden image
var d = room_height; // bottom side of hidden image

draw_set_color(c_white);
draw_set_alpha(1);
var cx, cy;
draw_primitive_begin_texture(pr_trianglelist, t);
for(var i = array_length_1d(coord) - 2; i >= 0; i -= 2) {
cx = coord[i];
cy = coord[i + 1];
draw_vertex_texture(cx, cy, (cx - l) / (r - l) * w, (cy - u) / (d - u) * h);
}
draw_primitive_end();``````
Try the code out with some random values for coord in the create event.

S

Sam L

Guest
Thanks again for the help!
My triangulation code is getting close!

However, I'm struggling with the texture thing. (I don't want to draw a large background, I want to apply a small tile (32x32) that repeats itself)

Is that what your code supposed to do? I really don't understand how it works, and I always end up with .. a "zoomed-in topleft part" of my 32x32 sprite. I'm totally lost about how the sprite gets drawn here.

jo-thijs

Member
You can set your sprite to tile horizontally and vertically when editing it.
Allow both and, make sure draw_set_repeat is set to true
and then use my previously suggested code where you replace room_width and room_height with 32.

S

Sam L

Guest
I can't find 'draw_set_repeat', maybe it's 'texture_set_repeat(true)' ? I tried it and now it does tile.. but for some reason it tiles a mixture of ALL my sprites/subimages

I also found background_htiled and background_vtiled, tried em with background_get_texture() but it didn't do anything for me.
I mean, my tile doesnt have to be a 'background' right..?

Here's the code.. any ideas what's going on?

var t = sprite_get_texture(sTexture,0)
var w = texture_get_width(t)
var h = texture_get_height(t)
texture_set_repeat(true)

var l=0
var r=32
var u=0
var d=32

draw_set_color(c_white)
draw_set_alpha(1)

var cx, cy;

draw_primitive_begin_texture(pr_trianglelist,t);

for(var i = array_length_1d(coord) -2; i >= 0; i -= 2) {
cx = coord;
cy = coord[i + 1];

draw_vertex_texture(cx, cy, (cx - l) / (r - l) * w, (cy - u) / (d - u) * h);

}

draw_primitive_end();

jo-thijs

Member
Oh yeah, my bad, I did mean texture_set_repeat.
After some researching, it might be you have to check the "used for 3D" box for the sprite.
I don't really know why though.

S

Sam L

Guest
Mission accomplished!
I'll PS some examples once my triangulation code is finished.

Edit : My man!!