3D and 2D sorting settled.

linux_template
sigonasr2 2 years ago
parent b4e2765f23
commit d59aa56318
  1. 11
      Faceball2030/Editor.cpp
  2. 1
      Faceball2030/Editor.h
  3. 9
      Faceball2030/main.cpp
  4. 20
      Faceball2030/pixelGameEngine.h

@ -7,6 +7,17 @@ extern FaceBall* game;
void Editor::Update(float fElapsedTime){
LoadLevelHandling();
vf2d center = { -(float)MAP_SIZE.x / 2 * GRID_SIZE.x + game->ScreenWidth()/2 , -(float)MAP_SIZE.y / 2 * GRID_SIZE.y + game->ScreenHeight()/2 };
for (int y = 0; y < MAP_SIZE.y; y++) {
for (int x = 0; x < MAP_SIZE.x; x++) {
vf2d squarePos = vf2d{ (float)x,(float)y }*GRID_SIZE + center;
if (game->GetMouseX() >= squarePos.x && game->GetMouseX() <= squarePos.x + GRID_SIZE.x &&
game->GetMouseY() >= squarePos.y && game->GetMouseY() <= squarePos.y + GRID_SIZE.y) {
game->FillRectDecal(squarePos, GRID_SIZE, { 0,0,255,64 });
}
game->DrawRectDecal(squarePos,GRID_SIZE);
}
}
}
void Editor::LoadLevelHandling() {

@ -47,6 +47,7 @@ class Editor {
vi2d MAP_SIZE;
bool reEnableTextEntry; //We must set this to true to cause Text Entry to reappear due to how the callback works.
std::vector<std::vector<Tile>> map;
const vi2d GRID_SIZE = { 32,32 };
public:
Editor() {}
void Update(float fElapsedTime);

@ -452,6 +452,7 @@ void FaceBall::RenderWorld() {
//std::sort(vecTrianglesToRaster.begin(),vecTrianglesToRaster.end(),[](triangle&t1,triangle&t2){return (t1.p[0].z+t1.p[1].z+t1.p[2].z)/3.0f>(t2.p[0].z+t2.p[1].z+t2.p[2].z)/3.0f;});
ClearBuffer(BLACK, true);
int triRenderCount = 0;
for (auto& triToRaster : vecTrianglesToRaster) {
Triangle clipped[2];
@ -491,8 +492,6 @@ void FaceBall::RenderWorld() {
nNewTriangles = listTriangles.size();
}
std::map<vf2d, vf2d>coords;
for (auto& t : listTriangles) {
// Rasterize triangle
SetDecalStructure(DecalStructure::LIST);
@ -519,12 +518,6 @@ void FaceBall::RenderWorld() {
SetDecalStructure(DecalStructure::FAN);
triRenderCount++;
}
for (const auto& key : coords) {
vf2d coord = key.first;
vf2d val = key.second;
DrawStringDecal({ coord.x,coord.y }, val.str());
}
}
SetDecalMode(DecalMode::NORMAL);

@ -865,6 +865,7 @@ namespace olc
olc::DecalMode mode = olc::DecalMode::NORMAL;
olc::DecalStructure structure = olc::DecalStructure::FAN;
uint32_t points = 0;
bool depthEnabled = false;
};
struct LayerDesc
@ -1090,6 +1091,7 @@ namespace olc
// Draws a multiline string as a decal, with tiniting and scaling
void DrawStringDecal(const olc::vf2d& pos, const std::string& sText, const Pixel col = olc::WHITE, const olc::vf2d& scale = { 1.0f, 1.0f });
void DrawStringPropDecal(const olc::vf2d& pos, const std::string& sText, const Pixel col = olc::WHITE, const olc::vf2d& scale = { 1.0f, 1.0f });
void DrawRectDecal(const olc::vf2d& pos, const olc::vf2d& size, const olc::Pixel col = olc::WHITE);
// Draws a single shaded filled rectangle as a decal
void FillRectDecal(const olc::vf2d& pos, const olc::vf2d& size, const olc::Pixel col = olc::WHITE);
// Draws a corner shaded rectangle as a decal
@ -1169,6 +1171,7 @@ namespace olc
std::string sAppName;
private: // Inner mysterious workings
bool depthEnabled = false;
olc::Sprite* pDrawTarget = nullptr;
Pixel::Mode nPixelMode = Pixel::NORMAL;
float fBlendFactor = 1.0f;
@ -2698,6 +2701,7 @@ namespace olc
di.pos.resize(elements);
di.uv.resize(elements);
di.w.resize(elements);
di.z.resize(elements);
di.tint.resize(elements);
di.points = elements;
for (uint32_t i = 0; i < elements; i++)
@ -2756,6 +2760,7 @@ namespace olc
}
di.mode = nDecalMode;
di.structure = nDecalStructure;
di.depthEnabled = true;
vLayers[nTargetLayer].vecDecalInstance.push_back(di);
}
@ -2849,7 +2854,18 @@ namespace olc
di.mode = olc::DecalMode::WIREFRAME;
vLayers[nTargetLayer].vecDecalInstance.push_back(di);
}
void PixelGameEngine::DrawRectDecal(const olc::vf2d& pos, const olc::vf2d& size, const olc::Pixel col)
{
auto m = nDecalMode;
SetDecalMode(olc::DecalMode::WIREFRAME);
olc::vf2d vNewSize = size;// (size - olc::vf2d(0.375f, 0.375f)).ceil();
std::array<olc::vf2d, 4> points = { { {pos}, {pos.x, pos.y + vNewSize.y}, {pos + vNewSize}, {pos.x + vNewSize.x, pos.y} } };
std::array<olc::vf2d, 4> uvs = { {{0,0},{0,0},{0,0},{0,0}} };
std::array<olc::Pixel, 4> cols = { {col, col, col, col} };
DrawExplicitDecal(nullptr, points.data(), uvs.data(), cols.data(), 4);
SetDecalMode(m);
}
void PixelGameEngine::FillRectDecal(const olc::vf2d& pos, const olc::vf2d& size, const olc::Pixel col)
{
olc::vf2d vNewSize = (size - olc::vf2d(0.375f, 0.375f)).ceil();
@ -4164,7 +4180,9 @@ namespace olc
}
else
{
glEnable(GL_DEPTH_TEST);
if (decal.depthEnabled) {
glEnable(GL_DEPTH_TEST);
}
glDepthFunc(GL_LESS);
if (nDecalMode == DecalMode::WIREFRAME)
glBegin(GL_LINE_LOOP);

Loading…
Cancel
Save