Culling unwanted faces(clips, triggers, sky) with CVars and starting to implement different backends

This commit is contained in:
Safariminer 2025-08-02 17:02:49 -04:00
parent 9c7a3219d9
commit 8f3533405a
5 changed files with 112 additions and 25 deletions

View File

@ -1,3 +1,6 @@
vid_2d_background false
vid_3d_renderer true
vid_3d_grid false
vid_2d_background false
vid_3d_cull_sky false
vid_3d_cull_clips true
vid_3d_cull_triggers true

View File

@ -0,0 +1,61 @@
#pragma once
#include <iostream>
#include <vector>
namespace MPFW {
namespace Backends {
namespace Video {
namespace Agnostic {
struct Color {
unsigned char r, g, b, a;
};
struct Picture {
std::vector<Color> data;
int width, height;
};
struct Vertex2D {
float x, y;
};
struct Vertex3D {
float x, y, z;
};
struct Vertex4D {
float x, y, z, w;
};
struct Triangle {
Vertex3D a, b, c;
};
struct TexturedTriangle {
Triangle tri;
int textureId;
};
}
struct ContextParameters {
std::string name;
int width, height, desiredFps;
};
// note: backend inputs should ALWAYS be in quake coords
// note 2: backends should ideally implement all functions.
class BackEnd {
public:
virtual void Create(ContextParameters param) = 0;
virtual int BE_LoadFont(std::string path) = 0;
virtual void BE_DrawText(int fontId, std::string text, int x, int y, int fontSize) = 0;
virtual int BE_LoadTexture(Agnostic::Picture pic) = 0;
virtual void BE_UnloadTexture(int picId) = 0;
virtual void BE_DrawColorTriangle(Agnostic::Triangle tri, Agnostic::Color col) = 0;
virtual void BE_DrawTexturedTriangle(Agnostic::TexturedTriangle tri) = 0;
virtual void BE_ImGui_Begin() = 0;
virtual void BE_ImGui_End() = 0;
};
}
}
}

View File

@ -355,6 +355,7 @@ void MPFW::Quake::Maps::MapFile::LoadBSPMap(std::string path)
Texture2D temp = LoadTextureFromImage(img);
rlMipTex mt;
mt.name = std::string((const char*)t.name);
mt.glTextureID = temp.id;
mt.height = temp.height;
mt.width = temp.width;
@ -416,6 +417,14 @@ void MPFW::Quake::Maps::MapFile::LoadBSPMap(std::string path)
));
}
cface.baselight = data.faces[i].baselight;
if (
Utils::Strings::IterativeStringExcerpt(data.textures[data.texInfo[data.faces[i].texinfoId].textureId].name, 0, 3) == "sky"
) {
cface.skyFace = true;
}
if (data.textures[data.texInfo[data.faces[i].texinfoId].textureId].name == "clip") cface.clipFace = true;
if (data.textures[data.texInfo[data.faces[i].texinfoId].textureId].name == "trigger") cface.triggerFace = true;
data.renderFaces.push_back(cface);

View File

@ -104,6 +104,12 @@ namespace MPFW {
std::vector<Vector3> vertices;
std::vector<Vector2> texCoords;
int glTextureId, glTextureWidth, glTextureHeight;
bool skyFace = false;
bool triggerFace = false;
bool clipFace = false;
unsigned char baselight;
};
@ -115,13 +121,13 @@ namespace MPFW {
using MipHeader = std::vector<long>;
struct cMiptex{
char name[16];
unsigned char name[16];
unsigned long width, height,
offset1, offset2, offset4, offset8;
};
struct rlMipTex {
char name[16];
std::string name;
unsigned long width, height;
unsigned long glTextureID;
int type;
@ -188,11 +194,14 @@ namespace MPFW {
int edgesCDBG = 0;
int texInfoCDBG = 0;
int facesCDBG = 0;
MapFile(){}
[[warning("Prefer using an empty map file linked to a command handler for map loading with CFGs.")]]
MapFile(std::string path) {
LoadBSPMap(path);
}
void LoadBSPMap(std::string path);
~MapFile(){}
};

View File

@ -253,34 +253,39 @@ int main() {
if (chr.cvars["vid_3d_renderer"] == "true") {
BeginMode3D(camera);
if(chr.cvars["vid_3d_grid"] == "true") DrawGrid(10000, 10);
for (int i = 0; i < map.data.renderFaces.size(); i++) {
rlColor4ub(255, 255, 255, 255);
rlSetTexture(map.data.renderFaces[i].glTextureId);
if (
!(chr.cvars["vid_3d_cull_sky"] == "true" && map.data.renderFaces[i].skyFace) &&
!(chr.cvars["vid_3d_cull_clips"] == "true" && map.data.renderFaces[i].clipFace) &&
!(chr.cvars["vid_3d_cull_triggers"] == "true" && map.data.renderFaces[i].triggerFace)
){
rlColor4ub(255, 255, 255, 255);
rlSetTexture(map.data.renderFaces[i].glTextureId);
for (int j = 1; j < map.data.renderFaces[i].vertices.size(); j++) {
rlBegin(RL_QUADS); // for texturing reasons because rlgl
Vector3 a = map.data.renderFaces[i].vertices[0],
b = map.data.renderFaces[i].vertices[j],
c = map.data.renderFaces[i].vertices[j - 1];
for (int j = 1; j < map.data.renderFaces[i].vertices.size(); j++) {
rlBegin(RL_QUADS); // for texturing reasons because rlgl
Vector3 a = map.data.renderFaces[i].vertices[0],
b = map.data.renderFaces[i].vertices[j],
c = map.data.renderFaces[i].vertices[j - 1];
Vector2 at = map.data.renderFaces[i].texCoords[0],
bt = map.data.renderFaces[i].texCoords[j],
ct = map.data.renderFaces[i].texCoords[j - 1];
Vector2 at = map.data.renderFaces[i].texCoords[0],
bt = map.data.renderFaces[i].texCoords[j],
ct = map.data.renderFaces[i].texCoords[j - 1];
rlTexCoord2f(at.x, at.y);
rlVertex3f(a.x, a.y, a.z);
rlTexCoord2f(bt.x, bt.y);
rlVertex3f(b.x, b.y, b.z);
rlTexCoord2f(ct.x, ct.y);
rlVertex3f(c.x, c.y, c.z);
rlVertex3f(c.x, c.y, c.z);
rlTexCoord2f(at.x, at.y);
rlVertex3f(a.x, a.y, a.z);
rlTexCoord2f(bt.x, bt.y);
rlVertex3f(b.x, b.y, b.z);
rlTexCoord2f(ct.x, ct.y);
rlVertex3f(c.x, c.y, c.z);
rlVertex3f(c.x, c.y, c.z);
rlEnd();
rlEnd();
}
}