• 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!

3D d3d_primitive_begin(pr_trianglelist);

X

Xenon

Guest
Hey guys i'm trying to draw a 3d terrain using 32x32 squares across the floor. I want to do this using the d3d_primitive functions but i need a better understanding of the functions. Out of the manual i found this code

Code:
d3d_primitive_begin(pr_trianglelist);
 d3d_vertex_color(100, 100, 0, c_blue, 0.1);
 d3d_vertex_color(100, 200, 0, c_blue, 0.1);
 d3d_vertex_color(150, 150, 200, c_red, 1);
 d3d_vertex_color(100, 200, 0, c_blue, 0.1);
 d3d_vertex_color(200, 200, 0, c_blue, 0.1);
 d3d_vertex_color(150, 150, 200, c_red, 1);
 d3d_vertex_color(200, 200, 0, c_blue, 0.1);
 d3d_vertex_color(100, 100, 0, c_blue, 0.1);
 d3d_vertex_color(150, 150, 200, c_red, 1);
 d3d_vertex_color(100, 100, 0, c_blue, 0.1);
 d3d_vertex_color(100, 200, 0, c_blue, 0.1);
 d3d_vertex_color(200, 200, 0, c_blue, 0.1);
 d3d_primitive_end();
  • How does the code define the faces and normals?
  • If i wanted to draw a single 32x32 square with the normal at 0,0,1 on the floor how would i do so?
  • How do i tell the computer if certain faces are attached or not for shading purposes? is that based off of each primitive or do faces need to be defined as attached to others, same thing with points do i attach them and vertices too?
 
X

Xenon

Guest
Okay can you explain to me how i can use vertex buffers to draw a 32x32 square on the floor with the normal 0,0,1?
Code:
vertex_format_begin();
 vertex_format_add_position_3d();
 vertex_format_add_colour();
 vertex_format_add_textcoord();
 my_format = vertex_format_end();
I've found this code but i do not fully understand the process, i create a vertex format and then build a primitive with the vertex format like this below but in 3d?
Code:
v_buff = vertex_create_buffer();
 vertex_begin(v_buff, global.my_format);
 vertex_position(v_buff, 10, 10);
 vertex_colour(v_buff, c_white, 1);
 vertex_texcoord(v_buff, 0, 0);
 vertex_position(v_buff, 110, 10);
 vertex_colour(v_buff, c_white, 1);
 vertex_texcoord(v_buff, 1, 0);
 vertex_position(v_buff, 110, 110);
 vertex_colour(v_buff, c_white, 1);
 vertex_texcoord(v_buff, 1, 1);
 vertex_end(v_buff);
 var tex = background_get_texture(background1);
 shader_set(shader_prim);
 vertex_submit(v_buff, pr_trianglelist, tex);
 shader_reset();
 
Last edited by a moderator:
X

Xenon

Guest
Alright i put this code into the create event
Code:
vertex_format_begin();
 vertex_format_add_position();
 vertex_format_add_colour();
 vertex_format_add_textcoord();
 v_format = vertex_format_end();
 v_buff = vertex_create_buffer();
 vertex_begin(v_buff, v_format);
 vertex_position_3d(v_buff, 10, 10,10);
 vertex_colour(v_buff, c_red, 1);
 vertex_texcoord(v_buff, 0, 0);
 vertex_position_3d(v_buff, 110, 10,10);
 vertex_colour(v_buff, c_white, 1);
 vertex_texcoord(v_buff, 1, 0);
 vertex_position_3d(v_buff, 110, 110,10);
 vertex_colour(v_buff, c_blue, 1);
 vertex_texcoord(v_buff, 1, 1);
 vertex_end(v_buff);
 var tex = -1;
   
    d3d_start();
    d3d_set_perspective(true);
    d3d_set_lighting(false);
    draw_set_color(c_white);
    d3d_set_culling(false);
    d3d_set_shading(false);
    texture_set_interpolation(true);
and i put this code in the draw event
Code:
    d3d_set_projection_ext(-45,45,45,0,0,0,0,1,0,60,1.33,1,256);
    shader_set(shader_prim);
 vertex_submit(v_buff, pr_trianglelist, tex);
 shader_reset();
and i got an error about the vertex format, am i using the code how i'm supposed to?

https://forum.yoyogames.com/index.p...arted-with-3d-in-gms2-project-download.12145/ answered my question.
 
Last edited by a moderator:
Top