Skip to content

Commit

Permalink
Renderer works again on ps2 ugh
Browse files Browse the repository at this point in the history
  • Loading branch information
EPICGameGuy committed Jan 7, 2024
1 parent efe2088 commit fc03e0a
Show file tree
Hide file tree
Showing 12 changed files with 71 additions and 168 deletions.
Binary file modified assets/levels/new_level.lvl
Binary file not shown.
10 changes: 5 additions & 5 deletions include/objects/teapot.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
#include "components/transform_component.hpp"
#include "components/collision_component.hpp"

class Teapot: public Renderable, public Debuggable
#include "objects/mesh_object.hpp"

class Teapot: public RootComponentInterface
{
public:
Teapot();
virtual void render(const GS::GSState& gs_state) override;
TransformComponent transform;
collision_component collision;

class teapot_render_proxy* render_proxy;
MeshObject teapot_mesh;

virtual const char* get_type_name() const override { return typeid(Teapot).name(); }
virtual TransformComponent* get_root_component() { return teapot_mesh.get_root_component(); }
};
3 changes: 2 additions & 1 deletion include/world/level.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace World
{
class Level: public Renderable
class Level: public Renderable, public Debuggable
{
public:
Level(Asset::Reference level_reference);
Expand All @@ -21,6 +21,7 @@ class Level: public Renderable

virtual ~Level() {};

virtual const char* get_type_name() const override { return typeid(Level).name(); }

public: // Data members
size_t level_data_size;
Expand Down
2 changes: 1 addition & 1 deletion src/engine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
#include "graph.h"

#ifndef FILESYSTEM_TYPE
#define FILESYSTEM_TYPE Filesystem::Type::cdrom
#define FILESYSTEM_TYPE Filesystem::Type::host
#endif

namespace Engine
Expand Down
91 changes: 3 additions & 88 deletions src/objects/teapot.cc
Original file line number Diff line number Diff line change
@@ -1,93 +1,8 @@
#include "egg/asset.hpp"
#include "objects/teapot.hpp"
#include "utils/rendering.hpp"
#include "renderer/mesh.hpp"
#include <malloc.h>
#include <stdio.h>

#include <draw.h>
#include <draw3d.h>

#include <graph.h>
#include <dma_tags.h>
#include <gif_tags.h>
#include <gs_psm.h>

#include <GL/gl.h> // The GL Header File
#include <dma.h>

static class teapot_render_proxy: public Renderable, public Debuggable
{
public:
teapot_render_proxy()
: Renderable(true)
{
teapot_mesh = nullptr;
debug_name = "teapot render proxy (singleton)";
}

virtual void on_gs_init() override
{
teapot_mesh = new Mesh("assets/models/kettle.mdl"_asset);
}

virtual void render(const GS::GSState& gs_state) override
{
//printf("teapot render proxy rendering. what the fuck is the deal?\n");
}

void teapot_render(const GS::GSState& gs_state, const TransformComponent& transform)
{
const Matrix local_world = Matrix::from_location_and_rotation(transform.get_location(), transform.get_rotation());

ScopedMatrix sm(local_world);

//printf("Drawing teapot\n");
teapot_mesh->draw(false);
}

AABB get_bounds() const
{
// Cache the bounds
static AABB out = compute_bounds();
return out;
}


virtual const char* get_type_name() const { return typeid(teapot_render_proxy).name(); }

protected:
AABB compute_bounds() const
{
AABB out;
// out.Min = vertices[0];
// out.Max = vertices[0];
// for (int i = 0; i < vertex_count; ++i)
// {
// out.Min.x = std::min(out.Min.x, vertices[i][0]);
// out.Min.y = std::min(out.Min.y, vertices[i][1]);
// out.Min.z = std::min(out.Min.z, vertices[i][2]);

// out.Max.x = std::max(out.Max.x, vertices[i][0]);
// out.Max.y = std::max(out.Max.y, vertices[i][1]);
// out.Max.z = std::max(out.Max.z, vertices[i][2]);
// }

return out;
}

Mesh* teapot_mesh;
} _teapot_render_proxy;

Teapot::Teapot()
: collision(&transform)
{
render_proxy = &_teapot_render_proxy;

collision.set_local_bounds(_teapot_render_proxy.get_bounds());
}

void Teapot::render(const GS::GSState& gs_state)
: collision(&teapot_mesh.transform)
, teapot_mesh("assets/models/kettle.mdl"_asset)
{
render_proxy->teapot_render(gs_state, transform);
//collision.set_local_bounds();
}
6 changes: 3 additions & 3 deletions src/objects/text_object.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ void TextObject::render(const GS::GSState& gs_state)
GS::Helpers::draw_2d_quad(Vector(screen_pos.x, screen_pos.y, text_size.x, text_size.y) + quad_background_offset, Colors::black());

//printf("############rendering text!\n");
float material[] = {1.0f, 1.0f, 1.0f, 1.0f};
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, material);
tsDrawString(screen_pos.x + text_screen_offset.x, screen_pos.y + text_screen_offset.y, text.c_str());
//float material[] = {1.0f, 1.0f, 1.0f, 1.0f};
//glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, material);
//tsDrawString(screen_pos.x + text_screen_offset.x, screen_pos.y + text_screen_offset.y, text.c_str());
}
}
}
Expand Down
File renamed without changes.
28 changes: 15 additions & 13 deletions src/renderer/gs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -182,21 +182,19 @@ static void init_renderer()
printf("Initializing graphics synthesizer: renderer\n");
glShadeModel(GL_SMOOTH); // Enable Smooth Shading
glClearColor(0.5f, 0.5f, 0.5f, 0.5f); // Black Background
//glClearDepth(1.0f); // Depth Buffer Setup
glEnable(GL_DEPTH_TEST); // Enables Depth Testing
//glEnable(GL_RESCALE_NORMAL);
//glEnable(GL_CULL_FACE);
glDepthFunc(GL_LEQUAL); // The Type Of Depth Testing To Do
glEnable(GL_DEPTH_TEST); // Enables Depth Testing
glDepthFunc(GL_LEQUAL); // The Type Of Depth Testing To Do
pglEnable(PGL_CLIPPING);

