SupernaturalCow
Member
Hi All,
You probably know me lately as the guy that keeps reviving that Projection Math thread... hehe, sorry.
Anyway, as a result of all that, I've come across a slightly separate issue: the cube I'm drawing isn't displaying quite right. Right?
This is what I want:
And this is what I'm getting:
Where's my front face? And why is the outline disappearing behind something else? It's not that I haven't turned on ztest/write, because I have.
Here's the relevant code:
I'm obviously also applying a perspective projection, but haven't included it because I don't think it'd be that relevant. Regardless, the full code is over in the aforementioned thread.
UPDATE: As this seems to be more curious than first expected, I've uploaded the project's code for your perusal: https://app.box.com/s/v111mxriomfm4ukv4ou8ubcv0slexzm1.
Thanks GMC!
You probably know me lately as the guy that keeps reviving that Projection Math thread... hehe, sorry.
Anyway, as a result of all that, I've come across a slightly separate issue: the cube I'm drawing isn't displaying quite right. Right?
This is what I want:
And this is what I'm getting:
Where's my front face? And why is the outline disappearing behind something else? It's not that I haven't turned on ztest/write, because I have.
Here's the relevant code:
Code:
/// @function object0/Create
// 3D vertex format
vertex_format_begin();
vertex_format_add_position_3d();
vertex_format_add_colour();
vertex_format_add_texcoord();
vformat = vertex_format_end();
// Vertex buffer
vbuffer = vertex_create_buffer();
// Draw a cube
vertex_begin(vbuffer, vformat);
draw_cube(0, 0, 0, 12, true);
vertex_end(vbuffer);
// Graphics settings
gpu_set_zwriteenable(true);
gpu_set_ztestenable(true);
gpu_set_cullmode(cull_noculling);
Code:
/// @function object0/Draw_GUI
vertex_submit(vbuffer, pr_trianglelist, -1);
Code:
///@function draw_cube(x, y, z, len, outline?)
var _cx = argument0,
_cy = argument1,
_cz = argument2,
_len = argument3,
_outline = argument4,
_hlen = _len/2,
_left = _cx-_hlen,
_right = _cx+_hlen,
_back = _cy-_hlen,
_front = _cy+_hlen,
_top = _cz-_hlen,
_bot = _cz+_hlen,
_b = 0.1,
_hb = _b/2,
_col_b = c_black,
_col_x = c_red,
_col_bx = merge_color(_col_x, _col_b, 0.5),
_col_y = c_green,
_col_by = merge_color(_col_y, _col_b, 0.5),
_col_z = c_blue,
_col_bz = merge_color(_col_z, _col_b, 0.5),
;
// Draw left and right face (fixed X)
draw_set_colour(_col_x);
draw_rect(_left, _left, _back, _front, _top, _bot);
draw_rect(_right, _right, _back, _front, _top, _bot);
if _outline {
draw_set_colour(_col_bx);
draw_rect(_left-_hb, _left+_hb, _back, _front, _top, _top);
draw_rect(_left-_hb, _left+_hb, _back, _front, _bot, _bot);
draw_rect(_left-_hb, _left+_hb, _back, _back, _top, _bot);
draw_rect(_left-_hb, _left+_hb, _front, _front, _top, _bot);
draw_rect(_right-_hb, _right+_hb, _back, _front, _top, _top);
draw_rect(_right-_hb, _right+_hb, _back, _front, _bot, _bot);
draw_rect(_right-_hb, _right+_hb, _back, _back, _top, _bot);
draw_rect(_right-_hb, _right+_hb, _front, _front, _top, _bot);
}
// Draw front and back face (fixed Y)
draw_set_colour(_col_y);
draw_rect(_left, _right, _back, _back, _top, _bot);
draw_rect(_left, _right, _front, _front, _top, _bot);
if _outline {
draw_set_colour(_col_by);
draw_rect(_left, _left, _back-_hb, _back+_hb, _top, _bot);
draw_rect(_right, _right, _back-_hb, _back+_hb, _top, _bot);
draw_rect(_left, _right, _back-_hb, _back+_hb, _top, _top);
draw_rect(_left, _right, _back-_hb, _back+_hb, _bot, _bot);
draw_rect(_left, _left, _front-_hb, _front+_hb, _top, _bot);
draw_rect(_right, _right, _front-_hb, _front+_hb, _top, _bot);
draw_rect(_left, _right, _front-_hb, _front+_hb, _top, _top);
draw_rect(_left, _right, _front-_hb, _front+_hb, _bot, _bot);
}
// Draw top and bottom face (fixed Z)
draw_set_colour(_col_z);
draw_rect(_left, _right, _back, _front, _top, _top);
draw_rect(_left, _right, _back, _front, _bot, _bot);
if _outline {
draw_set_colour(_col_bz);
draw_rect(_left, _left, _back, _front, _top-_hb, _top+_hb);
draw_rect(_right, _right, _back, _front, _top-_hb, _top+_hb);
draw_rect(_left, _right, _back, _back, _top-_hb, _top+_hb);
draw_rect(_left, _right, _front, _front, _top-_hb, _top+_hb);
draw_rect(_left, _left, _back, _front, _bot-_hb, _bot+_hb);
draw_rect(_right, _right, _back, _front, _bot-_hb, _bot+_hb);
draw_rect(_left, _right, _back, _back, _bot-_hb, _bot+_hb);
draw_rect(_left, _right, _front, _front, _bot-_hb, _bot+_hb);
}
Code:
/// @function draw_rect(left, right, back, front, top, bot)
var _left = argument0,
_right = argument1,
_back = argument2,
_front = argument3,
_top = argument4,
_bot = argument5,
;
// Tri #1
draw_vert(_left, _back, _top);
draw_vert(_right, _front, _top);
draw_vert(_left, _front, _bot);
// Tri #2
draw_vert(_right, _back, _top);
draw_vert(_right, _front, _bot);
draw_vert(_left, _back, _bot);
Code:
/// @function draw_vert(x, y, z)
var _x = argument0,
_y = argument1,
_z = argument2,
_col = draw_get_colour(),
_alpha = draw_get_alpha(),
_vb = vbuffer;
vertex_position_3d(_vb, _x, _y, _z);
vertex_colour(_vb, _col, _alpha);
vertex_texcoord(_vb, 0, 0);
UPDATE: As this seems to be more curious than first expected, I've uploaded the project's code for your perusal: https://app.box.com/s/v111mxriomfm4ukv4ou8ubcv0slexzm1.
Thanks GMC!
Last edited: