mirror of
https://github.com/Relintai/sfw.git
synced 2024-11-08 07:52:09 +01:00
Fix rendering.
This commit is contained in:
parent
41a20717b2
commit
663c551d14
@ -47,6 +47,7 @@ ccache g++ -Wall -D_REENTRANT -g -Isfw -Isfw/application -c sfw/application/wind
|
|||||||
ccache g++ -Wall -D_REENTRANT -g -Isfw -Isfw/application -c sfw/application/shader.cpp -o sfw/application/shader.o
|
ccache g++ -Wall -D_REENTRANT -g -Isfw -Isfw/application -c sfw/application/shader.cpp -o sfw/application/shader.o
|
||||||
ccache g++ -Wall -D_REENTRANT -g -Isfw -Isfw/application -c sfw/application/material.cpp -o sfw/application/material.o
|
ccache g++ -Wall -D_REENTRANT -g -Isfw -Isfw/application -c sfw/application/material.cpp -o sfw/application/material.o
|
||||||
ccache g++ -Wall -D_REENTRANT -g -Isfw -Isfw/application -c sfw/application/mesh.cpp -o sfw/application/mesh.o
|
ccache g++ -Wall -D_REENTRANT -g -Isfw -Isfw/application -c sfw/application/mesh.cpp -o sfw/application/mesh.o
|
||||||
|
ccache g++ -Wall -D_REENTRANT -g -Isfw -Isfw/application -c sfw/application/camera.cpp -o sfw/application/camera.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 game_scene.cpp -o game_scene.o
|
||||||
ccache g++ -Wall -D_REENTRANT -g -Isfw -Isfw/application -c main.cpp -o main.o
|
ccache g++ -Wall -D_REENTRANT -g -Isfw -Isfw/application -c main.cpp -o main.o
|
||||||
@ -59,6 +60,7 @@ ccache g++ -Wall -lm -ldl -lpthread -lX11 -D_REENTRANT -g sfw/aabb.o sfw/basis.
|
|||||||
sfw/pool_vector.o sfw/pool_allocator.o sfw/mutex.o sfw/stime.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/application.o sfw/application/scene.o sfw/application/window.o \
|
||||||
sfw/application/shader.o sfw/application/material.o sfw/application/mesh.o \
|
sfw/application/shader.o sfw/application/material.o sfw/application/mesh.o \
|
||||||
|
sfw/application/camera.o \
|
||||||
game_scene.o main.o \
|
game_scene.o main.o \
|
||||||
-o game
|
-o game
|
||||||
|
|
||||||
|
@ -5,6 +5,8 @@
|
|||||||
#include "3rd_glad.h"
|
#include "3rd_glad.h"
|
||||||
#include "memory.h"
|
#include "memory.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//#include "camera.h"
|
//#include "camera.h"
|
||||||
//#include "sprite.h"
|
//#include "sprite.h"
|
||||||
|
|
||||||
@ -101,7 +103,7 @@ void GameScene::render() {
|
|||||||
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
|
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
|
||||||
glClear(GL_COLOR_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
|
|
||||||
//camera->bind();
|
camera->bind();
|
||||||
|
|
||||||
//tile_map->render();
|
//tile_map->render();
|
||||||
|
|
||||||
@ -118,13 +120,6 @@ GameScene::GameScene() {
|
|||||||
up = false;
|
up = false;
|
||||||
down = false;
|
down = false;
|
||||||
|
|
||||||
camera = new OrthographicCamera();
|
|
||||||
camera->width = 16;
|
|
||||||
camera->height = 16;
|
|
||||||
camera->position.x = 8;
|
|
||||||
camera->position.y = 8;
|
|
||||||
//camera->position.z = -2;
|
|
||||||
|
|
||||||
int w;
|
int w;
|
||||||
int h;
|
int h;
|
||||||
SDL_GetWindowSize(Application::get_singleton()->window, &w, &h);
|
SDL_GetWindowSize(Application::get_singleton()->window, &w, &h);
|
||||||
@ -170,8 +165,16 @@ GameScene::GameScene() {
|
|||||||
tile_map->build_mesh();
|
tile_map->build_mesh();
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
camera = new OrthographicCamera();
|
||||||
|
camera->width = 2;
|
||||||
|
camera->height = 2;
|
||||||
|
camera->position.x = 0;
|
||||||
|
camera->position.y = 0;
|
||||||
|
//camera->position.z = -2;
|
||||||
|
|
||||||
mesh = memnew(Mesh(2));
|
mesh = memnew(Mesh(2));
|
||||||
material = memnew(ColoredMaterial());
|
material = memnew(ColoredMaterial());
|
||||||
|
material->color = glm::vec4(1, 1, 0, 1);
|
||||||
|
|
||||||
mesh->clear();
|
mesh->clear();
|
||||||
|
|
||||||
@ -218,6 +221,7 @@ GameScene::~GameScene() {
|
|||||||
delete sprite;
|
delete sprite;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
memdelete(camera);
|
||||||
memdelete(mesh);
|
memdelete(mesh);
|
||||||
memdelete(material);
|
memdelete(material);
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
#include "scene.h"
|
#include "scene.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
#include "camera.h"
|
|
||||||
#include "mesh_instance.h"
|
#include "mesh_instance.h"
|
||||||
#include "sprite.h"
|
#include "sprite.h"
|
||||||
#include "texture.h"
|
#include "texture.h"
|
||||||
@ -14,6 +14,7 @@
|
|||||||
|
|
||||||
#include "colored_material.h"
|
#include "colored_material.h"
|
||||||
#include "mesh.h"
|
#include "mesh.h"
|
||||||
|
#include "camera.h"
|
||||||
|
|
||||||
class GameScene : public Scene {
|
class GameScene : public Scene {
|
||||||
public:
|
public:
|
||||||
@ -29,13 +30,13 @@ public:
|
|||||||
bool up;
|
bool up;
|
||||||
bool down;
|
bool down;
|
||||||
|
|
||||||
Camera *camera;
|
|
||||||
Texture *texture;
|
Texture *texture;
|
||||||
TextureMaterial *material;
|
TextureMaterial *material;
|
||||||
TileMap *tile_map;
|
TileMap *tile_map;
|
||||||
Sprite *sprite;
|
Sprite *sprite;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
Camera *camera;
|
||||||
Mesh *mesh;
|
Mesh *mesh;
|
||||||
ColoredMaterial *material;
|
ColoredMaterial *material;
|
||||||
};
|
};
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
#include "../../libs/glm/vec4.hpp"
|
#include "../../libs/glm/vec4.hpp"
|
||||||
#include "../../libs/glm/gtc/type_ptr.hpp"
|
#include "../../libs/glm/gtc/type_ptr.hpp"
|
||||||
|
|
||||||
//#include "camera.h"
|
#include "camera.h"
|
||||||
|
|
||||||
class ColoredMaterial : public Material {
|
class ColoredMaterial : public Material {
|
||||||
public:
|
public:
|
||||||
@ -15,48 +15,43 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
void bind_uniforms() {
|
void bind_uniforms() {
|
||||||
//glUniformMatrix4fv(projection_matrix_location, 1, GL_FALSE, glm::value_ptr(Camera::current_camera->projection_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));
|
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() {
|
void setup_uniforms() {
|
||||||
// projection_matrix_location = get_uniform("u_proj_matrix");
|
projection_matrix_location = get_uniform("u_proj_matrix");
|
||||||
// model_view_matrix_location = get_uniform("u_model_view_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() {
|
const GLchar **get_vertex_shader_source() {
|
||||||
static const GLchar *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"
|
"attribute vec4 a_position;\n"
|
||||||
|
"\n"
|
||||||
"void main() {\n"
|
"void main() {\n"
|
||||||
" gl_Position = a_position;\n"
|
" gl_Position = u_proj_matrix * u_model_view_matrix * a_position;\n"
|
||||||
"}"
|
"}"
|
||||||
};
|
};
|
||||||
|
|
||||||
return vertex_shader_source;
|
return vertex_shader_source;
|
||||||
}
|
}
|
||||||
|
|
||||||
//"precision mediump float;\n"
|
|
||||||
//"\n"
|
|
||||||
//"uniform vec4 fragment_color;\n"
|
|
||||||
//"\n"
|
|
||||||
const GLchar **get_fragment_shader_source() {
|
const GLchar **get_fragment_shader_source() {
|
||||||
static const GLchar *fragment_shader_source[] = {
|
static const GLchar *fragment_shader_source[] = {
|
||||||
|
"precision mediump float;\n"
|
||||||
|
"\n"
|
||||||
|
"uniform vec4 fragment_color;\n"
|
||||||
|
"\n"
|
||||||
"void main() {\n"
|
"void main() {\n"
|
||||||
" gl_FragColor = vec4(1, 0, 0, 1);\n"
|
" gl_FragColor = fragment_color;\n"
|
||||||
"}"
|
"}"
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -168,21 +168,38 @@ void AppWindow::window_hints(unsigned flags) {
|
|||||||
|
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
/* We need to explicitly ask for a 3.2 context on OS X */
|
/* We need to explicitly ask for a 3.2 context on OS X */
|
||||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); // osx
|
//glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); // osx
|
||||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2); // osx, 2:#version150,3:330
|
//glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2); // osx, 2:#version150,3:330
|
||||||
#else
|
#else
|
||||||
// Compute shaders need 4.5 otherwise. But...
|
// Compute shaders need 4.5 otherwise. But...
|
||||||
// According to the GLFW docs, the context version hint acts as a minimum version.
|
// According to the GLFW docs, the context version hint acts as a minimum version.
|
||||||
// i.e, the context you actually get may be a higher or highest version (which is usually the case)
|
// i.e, the context you actually get may be a higher or highest version (which is usually the case)
|
||||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
|
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 2);
|
||||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
|
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0);
|
||||||
#endif
|
#endif
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); //osx
|
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); //osx
|
||||||
#endif
|
#endif
|
||||||
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); //osx+ems
|
//glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); //osx+ems
|
||||||
glfwWindowHint(GLFW_STENCIL_BITS, 8); //osx
|
glfwWindowHint(GLFW_STENCIL_BITS, 8); //osx
|
||||||
glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GL_TRUE);
|
glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GL_TRUE);
|
||||||
|
//according to the documentation, it must be GLFW_OPENGL_ANY_PROFILE.
|
||||||
|
//glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_ANY_PROFILE);
|
||||||
|
glfwWindowHint(GLFW_CLIENT_API, GLFW_OPENGL_ES_API);
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
#if defined(_WIN64) || defined(_WIN32)
|
||||||
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
|
||||||
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1);
|
||||||
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
|
||||||
|
#else
|
||||||
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
|
||||||
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
|
||||||
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES);
|
||||||
|
#endif
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
//glfwWindowHint( GLFW_RED_BITS, 8 );
|
//glfwWindowHint( GLFW_RED_BITS, 8 );
|
||||||
//glfwWindowHint( GLFW_GREEN_BITS, 8 );
|
//glfwWindowHint( GLFW_GREEN_BITS, 8 );
|
||||||
@ -369,13 +386,15 @@ bool AppWindow::create_from_handle(void *handle, float scale, unsigned int flags
|
|||||||
//glEnable(GL_TEXTURE_2D);
|
//glEnable(GL_TEXTURE_2D);
|
||||||
|
|
||||||
// 0:disable vsync, 1:enable vsync, <0:adaptive (allow vsync when framerate is higher than syncrate and disable vsync when framerate drops below syncrate)
|
// 0:disable vsync, 1:enable vsync, <0:adaptive (allow vsync when framerate is higher than syncrate and disable vsync when framerate drops below syncrate)
|
||||||
flags |= _vsync ? WINDOW_VSYNC : WINDOW_VSYNC_DISABLED;
|
//flags |= _vsync ? WINDOW_VSYNC : WINDOW_VSYNC_DISABLED;
|
||||||
flags |= _vsync_adaptive ? WINDOW_VSYNC_ADAPTIVE : 0;
|
//flags |= _vsync_adaptive ? WINDOW_VSYNC_ADAPTIVE : 0;
|
||||||
|
|
||||||
int has_adaptive_vsync = glfwExtensionSupported("WGL_EXT_swap_control_tear") || glfwExtensionSupported("GLX_EXT_swap_control_tear") || glfwExtensionSupported("EXT_swap_control_tear");
|
flags |= WINDOW_VSYNC_DISABLED;
|
||||||
int wants_adaptive_vsync = (flags & WINDOW_VSYNC_ADAPTIVE);
|
|
||||||
int interval = has_adaptive_vsync && wants_adaptive_vsync ? -1 : (flags & WINDOW_VSYNC_DISABLED ? 0 : 1);
|
//int has_adaptive_vsync = glfwExtensionSupported("WGL_EXT_swap_control_tear") || glfwExtensionSupported("GLX_EXT_swap_control_tear") || //glfwExtensionSupported("EXT_swap_control_tear");
|
||||||
glfwSwapInterval(interval);
|
//int wants_adaptive_vsync = (flags & WINDOW_VSYNC_ADAPTIVE);
|
||||||
|
//int interval = has_adaptive_vsync && wants_adaptive_vsync ? -1 : (flags & WINDOW_VSYNC_DISABLED ? 0 : 1);
|
||||||
|
//glfwSwapInterval(interval);
|
||||||
|
|
||||||
const GLFWvidmode *mode = glfwGetVideoMode(monitor ? monitor : glfwGetPrimaryMonitor());
|
const GLFWvidmode *mode = glfwGetVideoMode(monitor ? monitor : glfwGetPrimaryMonitor());
|
||||||
|
|
||||||
@ -385,7 +404,7 @@ bool AppWindow::create_from_handle(void *handle, float scale, unsigned int flags
|
|||||||
//PRINTF("GPU driver: %s\n", glGetString(GL_VERSION));
|
//PRINTF("GPU driver: %s\n", glGetString(GL_VERSION));
|
||||||
|
|
||||||
#ifndef __EMSCRIPTEN__
|
#ifndef __EMSCRIPTEN__
|
||||||
//PRINTF("GPU OpenGL: %d.%d\n", GLAD_VERSION_MAJOR(gl_version), GLAD_VERSION_MINOR(gl_version));
|
LOG_MSG("GPU OpenGL: " + String::num(GLAD_VERSION_MAJOR(gl_version)) + " " + String::num(GLAD_VERSION_MINOR(gl_version)));
|
||||||
|
|
||||||
if (FLAGS_TRANSPARENT) { // @transparent
|
if (FLAGS_TRANSPARENT) { // @transparent
|
||||||
glfwSetWindowAttrib(_window, GLFW_DECORATED, GLFW_FALSE); // @todo: is decorated an attrib or a hint?
|
glfwSetWindowAttrib(_window, GLFW_DECORATED, GLFW_FALSE); // @todo: is decorated an attrib or a hint?
|
||||||
|
Loading…
Reference in New Issue
Block a user