glEnableClientState(GL_VERTEX_ARRAY);
//glEnableClientState(GL_NORMAL_ARRAY);
glEnableClientState(GL_COLOR_ARRAY);
//glEnableClientState(GL_TEXTURE_COORD_ARRAY);

init_lights();
glDisableClientState(GL_NORMAL_ARRAY);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);

tsLoadFont();
//init_lights();

//tsLoadFont();

CVertexColorRenderer::Register();
CVertexColorVegetationRenderer::Register();
Expand Down Expand Up @@ -309,23 +307,27 @@ void init()

static void draw_objects(const GSState& gs_state)
{
int i = 0;
for (Renderable::TIterator Itr = Renderable::Itr(); Itr; ++Itr)
{
Debuggable::print_debug_object(&*Itr);
Itr->render(gs_state);
}

return;

// Text rendering
{
glPolygonMode(GL_FRONT, GL_FILL);
glDisable(GL_ALPHA_TEST);
glEnable(GL_TEXTURE_2D);
//glPolygonMode(GL_FRONT, GL_FILL);
//glDisable(GL_ALPHA_TEST);
//glEnable(GL_TEXTURE_2D);
glLoadIdentity();

for (TextRenderable::TIterator Itr = TextRenderable::Itr(); Itr; ++Itr)
{
Itr->render(gs_state);
}
glDisable(GL_TEXTURE_2D);
//glDisable(GL_TEXTURE_2D);

printf("8\n");
}
Expand Down
56 changes: 29 additions & 27 deletions src/renderer/helpers.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,37 +19,39 @@ void draw_2d_quad(const Vector& quad_rect, const Colors::Color& color)
glLoadIdentity();
glOrtho(0, GS::get_screen_res().x, GS::get_screen_res().y, 0, 0, 10);

glDisable(GL_TEXTURE_2D);
glEnable(GL_COLOR_MATERIAL);
glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE);
glDisable(GL_LIGHTING);
glEnable(GL_BLEND);

glBegin(GL_QUADS);
{
glColor4fv((const GLfloat*)&color_vector);
glTexCoord2f(0.f, 0.f);
glVertex3f(quad_rect.x, quad_rect.y, -1);

glColor4fv((const GLfloat*)&color_vector);
glTexCoord2f(0.f, 1.f);
glVertex3f(quad_rect.x, quad_rect.y + quad_rect.w, -1);

glColor4fv((const GLfloat*)&color_vector);
glTexCoord2f(1.f, 1.f);
glVertex3f(quad_rect.x + quad_rect.z, quad_rect.y + quad_rect.w, -1);

glColor4fv((const GLfloat*)&color_vector);
glTexCoord2f(1.f, 0.f);
glVertex3f(quad_rect.x + quad_rect.z, quad_rect.y, -1);
}
glEnd();
//glDisable(GL_TEXTURE_2D);
//glEnable(GL_COLOR_MATERIAL);
//glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE);
//glDisable(GL_LIGHTING);
//glEnable(GL_BLEND);

// glBegin(GL_QUADS);
// {
// glColor4fv((const GLfloat*)&color_vector);
// //glTexCoord2f(0.f, 0.f);
// glVertex3f(quad_rect.x, quad_rect.y, -1);

// glColor4fv((const GLfloat*)&color_vector);
// //glTexCoord2f(0.f, 1.f);
// glVertex3f(quad_rect.x, quad_rect.y + quad_rect.w, -1);

