Z缓冲区工作不正常(不显示任何内容)



这是我的Z缓冲区的代码,当我绘制它时,它会返回一个黑屏。

sf::VertexArray ZOrder(sf::VertexArray verticies, std::vector<float> z_buffer) {
std::vector<float> order;
for (int i = 0; i < verticies.getVertexCount(); i++) {
order.push_back(i); // {1, 2, 3, 4 ...
}
for (int i = 0; i < z_buffer.size(); i++) {
for (int i = 0; i < z_buffer.size(); i++) {
if (z_buffer[i] < z_buffer[i + 1]) {
std::iter_swap(z_buffer.begin() + i, z_buffer.begin() + i + 1);
std::iter_swap(order.begin() + i, order.begin() + i + 1);
}
}
}
sf::VertexArray darray(verticies.getPrimitiveType());
for (int i = 0; i < order.size(); i++) {
darray.append(verticies[order[i]]);
}
return darray;
}
// Draw Code:
dvertexa = ZOrder(dvertexa, z_buffer);
window.draw(dvertexa);

没有";dvrtexa=z阶(dvrtexa,z_buffer("它在没有深度测试的情况下表现得很正常。老实说,我现在真的很累,所以我可能只是个白痴,但我卡住了

固定:

sf::VertexArray ZOrder(sf::VertexArray verticies, std::vector<float> z_buffer) {
std::vector<float> order;
for (int i = 0; i < verticies.getVertexCount(); i++) {
order.push_back(i);
}
for (int i = 0; i < z_buffer.size(); i += 3) {
for (int i = 0; i < z_buffer.size(); i += 3) {
if (z_buffer[i] + z_buffer[i + 1] + z_buffer[i + 2] < z_buffer[i + 3] + z_buffer[i + 1 + 3] + z_buffer[i + 2 + 3]) {
std::iter_swap(z_buffer.begin() + i, z_buffer.begin() + i + 3);
std::iter_swap(z_buffer.begin() + i + 1, z_buffer.begin() + i + 1 + 3);
std::iter_swap(z_buffer.begin() + i + 2, z_buffer.begin() + i + 2 + 3);
std::iter_swap(order.begin() + i, order.begin() + i + 3);
std::iter_swap(order.begin() + i + 1, order.begin() + i + 1 + 3);
std::iter_swap(order.begin() + i + 2, order.begin() + i + 2 + 3);
}
}
}
sf::VertexArray darray(verticies.getPrimitiveType());
for (int i = 0; i < order.size(); i++) {
darray.append(verticies[order[i]]);
}
return darray;
}

相关内容

  • 没有找到相关文章

最新更新