rendering

This commit is contained in:
Kbz-8
2022-12-19 17:16:50 +01:00
parent f1e0499564
commit 54fc452aa2
13 changed files with 259 additions and 87 deletions

View File

@@ -6,16 +6,23 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/04 17:36:44 by maldavid #+# #+# */
/* Updated: 2022/12/19 00:46:55 by maldavid ### ########.fr */
/* Updated: 2022/12/19 15:53:35 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
#include "window.h"
#include <core/errors.h>
#include <glm/glm.hpp>
#include <glm/gtc/type_ptr.hpp>
#include <iostream>
namespace mlx
{
MLX_Window::MLX_Window(std::size_t w, std::size_t h, std::string title, int id) : _id(id), _renderer(new Renderer())
static glm::mat4 proj = glm::mat4(1.0);
MLX_Window::MLX_Window(std::size_t w, std::size_t h, std::string title, int id) : _id(id), _renderer(new Renderer()), _width(w), _height(h)
{
_win = SDL_CreateWindow(title.c_str(), SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, w, h, SDL_WINDOW_VULKAN | SDL_WINDOW_SHOWN);
if(!_win)
@@ -23,24 +30,31 @@ namespace mlx
_renderer->setWindow(this);
_renderer->init();
_vbo.create(sizeof(Vertex));
proj = glm::ortho<float>(_width, 0, _height, 0);
}
bool MLX_Window::beginFrame()
{
return _renderer->beginFrame();
bool success = _renderer->beginFrame();
if(success)
_vbo.bind(*_renderer);
return success;
}
void MLX_Window::pixel_put(int x, int y, int color)
{
uint32_t ucolor = color;
Vertex vert;
vert.pos = glm::vec2(x, y);
vert.color.r = (ucolor >> 16) & 0xFF;
vert.color.g = (ucolor >> 8) & 0xFF;
vert.color.b = ucolor & 0xFF;
float xf = glm::vec4(glm::vec4((float)x, (float)y, 0.0, 0.0) * proj).x;
float yf = glm::vec4(glm::vec4((float)x, (float)y, 0.0, 0.0) * proj).y;
std::cout << xf << " " << yf << " " << std::endl;
vert.pos = glm::vec2(xf, yf);
vert.color.r = (color >> 16) & 0xFF;
vert.color.g = (color >> 8) & 0xFF;
vert.color.b = color & 0xFF;
_vbo.setData(sizeof(Vertex), &vert);
_vbo.bind(*_renderer);
vkCmdDraw(_renderer->getActiveCmdBuffer().get(), 1, 1, 0, 0);
}
@@ -51,8 +65,8 @@ namespace mlx
MLX_Window::~MLX_Window()
{
_vbo.destroy();
_renderer->destroy();
_vbo.destroy();
if(_win)
SDL_DestroyWindow(_win);
}

View File

@@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/04 21:53:12 by maldavid #+# #+# */
/* Updated: 2022/12/19 00:40:26 by maldavid ### ########.fr */
/* Updated: 2022/12/19 14:43:19 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
@@ -40,6 +40,8 @@ namespace mlx
std::unique_ptr<Renderer> _renderer;
VBO _vbo;
SDL_Window* _win = nullptr;
int _width = 0;
int _height = 0;
int _id;
};
}