T
Toomuchbob
Guest
After the update I am having some issues where I generate a vertex buffer on an object and it draws 3d planes. I'm not certain the issue was in the previous version though because I made the change while I unable to test, updated and then tested.
This is the create event to make the object o_Cell, which runs script generateCells in it's create event, then draws them in the draw event with the following:
Draw event:
Game crashes everytime
Code:
/// _worldGeneration : Initialize World
//Enable z buffer
gpu_get_ztestenable();
gpu_get_zwriteenable();
//Camera
view_enabled = true;
view_set_visible(0, true);
camera = camera_create();
projection_matrix = matrix_build_projection_perspective_fov(60, view_wport[0] / view_hport[0], 1, 32000);
camera_set_proj_mat(camera, projection_matrix);
view_set_camera(0, camera);
camera_set_update_script(camera, camera_update);
//Get random seed
//randomize();
//Generate default grid structure
for (var i = 0; i < floor(room_width / GRID_SIZE); i++) {
for (var j = 0; j < floor(room_height / GRID_SIZE); j++) {
instance_create_depth(i * GRID_SIZE, j * GRID_SIZE, 0, o_Cell);
}
}
Code:
///generateCells(x, y, depth, gridSize) : Generate the cells, adding appropriate vertices at coordinates x, y;
xx = argument0;
yy = argument1;
depth = argument2;
gridSize = argument3;
//create our vertex format
vertex_format_begin();
vertex_format_add_position_3d();
vertex_format_add_color()
vertex_format_add_texcoord();
format = vertex_format_end();
//create our vertex buffer
v_cell = vertex_create_buffer();
vertex_begin(v_cell, format);
//first polygon
vertex_position_3d(v_cell, xx, yy, depth);
vertex_color(v_cell, c_white, 1);
vertex_texcoord(v_cell, 0, 0);
vertex_position_3d(v_cell, xx, yy, depth - gridSize);
vertex_color(v_cell, c_white, 1);
vertex_texcoord(v_cell, 1, 0);
vertex_position_3d(v_cell, xx + gridSize, yy, depth);
vertex_color(v_cell, c_white, 1);
vertex_texcoord(v_cell, 0, 1);
//second polygon
vertex_position_3d(v_cell, xx + gridSize, yy, depth);
vertex_color(v_cell, c_white, 1);
vertex_texcoord(v_cell, 0, 1);
vertex_position_3d(v_cell, xx , yy, depth - gridSize);
vertex_color(v_cell, c_white, 1);
vertex_texcoord(v_cell, 1, 0);
vertex_position_3d(v_cell, xx + gridSize, yy, depth - gridSize);
vertex_color(v_cell, c_white, 1);
vertex_texcoord(v_cell, 1, 1);
//Buffer End
vertex_end(v_cell);
Code:
/// Draw the cell
vertex_submit(v_cell, pr_trianglelist, sprite_get_texture(s_floor, 0));