mirror of
https://github.com/Relintai/sfw.git
synced 2024-11-08 07:52:09 +01:00
Initial test rendering setup.
This commit is contained in:
parent
3a6f715f35
commit
eed6d1aa59
@ -44,6 +44,10 @@ g++ -Wall -D_REENTRANT -g -Isfw -Isfw/application -c sfw/application/scene.cpp -
|
||||
g++ -Wall -D_REENTRANT -g -Isfw -Isfw/application -c sfw/application/window.cpp -o sfw/application/window.o
|
||||
|
||||
|
||||
g++ -Wall -D_REENTRANT -g -Isfw -Isfw/application -c sfw/application/shader.cpp -o sfw/application/shader.o
|
||||
g++ -Wall -D_REENTRANT -g -Isfw -Isfw/application -c sfw/application/material.cpp -o sfw/application/material.o
|
||||
g++ -Wall -D_REENTRANT -g -Isfw -Isfw/application -c sfw/application/mesh.cpp -o sfw/application/mesh.o
|
||||
|
||||
g++ -Wall -D_REENTRANT -g -Isfw -Isfw/application -c game_scene.cpp -o game_scene.o
|
||||
g++ -Wall -D_REENTRANT -g -Isfw -Isfw/application -c main.cpp -o main.o
|
||||
|
||||
@ -54,6 +58,7 @@ g++ -Wall -lm -ldl -lpthread -lX11 -D_REENTRANT -g sfw/aabb.o sfw/basis.o sfw/c
|
||||
sfw/ustring.o sfw/vector2.o sfw/vector2i.o sfw/vector3.o sfw/vector3i.o sfw/vector4.o sfw/vector4i.o \
|
||||
sfw/pool_vector.o sfw/pool_allocator.o sfw/mutex.o sfw/stime.o \
|
||||
sfw/application/application.o sfw/application/scene.o sfw/application/window.o \
|
||||
sfw/application/shader.o sfw/application/material.o sfw/application/mesh.o \
|
||||
game_scene.o main.o \
|
||||
-o game
|
||||
|
||||
|
@ -4,15 +4,11 @@
|
||||
#include "application.h"
|
||||
|
||||
#include "game_scene.h"
|
||||
#include "window.h"
|
||||
|
||||
class GameApplication : public Application {
|
||||
public:
|
||||
GameApplication() : Application() {
|
||||
scene = new GameScene();
|
||||
|
||||
AppWindow *w = memnew(AppWindow());
|
||||
w->create(100, 0);
|
||||
}
|
||||
|
||||
~GameApplication() {
|
||||
|
@ -3,6 +3,7 @@
|
||||
#include "application.h"
|
||||
|
||||
#include "3rd_glad.h"
|
||||
#include "memory.h"
|
||||
|
||||
//#include "camera.h"
|
||||
//#include "sprite.h"
|
||||
@ -97,7 +98,7 @@ void GameScene::update(float delta) {
|
||||
}
|
||||
|
||||
void GameScene::render() {
|
||||
glClearColor(1.0f, 0.0f, 0.0f, 1.0f);
|
||||
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
||||
//camera->bind();
|
||||
@ -105,6 +106,9 @@ void GameScene::render() {
|
||||
//tile_map->render();
|
||||
|
||||
//sprite->render();
|
||||
|
||||
material->bind();
|
||||
mesh->render();
|
||||
}
|
||||
|
||||
GameScene::GameScene() {
|
||||
@ -165,6 +169,44 @@ GameScene::GameScene() {
|
||||
|
||||
tile_map->build_mesh();
|
||||
*/
|
||||
|
||||
mesh = memnew(Mesh(2));
|
||||
material = memnew(ColoredMaterial());
|
||||
|
||||
mesh->clear();
|
||||
|
||||
//float width = 1;
|
||||
//float height = 1;
|
||||
|
||||
//float region_x = 0;
|
||||
//float region_y = 0;
|
||||
//float region_width = 1;
|
||||
//float region_height = 1;
|
||||
|
||||
//float w2 = width / 2.0;
|
||||
//float h2 = height / 2.0;
|
||||
|
||||
//mesh->add_uv(region_x, region_y);
|
||||
//mesh->add_vertex2(-w2, h2);
|
||||
|
||||
//mesh->add_uv(region_x + region_width, region_y + region_height);
|
||||
//mesh->add_vertex2(w2, -h2);
|
||||
|
||||
//mesh->add_uv(region_x, region_y + region_height);
|
||||
//mesh->add_vertex2(-w2, -h2);
|
||||
|
||||
//mesh->add_uv(region_x + region_width, region_y);
|
||||
//mesh->add_vertex2(w2, h2);
|
||||
|
||||
|
||||
mesh->add_vertex2(0, 0.5);
|
||||
mesh->add_vertex2(-0.5, -0.5);
|
||||
mesh->add_vertex2(0.5, -0.5);
|
||||
|
||||
mesh->add_triangle(0, 1, 2);
|
||||
//mesh->add_triangle(0, 1, 3);
|
||||
|
||||
mesh->upload();
|
||||
}
|
||||
|
||||
GameScene::~GameScene() {
|
||||
@ -175,4 +217,7 @@ GameScene::~GameScene() {
|
||||
delete tile_map;
|
||||
delete sprite;
|
||||
*/
|
||||
|
||||
memdelete(mesh);
|
||||
memdelete(material);
|
||||
}
|
||||
|
@ -6,12 +6,15 @@
|
||||
/*
|
||||
#include "camera.h"
|
||||
#include "mesh_instance.h"
|
||||
#include "sprite.h"
|
||||
#include "texture.h"
|
||||
#include "texture_material.h"
|
||||
#include "tile_map.h"
|
||||
#include "sprite.h"
|
||||
*/
|
||||
|
||||
#include "colored_material.h"
|
||||
#include "mesh.h"
|
||||
|
||||
class GameScene : public Scene {
|
||||
public:
|
||||
virtual void event();
|
||||
@ -32,6 +35,9 @@ public:
|
||||
TileMap *tile_map;
|
||||
Sprite *sprite;
|
||||
*/
|
||||
|
||||
Mesh *mesh;
|
||||
ColoredMaterial *material;
|
||||
};
|
||||
|
||||
#endif
|
6
main.cpp
6
main.cpp
@ -6,6 +6,7 @@
|
||||
#include "window.h"
|
||||
|
||||
#include "game_application.h"
|
||||
#include "window.h"
|
||||
|
||||
Application *application = NULL;
|
||||
|
||||
@ -14,6 +15,9 @@ void handle_frame() {
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
AppWindow *w = memnew(AppWindow());
|
||||
w->create(100, 0);
|
||||
|
||||
application = new GameApplication();
|
||||
|
||||
#ifdef __EMSCRIPTEN__
|
||||
@ -24,8 +28,6 @@ int main(int argc, char **argv) {
|
||||
// application->main_loop();
|
||||
//}
|
||||
|
||||
AppWindow *w = AppWindow::get_singleton();
|
||||
|
||||
while (application->running) {
|
||||
if (w->frame_begin()) {
|
||||
//w->resize();
|
||||
|
@ -1,6 +1,5 @@
|
||||
#include "application.h"
|
||||
|
||||
#include "opengl.h"
|
||||
#include <chrono>
|
||||
|
||||
#include "window.h"
|
||||
|
@ -1,7 +1,7 @@
|
||||
#ifndef CAMERA_H
|
||||
#define CAMERA_H
|
||||
|
||||
#include "opengl.h"
|
||||
#include "3rd_glad.h"
|
||||
|
||||
#include "./libs/glm/vec3.hpp"
|
||||
#include "./libs/glm/matrix.hpp"
|
||||
|
@ -3,10 +3,10 @@
|
||||
|
||||
#include "material.h"
|
||||
|
||||
#include "./libs/glm/vec4.hpp"
|
||||
#include "./libs/glm/gtc/type_ptr.hpp"
|
||||
#include "../../libs/glm/vec4.hpp"
|
||||
#include "../../libs/glm/gtc/type_ptr.hpp"
|
||||
|
||||
#include "camera.h"
|
||||
//#include "camera.h"
|
||||
|
||||
class ColoredMaterial : public Material {
|
||||
public:
|
||||
@ -15,42 +15,48 @@ public:
|
||||
}
|
||||
|
||||
void bind_uniforms() {
|
||||
glUniformMatrix4fv(projection_matrix_location, 1, GL_FALSE, glm::value_ptr(Camera::current_camera->projection_matrix));
|
||||
glUniformMatrix4fv(model_view_matrix_location, 1, GL_FALSE, glm::value_ptr(Camera::current_camera->model_view_matrix));
|
||||
//glUniformMatrix4fv(projection_matrix_location, 1, GL_FALSE, glm::value_ptr(Camera::current_camera->projection_matrix));
|
||||
//glUniformMatrix4fv(model_view_matrix_location, 1, GL_FALSE, glm::value_ptr(Camera::current_camera->model_view_matrix));
|
||||
|
||||
glUniform4f(tri_color_uniform_location, color.r, color.g, color.b, color.a);
|
||||
//glUniform4f(tri_color_uniform_location, color.r, color.g, color.b, color.a);
|
||||
}
|
||||
|
||||
void setup_uniforms() {
|
||||
projection_matrix_location = get_uniform("u_proj_matrix");
|
||||
model_view_matrix_location = get_uniform("u_model_view_matrix");
|
||||
// projection_matrix_location = get_uniform("u_proj_matrix");
|
||||
// model_view_matrix_location = get_uniform("u_model_view_matrix");
|
||||
|
||||
tri_color_uniform_location = get_uniform("fragment_color");
|
||||
//tri_color_uniform_location = get_uniform("fragment_color");
|
||||
}
|
||||
|
||||
// "uniform mat4 u_proj_matrix;\n"
|
||||
// "uniform mat4 u_model_view_matrix;\n"
|
||||
// "\n"
|
||||
//"attribute vec4 a_position;\n"
|
||||
// "\n"
|
||||
// "void main() {\n"
|
||||
// " gl_Position = u_proj_matrix * u_model_view_matrix * a_position;\n"
|
||||
// "}"
|
||||
|
||||
const GLchar **get_vertex_shader_source() {
|
||||
static const GLchar *vertex_shader_source[] = {
|
||||
"uniform mat4 u_proj_matrix;\n"
|
||||
"uniform mat4 u_model_view_matrix;\n"
|
||||
"\n"
|
||||
"attribute vec4 a_position;\n"
|
||||
"\n"
|
||||
"void main() {\n"
|
||||
" gl_Position = u_proj_matrix * u_model_view_matrix * a_position;\n"
|
||||
" gl_Position = a_position;\n"
|
||||
"}"
|
||||
};
|
||||
|
||||
return vertex_shader_source;
|
||||
}
|
||||
|
||||
//"precision mediump float;\n"
|
||||
//"\n"
|
||||
//"uniform vec4 fragment_color;\n"
|
||||
//"\n"
|
||||
const GLchar **get_fragment_shader_source() {
|
||||
static const GLchar *fragment_shader_source[] = {
|
||||
"precision mediump float;\n"
|
||||
"\n"
|
||||
"uniform vec4 fragment_color;\n"
|
||||
"\n"
|
||||
|
||||
"void main() {\n"
|
||||
" gl_FragColor = fragment_color;\n"
|
||||
" gl_FragColor = vec4(1, 0, 0, 1);\n"
|
||||
"}"
|
||||
};
|
||||
|
||||
|
@ -1,7 +1,6 @@
|
||||
#ifndef MATERIAL_H
|
||||
#define MATERIAL_H
|
||||
|
||||
#include "opengl.h"
|
||||
#include "shader.h"
|
||||
|
||||
class Material {
|
||||
|
@ -4,7 +4,7 @@
|
||||
#include <vector>
|
||||
#include <inttypes.h>
|
||||
|
||||
#include "opengl.h"
|
||||
#include "3rd_glad.h"
|
||||
|
||||
class Mesh {
|
||||
public:
|
||||
|
@ -2,9 +2,9 @@
|
||||
|
||||
#include "camera.h"
|
||||
|
||||
#include "./libs/glm/vec3.hpp"
|
||||
#include "./libs/glm/matrix.hpp"
|
||||
#include "./libs/glm/gtc/matrix_transform.hpp"
|
||||
#include "../../libs/glm/vec3.hpp"
|
||||
#include "../../libs/glm/matrix.hpp"
|
||||
#include "../../libs/glm/gtc/matrix_transform.hpp"
|
||||
|
||||
|
||||
void MeshInstance::render() {
|
||||
|
@ -3,11 +3,10 @@
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "opengl.h"
|
||||
#include "material.h"
|
||||
#include "mesh.h"
|
||||
|
||||
#include "./libs/glm/vec3.hpp"
|
||||
#include "../../libs/glm/vec3.hpp"
|
||||
|
||||
class MeshInstance {
|
||||
public:
|
||||
|
@ -1,7 +1,7 @@
|
||||
#ifndef SHADER_H
|
||||
#define SHADER_H
|
||||
|
||||
#include "opengl.h"
|
||||
#include "3rd_glad.h"
|
||||
#include <unordered_map>
|
||||
|
||||
class Shader {
|
||||
|
@ -1,7 +1,6 @@
|
||||
#ifndef TEXTURE_H
|
||||
#define TEXTURE_H
|
||||
|
||||
#include "opengl.h"
|
||||
#include <SDL.h>
|
||||
|
||||
class Texture {
|
||||
|
Loading…
Reference in New Issue
Block a user