mirror of
https://github.com/Relintai/sfw.git
synced 2024-11-08 07:52:09 +01:00
3d camera test render setup.
This commit is contained in:
parent
0d52245e20
commit
97841ab135
@ -53,6 +53,7 @@ ccache g++ -Wall -D_REENTRANT -g -Isfw -Isfw/application -c sfw/application/obje
|
||||
ccache g++ -Wall -D_REENTRANT -g -Isfw -Isfw/application -c sfw/application/sprite.cpp -o sfw/application/sprite.o
|
||||
ccache g++ -Wall -D_REENTRANT -g -Isfw -Isfw/application -c sfw/application/tile_map.cpp -o sfw/application/tile_map.o
|
||||
ccache g++ -Wall -D_REENTRANT -g -Isfw -Isfw/application -c sfw/application/texture.cpp -o sfw/application/texture.o
|
||||
ccache g++ -Wall -D_REENTRANT -g -Isfw -Isfw/application -c sfw/application/mesh_utils.cpp -o sfw/application/mesh_utils.o
|
||||
|
||||
ccache g++ -Wall -D_REENTRANT -g -Isfw -Isfw/application -c game_scene.cpp -o game_scene.o
|
||||
ccache g++ -Wall -D_REENTRANT -g -Isfw -Isfw/application -c main.cpp -o main.o
|
||||
@ -67,6 +68,7 @@ ccache g++ -Wall -lm -ldl -lpthread -lX11 -D_REENTRANT -g sfw/aabb.o sfw/basis.
|
||||
sfw/application/shader.o sfw/application/material.o sfw/application/mesh.o \
|
||||
sfw/application/camera.o sfw/application/mesh_instance.o sfw/application/object_2d.o \
|
||||
sfw/application/sprite.o sfw/application/tile_map.o sfw/application/texture.o \
|
||||
sfw/application/mesh_utils.o \
|
||||
game_scene.o main.o \
|
||||
-o game
|
||||
|
||||
|
@ -4,6 +4,7 @@
|
||||
|
||||
#include "3rd_glad.h"
|
||||
#include "memory.h"
|
||||
#include "mesh_utils.h"
|
||||
|
||||
void GameScene::event() {
|
||||
/*
|
||||
@ -98,6 +99,12 @@ void GameScene::render() {
|
||||
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
||||
static float rot = 0;
|
||||
|
||||
camera->camera_transform.basis = Basis(Vector3(0, 1, 0), rot);
|
||||
|
||||
rot += 0.01;
|
||||
|
||||
camera->bind();
|
||||
|
||||
//tile_map->render();
|
||||
@ -105,9 +112,10 @@ void GameScene::render() {
|
||||
//sprite->render();
|
||||
|
||||
//material->bind();
|
||||
//mesh->render();
|
||||
color_material->bind();
|
||||
mesh->render();
|
||||
|
||||
sprite->render();
|
||||
//sprite->render();
|
||||
}
|
||||
|
||||
GameScene::GameScene() {
|
||||
@ -125,23 +133,23 @@ GameScene::GameScene() {
|
||||
//float ar = static_cast<float>(w) / static_cast<float>(h);
|
||||
//camera->width = camera->height * ar;
|
||||
|
||||
texture = new Texture();
|
||||
texture->load_image("icon.png");
|
||||
//texture = new Texture();
|
||||
//texture->load_image("icon.png");
|
||||
//ha a textúrának van alpha csatornája:
|
||||
//texture->load_image("download.bmp", GL_RGBA, GL_RGBA);
|
||||
|
||||
material = new TextureMaterial();
|
||||
material->texture = texture;
|
||||
//material = new TextureMaterial();
|
||||
//material->texture = texture;
|
||||
|
||||
sprite = new Sprite();
|
||||
sprite->mesh_instance->material = material;
|
||||
//sprite = new Sprite();
|
||||
//sprite->mesh_instance->material = material;
|
||||
//sprite->position.x = 0;
|
||||
//sprite->position.y = 0;
|
||||
//sprite->region_x = 7.0 * (1.0 / 16.0);
|
||||
//sprite->region_y = 7.0 * (1.0 / 16.0);
|
||||
//sprite->region_width = 1.0 / 16.0;
|
||||
//sprite->region_height = 1.0 / 16.0;
|
||||
sprite->update_mesh();
|
||||
//sprite->update_mesh();
|
||||
/*
|
||||
tile_map = new TileMap();
|
||||
tile_map->material = material;
|
||||
@ -163,18 +171,24 @@ GameScene::GameScene() {
|
||||
tile_map->build_mesh();
|
||||
*/
|
||||
|
||||
camera = new OrthographicCamera();
|
||||
camera = new PerspectiveCamera();
|
||||
//camera->width = 2;
|
||||
//camera->height = 2;
|
||||
//camera->position.x = 0;
|
||||
//camera->position.y = 0;
|
||||
//camera->position.z = -2;
|
||||
camera->camera_transform.origin.z -= 2;
|
||||
camera->screen_aspect_ratio = 1980.0 / 1080.0;
|
||||
|
||||
mesh = memnew(Mesh(2));
|
||||
cmaterial = memnew(ColoredMaterial());
|
||||
mesh = memnew(Mesh());
|
||||
//cmaterial = memnew(ColoredMaterial());
|
||||
//cmaterial->color = glm::vec4(1, 1, 0, 1);
|
||||
color_material = memnew(ColorMaterial());
|
||||
|
||||
mesh->clear();
|
||||
//mesh->clear();
|
||||
|
||||
MeshUtils::create_cone(mesh);
|
||||
mesh->upload();
|
||||
|
||||
//float width = 1;
|
||||
//float height = 1;
|
||||
@ -199,6 +213,7 @@ GameScene::GameScene() {
|
||||
//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);
|
||||
@ -207,6 +222,7 @@ GameScene::GameScene() {
|
||||
//mesh->add_triangle(0, 1, 3);
|
||||
|
||||
mesh->upload();
|
||||
*/
|
||||
}
|
||||
|
||||
GameScene::~GameScene() {
|
||||
@ -214,12 +230,13 @@ GameScene::~GameScene() {
|
||||
delete tile_map;
|
||||
*/
|
||||
memdelete(camera);
|
||||
memdelete(texture);
|
||||
memdelete(material);
|
||||
//memdelete(texture);
|
||||
//memdelete(material);
|
||||
|
||||
memdelete(sprite);
|
||||
//memdelete(sprite);
|
||||
|
||||
memdelete(camera);
|
||||
memdelete(mesh);
|
||||
memdelete(material);
|
||||
//memdelete(material);
|
||||
memdelete(color_material);
|
||||
}
|
||||
|
13
game_scene.h
13
game_scene.h
@ -12,14 +12,13 @@
|
||||
#include "tile_map.h"
|
||||
*/
|
||||
|
||||
#include "camera.h"
|
||||
#include "color_material.h"
|
||||
#include "colored_material.h"
|
||||
#include "mesh.h"
|
||||
#include "camera.h"
|
||||
#include "sprite.h"
|
||||
#include "texture.h"
|
||||
#include "texture_material.h"
|
||||
#include "camera.h"
|
||||
#include "sprite.h"
|
||||
|
||||
|
||||
class GameScene : public Scene {
|
||||
public:
|
||||
@ -36,14 +35,18 @@ public:
|
||||
bool down;
|
||||
*/
|
||||
|
||||
/*
|
||||
Texture *texture;
|
||||
TextureMaterial *material;
|
||||
//TileMap *tile_map;
|
||||
Sprite *sprite;
|
||||
*/
|
||||
|
||||
Camera *camera;
|
||||
Mesh *mesh;
|
||||
ColoredMaterial *cmaterial;
|
||||
ColorMaterial *color_material;
|
||||
|
||||
//ColoredMaterial *cmaterial;
|
||||
};
|
||||
|
||||
#endif
|
@ -28,7 +28,6 @@ Camera *Camera::current_camera = NULL;
|
||||
|
||||
void OrthographicCamera::bind() {
|
||||
Camera::bind();
|
||||
|
||||
projection_matrix.set_orthogonal(
|
||||
size,
|
||||
screen_aspect_ratio,
|
||||
|
@ -6,25 +6,27 @@
|
||||
#include "camera.h"
|
||||
|
||||
class ColorMaterial : public Material {
|
||||
|
||||
public:
|
||||
int get_material_id() {
|
||||
return 2;
|
||||
}
|
||||
|
||||
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));
|
||||
set_uniform(projection_matrix_location, Camera::current_camera->projection_matrix);
|
||||
set_uniform(camera_matrix_location, Camera::current_camera->camera_transform);
|
||||
set_uniform(model_view_matrix_location, Camera::current_camera->model_view_matrix);
|
||||
}
|
||||
|
||||
void setup_uniforms() {
|
||||
projection_matrix_location = get_uniform("u_proj_matrix");
|
||||
camera_matrix_location = get_uniform("u_camera_matrix");
|
||||
model_view_matrix_location = get_uniform("u_model_view_matrix");
|
||||
}
|
||||
|
||||
const GLchar** get_vertex_shader_source() {
|
||||
const GLchar **get_vertex_shader_source() {
|
||||
static const GLchar *vertex_shader_source[] = {
|
||||
"uniform mat4 u_proj_matrix;\n"
|
||||
"uniform mat4 u_camera_matrix;\n"
|
||||
"uniform mat4 u_model_view_matrix;\n"
|
||||
"\n"
|
||||
"attribute vec4 a_position;\n"
|
||||
@ -34,14 +36,14 @@ public:
|
||||
"\n"
|
||||
"void main() {\n"
|
||||
" v_color = a_color;\n"
|
||||
" gl_Position = u_proj_matrix * u_model_view_matrix * a_position;\n"
|
||||
" gl_Position = u_proj_matrix * u_camera_matrix * u_model_view_matrix * a_position;\n"
|
||||
"}\n"
|
||||
};
|
||||
|
||||
return vertex_shader_source;
|
||||
}
|
||||
|
||||
const GLchar** get_fragment_shader_source() {
|
||||
const GLchar **get_fragment_shader_source() {
|
||||
static const GLchar *fragment_shader_source[] = {
|
||||
"precision mediump float;"
|
||||
"varying vec4 v_color;\n"
|
||||
@ -53,13 +55,14 @@ public:
|
||||
}
|
||||
|
||||
ColorMaterial() {
|
||||
color = glm::vec4(1, 1, 1, 1);
|
||||
projection_matrix_location = 0;
|
||||
camera_matrix_location = 0;
|
||||
model_view_matrix_location = 0;
|
||||
}
|
||||
|
||||
GLint projection_matrix_location;
|
||||
GLint camera_matrix_location;
|
||||
GLint model_view_matrix_location;
|
||||
|
||||
glm::vec4 color;
|
||||
};
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user