okay obj files load now

main
Brett 2024-01-11 14:36:48 -05:00
parent 3e8eea09b5
commit 9ccf0badc2
11 changed files with 30672 additions and 7 deletions

View File

@ -0,0 +1,25 @@
#ifdef __cplusplus
#include <string>
const std::string shader_3d_textured_frag = R"("
#version 300 es
precision mediump float;
out vec4 FragColor;
in vec2 uv;
in vec2 pos;
in vec3 normal;
uniform sampler2D tex;
uniform vec4 color;
uniform vec4 use_texture;
vec4 linear_iter(vec4 i, vec4 p, float factor){
return (i + p) * factor;
}
void main() {
FragColor = texture(tex, uv) * vec4(abs(normal), 1.0);
}
")";
#endif

View File

@ -0,0 +1,34 @@
#ifdef __cplusplus
#include <string>
const std::string shader_3d_textured_vert = R"("
#version 300 es
precision mediump float;
layout (location = 0) in vec3 vertex_in;
layout (location = 1) in vec2 uv_in;
layout (location = 2) in vec3 normal_in;
out vec2 pos;
out vec3 normal;
out vec2 uv;
layout (std140) uniform GlobalMatrices
{
mat4 projection;
mat4 ortho;
mat4 view;
mat4 pvm;
mat4 ovm;
};
uniform mat4 model;
void main() {
gl_Position = pvm * model * vec4(vertex_in, 1.0);
pos = vertex_in.xy;
uv = uv_in;
normal = normal_in;
}
")";
#endif

View File

@ -29,7 +29,7 @@ namespace blt::gfx
private:
blt::vec3 position_;
blt::vec3 rotation_;
blt::vec3 speed_ {50, 50, 50};
blt::vec3 speed_ {25, 25, 25};
public:
void update();

View File

@ -109,6 +109,8 @@ namespace blt::gfx
shader_base_t& setFloat(const std::string& name, float value);
shader_base_t& setMatrix(const std::string& name, blt::mat4x4& matrix);
// poor solution: TODO
shader_base_t& setMatrix(const std::string& name, blt::mat4x4&& matrix);
shader_base_t& setVec2(const std::string& name, const blt::vec2& vec);

View File

@ -0,0 +1,132 @@
# Blender 3.4.1 MTL File: 'random scene with lots of DIFFERENT objects.blend'
# www.blender.org
newmtl Material.001
Ns 250.000000
Ka 1.000000 1.000000 1.000000
Kd 0.800000 0.800000 0.800000
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
Ni 1.450000
d 1.000000
illum 2
newmtl Material.002
Ns 250.000000
Ka 1.000000 1.000000 1.000000
Kd 0.800000 0.800000 0.800000
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
Ni 1.450000
d 1.000000
illum 2
newmtl Material.003
Ns 250.000000
Ka 1.000000 1.000000 1.000000
Kd 0.800000 0.800000 0.800000
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
Ni 1.450000
d 1.000000
illum 2
newmtl Material.004
Ns 250.000000
Ka 1.000000 1.000000 1.000000
Kd 0.800000 0.800000 0.800000
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
Ni 1.450000
d 1.000000
illum 2
newmtl Material.005
Ns 250.000000
Ka 1.000000 1.000000 1.000000
Kd 0.800000 0.800000 0.800000
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
Ni 1.450000
d 1.000000
illum 2
newmtl Material.006
Ns 250.000000
Ka 1.000000 1.000000 1.000000
Kd 0.800000 0.800000 0.800000
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
Ni 1.450000
d 1.000000
illum 2
newmtl Material.007
Ns 250.000000
Ka 1.000000 1.000000 1.000000
Kd 0.800000 0.800000 0.800000
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
Ni 1.450000
d 1.000000
illum 2
newmtl Material.008
Ns 250.000000
Ka 1.000000 1.000000 1.000000
Kd 0.800000 0.800000 0.800000
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
Ni 1.450000
d 1.000000
illum 2
newmtl Material.009
Ns 250.000000
Ka 1.000000 1.000000 1.000000
Kd 0.800000 0.800000 0.800000
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
Ni 1.450000
d 1.000000
illum 2
newmtl Material.010
Ns 250.000000
Ka 1.000000 1.000000 1.000000
Kd 0.800000 0.800000 0.800000
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
Ni 1.450000
d 1.000000
illum 2
newmtl Material.011
Ns 250.000000
Ka 1.000000 1.000000 1.000000
Kd 0.800000 0.800000 0.800000
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
Ni 1.450000
d 1.000000
illum 2
newmtl Material.012
Ns 250.000000
Ka 1.000000 1.000000 1.000000
Kd 0.800000 0.800000 0.800000
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
Ni 1.450000
d 1.000000
illum 2
newmtl Material.013
Ns 250.000000
Ka 1.000000 1.000000 1.000000
Kd 0.800000 0.800000 0.800000
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
Ni 1.450000
d 1.000000
illum 2

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,132 @@
# Blender 3.4.1 MTL File: 'random scene with lots of DIFFERENT objects.blend'
# www.blender.org
newmtl Material.001
Ns 250.000000
Ka 1.000000 1.000000 1.000000
Kd 0.800000 0.800000 0.800000
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
Ni 1.450000
d 1.000000
illum 2
newmtl Material.002
Ns 250.000000
Ka 1.000000 1.000000 1.000000
Kd 0.800000 0.800000 0.800000
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
Ni 1.450000
d 1.000000
illum 2
newmtl Material.003
Ns 250.000000
Ka 1.000000 1.000000 1.000000
Kd 0.800000 0.800000 0.800000
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
Ni 1.450000
d 1.000000
illum 2
newmtl Material.004
Ns 250.000000
Ka 1.000000 1.000000 1.000000
Kd 0.800000 0.800000 0.800000
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
Ni 1.450000
d 1.000000
illum 2
newmtl Material.005
Ns 250.000000
Ka 1.000000 1.000000 1.000000
Kd 0.800000 0.800000 0.800000
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
Ni 1.450000
d 1.000000
illum 2
newmtl Material.006
Ns 250.000000
Ka 1.000000 1.000000 1.000000
Kd 0.800000 0.800000 0.800000
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
Ni 1.450000
d 1.000000
illum 2
newmtl Material.007
Ns 250.000000
Ka 1.000000 1.000000 1.000000
Kd 0.800000 0.800000 0.800000
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
Ni 1.450000
d 1.000000
illum 2
newmtl Material.008
Ns 250.000000
Ka 1.000000 1.000000 1.000000
Kd 0.800000 0.800000 0.800000
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
Ni 1.450000
d 1.000000
illum 2
newmtl Material.009
Ns 250.000000
Ka 1.000000 1.000000 1.000000
Kd 0.800000 0.800000 0.800000
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
Ni 1.450000
d 1.000000
illum 2
newmtl Material.010
Ns 250.000000
Ka 1.000000 1.000000 1.000000
Kd 0.800000 0.800000 0.800000
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
Ni 1.450000
d 1.000000
illum 2
newmtl Material.011
Ns 250.000000
Ka 1.000000 1.000000 1.000000
Kd 0.800000 0.800000 0.800000
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
Ni 1.450000
d 1.000000
illum 2
newmtl Material.012
Ns 250.000000
Ka 1.000000 1.000000 1.000000
Kd 0.800000 0.800000 0.800000
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
Ni 1.450000
d 1.000000
illum 2
newmtl Material.013
Ns 250.000000
Ka 1.000000 1.000000 1.000000
Kd 0.800000 0.800000 0.800000
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
Ni 1.450000
d 1.000000
illum 2

