Reformatted all files
This commit is contained in:
parent
8c29b72961
commit
72d8bf1644
@ -1,84 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
#
|
|
||||||
# clang-format-all: a tool to run clang-format on an entire project
|
|
||||||
# Copyright (C) 2016 Evan Klitzke <evan@eklitzke.org>
|
|
||||||
#
|
|
||||||
# This program is free software: you can redistribute it and/or modify
|
|
||||||
# it under the terms of the GNU General Public License as published by
|
|
||||||
# the Free Software Foundation, either version 3 of the License, or
|
|
||||||
# (at your option) any later version.
|
|
||||||
#
|
|
||||||
# This program is distributed in the hope that it will be useful,
|
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
# GNU General Public License for more details.
|
|
||||||
#
|
|
||||||
# You should have received a copy of the GNU General Public License
|
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
function usage {
|
|
||||||
echo "Usage: $0 DIR..."
|
|
||||||
exit 1
|
|
||||||
}
|
|
||||||
|
|
||||||
if [ $# -eq 0 ]; then
|
|
||||||
usage
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Variable that will hold the name of the clang-format command
|
|
||||||
FMT=""
|
|
||||||
|
|
||||||
# Some distros just call it clang-format. Others (e.g. Ubuntu) are insistent
|
|
||||||
# that the version number be part of the command. We prefer clang-format if
|
|
||||||
# that's present, otherwise we work backwards from highest version to lowest
|
|
||||||
# version.
|
|
||||||
for clangfmt in clang-format{,-{4,3}.{9,8,7,6,5,4,3,2,1,0}}; do
|
|
||||||
if which "$clangfmt" &>/dev/null; then
|
|
||||||
FMT="$clangfmt"
|
|
||||||
break
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
# Check if we found a working clang-format
|
|
||||||
if [ -z "$FMT" ]; then
|
|
||||||
echo "failed to find clang-format"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Check all of the arguments first to make sure they're all directories
|
|
||||||
for dir in "$@"; do
|
|
||||||
if [ ! -d "${dir}" ]; then
|
|
||||||
echo "${dir} is not a directory"
|
|
||||||
usage
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
# Find a dominating file, starting from a given directory and going up.
|
|
||||||
find-dominating-file() {
|
|
||||||
if [ -r "$1"/"$2" ]; then
|
|
||||||
return 0
|
|
||||||
fi
|
|
||||||
if [ "$1" = "/" ]; then
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
find-dominating-file "$(realpath "$1"/..)" "$2"
|
|
||||||
return $?
|
|
||||||
}
|
|
||||||
|
|
||||||
# Run clang-format -i on all of the things
|
|
||||||
for dir in "$@"; do
|
|
||||||
pushd "${dir}" &>/dev/null
|
|
||||||
if ! find-dominating-file . .clang-format; then
|
|
||||||
echo "Failed to find dominating .clang-format starting at $PWD"
|
|
||||||
continue
|
|
||||||
fi
|
|
||||||
find . \
|
|
||||||
\( -name '*.c' \
|
|
||||||
-o -name '*.cc' \
|
|
||||||
-o -name '*.cpp' \
|
|
||||||
-o -name '*.h' \
|
|
||||||
-o -name '*.hh' \
|
|
||||||
-o -name '*.hpp' \) \
|
|
||||||
-exec "${FMT}" -i '{}' \;
|
|
||||||
popd &>/dev/null
|
|
||||||
done
|
|
@ -10,11 +10,15 @@ namespace glez {
|
|||||||
struct rgba {
|
struct rgba {
|
||||||
rgba() = default;
|
rgba() = default;
|
||||||
inline constexpr rgba(int r, int g, int b)
|
inline constexpr rgba(int r, int g, int b)
|
||||||
: r(r / 255.0f), g(g / 255.0f), b(b / 255.0f), a(1.0f)
|
: r(r / 255.0f)
|
||||||
{}
|
, g(g / 255.0f)
|
||||||
|
, b(b / 255.0f)
|
||||||
|
, a(1.0f) { }
|
||||||
inline constexpr rgba(int r, int g, int b, int a)
|
inline constexpr rgba(int r, int g, int b, int a)
|
||||||
: r(r / 255.0f), g(g / 255.0f), b(b / 255.0f), a(a / 255.0f)
|
: r(r / 255.0f)
|
||||||
{}
|
, g(g / 255.0f)
|
||||||
|
, b(b / 255.0f)
|
||||||
|
, a(a / 255.0f) { }
|
||||||
|
|
||||||
float r;
|
float r;
|
||||||
float g;
|
float g;
|
||||||
|
@ -4,47 +4,45 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <vector>
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <glez/texture.hpp>
|
#include <freetype-gl.h>
|
||||||
#include <glez/font.hpp>
|
#include <glez/font.hpp>
|
||||||
#include <glez/glez.hpp>
|
#include <glez/glez.hpp>
|
||||||
|
#include <glez/texture.hpp>
|
||||||
|
#include <vector>
|
||||||
#include <vertex-buffer.h>
|
#include <vertex-buffer.h>
|
||||||
#include <glez/font.hpp>
|
|
||||||
#include <freetype-gl.h>
|
|
||||||
|
|
||||||
namespace glez::detail::record {
|
namespace glez::detail::record {
|
||||||
|
|
||||||
class RecordedCommands {
|
class RecordedCommands {
|
||||||
public:
|
public:
|
||||||
struct segment
|
struct segment {
|
||||||
{
|
std::size_t start { 0 };
|
||||||
std::size_t start{ 0 };
|
std::size_t size { 0 };
|
||||||
std::size_t size{ 0 };
|
glez::texture* texture { nullptr };
|
||||||
glez::texture *texture{ nullptr };
|
glez::font* font { nullptr };
|
||||||
glez::font *font{ nullptr };
|
|
||||||
};
|
};
|
||||||
|
|
||||||
RecordedCommands();
|
RecordedCommands();
|
||||||
~RecordedCommands();
|
~RecordedCommands();
|
||||||
|
|
||||||
void reset();
|
void reset();
|
||||||
void store(glez::vertex *vertices, size_t vcount,
|
void store(glez::vertex* vertices, size_t vcount,
|
||||||
uint32_t *indices, size_t icount);
|
uint32_t* indices, size_t icount);
|
||||||
void bindTexture(glez::texture *tx);
|
void bindTexture(glez::texture* tx);
|
||||||
void bindFont(glez::font *font);
|
void bindFont(glez::font* font);
|
||||||
void render();
|
void render();
|
||||||
void end();
|
void end();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void cutSegment();
|
void cutSegment();
|
||||||
|
|
||||||
ftgl::vertex_buffer_t *vertex_buffer{};
|
ftgl::vertex_buffer_t* vertex_buffer {};
|
||||||
std::vector<segment> segments{};
|
std::vector<segment> segments {};
|
||||||
segment current{};
|
segment current {};
|
||||||
};
|
};
|
||||||
|
|
||||||
extern RecordedCommands *currentRecord;
|
extern RecordedCommands* currentRecord;
|
||||||
extern bool isReplaying;
|
extern bool isReplaying;
|
||||||
|
|
||||||
} // namespace glez::detail::record
|
} // namespace glez::detail::record
|
||||||
|
@ -5,10 +5,10 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <string>
|
|
||||||
#include "color.hpp"
|
#include "color.hpp"
|
||||||
#include "font.hpp"
|
#include "font.hpp"
|
||||||
#include "texture.hpp"
|
#include "texture.hpp"
|
||||||
|
#include <string>
|
||||||
|
|
||||||
namespace glez::draw {
|
namespace glez::draw {
|
||||||
|
|
||||||
@ -17,12 +17,12 @@ void rect(float x, float y, float w, float h, rgba color);
|
|||||||
void triangle(float x, float y, float x2, float y2, float x3, float y3, rgba color);
|
void triangle(float x, float y, float x2, float y2, float x3, float y3, rgba color);
|
||||||
void rect_outline(float x, float y, float w, float h, rgba color, float thickness);
|
void rect_outline(float x, float y, float w, float h, rgba color, float thickness);
|
||||||
void rect_textured(float x, float y, float w, float h, rgba color,
|
void rect_textured(float x, float y, float w, float h, rgba color,
|
||||||
texture &texture, float tx, float ty, float tw, float th,
|
texture& texture, float tx, float ty, float tw, float th,
|
||||||
float angle);
|
float angle);
|
||||||
void circle(float x, float y, float radius, rgba color, float thickness, int steps);
|
void circle(float x, float y, float radius, rgba color, float thickness, int steps);
|
||||||
|
|
||||||
void string(float x, float y, const std::string &string, font &font, rgba color,
|
void string(float x, float y, const std::string& string, font& font, rgba color,
|
||||||
float *width, float *height);
|
float* width, float* height);
|
||||||
void outlined_string(float x, float y, const std::string &string, font &font,
|
void outlined_string(float x, float y, const std::string& string, font& font,
|
||||||
rgba color, rgba outline, float *width, float *height);
|
rgba color, rgba outline, float* width, float* height);
|
||||||
} // namespace glez::draw
|
} // namespace glez::draw
|
||||||
|
@ -13,19 +13,20 @@ namespace glez {
|
|||||||
|
|
||||||
class font {
|
class font {
|
||||||
public:
|
public:
|
||||||
font(){}
|
font() { }
|
||||||
static font loadFromFile(const std::string &path, float size);
|
static font loadFromFile(const std::string& path, float size);
|
||||||
font(font&&);
|
font(font&&);
|
||||||
~font();
|
~font();
|
||||||
|
|
||||||
glez::font& operator=(glez::font&&);
|
glez::font& operator=(glez::font&&);
|
||||||
|
|
||||||
//void stringSize(std::string_view string, float* width, float* height);
|
// void stringSize(std::string_view string, float* width, float* height);
|
||||||
void stringSize(const std::string& string, float* width, float* height);
|
void stringSize(const std::string& string, float* width, float* height);
|
||||||
inline bool isLoaded() { return this->m_font != nullptr && this->atlas != nullptr; };
|
inline bool isLoaded() { return this->m_font != nullptr && this->atlas != nullptr; };
|
||||||
|
|
||||||
public:
|
public:
|
||||||
texture_font_t* m_font = nullptr;
|
texture_font_t* m_font = nullptr;
|
||||||
texture_atlas_t* atlas = nullptr;
|
texture_atlas_t* atlas = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace glez::detail::font
|
} // namespace glez
|
||||||
|
@ -5,9 +5,9 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <vertex-buffer.h>
|
|
||||||
#include <freetype-gl.h>
|
#include <freetype-gl.h>
|
||||||
#include <glez/color.hpp>
|
#include <glez/color.hpp>
|
||||||
|
#include <vertex-buffer.h>
|
||||||
|
|
||||||
namespace glez {
|
namespace glez {
|
||||||
|
|
||||||
@ -23,7 +23,7 @@ enum class mode {
|
|||||||
FREETYPE
|
FREETYPE
|
||||||
};
|
};
|
||||||
|
|
||||||
extern ftgl::vertex_buffer_t *buffer;
|
extern ftgl::vertex_buffer_t* buffer;
|
||||||
struct vertex {
|
struct vertex {
|
||||||
ftgl::vec2 position;
|
ftgl::vec2 position;
|
||||||
ftgl::vec2 uv;
|
ftgl::vec2 uv;
|
||||||
@ -33,4 +33,4 @@ struct vertex {
|
|||||||
|
|
||||||
void bind(GLuint texture);
|
void bind(GLuint texture);
|
||||||
|
|
||||||
}; // namespace glez::detail::program
|
}; // namespace glez
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <vector>
|
#include <vector>
|
||||||
int decodePNG(unsigned char *&out_image, int &image_width, int &image_height,
|
int decodePNG(unsigned char*& out_image, int& image_width, int& image_height,
|
||||||
const unsigned char *in_png, size_t in_size,
|
const unsigned char* in_png, size_t in_size,
|
||||||
bool convert_to_rgba32 = true);
|
bool convert_to_rgba32 = true);
|
||||||
|
@ -4,16 +4,13 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
namespace glez::detail::record
|
namespace glez::detail::record {
|
||||||
{
|
|
||||||
class RecordedCommands;
|
class RecordedCommands;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace glez::record
|
namespace glez::record {
|
||||||
{
|
|
||||||
|
|
||||||
class Record
|
class Record {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
Record();
|
Record();
|
||||||
~Record();
|
~Record();
|
||||||
@ -22,7 +19,7 @@ public:
|
|||||||
void end();
|
void end();
|
||||||
void replay();
|
void replay();
|
||||||
|
|
||||||
detail::record::RecordedCommands *commands{ nullptr };
|
detail::record::RecordedCommands* commands { nullptr };
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace glez::record
|
} // namespace glez::record
|
||||||
|
@ -5,18 +5,17 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <freetype-gl.h>
|
|
||||||
#include <string>
|
|
||||||
#include <limits>
|
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
|
#include <freetype-gl.h>
|
||||||
|
#include <limits>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
namespace glez
|
namespace glez {
|
||||||
{
|
|
||||||
|
|
||||||
class texture {
|
class texture {
|
||||||
public:
|
public:
|
||||||
texture(){}
|
texture() { }
|
||||||
static texture loadFromFile(const std::string &path);
|
static texture loadFromFile(const std::string& path);
|
||||||
static texture loadFromMemory(const std::byte* mem, std::size_t size, unsigned w, unsigned h);
|
static texture loadFromMemory(const std::byte* mem, std::size_t size, unsigned w, unsigned h);
|
||||||
texture(texture&&);
|
texture(texture&&);
|
||||||
~texture();
|
~texture();
|
||||||
@ -26,6 +25,7 @@ public:
|
|||||||
void bind();
|
void bind();
|
||||||
|
|
||||||
inline bool isLoaded() { return this->init; }
|
inline bool isLoaded() { return this->init; }
|
||||||
|
|
||||||
public:
|
public:
|
||||||
bool init = false;
|
bool init = false;
|
||||||
bool bound = false;
|
bool bound = false;
|
||||||
@ -33,7 +33,7 @@ public:
|
|||||||
int height = 0;
|
int height = 0;
|
||||||
|
|
||||||
GLuint id;
|
GLuint id;
|
||||||
GLubyte *data;
|
GLubyte* data;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace glez::texture
|
} // namespace glez
|
||||||
|
@ -3,23 +3,20 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <glez/detail/record.hpp>
|
|
||||||
#include <glez/record.hpp>
|
|
||||||
#include <glez/glez.hpp>
|
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
#include <glez/detail/record.hpp>
|
||||||
|
#include <glez/glez.hpp>
|
||||||
|
#include <glez/record.hpp>
|
||||||
|
|
||||||
namespace glez::detail::record
|
namespace glez::detail::record {
|
||||||
{
|
|
||||||
|
|
||||||
void RecordedCommands::render()
|
void RecordedCommands::render() {
|
||||||
{
|
|
||||||
isReplaying = true;
|
isReplaying = true;
|
||||||
vertex_buffer_render_setup(vertex_buffer, GL_TRIANGLES);
|
vertex_buffer_render_setup(vertex_buffer, GL_TRIANGLES);
|
||||||
for (const auto &i : segments) {
|
for (const auto& i : segments) {
|
||||||
if (i.texture) {
|
if (i.texture) {
|
||||||
i.texture->bind();
|
i.texture->bind();
|
||||||
}
|
} else if (i.font) {
|
||||||
else if (i.font) {
|
|
||||||
if (i.font->atlas->id == 0) {
|
if (i.font->atlas->id == 0) {
|
||||||
glGenTextures(1, &i.font->atlas->id);
|
glGenTextures(1, &i.font->atlas->id);
|
||||||
}
|
}
|
||||||
@ -32,18 +29,18 @@ void RecordedCommands::render()
|
|||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RED, i.font->atlas->width,
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RED, i.font->atlas->width,
|
||||||
i.font->atlas->height, 0, GL_RED, GL_UNSIGNED_BYTE,
|
i.font->atlas->height, 0, GL_RED, GL_UNSIGNED_BYTE,
|
||||||
i.font->atlas->data);
|
i.font->atlas->data);
|
||||||
i.font->atlas->dirty = 0;
|
i.font->atlas->dirty = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
glDrawElements(GL_TRIANGLES, i.size, GL_UNSIGNED_INT, (void *) (i.start * 4));
|
glDrawElements(GL_TRIANGLES, i.size, GL_UNSIGNED_INT, (void*)(i.start * 4));
|
||||||
}
|
}
|
||||||
vertex_buffer_render_finish(vertex_buffer);
|
vertex_buffer_render_finish(vertex_buffer);
|
||||||
isReplaying = false;
|
isReplaying = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RecordedCommands::store(glez::vertex *vertices, size_t vcount, uint32_t *indices, size_t icount) {
|
void RecordedCommands::store(glez::vertex* vertices, size_t vcount, uint32_t* indices, size_t icount) {
|
||||||
vertex_buffer_push_back(vertex_buffer, vertices, vcount, indices, icount);
|
vertex_buffer_push_back(vertex_buffer, vertices, vcount, indices, icount);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -61,24 +58,21 @@ void RecordedCommands::reset() {
|
|||||||
memset(¤t, 0, sizeof(current));
|
memset(¤t, 0, sizeof(current));
|
||||||
}
|
}
|
||||||
|
|
||||||
void RecordedCommands::bindTexture(glez::texture *tx) {
|
void RecordedCommands::bindTexture(glez::texture* tx) {
|
||||||
if (current.texture != tx) {
|
if (current.texture != tx) {
|
||||||
cutSegment();
|
cutSegment();
|
||||||
current.texture = tx;
|
current.texture = tx;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void RecordedCommands::bindFont(glez::font *font)
|
void RecordedCommands::bindFont(glez::font* font) {
|
||||||
{
|
if (current.font != font) {
|
||||||
if (current.font != font)
|
|
||||||
{
|
|
||||||
cutSegment();
|
cutSegment();
|
||||||
current.font = font;
|
current.font = font;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void RecordedCommands::cutSegment()
|
void RecordedCommands::cutSegment() {
|
||||||
{
|
|
||||||
current.size = vertex_buffer->indices->size - current.start;
|
current.size = vertex_buffer->indices->size - current.start;
|
||||||
if (current.size)
|
if (current.size)
|
||||||
segments.push_back(current);
|
segments.push_back(current);
|
||||||
@ -86,39 +80,33 @@ void RecordedCommands::cutSegment()
|
|||||||
current.start = vertex_buffer->indices->size;
|
current.start = vertex_buffer->indices->size;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RecordedCommands::end()
|
void RecordedCommands::end() {
|
||||||
{
|
|
||||||
cutSegment();
|
cutSegment();
|
||||||
}
|
}
|
||||||
|
|
||||||
RecordedCommands *currentRecord{ nullptr };
|
RecordedCommands* currentRecord { nullptr };
|
||||||
bool isReplaying{ false };
|
bool isReplaying { false };
|
||||||
|
|
||||||
} // namespace glez::detail::record
|
} // namespace glez::detail::record
|
||||||
|
|
||||||
glez::record::Record::Record()
|
glez::record::Record::Record() {
|
||||||
{
|
commands = new glez::detail::record::RecordedCommands {};
|
||||||
commands = new glez::detail::record::RecordedCommands{};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
glez::record::Record::~Record()
|
glez::record::Record::~Record() {
|
||||||
{
|
|
||||||
delete commands;
|
delete commands;
|
||||||
}
|
}
|
||||||
|
|
||||||
void glez::record::Record::begin()
|
void glez::record::Record::begin() {
|
||||||
{
|
|
||||||
detail::record::currentRecord = commands;
|
detail::record::currentRecord = commands;
|
||||||
commands->reset();
|
commands->reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
void glez::record::Record::end()
|
void glez::record::Record::end() {
|
||||||
{
|
|
||||||
commands->end();
|
commands->end();
|
||||||
detail::record::currentRecord = nullptr;
|
detail::record::currentRecord = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void glez::record::Record::replay()
|
void glez::record::Record::replay() {
|
||||||
{
|
|
||||||
commands->render();
|
commands->render();
|
||||||
}
|
}
|
||||||
|
93
src/draw.cpp
93
src/draw.cpp
@ -4,29 +4,28 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
#include <cmath>
|
||||||
|
#include <cstring>
|
||||||
|
#include <glez/detail/record.hpp>
|
||||||
|
#include <glez/detail/render.hpp>
|
||||||
#include <glez/draw.hpp>
|
#include <glez/draw.hpp>
|
||||||
#include <glez/font.hpp>
|
#include <glez/font.hpp>
|
||||||
#include <glez/detail/render.hpp>
|
|
||||||
#include <glez/glez.hpp>
|
#include <glez/glez.hpp>
|
||||||
#include <vertex-buffer.h>
|
|
||||||
#include <cstring>
|
|
||||||
#include <glez/texture.hpp>
|
#include <glez/texture.hpp>
|
||||||
#include <cmath>
|
#include <vertex-buffer.h>
|
||||||
#include <glez/detail/record.hpp>
|
|
||||||
|
|
||||||
namespace indices
|
namespace indices {
|
||||||
{
|
|
||||||
|
|
||||||
static GLuint rectangle[6] = { 0, 1, 2, 2, 3, 0 };
|
static GLuint rectangle[6] = { 0, 1, 2, 2, 3, 0 };
|
||||||
static GLuint triangle[3] = { 0, 1, 2 };
|
static GLuint triangle[3] = { 0, 1, 2 };
|
||||||
} // namespace indices
|
} // namespace indices
|
||||||
|
|
||||||
void internal_draw_string(float x, float y, const std::string &string,
|
void internal_draw_string(float x, float y, const std::string& string,
|
||||||
glez::font& font, glez::rgba color, float *width, float *height) {
|
glez::font& font, glez::rgba color, float* width, float* height) {
|
||||||
assert(font.isLoaded());
|
assert(font.isLoaded());
|
||||||
auto* fnt = font.m_font;
|
auto* fnt = font.m_font;
|
||||||
float pen_x = x;
|
float pen_x = x;
|
||||||
float pen_y = y + fnt->height / 1.5f;
|
float pen_y = y + fnt->height / 1.5f;
|
||||||
float size_y = 0;
|
float size_y = 0;
|
||||||
|
|
||||||
if (glez::detail::record::currentRecord) {
|
if (glez::detail::record::currentRecord) {
|
||||||
@ -43,18 +42,18 @@ void internal_draw_string(float x, float y, const std::string &string,
|
|||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RED, fnt->atlas->width,
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RED, fnt->atlas->width,
|
||||||
fnt->atlas->height, 0, GL_RED, GL_UNSIGNED_BYTE,
|
fnt->atlas->height, 0, GL_RED, GL_UNSIGNED_BYTE,
|
||||||
fnt->atlas->data);
|
fnt->atlas->data);
|
||||||
fnt->atlas->dirty = 0;
|
fnt->atlas->dirty = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *sstring = string.c_str();
|
const char* sstring = string.c_str();
|
||||||
|
|
||||||
bool skipped{ false };
|
bool skipped { false };
|
||||||
|
|
||||||
for (size_t i = 0; i < string.size(); ++i) {
|
for (size_t i = 0; i < string.size(); ++i) {
|
||||||
texture_glyph_t *glyph = texture_font_find_glyph(fnt, &sstring[i]);
|
texture_glyph_t* glyph = texture_font_find_glyph(fnt, &sstring[i]);
|
||||||
if (glyph == NULL) {
|
if (glyph == NULL) {
|
||||||
texture_font_load_glyph(fnt, &sstring[i]);
|
texture_font_load_glyph(fnt, &sstring[i]);
|
||||||
if (!skipped)
|
if (!skipped)
|
||||||
@ -64,7 +63,7 @@ void internal_draw_string(float x, float y, const std::string &string,
|
|||||||
}
|
}
|
||||||
skipped = false;
|
skipped = false;
|
||||||
glez::vertex vertices[4];
|
glez::vertex vertices[4];
|
||||||
for (auto &vertex : vertices) {
|
for (auto& vertex : vertices) {
|
||||||
vertex.color = color;
|
vertex.color = color;
|
||||||
vertex.mode = static_cast<int>(glez::mode::FREETYPE);
|
vertex.mode = static_cast<int>(glez::mode::FREETYPE);
|
||||||
}
|
}
|
||||||
@ -72,26 +71,26 @@ void internal_draw_string(float x, float y, const std::string &string,
|
|||||||
if (i > 0)
|
if (i > 0)
|
||||||
x += texture_glyph_get_kerning(glyph, &sstring[i - 1]);
|
x += texture_glyph_get_kerning(glyph, &sstring[i - 1]);
|
||||||
|
|
||||||
float x0 = (int) (pen_x + glyph->offset_x);
|
float x0 = (int)(pen_x + glyph->offset_x);
|
||||||
float y0 = (int) (pen_y - glyph->offset_y);
|
float y0 = (int)(pen_y - glyph->offset_y);
|
||||||
float x1 = (int) (x0 + glyph->width);
|
float x1 = (int)(x0 + glyph->width);
|
||||||
float y1 = (int) (y0 + glyph->height);
|
float y1 = (int)(y0 + glyph->height);
|
||||||
float s0 = glyph->s0;
|
float s0 = glyph->s0;
|
||||||
float t0 = glyph->t0;
|
float t0 = glyph->t0;
|
||||||
float s1 = glyph->s1;
|
float s1 = glyph->s1;
|
||||||
float t1 = glyph->t1;
|
float t1 = glyph->t1;
|
||||||
|
|
||||||
vertices[0].position = { x0, y0 };
|
vertices[0].position = { x0, y0 };
|
||||||
vertices[0].uv = { s0, t0 };
|
vertices[0].uv = { s0, t0 };
|
||||||
|
|
||||||
vertices[1].position = { x0, y1 };
|
vertices[1].position = { x0, y1 };
|
||||||
vertices[1].uv = { s0, t1 };
|
vertices[1].uv = { s0, t1 };
|
||||||
|
|
||||||
vertices[2].position = { x1, y1 };
|
vertices[2].position = { x1, y1 };
|
||||||
vertices[2].uv = { s1, t1 };
|
vertices[2].uv = { s1, t1 };
|
||||||
|
|
||||||
vertices[3].position = { x1, y0 };
|
vertices[3].position = { x1, y0 };
|
||||||
vertices[3].uv = { s1, t0 };
|
vertices[3].uv = { s1, t0 };
|
||||||
|
|
||||||
pen_x += glyph->advance_x;
|
pen_x += glyph->advance_x;
|
||||||
// pen_x = (int) pen_x + 1;
|
// pen_x = (int) pen_x + 1;
|
||||||
@ -123,8 +122,8 @@ void line(float x, float y, float dx, float dy, rgba color, float thickness) {
|
|||||||
|
|
||||||
vertex vertices[4];
|
vertex vertices[4];
|
||||||
|
|
||||||
for (auto &vertex : vertices) {
|
for (auto& vertex : vertices) {
|
||||||
vertex.mode = static_cast<int>(mode::PLAIN);
|
vertex.mode = static_cast<int>(mode::PLAIN);
|
||||||
vertex.color = color;
|
vertex.color = color;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -155,17 +154,17 @@ void line(float x, float y, float dx, float dy, rgba color, float thickness) {
|
|||||||
|
|
||||||
if (detail::record::currentRecord)
|
if (detail::record::currentRecord)
|
||||||
detail::record::currentRecord->store(vertices, 4, indices::rectangle,
|
detail::record::currentRecord->store(vertices, 4, indices::rectangle,
|
||||||
6);
|
6);
|
||||||
else
|
else
|
||||||
ftgl::vertex_buffer_push_back(buffer, vertices, 4,
|
ftgl::vertex_buffer_push_back(buffer, vertices, 4,
|
||||||
indices::rectangle, 6);
|
indices::rectangle, 6);
|
||||||
}
|
}
|
||||||
|
|
||||||
void rect(float x, float y, float w, float h, rgba color) {
|
void rect(float x, float y, float w, float h, rgba color) {
|
||||||
vertex vertices[4];
|
vertex vertices[4];
|
||||||
|
|
||||||
for (auto &vertex : vertices) {
|
for (auto& vertex : vertices) {
|
||||||
vertex.mode = static_cast<int>(mode::PLAIN);
|
vertex.mode = static_cast<int>(mode::PLAIN);
|
||||||
vertex.color = color;
|
vertex.color = color;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -183,8 +182,8 @@ void rect(float x, float y, float w, float h, rgba color) {
|
|||||||
void triangle(float x, float y, float x2, float y2, float x3, float y3, rgba color) {
|
void triangle(float x, float y, float x2, float y2, float x3, float y3, rgba color) {
|
||||||
vertex vertices[3];
|
vertex vertices[3];
|
||||||
|
|
||||||
for (auto &vertex : vertices) {
|
for (auto& vertex : vertices) {
|
||||||
vertex.mode = static_cast<int>(mode::PLAIN);
|
vertex.mode = static_cast<int>(mode::PLAIN);
|
||||||
vertex.color = color;
|
vertex.color = color;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -206,7 +205,7 @@ void rect_outline(float x, float y, float w, float h, rgba color, float thicknes
|
|||||||
}
|
}
|
||||||
|
|
||||||
void circle(float x, float y, float radius, rgba color, float thickness,
|
void circle(float x, float y, float radius, rgba color, float thickness,
|
||||||
int steps) {
|
int steps) {
|
||||||
float px = 0;
|
float px = 0;
|
||||||
float py = 0;
|
float py = 0;
|
||||||
for (int i = 0; i <= steps; i++) {
|
for (int i = 0; i <= steps; i++) {
|
||||||
@ -220,19 +219,19 @@ void circle(float x, float y, float radius, rgba color, float thickness,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void string(float x, float y, const std::string &string, font &font, rgba color, float *width, float *height) {
|
void string(float x, float y, const std::string& string, font& font, rgba color, float* width, float* height) {
|
||||||
auto fnt = font.m_font;
|
auto fnt = font.m_font;
|
||||||
fnt->rendermode = RENDER_NORMAL;
|
fnt->rendermode = RENDER_NORMAL;
|
||||||
fnt->outline_thickness = 0.0f;
|
fnt->outline_thickness = 0.0f;
|
||||||
internal_draw_string(x, y, string, font, color, width, height);
|
internal_draw_string(x, y, string, font, color, width, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
void outlined_string(float x, float y, const std::string& string, font& font, rgba color, rgba outline, float *width, float *height) {
|
void outlined_string(float x, float y, const std::string& string, font& font, rgba color, rgba outline, float* width, float* height) {
|
||||||
auto fnt = font.m_font;
|
auto fnt = font.m_font;
|
||||||
fnt->rendermode = RENDER_OUTLINE_POSITIVE;
|
fnt->rendermode = RENDER_OUTLINE_POSITIVE;
|
||||||
fnt->outline_thickness = 1.0f;
|
fnt->outline_thickness = 1.0f;
|
||||||
internal_draw_string(x, y, string, font, outline, width, height);
|
internal_draw_string(x, y, string, font, outline, width, height);
|
||||||
fnt->rendermode = RENDER_NORMAL;
|
fnt->rendermode = RENDER_NORMAL;
|
||||||
fnt->outline_thickness = 0.0f;
|
fnt->outline_thickness = 0.0f;
|
||||||
internal_draw_string(x, y, string, font, color, width, height);
|
internal_draw_string(x, y, string, font, color, width, height);
|
||||||
}
|
}
|
||||||
@ -242,8 +241,8 @@ void rect_textured(float x, float y, float w, float h, rgba color, texture& text
|
|||||||
texture.load();*/
|
texture.load();*/
|
||||||
assert(texture.isLoaded());
|
assert(texture.isLoaded());
|
||||||
|
|
||||||
//if (!texture.canLoad())
|
// if (!texture.canLoad())
|
||||||
//return;
|
// return;
|
||||||
|
|
||||||
if (glez::detail::record::currentRecord)
|
if (glez::detail::record::currentRecord)
|
||||||
glez::detail::record::currentRecord->bindTexture(&texture);
|
glez::detail::record::currentRecord->bindTexture(&texture);
|
||||||
@ -252,8 +251,8 @@ void rect_textured(float x, float y, float w, float h, rgba color, texture& text
|
|||||||
|
|
||||||
vertex vertices[4];
|
vertex vertices[4];
|
||||||
|
|
||||||
for (auto &vertex : vertices) {
|
for (auto& vertex : vertices) {
|
||||||
vertex.mode = static_cast<int>(mode::TEXTURED);
|
vertex.mode = static_cast<int>(mode::TEXTURED);
|
||||||
vertex.color = color;
|
vertex.color = color;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -266,7 +265,7 @@ void rect_textured(float x, float y, float w, float h, rgba color, texture& text
|
|||||||
float cx = x + float(w) / 2.0f;
|
float cx = x + float(w) / 2.0f;
|
||||||
float cy = y + float(h) / 2.0f;
|
float cy = y + float(h) / 2.0f;
|
||||||
|
|
||||||
for (auto &v : vertices) {
|
for (auto& v : vertices) {
|
||||||
float ox = v.position.x;
|
float ox = v.position.x;
|
||||||
float oy = v.position.y;
|
float oy = v.position.y;
|
||||||
|
|
||||||
|
19
src/font.cpp
19
src/font.cpp
@ -3,14 +3,14 @@
|
|||||||
Copyright (c) 2018 nullworks. All rights reserved.
|
Copyright (c) 2018 nullworks. All rights reserved.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <glez/font.hpp>
|
|
||||||
#include <vector>
|
|
||||||
#include <memory>
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
#include <glez/font.hpp>
|
||||||
|
#include <memory>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
namespace glez {
|
namespace glez {
|
||||||
|
|
||||||
font font::loadFromFile(const std::string &path, float size) {
|
font font::loadFromFile(const std::string& path, float size) {
|
||||||
assert(size > 0);
|
assert(size > 0);
|
||||||
|
|
||||||
font ret;
|
font ret;
|
||||||
@ -36,7 +36,7 @@ glez::font& font::operator=(glez::font&& var) {
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
void font::stringSize(const std::string& string, float* width, float* height) {
|
void font::stringSize(const std::string& string, float* width, float* height) {
|
||||||
assert(this->isLoaded());
|
assert(this->isLoaded());
|
||||||
float penX = 0;
|
float penX = 0;
|
||||||
|
|
||||||
float size_x = 0;
|
float size_x = 0;
|
||||||
@ -44,12 +44,11 @@ void font::stringSize(const std::string& string, float* width, float* height) {
|
|||||||
|
|
||||||
texture_font_load_glyphs(m_font, string.c_str());
|
texture_font_load_glyphs(m_font, string.c_str());
|
||||||
|
|
||||||
const char *sstring = string.c_str();
|
const char* sstring = string.c_str();
|
||||||
|
|
||||||
for (size_t i = 0; i < string.size(); ++i)
|
for (size_t i = 0; i < string.size(); ++i) {
|
||||||
{
|
|
||||||
// c_str guarantees a NULL terminator
|
// c_str guarantees a NULL terminator
|
||||||
texture_glyph_t *glyph = texture_font_find_glyph(m_font, &sstring[i]);
|
texture_glyph_t* glyph = texture_font_find_glyph(m_font, &sstring[i]);
|
||||||
if (glyph == nullptr)
|
if (glyph == nullptr)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
@ -68,4 +67,4 @@ void font::stringSize(const std::string& string, float* width, float* height) {
|
|||||||
*height = size_y;
|
*height = size_y;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace glez::detail::font
|
} // namespace glez
|
||||||
|
34
src/glez.cpp
34
src/glez.cpp
@ -3,20 +3,19 @@
|
|||||||
Copyright (c) 2018 nullworks. All rights reserved.
|
Copyright (c) 2018 nullworks. All rights reserved.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <freetype-gl.h>
|
|
||||||
#include <vertex-buffer.h>
|
|
||||||
#include <mat4.h>
|
|
||||||
#include <glez/glez.hpp>
|
|
||||||
#include <cstdio>
|
|
||||||
#include <stdexcept>
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
#include <cstdio>
|
||||||
|
#include <cstring>
|
||||||
|
#include <freetype-gl.h>
|
||||||
|
#include <glez/detail/record.hpp>
|
||||||
#include <glez/detail/render.hpp>
|
#include <glez/detail/render.hpp>
|
||||||
#include <glez/font.hpp>
|
#include <glez/font.hpp>
|
||||||
#include <cstring>
|
|
||||||
#include <glez/glez.hpp>
|
#include <glez/glez.hpp>
|
||||||
#include <glez/detail/record.hpp>
|
#include <mat4.h>
|
||||||
|
#include <stdexcept>
|
||||||
|
#include <vertex-buffer.h>
|
||||||
|
|
||||||
static const char *shader_vertex = R"END(
|
static const char* shader_vertex = R"END(
|
||||||
#version 130
|
#version 130
|
||||||
uniform mat4 projection;
|
uniform mat4 projection;
|
||||||
in vec2 vertex;
|
in vec2 vertex;
|
||||||
@ -35,7 +34,7 @@ void main()
|
|||||||
}
|
}
|
||||||
)END";
|
)END";
|
||||||
|
|
||||||
static const char *shader_fragment = R"END(
|
static const char* shader_fragment = R"END(
|
||||||
#version 130
|
#version 130
|
||||||
uniform sampler2D texture;
|
uniform sampler2D texture;
|
||||||
in vec4 frag_Color;
|
in vec4 frag_Color;
|
||||||
@ -60,9 +59,9 @@ void main()
|
|||||||
}
|
}
|
||||||
)END";
|
)END";
|
||||||
|
|
||||||
static GLuint shader{ 0 };
|
static GLuint shader { 0 };
|
||||||
|
|
||||||
static GLuint compile(const char *source, GLenum type) {
|
static GLuint compile(const char* source, GLenum type) {
|
||||||
GLint status;
|
GLint status;
|
||||||
GLuint result = glCreateShader(type);
|
GLuint result = glCreateShader(type);
|
||||||
|
|
||||||
@ -70,8 +69,7 @@ static GLuint compile(const char *source, GLenum type) {
|
|||||||
glCompileShader(result);
|
glCompileShader(result);
|
||||||
glGetShaderiv(result, GL_COMPILE_STATUS, &status);
|
glGetShaderiv(result, GL_COMPILE_STATUS, &status);
|
||||||
|
|
||||||
if (status != GL_TRUE)
|
if (status != GL_TRUE) {
|
||||||
{
|
|
||||||
char error[512];
|
char error[512];
|
||||||
GLsizei length;
|
GLsizei length;
|
||||||
glGetShaderInfoLog(result, 512, &length, error);
|
glGetShaderInfoLog(result, 512, &length, error);
|
||||||
@ -113,8 +111,7 @@ void resize(int width, int height) {
|
|||||||
glUseProgram(0);
|
glUseProgram(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void init(int width, int height)
|
void init(int width, int height) {
|
||||||
{
|
|
||||||
buffer = ftgl::vertex_buffer_new("vertex:2f,tex_coord:2f,color:4f,drawmode:1i");
|
buffer = ftgl::vertex_buffer_new("vertex:2f,tex_coord:2f,color:4f,drawmode:1i");
|
||||||
shader = link(compile(shader_vertex, GL_VERTEX_SHADER), compile(shader_fragment, GL_FRAGMENT_SHADER));
|
shader = link(compile(shader_vertex, GL_VERTEX_SHADER), compile(shader_fragment, GL_FRAGMENT_SHADER));
|
||||||
|
|
||||||
@ -130,8 +127,7 @@ void shutdown() {
|
|||||||
glDeleteProgram(shader);
|
glDeleteProgram(shader);
|
||||||
}
|
}
|
||||||
|
|
||||||
static GLuint current_texture{ 0 };
|
static GLuint current_texture { 0 };
|
||||||
|
|
||||||
|
|
||||||
void begin() {
|
void begin() {
|
||||||
glPushAttrib(GL_CURRENT_BIT | GL_ENABLE_BIT | GL_TEXTURE_BIT | GL_COLOR_BUFFER_BIT);
|
glPushAttrib(GL_CURRENT_BIT | GL_ENABLE_BIT | GL_TEXTURE_BIT | GL_COLOR_BUFFER_BIT);
|
||||||
@ -183,4 +179,4 @@ void bind(GLuint texture) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
} // namespace glez
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -3,27 +3,25 @@
|
|||||||
Copyright (c) 2018 nullworks. All rights reserved.
|
Copyright (c) 2018 nullworks. All rights reserved.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <glez/texture.hpp>
|
|
||||||
#include <glez/glez.hpp>
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <vector>
|
|
||||||
#include <glez/picopng/picopng.hpp>
|
|
||||||
#include <memory>
|
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
#include <glez/glez.hpp>
|
||||||
|
#include <glez/picopng/picopng.hpp>
|
||||||
|
#include <glez/texture.hpp>
|
||||||
|
#include <memory>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
#include <fstream> // required to load the file
|
#include <fstream> // required to load the file
|
||||||
|
|
||||||
namespace glez
|
namespace glez {
|
||||||
{
|
|
||||||
|
|
||||||
void texture::bind()
|
void texture::bind() {
|
||||||
{
|
|
||||||
if (!bound) {
|
if (!bound) {
|
||||||
glGenTextures(1, &id);
|
glGenTextures(1, &id);
|
||||||
glBindTexture(GL_TEXTURE_2D, id);
|
glBindTexture(GL_TEXTURE_2D, id);
|
||||||
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_SRGB8_ALPHA8, width, height, 0,
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_SRGB8_ALPHA8, width, height, 0,
|
||||||
GL_RGBA, GL_UNSIGNED_BYTE, data);
|
GL_RGBA, GL_UNSIGNED_BYTE, data);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
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_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||||
@ -33,7 +31,7 @@ void texture::bind()
|
|||||||
glez::bind(id);
|
glez::bind(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
texture texture::loadFromFile(const std::string &path) {
|
texture texture::loadFromFile(const std::string& path) {
|
||||||
std::ifstream file(path.c_str(), std::ios::in | std::ios::binary | std::ios::ate);
|
std::ifstream file(path.c_str(), std::ios::in | std::ios::binary | std::ios::ate);
|
||||||
|
|
||||||
std::streamsize size = 0;
|
std::streamsize size = 0;
|
||||||
@ -45,8 +43,8 @@ texture texture::loadFromFile(const std::string &path) {
|
|||||||
if (size < 1)
|
if (size < 1)
|
||||||
throw std::runtime_error("Unable to load texture from file!");
|
throw std::runtime_error("Unable to load texture from file!");
|
||||||
|
|
||||||
unsigned char *buffer = new unsigned char[(size_t) size + 1];
|
unsigned char* buffer = new unsigned char[(size_t)size + 1];
|
||||||
file.read((char *) buffer, size);
|
file.read((char*)buffer, size);
|
||||||
file.close();
|
file.close();
|
||||||
texture ret;
|
texture ret;
|
||||||
int error = decodePNG(ret.data, ret.width, ret.height, buffer, size);
|
int error = decodePNG(ret.data, ret.width, ret.height, buffer, size);
|
||||||
@ -56,13 +54,12 @@ texture texture::loadFromFile(const std::string &path) {
|
|||||||
printf("Error loading texture, error code %i\n", error);
|
printf("Error loading texture, error code %i\n", error);
|
||||||
throw std::runtime_error("See above!");
|
throw std::runtime_error("See above!");
|
||||||
}
|
}
|
||||||
ret.init = true;
|
ret.init = true;
|
||||||
ret.bound = false;
|
ret.bound = false;
|
||||||
ret.id = 0;
|
ret.id = 0;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
texture texture::loadFromMemory(const std::byte* mem, std::size_t size, unsigned w, unsigned h) {
|
texture texture::loadFromMemory(const std::byte* mem, std::size_t size, unsigned w, unsigned h) {
|
||||||
if (size < 1)
|
if (size < 1)
|
||||||
throw std::runtime_error("Unable to load texture from memory!");
|
throw std::runtime_error("Unable to load texture from memory!");
|
||||||
@ -74,9 +71,9 @@ texture texture::loadFromMemory(const std::byte* mem, std::size_t size, unsigned
|
|||||||
ret.width = w;
|
ret.width = w;
|
||||||
ret.height = h;
|
ret.height = h;
|
||||||
ret.data = buffer;
|
ret.data = buffer;
|
||||||
ret.init = true;
|
ret.init = true;
|
||||||
ret.bound = false;
|
ret.bound = false;
|
||||||
ret.id = 0;
|
ret.id = 0;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -89,20 +86,20 @@ texture::~texture() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
texture& texture::operator=(texture&& var) {
|
texture& texture::operator=(texture&& var) {
|
||||||
this->init = var.init;
|
this->init = var.init;
|
||||||
this->bound = var.bound;
|
this->bound = var.bound;
|
||||||
this->width = var.width;
|
this->width = var.width;
|
||||||
this->height = var.height;
|
this->height = var.height;
|
||||||
this->id = var.id;
|
this->id = var.id;
|
||||||
this->data = var.data;
|
this->data = var.data;
|
||||||
|
|
||||||
var.init = false;
|
var.init = false;
|
||||||
var.bound = false;
|
var.bound = false;
|
||||||
var.width = 0;
|
var.width = 0;
|
||||||
var.height = 0;
|
var.height = 0;
|
||||||
var.id = 0;
|
var.id = 0;
|
||||||
var.data = nullptr;
|
var.data = nullptr;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace glez::detail::texture
|
} // namespace glez
|
||||||
|
Loading…
x
Reference in New Issue
Block a user