Hi. I'm trying to do something that should be... super-simple, but apparently isn't, lol. I'm trying to learn how to get GMS to draw a simple, all-black cuboid.
At the beginning of time, I specify a vertex format:
Then I have an Object that's responsible for building a Vertex Buffer, using this code in its Step Event:
Once the Vertex Buffer is built, it's trying to draw it via a shader in the Draw Event:
Using this shader:
When I run my little test project, "drawing box" is printed to the console, but the 3D box does not draw in the Room. If I un-comment draw_self() in the Draw Event, the object is in the Room, sure enough.
Where did I go wrong here? Please help; it was fairly confusing just getting to this point and it seems like it should work... but it doesn't.
At the beginning of time, I specify a vertex format:
GML:
global.hasBuiltFormat = false;
function scr_3D_Wall_Mesh_Format(){
vertex_format_begin();
vertex_format_add_colour();
vertex_format_add_position_3d();
vertex_format_add_colour();
vertex_format_add_position_3d();
vertex_format_add_colour();
vertex_format_add_position_3d();
vertex_format_add_colour();
vertex_format_add_position_3d();
vertex_format_add_colour();
vertex_format_add_position_3d();
vertex_format_add_colour();
vertex_format_add_position_3d();
vertex_format_add_colour();
vertex_format_add_position_3d();
vertex_format_add_colour();
vertex_format_add_position_3d();
global.vFormat = vertex_format_end();
global.hasBuiltFormat = true;
show_debug_message("built format!");
}
GML:
if(!hasBuiltBuffer){
if(global.hasBuiltFormat = false){
scr_3D_Wall_Mesh_Format();
} else {
vertex_begin(vBuffer,global.vFormat);
vertex_color(vBuffer,c_black,1);
vertex_position_3d(vBuffer,bbox_bottom,-100,bbox_left);
vertex_color(vBuffer,c_black,1);
vertex_position_3d(vBuffer,bbox_top,-100,bbox_left);
vertex_color(vBuffer,c_black,1);
vertex_position_3d(vBuffer,bbox_top,-100,bbox_right);
vertex_color(vBuffer,c_black,1);
vertex_position_3d(vBuffer,bbox_bottom,-100,bbox_right);
vertex_color(vBuffer,c_black,1);
vertex_position_3d(vBuffer,bbox_bottom,0,bbox_left);
vertex_color(vBuffer,c_black,1);
vertex_position_3d(vBuffer,bbox_top,0,bbox_left);
vertex_color(vBuffer,c_black,1);
vertex_position_3d(vBuffer,bbox_top,0,bbox_right);
vertex_color(vBuffer,c_black,1);
vertex_position_3d(vBuffer,bbox_bottom,0,bbox_right);
vertex_end(vBuffer);
vertex_freeze(vBuffer);
hasBuiltBuffer = true;
}
}
GML:
if(hasBuiltBuffer){
show_debug_message("drawing box");
shader_set(sh_BlackBox);
vertex_submit(vBuffer, pr_trianglestrip, -1);
shader_reset();
}
C:
//VERTEX
attribute vec3 in_Position; // (x,y,z)
void main()
{
vec4 object_space_pos = vec4( in_Position.x, in_Position.y, in_Position.z, 1.0);
gl_Position = gm_Matrices[MATRIX_WORLD_VIEW_PROJECTION] * object_space_pos;
}
//FRAGMENT
const vec4 black = vec4(0.0,0.0,0.0,1.0);
void main()
{
gl_FragColor = black;
}
Where did I go wrong here? Please help; it was fairly confusing just getting to this point and it seems like it should work... but it doesn't.