File diff suppressed because it is too large Load Diff

View File

@ -35,6 +35,8 @@ void blt::gfx::first_person_camera::update()
if (isKeyPressed(GLFW_KEY_LEFT_CONTROL))
speed_multi = 10;
if (isKeyPressed(GLFW_KEY_LEFT_ALT))
speed_multi = 0.5;
if (isKeyPressed(GLFW_KEY_W))
move_at[2] = -1;

View File

@ -320,4 +320,10 @@ namespace blt::gfx
v.i = loc;
return v;
}
shader_base_t& shader_base_t::setMatrix(const std::string& name, mat4x4&& matrix)
{
mat4x4 mat = matrix;
return setMatrix(name, mat);
}
}

View File

@ -8,12 +8,16 @@
#include "blt/gfx/renderer/camera.h"
#include <blt/parse/obj_loader.h>
#include <blt/gfx/renderer/3d_textured.vert>
#include <blt/gfx/renderer/3d_textured.frag>
blt::gfx::matrix_state_manager global_matrices;
blt::gfx::resource_manager resources;
blt::gfx::batch_renderer_2d renderer_2d(resources);
blt::gfx::first_person_camera camera;
std::vector<blt::gfx::vertex_array*> vaos;
std::vector<std::pair<blt::gfx::vertex_array*, size_t>> vaos;
blt::gfx::shader_t* shader;
float x = 0, y = 0, z = 0;
float bx = 500, by = 500;
@ -54,15 +58,17 @@ void init()
resources.enqueue("../resources/textures/cumdollar.jpg", "ibuythat");
resources.enqueue("../resources/textures/dfoedbi-28157978-1555-45c3-b2f4-d5e5fe25b253.png", "niko");
auto object = blt::gfx::quick_load("../resources/models/complex_cube.obj");
auto object = blt::gfx::quick_load("../resources/models/many_objects.obj");
vbo_t vertices_vbo;
vertices_vbo.create();
vertices_vbo.allocate(static_cast<long>(object.vertex_data().size() * sizeof(blt::gfx::constructed_vertex_t)), object.vertex_data().data());
auto ptr = vertex_array::createSharedVBO(vertices_vbo);
for (auto obj : object.objects())
{
vbo_t indices_vbo;
indices_vbo.create(GL_ELEMENT_ARRAY_BUFFER);
indices_vbo.allocate(static_cast<long>(obj.indices.size() * sizeof(blt::gfx::triangle_t)), obj.indices.data());
auto* vao = new vertex_array();
@ -72,9 +78,11 @@ void init()
vao->bindElement(indices_vbo);
vaos.push_back(vao);
vaos.emplace_back(vao, obj.indices.size() * 3);
}
shader = new shader_t(shader_3d_textured_vert, shader_3d_textured_frag);
global_matrices.create_internals();
resources.load_resources();
renderer_2d.create();
@ -95,7 +103,22 @@ void update(std::int32_t width, std::int32_t height)
camera.update_view(global_matrices);
global_matrices.update();
local_render(width, height);
//local_render(width, height);
shader->bind();
shader->setMatrix("model", blt::mat4x4());
glActiveTexture(GL_TEXTURE0);
glEnable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE);
glEnable(GL_MULTISAMPLE);
glCullFace(GL_BACK);
if (auto img = resources.get("niko"))
img.value()->bind();
for (auto p : vaos)
{
p.first->bind();
glDrawElements(GL_TRIANGLES, (int)p.second, GL_UNSIGNED_INT, 0);
}
renderer_2d.render();
}
@ -106,8 +129,8 @@ int main()
global_matrices.cleanup();
resources.cleanup();
renderer_2d.cleanup();
for (auto* p : vaos)
delete p;
for (auto p : vaos)
delete p.first;
blt::gfx::cleanup();
return 0;
}