add draw types

This commit is contained in:
2026-02-16 22:41:20 -06:00
parent 5fd5eb892b
commit fda88a906b
4 changed files with 64 additions and 15 deletions

View File

@@ -5,18 +5,41 @@
#include "extratools.h"
#include "utils/Renderer/RenderTarget.h"
namespace Archimedes {
class Object {
public:
Object() {};
Object(RenderTarget rt) : mesh(rt) {};
Object(VertexBuffer vb, IndexArray ia, VertexLayout vl, Shader s, glm::mat4 t)
: mesh(vb, ia, vl, s), worldTransform(t) {}
Object() {}
~Object() {};
///scales an object absolutely
void scaleTo() {}
void scaleRel() {}
void moveTo() {}
void moveRel() {}
void rotateTo() {}
void rotateRel() {}
private:
glm::vec3 position = glm::vec3(0);
glm::vec3 rotation = glm::vec3(0);
glm::mat4 worldTransform = glm::mat4(1.0f);
RenderTarget mesh;
};
}

View File

@@ -12,6 +12,13 @@ namespace Archimedes {
class Renderer {
public:
enum class RenderMode {
Triangles,
Lines,
Points
};
int w, h;
glm::vec4 clearColor = { 0.0f, 0.0f, 0.0f, 1.0f };
@@ -37,7 +44,7 @@ namespace Archimedes {
virtual void useRenderTarget(RenderTarget& rt) = 0;
virtual void draw(const RenderTarget&) = 0;
virtual void draw(const RenderTarget& rt, RenderMode mode = RenderMode::Triangles) = 0;
virtual Renderer* getRendererImpl() = 0;

View File

@@ -173,6 +173,7 @@ namespace Archimedes {
return rt;
};
void useRenderTarget(RenderTarget& rt) override {
glGenVertexArrays(1, &rt.vertexArray.id);
@@ -202,7 +203,7 @@ namespace Archimedes {
};
void draw(const RenderTarget& rt) override {
void draw(const RenderTarget& rt, RenderMode mode) override {
glUseProgram(rt.shader.id);
@@ -218,7 +219,17 @@ namespace Archimedes {
glBindVertexArray(rt.vertexArray.id);
switch(mode) {
case RenderMode::Triangles:
glDrawElements(GL_TRIANGLES, rt.indexArray.getCount(), GL_UNSIGNED_INT, nullptr);
case RenderMode::Lines:
glDrawElements(GL_LINES, rt.indexArray.getCount(), GL_UNSIGNED_INT, nullptr);
case RenderMode::Points:
glDrawElements(GL_POINTS, rt.indexArray.getCount(), GL_UNSIGNED_INT, nullptr);
default:
break;
}
glBindVertexArray(0);
}

View File

@@ -86,14 +86,22 @@ void Sandbox::onLoad() {
void Sandbox::run() {
static float scale = 100.0f;
static float scale = 1.0f;
static glm::vec3 pos(0), rot(0);
static glm::vec3 camPos(0.0f, 0.0f, 3.0f), camRot(0.0f, 0.0f, 0.0f);
static glm::vec3 camPos(0.0f, 0.0f, 3.0f), camRot(0.0f, glm::pi<float>(), 0.0f);
static glm::mat4 orthoCamera, perspCamera, cameraTransform;
std::vector<glm::vec3> otf = {
glm::vec3(0.5f, 0.5f, 0.0f),
glm::vec3(-0.5f, -0.5f, 0.0f),
glm::vec3(-0.5f, 0.5f, 0.0f),
glm::vec3(0.5f, -0.5f, 0.0f)
};
/*
cameraTransform = glm::mat4(1.0f);
cameraTransform = glm::translate(cameraTransform, camPos);
@@ -104,7 +112,7 @@ void Sandbox::run() {
cameraTransform = glm::lookAt(
camPos,
glm::normalize(glm::vec3(glm::cos(camRot.y) * glm::cos(camRot.x), glm::sin(camRot.x), glm::sin(camRot.y) * glm::cos(camRot.x))),
camPos + glm::normalize(glm::vec3(glm::sin(camRot.y) * glm::cos(camRot.x), glm::sin(camRot.x), glm::cos(camRot.y) * glm::cos(camRot.x))),
glm::vec3(0.0f, 1.0f, 0.0f)
);
/*
@@ -169,9 +177,9 @@ void Sandbox::run() {
ImGui::Text("Properties");
ImGui::SliderFloat("pitch", &rot.x, -3.14159265359f, 3.14159265359f);
ImGui::SliderFloat("yaw", &rot.y, -3.14159265359f, 3.14159265359f);
ImGui::SliderFloat("roll", &rot.z, -3.14159265359f, 3.14159265359f);
ImGui::SliderFloat("pitch", &rot.x, -glm::pi<float>(), glm::pi<float>());
ImGui::SliderFloat("yaw", &rot.y, -glm::pi<float>(), glm::pi<float>());
ImGui::SliderFloat("roll", &rot.z, -glm::pi<float>(), glm::pi<float>());
ImGui::SliderFloat("scale", &scale, 0.1f, 10.0f);
@@ -181,9 +189,9 @@ void Sandbox::run() {
ImGui::Text("Camera Properties");
ImGui::SliderFloat("c_pitch", &camRot.x, -3.14159265359f, 3.14159265359f);
ImGui::SliderFloat("c_yaw", &camRot.y, -3.14159265359f, 3.14159265359f);
ImGui::SliderFloat("c_roll", &camRot.z, -3.14159265359f, 3.14159265359f);
ImGui::SliderFloat("c_pitch", &camRot.x, -glm::pi<float>(), glm::pi<float>());
ImGui::SliderFloat("c_yaw", &camRot.y, 0, 2 * glm::pi<float>());
ImGui::SliderFloat("c_roll", &camRot.z, -glm::pi<float>(), glm::pi<float>());
ImGui::SliderFloat("c_x", &camPos.x, -10.0f, 10.0f);
ImGui::SliderFloat("c_y", &camPos.y, -10.0f, 10.0f);