[nostalgia/core] Fix imgui initialization
This commit is contained in:
parent
14cddf3d36
commit
3e555d38e5
@ -8,7 +8,6 @@
|
|||||||
|
|
||||||
#include <GLFW/glfw3.h>
|
#include <GLFW/glfw3.h>
|
||||||
#include <imgui.h>
|
#include <imgui.h>
|
||||||
#include <imgui_impl_glfw.h>
|
|
||||||
|
|
||||||
#include <nostalgia/core/userland/gfx.hpp>
|
#include <nostalgia/core/userland/gfx.hpp>
|
||||||
|
|
||||||
@ -38,10 +37,10 @@ ox::Error initGfx(Context *ctx) noexcept {
|
|||||||
}
|
}
|
||||||
glfwSetWindowUserPointer(id->window, ctx);
|
glfwSetWindowUserPointer(id->window, ctx);
|
||||||
glfwMakeContextCurrent(id->window);
|
glfwMakeContextCurrent(id->window);
|
||||||
oxReturnError(renderer::init(ctx));
|
IMGUI_CHECKVERSION();
|
||||||
oxReturnError(OxError(glfwInit() != 0));
|
|
||||||
ImGui::CreateContext();
|
ImGui::CreateContext();
|
||||||
ImGui_ImplGlfw_InitForOpenGL(id->window, true);
|
ImGui::GetIO().ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard;
|
||||||
|
oxReturnError(renderer::init(ctx));
|
||||||
return OxError(0);
|
return OxError(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,11 +8,14 @@
|
|||||||
|
|
||||||
#include <array>
|
#include <array>
|
||||||
|
|
||||||
|
#include <nostalgia/glutils/glutils.hpp>
|
||||||
|
|
||||||
|
#define IMGUI_IMPL_OPENGL_ES3
|
||||||
|
#include <imgui_impl_opengl3.h>
|
||||||
|
|
||||||
#include <ox/std/bit.hpp>
|
#include <ox/std/bit.hpp>
|
||||||
#include <ox/std/fmt.hpp>
|
#include <ox/std/fmt.hpp>
|
||||||
|
|
||||||
#include <nostalgia/glutils/glutils.hpp>
|
|
||||||
|
|
||||||
#include <nostalgia/core/config.hpp>
|
#include <nostalgia/core/config.hpp>
|
||||||
#include <nostalgia/core/gfx.hpp>
|
#include <nostalgia/core/gfx.hpp>
|
||||||
|
|
||||||
@ -48,7 +51,7 @@ struct GlImplData {
|
|||||||
};
|
};
|
||||||
|
|
||||||
constexpr const GLchar *bgvshad = R"(
|
constexpr const GLchar *bgvshad = R"(
|
||||||
#version 150
|
{}
|
||||||
in vec2 vTexCoord;
|
in vec2 vTexCoord;
|
||||||
in vec2 position;
|
in vec2 position;
|
||||||
out vec2 fTexCoord;
|
out vec2 fTexCoord;
|
||||||
@ -59,7 +62,7 @@ constexpr const GLchar *bgvshad = R"(
|
|||||||
})";
|
})";
|
||||||
|
|
||||||
constexpr const GLchar *bgfshad = R"(
|
constexpr const GLchar *bgfshad = R"(
|
||||||
#version 150
|
{}
|
||||||
out vec4 outColor;
|
out vec4 outColor;
|
||||||
in vec2 fTexCoord;
|
in vec2 fTexCoord;
|
||||||
uniform sampler2D image;
|
uniform sampler2D image;
|
||||||
@ -114,7 +117,7 @@ static void initBackgroundBufferObjects(Context *ctx, Background *bg) noexcept {
|
|||||||
const auto i = bgVertexRow(x, y);
|
const auto i = bgVertexRow(x, y);
|
||||||
auto vbo = &bg->bgVertices[i * BgVertexVboLength];
|
auto vbo = &bg->bgVertices[i * BgVertexVboLength];
|
||||||
auto ebo = &bg->bgElements[i * BgVertexEboLength];
|
auto ebo = &bg->bgElements[i * BgVertexEboLength];
|
||||||
setTileBufferObject(ctx, i * BgVertexVboRows, x, y, 0, vbo, ebo);
|
setTileBufferObject(ctx, i * BgVertexVboRows, static_cast<float>(x), static_cast<float>(y), 0, vbo, ebo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -191,7 +194,7 @@ static void drawBackground(Background *bg) noexcept {
|
|||||||
renderer::sendVbo(*bg);
|
renderer::sendVbo(*bg);
|
||||||
}
|
}
|
||||||
glBindTexture(GL_TEXTURE_2D, bg->tex);
|
glBindTexture(GL_TEXTURE_2D, bg->tex);
|
||||||
glDrawElements(GL_TRIANGLES, bg->bgElements.size(), GL_UNSIGNED_INT, 0);
|
glDrawElements(GL_TRIANGLES, static_cast<GLsizei>(bg->bgElements.size()), GL_UNSIGNED_INT, nullptr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -206,12 +209,16 @@ static void drawBackgrounds(GlImplData *id) noexcept {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ox::Error init(Context *ctx) noexcept {
|
ox::Error init(Context *ctx) noexcept {
|
||||||
|
constexpr auto GlslVersion = "#version 150";
|
||||||
const auto id = new GlImplData;
|
const auto id = new GlImplData;
|
||||||
ctx->setRendererData(id);
|
ctx->setRendererData(id);
|
||||||
oxReturnError(glutils::buildShaderProgram(bgvshad, bgfshad).moveTo(&id->bgShader));
|
const auto vshad = ox::sfmt(bgvshad, GlslVersion);
|
||||||
|
const auto fshad = ox::sfmt(bgfshad, GlslVersion);
|
||||||
|
oxReturnError(glutils::buildShaderProgram(vshad.c_str(), fshad.c_str()).moveTo(&id->bgShader));
|
||||||
for (auto &bg : id->backgrounds) {
|
for (auto &bg : id->backgrounds) {
|
||||||
initBackgroundBufferset(ctx, id->bgShader, &bg);
|
initBackgroundBufferset(ctx, id->bgShader, &bg);
|
||||||
}
|
}
|
||||||
|
ImGui_ImplOpenGL3_Init(GlslVersion);
|
||||||
return OxError(0);
|
return OxError(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -298,7 +305,7 @@ void setTile(Context *ctx, int layer, int column, int row, uint8_t tile) noexcep
|
|||||||
auto &bg = id->backgrounds[z];
|
auto &bg = id->backgrounds[z];
|
||||||
auto vbo = &bg.bgVertices[i * renderer::BgVertexVboLength];
|
auto vbo = &bg.bgVertices[i * renderer::BgVertexVboLength];
|
||||||
auto ebo = &bg.bgElements[i * renderer::BgVertexEboLength];
|
auto ebo = &bg.bgElements[i * renderer::BgVertexEboLength];
|
||||||
renderer::setTileBufferObject(ctx, i * renderer::BgVertexVboRows, x, y, tile, vbo, ebo);
|
renderer::setTileBufferObject(ctx, i * renderer::BgVertexVboRows, static_cast<float>(x), static_cast<float>(y), tile, vbo, ebo);
|
||||||
bg.updated = true;
|
bg.updated = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user