• 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 [SOLVED] How to draw a circle, using a rectangle? (texture mapping)

G'day G'day,

How would one go about drawing a circle, using a sprite that is in the shape of a rectangle?
If using 'regular' code, unless there are only very fine changes in the angle of each rectangle as you draw it around the central point of the would-be circle, the edges of each sprite not meeting up would be very visible.

Would a shader be needed to "bend" the rectangular sprite slightly, in addition to adjusting the image angle?

 
Last edited:
B

brokenjava

Guest
spin the rectangle really really fast then you have a circle :).
or just draw to a surface and spin 1 degree draw repeat. Its really silly but would work.
 
Last edited by a moderator:

Binsk

Member
Not positive on what you are trying to accomplish. You can use primitives if you want to "bend" the image, or perhaps a sprite mask along with either a shader or a surface to create a stencil.
 
B

brokenjava

Guest
How would one go about drawing a circle, using a sprite that is in the shape of a rectangle?
draw the sprite along a circular path calculate the path using pi. I get it, it was a trick question.
 
Thank you everyone for writing in! I have posted an example image in the original post. The size of the rectangle and/or the circle are allowed to change as necessary.
 
B

brokenjava

Guest
Thank you everyone for writing in! I have posted an example image in the original post. The size of the rectangle and/or the circle are allowed to change as necessary.
May i ask what the point of this is? Why use a rectangle and not some other shape, what are you trying to accomplish?
 
May i ask what the point of this is? Why use a rectangle and not some other shape, what are you trying to accomplish?
Variable-sized asteroid belts orbiting some central point. As for why a rectangle, the sprite that has the asteroids is by nature, a square/rectangular thing.
 
B

brokenjava

Guest
I'm ok with making stuff orbit a point, but thank you brokenjava. I need to draw a sprite, repeated seamlessly around a central point. I think it will need texture mapping and primitives, a so called "quad strip" and this I've not done before at all.
Ok now that makes more sence. I would look into is a quad strip supported in opengl es, and for that matter what opengl/directx api the black box chooses. I would suggest a triangle strip, over a quad just because.
 
Ok now that makes more sence. I would look into is a quad strip supported in opengl es, and for that matter what opengl/directx api the black box chooses. I would suggest a triangle strip, over a quad just because.
I only vaguely understand what you refer to here. :confused:

If I not misunderstood, you could use something like this:
Yep, this looks like the idea... dammit this stuff looks kinda hard. :confused: But I absolutely, absolutely need this.
 
Last edited:
Success!! :D That 3 part tutorial series was amazing! Thank you @Dmi7ry for linking them, very much appreciated.

Incidentally, I am using the pr_triangle_strip primitive--not a quad as I thought I might have had to do. (are quad strips even possible with GML primitives here?) Anyway it turns out @brokenjava was on the money re triangles.

If the radius of the circle is large compared to the texture width specified when drawing, the distortion is not noticeable. If anyone is interested, completing part 2 of the tutorial linked above (creating custom 2D geometry) and substituting the path there for a circular one will do the trick!

Code:
/// create a perfect circular path
p_circle = path_add();
path_set_kind(p_circle, 1); // smooth path true or false
path_set_precision(p_circle, 8); // set precision, 8 = max smoothness
radius = 500;
var i = 0;
repeat(10)
{
    path_add_point(p_circle, x + lengthdir_x(radius, i), y + lengthdir_y(radius, i), 100);
    i += 36;
}

Here is the result:



Note: the texture used was seamless
 
Last edited:
B

brokenjava

Guest
Incidentally, I am using the pr_triangle_strip primitive--not a quad as I thought I might have had to do. (are quad strips even possible with GML primitives here?) Anyway it turns out @brokenjava was on the money re triangles.
The only reason i am using game maker is because opening up the opengl manual pages is hard and i wanted to display something more complex than a spinning triangle on my phone in less than 3 weeks. Did you get it to orbit(rotate) yet? I would suggest drawing it to a surface and then just rotate the whole surface.
 
@brokenjava @Dmi7ry @Fel666 I had the ring rotating from its center point, by way of rotating the actual path with path_rotate(pth_circle, 0.1); However, this only works if you don't create a model and redraw the triangles along the path each step.
I went on to create a model, (and that is actually it in the screen shot above) but I do not know how to rotate the actual model. I tried d3d_transform_set_rotation_x and d3d_transform_add_rotation_x but this 'transforms' the whole screen and not the model. No clue about what to do about this at present.
As it happens, I don't actually need to rotate the ring, but if I did, I couldn't really use a surface because I need to draw the ring at a circumference many times greater than the screen.
 

Dmi7ry

Member
I tried d3d_transform_set_rotation_x and d3d_transform_add_rotation_x but this 'transforms' the whole screen and not the model. No clue about what to do about this at present.
Code:
d3d_transform...
d3d_model_draw...
d3d_transform_set_identity();
 
Nice. So, I have a rotating 3D model now, thank you again @Dmi7ry !
However, it was necessary to use d3d_transform_add_translation with my originally intended coordinates (for reasons explained in this tutorial) and in the d3d_model_draw function instead use coordinates of 0, 0, 0.
Code:
d3d_transform_add_rotation_z(rotation_angle);
d3d_transform_add_translation(drawX, drawY, 0); // drawX and drawY are my originally intended draw coordinates
d3d_model_draw(mdl_asteroid_ring, 0, 0, 0, tex); // use coordinates 0, 0, 0 instead of drawX and drawY
d3d_transform_set_identity();
This thread is double solved!
 
Last edited:
Top