GMS 2 3D: drawing a vertex buffer at different coordinates/location?


Hello, I'm just curious if anyone knows of a way to draw a frozen vertex buffer at a different location on screen? I've checked through the documentation for a way to do this and so far the only thing I could find is:
matrix_transform_vertex(matrix, x,y,z,)
However, since i'm pretty sure a vertex buffer isn't a matrix I don't really know where to go from here or how to use this function. Of course it's possible to run a script to recreate the vertices at the desired location, rotation, and depth, I just figured that there is probably some built in function to do this somewhere that I can't find, or don't understand how to use.



Heavy metal viking dentist
GMC Elder
Vertex shaders let you move vertices around freely! The method depends on exactly what you want to happen.


If you just want to draw the same vertex buffer multiple times with a different transformation, you need to set the world matrix to the transform you want for that batch using the matrix_set() function:
matrix_set(matrix_world,some_transform_matrix);  // Easiest is to use matrix_build()
If you want to draw groups of vertices or triangles of a vertex buffer with different transforms, you'll have to 'tag' the vertices with an index and pass in the transforms via a uniform array, then get the right transform in the vertex shader using the index.
In both cases, you can use a frozen vertex buffer.


Thanks so much for the replies! I've got the shader method working fairly well but I'm missing some features. Basically I am trying to create an easy to use function for drawing a sprite or a model in 3D. So in other words I'm creating a "draw_sprite_ext" sort of function for a vertex buffer.

I don't mean to be a bother, but if people are interested and could help me sort out some of the features that would be amazing. I'm still fairly new to shaders and 3D so it's a bit of a grind trying to sort through this on my own.

The main items I am having issues with are:
  • Rotating a frozen vertex buffer
  • Scaling x,y,z separately
  • drawing textures without needing a separate texture page
Ideally, after trying different methods it seems to me that using a shader is the best option. Currently this is as far as I have gotten with the shader which works with x,y,z positions and can adjust size with a general scale value.
attribute vec3 in_Position;                // (x,y,z)
attribute vec4 in_Colour;                  // (r,g,b,a)
attribute vec2 in_TextureCoord;            // (u,v)

varying vec2 v_vTexcoord;
varying vec4 v_vColour;

uniform float xPos;
uniform float yPos;
uniform float zPos;

uniform float objScale;

void main()
    vec4 object_space_pos = vec4(in_Position.x+xPos, in_Position.y+yPos, in_Position.z+zPos, objScale);
    gl_Position = gm_Matrices[MATRIX_WORLD_VIEW_PROJECTION] * object_space_pos;
    v_vColour = in_Colour;
    v_vTexcoord = in_TextureCoord;
The fragment shader is currently untouched, however I have also been looking into ways of using the texture UV's of sprites so that they can be used from a combined texture page. So far it seems the only way to do that is to texture_set_stage() a texture to the shader and call that in the fragment instead of "gm_BaseTexture".

Anyway thanks for the help! and sorry if this is bothersome.
rotating, scaling, translating, and some other kinds of distortions can be done easily by changing the world matrix. The question is what is the cost of changing a matrix? And is there a better way of doing it? You can always combine textures onto one texture page, and then draw different parts of that texture by adjusting the texture coordinates somewhere in your vertex or fragment shader, for example based on the present value of a uniform variable. I know you can draw normal sprites in 3d, and you can even transform them, rotate, scale, translate, etc... so in that case the texture coordinates will be automatically set by gamemaker. Again the question is what is the cost of changing the state of the world matrix on an individual instance basis? Oh one gotcha to warn you about, this applies to GMS1.4, and I don't know if it also applies to GMS2, but if you try to draw some 2d stuff in 3d from inside of normal draw events, they might be culled (not drawn at all) if they are out of the present view, regardless if they would be visible in the present 3d projection.


(Sorry, posted in the wrong thread. Feel free to delete)
Last edited by a moderator: