adding models
This commit is contained in:
parent
583955d97a
commit
4f82475251
|
@ -2,6 +2,8 @@
|
||||||
#include <GL/glew.h>
|
#include <GL/glew.h>
|
||||||
#include <GLFW/glfw3.h>
|
#include <GLFW/glfw3.h>
|
||||||
|
|
||||||
|
#include <assimp/Importer.hpp>
|
||||||
|
|
||||||
#include "arrays.hpp"
|
#include "arrays.hpp"
|
||||||
#include "font.hpp"
|
#include "font.hpp"
|
||||||
|
|
||||||
|
@ -14,11 +16,24 @@ static void* ptr_diff(void* a, void* b)
|
||||||
return (void*)((size_t)a - (size_t)b);
|
return (void*)((size_t)a - (size_t)b);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void processNode(aiNode *node, const aiScene *scene)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
Mesh processMesh(aiMesh *mesh, const aiScene *scene)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
unsigned int arrays::init()
|
unsigned int arrays::init()
|
||||||
{
|
{
|
||||||
vertex v;
|
vertex v;
|
||||||
unsigned long handle = font::chars['*'].handle;
|
unsigned long handle = font::chars['*'].handle;
|
||||||
|
|
||||||
|
Assimp::Importer importer;
|
||||||
|
const aiScene *scene = importer.ReadFile("monkey.obj", aiProcess_Triangulate | aiProcess_FlipUVs);
|
||||||
|
|
||||||
arrays::vertex vertices[4] = {
|
arrays::vertex vertices[4] = {
|
||||||
{handle, {0.0f, 1.0f}, {-0.5f, -0.5f, 0.0f}},
|
{handle, {0.0f, 1.0f}, {-0.5f, -0.5f, 0.0f}},
|
||||||
{handle, {0.0f, 0.0f}, {-0.5f, 0.5f, 0.0f}},
|
{handle, {0.0f, 0.0f}, {-0.5f, 0.5f, 0.0f}},
|
||||||
|
|
|
@ -38,15 +38,22 @@ in vec2 texPos;
|
||||||
|
|
||||||
out vec4 FragColour;
|
out vec4 FragColour;
|
||||||
|
|
||||||
|
uniform bool do_tex;
|
||||||
|
uniform mat4 tex_mat;
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
FragColour = vec4(1) * texture2D(tex, texPos);
|
vec4 texdata = do_tex ? texture2D(tex, texPos) : vec4(1);
|
||||||
|
FragColour = tex_mat * texdata;
|
||||||
}
|
}
|
||||||
|
|
||||||
)";
|
)";
|
||||||
|
|
||||||
static unsigned int prog_id;
|
static unsigned int prog_id;
|
||||||
|
|
||||||
|
int shader::gl_tex_mat;
|
||||||
|
int shader::gl_do_tex;
|
||||||
|
|
||||||
static int load_shader(const char** src, int type)
|
static int load_shader(const char** src, int type)
|
||||||
{
|
{
|
||||||
int id = glCreateShader(type);
|
int id = glCreateShader(type);
|
||||||
|
@ -78,6 +85,9 @@ unsigned int shader::init_program()
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gl_tex_mat = glGetUniformLocation(prog_id, "tex_mat");
|
||||||
|
gl_do_tex = glGetUniformLocation(prog_id, "do_tex");
|
||||||
|
|
||||||
glUseProgram(prog_id);
|
glUseProgram(prog_id);
|
||||||
glDeleteShader(vsh_id);
|
glDeleteShader(vsh_id);
|
||||||
glDeleteShader(fsh_id);
|
glDeleteShader(fsh_id);
|
||||||
|
|
|
@ -4,6 +4,9 @@
|
||||||
namespace sim::graphics::shader
|
namespace sim::graphics::shader
|
||||||
{
|
{
|
||||||
|
|
||||||
|
extern int gl_tex_mat;
|
||||||
|
extern int gl_do_tex;
|
||||||
|
|
||||||
unsigned int init_program();
|
unsigned int init_program();
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
#include <GL/glew.h>
|
#include <GL/glew.h>
|
||||||
#include <GLFW/glfw3.h>
|
#include <GLFW/glfw3.h>
|
||||||
|
|
||||||
|
#include <glm/matrix.hpp>
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
#include "arrays.hpp"
|
#include "arrays.hpp"
|
||||||
|
@ -27,7 +29,7 @@ void window::create()
|
||||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
|
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
|
||||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 6);
|
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 6);
|
||||||
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
|
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
|
||||||
// glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, true);
|
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, true);
|
||||||
glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, true);
|
glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, true);
|
||||||
|
|
||||||
win = glfwCreateWindow(800, 600, "FastNuclearSim", nullptr, nullptr);
|
win = glfwCreateWindow(800, 600, "FastNuclearSim", nullptr, nullptr);
|
||||||
|
@ -45,6 +47,10 @@ void window::create()
|
||||||
|
|
||||||
glEnable(GL_DEBUG_OUTPUT);
|
glEnable(GL_DEBUG_OUTPUT);
|
||||||
glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS);
|
glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS);
|
||||||
|
glEnable(GL_DEPTH_TEST);
|
||||||
|
glEnable(GL_BLEND);
|
||||||
|
|
||||||
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||||
glDebugMessageCallback(cb_debug_message, nullptr);
|
glDebugMessageCallback(cb_debug_message, nullptr);
|
||||||
|
|
||||||
keyboard::init();
|
keyboard::init();
|
||||||
|
@ -59,8 +65,19 @@ void window::create()
|
||||||
|
|
||||||
void window::loop()
|
void window::loop()
|
||||||
{
|
{
|
||||||
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
|
glClearColor(0.2f, 0.3f, 0.5f, 1.0f);
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
|
|
||||||
|
glm::mat4 m = {
|
||||||
|
1, 1, 1, 1,
|
||||||
|
0, 0, 0, 0,
|
||||||
|
0, 0, 0, 0,
|
||||||
|
0, 0, 0, 0
|
||||||
|
};
|
||||||
|
|
||||||
|
glUniformMatrix4fv(shader::gl_tex_mat, 1, false, &m[0][0]);
|
||||||
|
glUniform1i(shader::gl_do_tex, 1);
|
||||||
|
|
||||||
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);
|
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);
|
||||||
|
|
||||||
glfwSwapBuffers(win);
|
glfwSwapBuffers(win);
|
||||||
|
|
Loading…
Reference in New Issue