GMS 2 [Solved] Texture page dimensions / width to height ratio

Bart

WiseBart
Hi all.

I'm trying to debug-draw a texture page/group.
So I use a simple vertex buffer with a square consisting of 2 triangles and pass the texture page.
After doing a preview in the Windows Graphics options, the texture page dimensions appear to be 1024x2048. So not square.

A rectangular (and not square) texture page still has (0, 0) as the top-left uv and (1, 1) as the bottom-right uv. texture_get_width and texture_get_height return these values in the 0-1 range.
Is there any way to know what the actual dimensions of a texture page turn out to be? Or to know the ratio of width to height?

Maybe there's a function I don't know of or a trick/workaround that I'm missing.
Although if I'm not mistaken it doesn't seem like this is currently possible in GM?

EDIT: Found the solution... Divide texel width by texel height texel height by texel width to get the ratio of width to height. Thanks to @flyingsaucerinvasion for the correction.
Here's the explanation:
Code:
// w = width, h = height, tw = texel width, th = texel height
w = 1 / tw;
h = 1 / th;
// So:
w * tw = h * th;
w / h = th / tw;
It doesn't seem to be possible to get the actual texture page size, although that's something that could be hard-coded. This is also possible. See the answer below.
 
Last edited:
It is possible to get the width and height of the texture.

width = 1 / texture_get_texel_width(tex);

height = 1 / texture_get_texel_height(tex);

I don't even know what texture_get_width and texture_get_height are supposed to return. They always seem to return 1 no matter what. The manual is extremely ambiguous on these functions.

EDIT:

One other thing, width/height is actually equal to texel_height/texel_width
 
Last edited:

Bart

WiseBart
It is possible to get the width and height of the texture.

width = 1 / texture_get_texel_width(tex);

height = 1 / texture_get_texel_height(tex);

I don't even know what texture_get_width and texture_get_height are supposed to return. They always seem to return 1 no matter what. The manual is extremely ambiguous on these functions.
Ah yes, you're right. How could I miss that...

Those functions do indeed seem to return 1 in most (all?) cases. I may try to figure that out at some point.
EDIT:

One other thing, width/height is actually equal to texel_height/texel_width
Also right. I wasn't sure why I had to divide instead of multiply.
Modified it in the original post.

Thanks for your help!
 
Top