Works!
This commit is contained in:
parent
a987fc42a6
commit
b2e8b9f74b
@ -8,7 +8,7 @@ set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS ${CMAKE_BUILD_TYPE_VALUES})
|
||||
|
||||
cmake_minimum_required(VERSION 3.0)
|
||||
|
||||
project(glez LANGUAGES C CXX VERSION 0.0.1)
|
||||
project(glez LANGUAGES C CXX VERSION 0.2.0)
|
||||
|
||||
set(export_dest "lib/${PROJECT_NAME}-${PROJECT_VERSION}")
|
||||
set(include_dest "include/${PROJECT_NAME}-${PROJECT_VERSION}")
|
||||
@ -20,8 +20,8 @@ find_package(GLEW REQUIRED)
|
||||
|
||||
add_library(${PROJECT_NAME} STATIC "")
|
||||
|
||||
target_compile_definitions(glez PRIVATE
|
||||
_GLIBCXX_USE_CXX11_ABI=0)
|
||||
#target_compile_definitions(glez PRIVATE
|
||||
# _GLIBCXX_USE_CXX11_ABI=0)
|
||||
|
||||
set_target_properties(${PROJECT_NAME} PROPERTIES COMPILE_FLAGS "-m32" LINK_FLAGS "-m32")
|
||||
|
||||
@ -41,13 +41,13 @@ target_include_directories(${PROJECT_NAME} PUBLIC
|
||||
|
||||
target_compile_definitions(${PROJECT_NAME} PRIVATE ${PNG_DEFINITIONS})
|
||||
|
||||
target_link_libraries(${PROJECT_NAME} ${PNG_LIBRARIES} ${GLEW_LIBRARIES} ${PROJECT_SOURCE_DIR}/freetype/lib/libfreetype.a)
|
||||
target_link_libraries(${PROJECT_NAME} ${PNG_LIBRARIES} ${GLEW_LIBRARIES} ${PROJECT_SOURCE_DIR}/freetype/lib/libfreetype.a z GL)
|
||||
|
||||
add_subdirectory(src)
|
||||
add_subdirectory(include/glez)
|
||||
add_subdirectory(ftgl)
|
||||
|
||||
install(TARGETS ${PROJECT_NAME} EXPORT ${PROJECT_NAME} DESTINATION "${lib_dest}")
|
||||
install(FILES "include/glez.h" DESTINATION "${include_dest}")
|
||||
install(DIRECTORY include/ DESTINATION "${include_dest}")
|
||||
install(EXPORT ${PROJECT_NAME} DESTINATION "${lib_dest}")
|
||||
install(FILES ${PROJECT_NAME}-config.cmake DESTINATION ${export_dest})
|
||||
|
@ -1,31 +0,0 @@
|
||||
/*
|
||||
Created by Jenny White on 30.04.18.
|
||||
Copyright (c) 2018 nullworks. All rights reserved.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
#include "render.hpp"
|
||||
|
||||
namespace glez::detail::builder
|
||||
{
|
||||
|
||||
class Builder
|
||||
{
|
||||
public:
|
||||
Builder(int mode, GLuint texture);
|
||||
|
||||
Builder &setColor(types::rgba color);
|
||||
|
||||
Builder &push(float x, float y, float u, float v);
|
||||
Builder &push(float x, float y);
|
||||
|
||||
protected:
|
||||
types::rgba color;
|
||||
|
||||
GLuint texture{ 0 };
|
||||
int mode{ 0 };
|
||||
std::vector<render::vertex> vertices{};
|
||||
};
|
||||
}
|
@ -25,6 +25,9 @@ void resize(int width, int height);
|
||||
void draw();
|
||||
void reset();
|
||||
|
||||
void begin();
|
||||
void end();
|
||||
|
||||
unsigned next_index();
|
||||
|
||||
extern vertex_buffer_t *buffer;
|
||||
|
@ -6,8 +6,13 @@
|
||||
|
||||
#include <vector>
|
||||
#include <cstdint>
|
||||
#include <glez/texture.hpp>
|
||||
#include <glez/font.hpp>
|
||||
#include "render.hpp"
|
||||
#include "../../../ftgl/vertex-buffer.h"
|
||||
#include "texture.hpp"
|
||||
#include "font.hpp"
|
||||
#include "../../../ftgl/freetype-gl.h"
|
||||
|
||||
namespace glez::detail::record
|
||||
{
|
||||
@ -17,9 +22,10 @@ class RecordedCommands
|
||||
public:
|
||||
struct segment
|
||||
{
|
||||
std::size_t start{};
|
||||
std::size_t size{};
|
||||
uint32_t texture{};
|
||||
std::size_t start{ 0 };
|
||||
std::size_t size{ 0 };
|
||||
glez::detail::texture::texture *texture{ nullptr };
|
||||
ftgl::texture_font_t *font{ nullptr };
|
||||
};
|
||||
|
||||
RecordedCommands();
|
||||
@ -27,17 +33,19 @@ public:
|
||||
|
||||
void reset();
|
||||
void store(glez::detail::render::vertex *vertices, size_t vcount, uint32_t *indices, size_t icount);
|
||||
void bind(uint32_t texture);
|
||||
void bindTexture(glez::detail::texture::texture *tx);
|
||||
void bindFont(ftgl::texture_font_t *font);
|
||||
void render();
|
||||
void end();
|
||||
protected:
|
||||
void drawSegment(std::size_t index);
|
||||
void cutSegment();
|
||||
|
||||
uint32_t currentTexture{ 0 };
|
||||
size_t nextStart{ 0 };
|
||||
ftgl::vertex_buffer_t *vertex_buffer{};
|
||||
std::vector<segment> segments{};
|
||||
segment current{};
|
||||
};
|
||||
|
||||
extern RecordedCommands *currentRecord;
|
||||
extern bool isReplaying;
|
||||
|
||||
}
|
@ -15,8 +15,5 @@ void shutdown();
|
||||
void resize(int width, int height);
|
||||
|
||||
void begin();
|
||||
void recordBegin();
|
||||
void recordEnd();
|
||||
void recordReplay();
|
||||
void end();
|
||||
};
|
@ -18,6 +18,10 @@ public:
|
||||
Record();
|
||||
~Record();
|
||||
|
||||
void begin();
|
||||
void end();
|
||||
void replay();
|
||||
|
||||
detail::record::RecordedCommands *commands{ nullptr };
|
||||
};
|
||||
|
||||
|
@ -135,9 +135,7 @@ void shutdown()
|
||||
|
||||
void draw()
|
||||
{
|
||||
glUseProgram(shader);
|
||||
vertex_buffer_render(buffer, GL_TRIANGLES);
|
||||
glUseProgram(0);
|
||||
}
|
||||
|
||||
void reset()
|
||||
@ -149,4 +147,15 @@ unsigned next_index()
|
||||
{
|
||||
return buffer->vertices->size;
|
||||
}
|
||||
|
||||
void begin()
|
||||
{
|
||||
glUseProgram(shader);
|
||||
}
|
||||
|
||||
void end()
|
||||
{
|
||||
glUseProgram(0);
|
||||
}
|
||||
|
||||
}
|
@ -5,28 +5,46 @@
|
||||
#include <cstddef>
|
||||
#include <glez/detail/record.hpp>
|
||||
#include <glez/record.hpp>
|
||||
#include <cstring>
|
||||
|
||||
namespace glez::detail::record
|
||||
{
|
||||
|
||||
void RecordedCommands::drawSegment(std::size_t index)
|
||||
{
|
||||
glDrawElements(GL_TRIANGLES, segments[index].size, GL_UNSIGNED_INT, (void *)(segments[index].start * sizeof(glez::detail::render::vertex)));
|
||||
}
|
||||
|
||||
void RecordedCommands::render()
|
||||
{
|
||||
isReplaying = true;
|
||||
vertex_buffer_render_setup(vertex_buffer, GL_TRIANGLES);
|
||||
vertex_buffer_render_finish(vertex_buffer);
|
||||
}
|
||||
|
||||
void RecordedCommands::bind(uint32_t texture)
|
||||
{
|
||||
if (currentTexture != texture)
|
||||
for (const auto& i: segments)
|
||||
{
|
||||
segments.push_back(segment{ nextStart, vertex_buffer->indices->size - nextStart, texture });
|
||||
currentTexture = texture;
|
||||
if (i.texture)
|
||||
{
|
||||
i.texture->bind();
|
||||
}
|
||||
else if (i.font)
|
||||
{
|
||||
if (i.font->atlas->id == 0)
|
||||
{
|
||||
glGenTextures(1, &i.font->atlas->id);
|
||||
}
|
||||
|
||||
glez::detail::render::bind(i.font->atlas->id);
|
||||
|
||||
if (i.font->atlas->dirty)
|
||||
{
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RED, i.font->atlas->width,
|
||||
i.font->atlas->height, 0, GL_RED, GL_UNSIGNED_BYTE,
|
||||
i.font->atlas->data);
|
||||
i.font->atlas->dirty = 0;
|
||||
}
|
||||
}
|
||||
glDrawElements(GL_TRIANGLES, i.size, GL_UNSIGNED_INT, (void *)(i.start * 4));
|
||||
}
|
||||
vertex_buffer_render_finish(vertex_buffer);
|
||||
isReplaying = false;
|
||||
}
|
||||
|
||||
void
|
||||
@ -50,9 +68,43 @@ void RecordedCommands::reset()
|
||||
{
|
||||
vertex_buffer_clear(vertex_buffer);
|
||||
segments.clear();
|
||||
memset(¤t, 0, sizeof(current));
|
||||
}
|
||||
|
||||
void RecordedCommands::bindTexture(glez::detail::texture::texture *tx)
|
||||
{
|
||||
if (current.texture != tx)
|
||||
{
|
||||
cutSegment();
|
||||
current.texture = tx;
|
||||
}
|
||||
}
|
||||
|
||||
void RecordedCommands::bindFont(ftgl::texture_font_t *font)
|
||||
{
|
||||
if (current.font != font)
|
||||
{
|
||||
cutSegment();
|
||||
current.font = font;
|
||||
}
|
||||
}
|
||||
|
||||
void RecordedCommands::cutSegment()
|
||||
{
|
||||
current.size = vertex_buffer->indices->size - current.start;
|
||||
if (current.size)
|
||||
segments.push_back(current);
|
||||
memset(¤t, 0, sizeof(segment));
|
||||
current.start = vertex_buffer->indices->size;
|
||||
}
|
||||
|
||||
void RecordedCommands::end()
|
||||
{
|
||||
cutSegment();
|
||||
}
|
||||
|
||||
RecordedCommands *currentRecord{ nullptr };
|
||||
bool isReplaying{ false };
|
||||
|
||||
}
|
||||
|
||||
@ -65,3 +117,20 @@ glez::record::Record::~Record()
|
||||
{
|
||||
delete commands;
|
||||
}
|
||||
|
||||
void glez::record::Record::begin()
|
||||
{
|
||||
detail::record::currentRecord = commands;
|
||||
commands->reset();
|
||||
}
|
||||
|
||||
void glez::record::Record::end()
|
||||
{
|
||||
commands->end();
|
||||
detail::record::currentRecord = nullptr;
|
||||
}
|
||||
|
||||
void glez::record::Record::replay()
|
||||
{
|
||||
commands->render();
|
||||
}
|
||||
|
@ -7,6 +7,7 @@
|
||||
#include <glez/detail/font.hpp>
|
||||
#include <cstring>
|
||||
#include <glez/detail/program.hpp>
|
||||
#include <glez/detail/record.hpp>
|
||||
|
||||
static GLuint current_texture{ 0 };
|
||||
|
||||
@ -41,12 +42,15 @@ void begin()
|
||||
glEnableClientState(GL_INDEX_ARRAY);
|
||||
|
||||
current_texture = 0;
|
||||
|
||||
program::begin();
|
||||
}
|
||||
|
||||
void end()
|
||||
{
|
||||
program::draw();
|
||||
program::reset();
|
||||
program::end();
|
||||
glPopClientAttrib();
|
||||
glPopAttrib();
|
||||
}
|
||||
@ -55,8 +59,11 @@ void bind(GLuint texture)
|
||||
{
|
||||
if (current_texture != texture)
|
||||
{
|
||||
program::draw();
|
||||
program::reset();
|
||||
if (!detail::record::isReplaying)
|
||||
{
|
||||
program::draw();
|
||||
program::reset();
|
||||
}
|
||||
current_texture = texture;
|
||||
glBindTexture(GL_TEXTURE_2D, texture);
|
||||
}
|
||||
|
46
src/draw.cpp
46
src/draw.cpp
@ -28,35 +28,48 @@ void internal_draw_string(float x, float y, const std::string &string,
|
||||
float pen_y = y + fnt->height / 1.5f;
|
||||
float size_y = 0;
|
||||
|
||||
if (fnt->atlas->id == 0)
|
||||
if (glez::detail::record::currentRecord)
|
||||
{
|
||||
glGenTextures(1, &fnt->atlas->id);
|
||||
glez::detail::record::currentRecord->bindFont(fnt);
|
||||
}
|
||||
|
||||
glez::detail::render::bind(fnt->atlas->id);
|
||||
|
||||
if (fnt->atlas->dirty)
|
||||
else
|
||||
{
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RED, fnt->atlas->width,
|
||||
fnt->atlas->height, 0, GL_RED, GL_UNSIGNED_BYTE,
|
||||
fnt->atlas->data);
|
||||
fnt->atlas->dirty = 0;
|
||||
if (fnt->atlas->id == 0)
|
||||
{
|
||||
glGenTextures(1, &fnt->atlas->id);
|
||||
}
|
||||
|
||||
glez::detail::render::bind(fnt->atlas->id);
|
||||
|
||||
if (fnt->atlas->dirty)
|
||||
{
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RED, fnt->atlas->width,
|
||||
fnt->atlas->height, 0, GL_RED, GL_UNSIGNED_BYTE,
|
||||
fnt->atlas->data);
|
||||
fnt->atlas->dirty = 0;
|
||||
}
|
||||
}
|
||||
|
||||
const char *sstring = string.c_str();
|
||||
|
||||
bool skipped{ false };
|
||||
|
||||
for (size_t i = 0; i < string.size(); ++i)
|
||||
{
|
||||
texture_glyph_t *glyph = texture_font_find_glyph(fnt, &sstring[i]);
|
||||
if (glyph == NULL)
|
||||
{
|
||||
texture_font_load_glyph(fnt, &sstring[i]);
|
||||
if (!skipped)
|
||||
--i;
|
||||
skipped = true;
|
||||
continue;
|
||||
}
|
||||
skipped = false;
|
||||
glez::detail::render::vertex vertices[4];
|
||||
for (auto &vertex : vertices)
|
||||
{
|
||||
@ -243,7 +256,10 @@ void rect_textured(float x, float y, float w, float h, rgba color, texture &text
|
||||
texture.load();
|
||||
|
||||
auto &tex = detail::texture::get(texture.getHandle());
|
||||
tex.bind();
|
||||
if (glez::detail::record::currentRecord)
|
||||
glez::detail::record::currentRecord->bindTexture(&tex);
|
||||
else
|
||||
tex.bind();
|
||||
|
||||
detail::render::vertex vertices[4];
|
||||
|
||||
|
15
src/glez.cpp
15
src/glez.cpp
@ -45,19 +45,4 @@ void preInit()
|
||||
{
|
||||
detail::font::init();
|
||||
}
|
||||
|
||||
void glez::recordBegin(record::Record& rc)
|
||||
{
|
||||
detail::record::currentRecord = rc.commands;
|
||||
}
|
||||
|
||||
void glez::recordEnd()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void glez::recordReplay()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user