3:43 The other super important aspect of triangles when it comes to 3D rendering is that, for any triangle, you can guarantee that there is exactly one plane in 3D space that passes through its three vertices. This is not necessarily the case if you have four or more points in space.
Here is the updated vertex_add_point script for GMS 2.3 /// @param vbuffer /// @param xx /// @param yy /// @param zz /// @param nx /// @param ny /// @param nz /// @param utex /// @param vtex /// @param color /// @param alpha function vertex_add_point(argument0, argument1, argument2, argument3, argument4, argument5, argument6, argument7, argument8, argument9, argument10) { var vbuffer = argument0; var xx = argument1; var yy = argument2; var zz = argument3; var nx = argument4; var ny = argument5; var nz = argument6; var utex = argument7; var vtex = argument8; var color = argument9; var alpha = argument10; // Collapse four function calls into a single one vertex_position_3d(vbuffer, xx, yy, zz); vertex_normal(vbuffer, nx, ny, nz); vertex_texcoord(vbuffer, utex, vtex); vertex_color(vbuffer, color, alpha); }
For anyone messing around with this code, do not repeat my mistake: the order at which you set vertex format parameters and the order at which you apply these parameters to vertex buffers must be identical. These functions are very sensitive to this. I accidently swapped vertex_format_add_texcoord with vertex_format_add_color without thinking and kept wondering afterwards why all my tiles suddenly lost their texture and became blue.
yeah, at 6:15 he was confused. The idea behind this is that the API of the engine is working like a state machine. The format has been defined in this specific order, and the vertex buffer must match the format. OpenGL is working the same way.
Howdy Michael, and happy new year!! I've watched this video a couple of times now. The first time was for your sense of humour, the second time was also for your sense of humour. The third time, which is now, was coming back after having a crack at using primitives as an alternative for creating vertex graphics; for example; //Object Draw event; var matrix = matrix_build(x,y,0,0,0,image_angle,1,1,1) matrix_set(matrix_world,matrix); draw_primitive_begin(pr_trianglefan); draw_vertex_color(400,400,c_black,1); draw_vertex_color(400,600,c_black,1); draw_vertex_color(600,600,c_black,1); draw_primitive_end(); matrix_set(matrix_world, matrix_build_identity()); The above is far simpler to code 2D shapes (less command overhead), but yet somewhat similar to what you've detailed in your video - but I'm guess at the cost of frame rate? Would creating graphics with primitives/matrix be far slower compared to what you've just described in this video? And can you think of any advantages/disadvantages to either or method? As I have my project working using primitive graphics, I can't help but notice that with roughly 100 objects the frame rate starts to drop with each new object added... (although I am also pushing the vertex data into generating 2D fixtures for Box Physics collision too, so this might also have something to do with it, guess I need to isolate the primitive drawing method vs your vertex buffer drawing method and compare performance).
It would be about as fast either way (beginning or ending a primitive incurs a batch break, as do the matrix functions, which are especially slow) but saving the vertex data to a vertex buffer allows you to reuse them more easily - so you can work faster - and saves you the trouble of having to define every vertex every single time you try to draw something, which isn't really a problem for a single triangle but adds up quickly for larger objects. If you need the vertex data to change on the fly - if the physics system is allowed to deform it, for example - then you might be better off using the draw_primitive functions, though. If you just need to generate the fixtures from the vertex positions, you can probably get away with just doing that in the Create event.
Point List is great for Particles and things of that nature. You can enlarge the point size in the shader which would give you the equivalent of a bunch of small quads yet they can be drawn with nothing more than a single point.
for when your writing the script i have done the same thing as what you did but it says that the" vertex_position_3d (vbuffer, xx, yy, zz,);" is undefined why is that? at 12:25
I just fixed it, instead of creating parameters using '/// @param' , I put 'function vertex_add_point([11 arguments])' into the top of the script and put all the code in braces.
6:15 I think the vertex_format_end() returning the ID makes sense instead of vertex_format_start(). When you come form hardcore code in OpenGL world (and more obviously from fixed function pipeline), the API of the graphical engine is working like a state machine. The actual ID is returned upon completion of the state machine, when you reach the end state. If the ID was created earlier, then the ID would point to a structure that is in an inconsistent state (i.e. not fully defined). Imagine what could happen if you use this ID before it is actually defined with all the vertices, colors, texture coords.
If your triangle isn't being drawn: It's POSSIBLY to do with the camera being in the wrong place. To fix this, replace the camera_set_view_mat script in the draw event with this: camera_set_view_mat(camera, matrix_build_lookat(0, 0, 400, room_width, room_height, 0, 0, 0, -1)); i'd have explained it more but i'm not the best at wording stuff.
Herro! Started getting into this series and had the same problem with getting the error. ERROR in action number 1 of create event for object : vertex position 3d argument 1 incorrect type (undefined) expecting a vertex_buffer etc.
My floor and player textures are drawing fine, but when I do a shadow and an enemy the texture is drawing the specified sprite, then a strip of sprites. I'm doing the same vertex_submit with sprite_get_texture for them so I don't know why this is happening I saw a reddit post saying it has something to do with VRAM?
the cool thing for gms2 is that all you have to do is middle click to find out what somthing is. when i dont know what a code does i middle click it and it gives me stuff about it
I'm so confused? I've checked my code against the video however when I run the game the triangle never appears? Any idea what could have gone wrong? The Camera shows the same it's just the triangles that don't appear?
I figured it out, you need to change the camera objects draw function. Inside the draw function make sure that in camera_set_view_mat, the matrix has 400 as the 3rd entry
@@fourriversfarm For UV mapping in general, this video looks pretty decent: ua-cam.com/video/dj0uXid9oGo/v-deo.html I also made this a few years ago: ua-cam.com/video/ajl3l0gu34k/v-deo.html Other than that, just opening a model in Blender or Game Maker Model Creator and fiddling with the texture UVs could be pretty useful, you'll get a feel for how textures wrap around the faces that way.
I was tired trying to write everything down so I could format my own code as I get better but then I kept misspelling everything until my Bluetooth decided to let me know they are dying and man am I awake now... And sleep send help
How are fps? I have a GTX 1080. What do you think fps would be like with 20k plus triangles with pos, text, color, and normals? Just basically wondering how fast the vertex buffers actually are for the quality of texturing etc.
Depends on how you draw them. Generally speaking, 20k triangles is nothing, but if you draw them one-by-one it'll be much slower than drawing them all in the same vertex buffer.
Towards the end of the video you talk about method to make sure the camera is done first by either setting it to a high depth or your other work around by calling from the objects. Is there a reason you don't just apply the camera in the draw begin step? Then everything in the regular draw step could just be done normally right?
As far as I know that should work too, I just like having it in the same event as the rest of the draw code. I usually like to loop through objects in the camera's draw event instead of letting them draw themselves since you get more control over things that way.
I was checking out the manual entry for vertex_normal and I don't understand what it means by "The above code will set the surface normal of the vertex being defined." What does surface normal mean? I'm up to 9:59 in the video and I started watching from the part about depth-sorting. I'm looking to use vertex buffers for isometric games.
Normals come into play when you start doing 3D lighting: ua-cam.com/video/mspdUDlVEXI/v-deo.html If you don't need that don't worry about it (you can either set it to all 0s, or get rid of completely).
I made this one a few years ago on DLLs: ua-cam.com/video/jkgMxrDvwPs/v-deo.html but GMS1 / 2 changed the extension systems by a fair amount, so revisiting that one might not be a bad idea . . .
would not recommend doing that in the step event unless you have to, even if you delete them properly when you're finished it could slow the game down if you're generating too much of it
Generally you see them clockwise, although if you need them to be counterclockwise for whatever reason you can set the culling direction to counterclockwise. Ultimately it's more important that everything in the game is consistent with everything else in the game.
@@DragoniteSpam Okay: Interesting: docs2.yoyogames.com/source/_build/3_scripting/4_gml_reference/drawing/gpu/gpu_set_cullmode.html I had seen the d3d article and didn't realize it was referring to 1.4.
@@Ragnark1 Yeah they added the ability to define the culling direction in 2, it's not something that's usually useful but is nice on occasion - if you want to render something inside-out, for example.
@@DragoniteSpam I have been reading tons of material that states that OpenGL's winding order for vertices is actually counter-clockwise. Does GMS have a preference or best-practice?
13:30 hey so I wrote this all out but for some reason I keep getting an error saying there is something wrong with line 25 and it’s expected a number in the parentheses bit there is numbers there;-;
ERROR in action number 1 of Create Event for object obj_camera: vertex_color argument 3 incorrect type (undefined) expecting a Number (YYGF) at gml_Script_vertex_add_point_new (line 19) - vertex_color(vbuffer, color, alpha) ############################################################################################ gml_Script_vertex_add_point_new (line 19) gml_Object_obj_camera_Create_0 (line 24) - vertex_add_point_new(v_buffer, x1, y1, 100, 0, 0, 1, c_white, 1) Also i am using 2023 version maybe its because of this
3:43 The other super important aspect of triangles when it comes to 3D rendering is that, for any triangle, you can guarantee that there is exactly one plane in 3D space that passes through its three vertices. This is not necessarily the case if you have four or more points in space.
this playlist is the holy grail of GMS tutorials, thank you
Here is the updated vertex_add_point script for GMS 2.3
/// @param vbuffer
/// @param xx
/// @param yy
/// @param zz
/// @param nx
/// @param ny
/// @param nz
/// @param utex
/// @param vtex
/// @param color
/// @param alpha
function vertex_add_point(argument0, argument1, argument2, argument3, argument4, argument5, argument6, argument7, argument8, argument9, argument10) {
var vbuffer = argument0;
var xx = argument1;
var yy = argument2;
var zz = argument3;
var nx = argument4;
var ny = argument5;
var nz = argument6;
var utex = argument7;
var vtex = argument8;
var color = argument9;
var alpha = argument10;
// Collapse four function calls into a single one
vertex_position_3d(vbuffer, xx, yy, zz);
vertex_normal(vbuffer, nx, ny, nz);
vertex_texcoord(vbuffer, utex, vtex);
vertex_color(vbuffer, color, alpha);
}
Savior, give this man a prize
Thank you sir !
This is what worked for me:
/// @param vbuffer
/// @param xx
/// @param yy
/// @param zz
/// @param nx
/// @param ny
/// @param nz
/// @param utex
/// @param vtex
/// @param color
/// @param alpha
function vertex_add_point(vbuffer, xx, yy, zz, nx, ny, nz, utex, vtex, color, alpha) {
// Collapse four function calls into a single one
vertex_position_3d(vbuffer, xx, yy, zz);
vertex_normal(vbuffer, nx, ny, nz);
vertex_texcoord(vbuffer, utex, vtex);
vertex_color(vbuffer, color, alpha);
}
marry me
you cured my depression, thank you.
For anyone messing around with this code, do not repeat my mistake: the order at which you set vertex format parameters and the order at which you apply these parameters to vertex buffers must be identical. These functions are very sensitive to this.
I accidently swapped vertex_format_add_texcoord with vertex_format_add_color without thinking and kept wondering afterwards why all my tiles suddenly lost their texture and became blue.
yeah, at 6:15 he was confused. The idea behind this is that the API of the engine is working like a state machine. The format has been defined in this specific order, and the vertex buffer must match the format. OpenGL is working the same way.
Great work. Cant wait to see the series go further into computer graphics.
this guy is the sonic of typing
this is great, i used to watch your 3d tutorials from back in 2016
Howdy Michael, and happy new year!!
I've watched this video a couple of times now. The first time was for your sense of humour, the second time was also for your sense of humour. The third time, which is now, was coming back after having a crack at using primitives as an alternative for creating vertex graphics; for example;
//Object Draw event;
var matrix = matrix_build(x,y,0,0,0,image_angle,1,1,1)
matrix_set(matrix_world,matrix);
draw_primitive_begin(pr_trianglefan);
draw_vertex_color(400,400,c_black,1);
draw_vertex_color(400,600,c_black,1);
draw_vertex_color(600,600,c_black,1);
draw_primitive_end();
matrix_set(matrix_world, matrix_build_identity());
The above is far simpler to code 2D shapes (less command overhead), but yet somewhat similar to what you've detailed in your video - but I'm guess at the cost of frame rate?
Would creating graphics with primitives/matrix be far slower compared to what you've just described in this video? And can you think of any advantages/disadvantages to either or method?
As I have my project working using primitive graphics, I can't help but notice that with roughly 100 objects the frame rate starts to drop with each new object added... (although I am also pushing the vertex data into generating 2D fixtures for Box Physics collision too, so this might also have something to do with it, guess I need to isolate the primitive drawing method vs your vertex buffer drawing method and compare performance).
It would be about as fast either way (beginning or ending a primitive incurs a batch break, as do the matrix functions, which are especially slow) but saving the vertex data to a vertex buffer allows you to reuse them more easily - so you can work faster - and saves you the trouble of having to define every vertex every single time you try to draw something, which isn't really a problem for a single triangle but adds up quickly for larger objects.
If you need the vertex data to change on the fly - if the physics system is allowed to deform it, for example - then you might be better off using the draw_primitive functions, though. If you just need to generate the fixtures from the vertex positions, you can probably get away with just doing that in the Create event.
Point List is great for Particles and things of that nature. You can enlarge the point size in the shader which would give you the equivalent of a bunch of small quads yet they can be drawn with nothing more than a single point.
@Jaxon Valentino You....
@@dustincash414 And you....
i guess now with all this self isolation i should work on my much neglected game
Do it!
for when your writing the script i have done the same thing as what you did but it says that the" vertex_position_3d (vbuffer, xx, yy, zz,);" is undefined why is that? at 12:25
i'm also having that problem
same for me, its pulling the error from xx saying it's undefined and expecting a number even though the script isn't even being called
I just fixed it, instead of creating parameters using '/// @param' , I put 'function vertex_add_point([11 arguments])' into the top of the script and put all the code in braces.
Amazing tutorial! Truly underrated channel
hey thanks so much for doing these tutorials my man, learning a lot
6:15 I think the vertex_format_end() returning the ID makes sense instead of vertex_format_start(). When you come form hardcore code in OpenGL world (and more obviously from fixed function pipeline), the API of the graphical engine is working like a state machine. The actual ID is returned upon completion of the state machine, when you reach the end state. If the ID was created earlier, then the ID would point to a structure that is in an inconsistent state (i.e. not fully defined). Imagine what could happen if you use this ID before it is actually defined with all the vertices, colors, texture coords.
Just discovered your channel. Very good stuff. Eagerly awaiting future content.
Really good and thorough explanations. Love it!
The triangles won't draw
If your triangle isn't being drawn:
It's POSSIBLY to do with the camera being in the wrong place.
To fix this, replace the camera_set_view_mat script in the draw event with this:
camera_set_view_mat(camera, matrix_build_lookat(0, 0, 400, room_width, room_height, 0, 0, 0, -1));
i'd have explained it more but i'm not the best at wording stuff.
well that fixed my issue! thanks kind stranger
Awesome stuff, super clear too!
Herro! Started getting into this series and had the same problem with getting the error. ERROR in action number 1 of create event for object : vertex position 3d argument 1 incorrect type (undefined) expecting a vertex_buffer etc.
estuve 30 minutos adivinando porque el triangulo no se dibujaba y era que la camara estaba muy baja como para ver el triangulo
Esto ayudó a mucho gracias
My floor and player textures are drawing fine, but when I do a shadow and an enemy the texture is drawing the specified sprite, then a strip of sprites. I'm doing the same vertex_submit with sprite_get_texture for them so I don't know why this is happening
I saw a reddit post saying it has something to do with VRAM?
usually this happens if some or all of your texture pages aren't on their own texture page when they should be
Is there a follow up video on zbuffer/depth ?, could really use it please.
the cool thing for gms2 is that all you have to do is middle click to find out what somthing is. when i dont know what a code does i middle click it and it gives me stuff about it
Awesome video it was extremely helpful, but is there any way that I can rotate my vertices around a point to make a rotating triangle?
following this tutorial make me wanna remake Kirby's Dream Course
I'm so confused? I've checked my code against the video however when I run the game the triangle never appears? Any idea what could have gone wrong? The Camera shows the same it's just the triangles that don't appear?
I figured it out, you need to change the camera objects draw function. Inside the draw function make sure that in camera_set_view_mat, the matrix has 400 as the 3rd entry
@@pikuhana hero,it works,thanks
@@pikuhana THANKS, boy I was so confused
@Clown Triangle was being drawn out of view, so changing the perspective puts it in view
question and what to write in the script on the new version of the engine
ua-cam.com/video/n8-MuIuOQFE/v-deo.html
what to do if I followed code exactly and no triangle appears?
Check the example project
@@DragoniteSpam when I downloaded the example project it gave me a blue and white checkered ground, which I think is the next video
15:11 done the same thing but Triangle doesn't appear
Too
Do you know when the next part will be published? Id really love to see how to use the texcoord and normal formats! :D
Probably next week.
@@DragoniteSpam Cool, any resources you can link me to that would help me set up texcoord? Id really love to render these flowers in my scene lol
@@fourriversfarm For UV mapping in general, this video looks pretty decent: ua-cam.com/video/dj0uXid9oGo/v-deo.html
I also made this a few years ago: ua-cam.com/video/ajl3l0gu34k/v-deo.html
Other than that, just opening a model in Blender or Game Maker Model Creator and fiddling with the texture UVs could be pretty useful, you'll get a feel for how textures wrap around the faces that way.
@@DragoniteSpam Great! Thank you
@@fourriversfarm Have fun!
I was tired trying to write everything down so I could format my own code as I get better but then I kept misspelling everything until my Bluetooth decided to let me know they are dying and man am I awake now... And sleep send help
For some reason there is an error on vertex_add_point script on line 25 saying it is expecting a number. Any help?
This was pre-2.3, you need to define the script contents in functions now
@@PASSARU okay thanks
How are fps? I have a GTX 1080. What do you think fps would be like with 20k plus triangles with pos, text, color, and normals? Just basically wondering how fast the vertex buffers actually are for the quality of texturing etc.
Depends on how you draw them. Generally speaking, 20k triangles is nothing, but if you draw them one-by-one it'll be much slower than drawing them all in the same vertex buffer.
Very helpful! But is there a way to make the vertex drawings on other objects? I tried this and it didn't work.
oh nvmd
Towards the end of the video you talk about method to make sure the camera is done first by either setting it to a high depth or your other work around by calling from the objects. Is there a reason you don't just apply the camera in the draw begin step? Then everything in the regular draw step could just be done normally right?
As far as I know that should work too, I just like having it in the same event as the rest of the draw code. I usually like to loop through objects in the camera's draw event instead of letting them draw themselves since you get more control over things that way.
@@DragoniteSpam makes sense. Thanks.
I was checking out the manual entry for vertex_normal and I don't understand what it means by "The above code will set the surface normal of the vertex being defined." What does surface normal mean? I'm up to 9:59 in the video and I started watching from the part about depth-sorting. I'm looking to use vertex buffers for isometric games.
Normals come into play when you start doing 3D lighting: ua-cam.com/video/mspdUDlVEXI/v-deo.html
If you don't need that don't worry about it (you can either set it to all 0s, or get rid of completely).
@@DragoniteSpam So "surface normal" relates to 3D lighting?
@@GameMakerRob You can also use them to evaluate physics responses when things collide, but for the most part yes.
@@DragoniteSpam OK thank you :)
Unrelated, but can you make an updated series for writing extensions?
I made this one a few years ago on DLLs:
ua-cam.com/video/jkgMxrDvwPs/v-deo.html
but GMS1 / 2 changed the extension systems by a fair amount, so revisiting that one might not be a bad idea . . .
Can one put the vertex creation code on a step event or would that create an infinite amount of vertex or cause some other problem?
would not recommend doing that in the step event unless you have to, even if you delete them properly when you're finished it could slow the game down if you're generating too much of it
@@DragoniteSpam Then, What can I do to move the vertex with inputs?
@@plazer2044 ua-cam.com/video/IeoAzmFdu6k/v-deo.html
I may just be stupid or something but did you define your functions? They’re not working for me and I’m not sure why?
This was pre-2.3, you need to define the script contents in functions now
Should vertices be entered clockwise or counter-clockwise? I noticed you entered yours in clockwise.
Generally you see them clockwise, although if you need them to be counterclockwise for whatever reason you can set the culling direction to counterclockwise. Ultimately it's more important that everything in the game is consistent with everything else in the game.
@@DragoniteSpam Okay: Interesting: docs2.yoyogames.com/source/_build/3_scripting/4_gml_reference/drawing/gpu/gpu_set_cullmode.html
I had seen the d3d article and didn't realize it was referring to 1.4.
@@Ragnark1 Yeah they added the ability to define the culling direction in 2, it's not something that's usually useful but is nice on occasion - if you want to render something inside-out, for example.
@@DragoniteSpam I have been reading tons of material that states that OpenGL's winding order for vertices is actually counter-clockwise. Does GMS have a preference or best-practice?
@@Ragnark1 Aside from what I mentioned earlier, not really. As far as I'm aware the documentation doesn't prefer one over the other or anything.
Ive already switched to unity and learning C#. missing game maker......
C# seriously breaks my brain.
@@sartanko then what about me ? Im a civil engineer.
13:30 hey so I wrote this all out but for some reason I keep getting an error saying there is something wrong with line 25 and it’s expected a number in the parentheses bit there is numbers there;-;
"When you cut a triangle u always end up wih 2 triangles no matter how hard u try" - PFFFFF CAP i just cut them horizontally
:DDDD gg
📝🐀
ERROR in
action number 1
of Create Event
for object obj_camera:
vertex_color argument 3 incorrect type (undefined) expecting a Number (YYGF)
at gml_Script_vertex_add_point_new (line 19) - vertex_color(vbuffer, color, alpha)
############################################################################################
gml_Script_vertex_add_point_new (line 19)
gml_Object_obj_camera_Create_0 (line 24) - vertex_add_point_new(v_buffer, x1, y1, 100, 0, 0, 1, c_white, 1)
Also i am using 2023 version maybe its because of this
Nope, check your code again
@@DragoniteSpam no i reapeted all like in video... also the error is because of vertex_add_point function.
@@96isthebestnumber Trust me, you've missed something.