// glColor4fv((const GLfloat*)&color_vector);
// //glTexCoord2f(1.f, 1.f);
// glVertex3f(quad_rect.x + quad_rect.z, quad_rect.y + quad_rect.w, -1);

// glColor4fv((const GLfloat*)&color_vector);
// //glTexCoord2f(1.f, 0.f);
// glVertex3f(quad_rect.x + quad_rect.z, quad_rect.y, -1);
// }
// glEnd();

glPopMatrix();
glMatrixMode(GL_MODELVIEW);
glPopMatrix();

glDisable(GL_BLEND);
glEnable(GL_LIGHTING);
//glDisable(GL_BLEND);
//glEnable(GL_LIGHTING);

//glFlush();
}
} // namespace GS::Helpers
35 changes: 8 additions & 27 deletions src/renderer/mesh.cc
Original file line number Diff line number Diff line change
Expand Up @@ -87,17 +87,22 @@ void Mesh::compile()
check((uintptr_t)mesh->nrm.get_ptr() % 16 == 0);
check((uintptr_t)mesh->uvs.get_ptr() % 16 == 0);

check(mesh->pos.offset > 0);

glVertexPointer(4, GL_FLOAT, 0, mesh->pos.get_ptr());
pglNormalPointer(4, GL_FLOAT, 0, mesh->nrm.get_ptr());

if (mesh->nrm.offset > 0)
{
pglNormalPointer(4, GL_FLOAT, 0, mesh->nrm.get_ptr());
}

if (mesh->uvs.offset > 0)
{
//glTexCoordPointer(2, GL_FLOAT, 0, mesh->uvs.get_ptr());
glTexCoordPointer(2, GL_FLOAT, 0, mesh->uvs.get_ptr());
}

if (mesh->colors.offset > 0)
{
//printf("Mesh: %d has colors\n", list);
glColorPointer(4, GL_FLOAT, 0, mesh->colors.get_ptr());
}

Expand All @@ -118,12 +123,6 @@ void Mesh::compile()

void Mesh::draw(bool flush)
{
// if (this == nullptr)
// {
// printf("Mesh::Draw: this is nullptr? wtf\n");
// return;
// }

if (mesh == nullptr)
{
printf("Mesh::draw: Mesh nullptr, not drawing!\n");
Expand All @@ -137,24 +136,6 @@ void Mesh::draw(bool flush)
compile();
}


// {
// static char debug_str[256];
// memset(debug_str, 0, sizeof(debug_str));
// strncpy(debug_str, "Mesh::draw called with an invalid mesh! Did you compile the mesh before drawing it?\n", sizeof(debug_str));
// if (path != nullptr)
// {
// printf("%s\n", path->data());
// printf("list: %d\n", list);
// strncat(debug_str, path->data(), sizeof(debug_str));
// strncat(debug_str, "\n", sizeof(debug_str));
// }

// printf("list >= 0? %s\n", is_valid() ? "TRUE" : "FALSE");
// printf("list num: %d\n", list);
// checkf(is_valid(), debug_str);
// }

glCallList(list);
if (flush)
{
Expand Down
1 change: 1 addition & 0 deletions src/world/level.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ namespace World
{
Level::Level(Asset::Reference level_reference)
{
debug_name = "Level";
checkf(Filesystem::load_file(level_reference, level_data, level_data_size), "unable to load level!");
level = (LevelFileHeader*)level_data.get();

Expand Down
7 changes: 4 additions & 3 deletions src/world/levels/level1.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ class Level1Player
Level1Player()
: teeth_model("assets/models/level1/Mouth.mdl"_asset)
{
camera_transform.set_parent(teapot_model.transform);
camera_transform.set_parent(*teapot_model.get_root_component());
camera_transform.set_location(Vector(0.f, teapot_model.collision.get_local_bounds().get_half_extents().y));

Camera::get().transform.set_parent(camera_transform);

movement.updated_rotation_component = &camera_transform;
movement.updated_location_component = &teapot_model.transform;
movement.updated_location_component = teapot_model.get_root_component();
movement.collision_component = &teapot_model.collision;

teeth_model.get_root_component()->set_parent(Camera::get().transform);
Expand Down Expand Up @@ -55,8 +55,9 @@ class Level1: public World::Level
Level1(Asset::Reference level)
: World::Level(level)
{
debug_name = "Level1";
// Player teapot
player.teapot_model.transform.set_location(Vector(0.f, 0.f, 0.f));
player.teapot_model.get_root_component()->set_location(Vector(0.f, 0.f, 0.f));

t1.get_root_component()->set_location(Vector(100.f, 0.f, 0.f));
t1.set_prompt("Cream of mushroom");
Expand Down

0 comments on commit fc03e0a

Please sign in to comment.