mirror of
https://github.com/seekrs/MacroLibX.git
synced 2026-01-11 22:53:34 +00:00
rendering
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user