Skip to content
Snippets Groups Projects
Commit 1619a0b8 authored by Odilitime's avatar Odilitime
Browse files

new files

parent 6f0a02fc
No related branches found
No related tags found
No related merge requests found
#include "AnimeComponent.h"
#include "../../../anime.h"
#include <cmath>
AnimeComponent::AnimeComponent(const float rawX, const float rawY, const float rawWidth, const float rawHeight, const int windowWidth, const int windowHeight) : BoxComponent(rawX, rawY, rawWidth, rawHeight, windowWidth, windowHeight){
x = rawX;
y = rawY;
width = rawWidth;
height = rawHeight;
if (width == 512) {
for (int py = 0; py < 1024; py++) {
for (int px = 0; px < 1024; px++) {
for (int i = 0; i < 4; i++) {
data[1023 - py][px][i] = anime.pixel_data[((px * 4) + (py * 4 * 1024)) + i];
}
}
}
}
float vx = rawX;
float vy = rawY;
float vWidth = rawWidth;
float vHeight = rawHeight;
pointToViewport(vx, vy, windowWidth, windowHeight);
distanceToViewport(vWidth, vHeight, windowWidth, windowHeight);
vertices[(0 * 5) + 0] = vx;
vertices[(0 * 5) + 1] = vy + vHeight;
vertices[(1 * 5) + 0] = vx + vWidth;
vertices[(1 * 5) + 1] = vy + vHeight;
vertices[(2 * 5) + 0] = vx + vWidth;
vertices[(2 * 5) + 1] = vy;
vertices[(3 * 5) + 0] = vx;
vertices[(3 * 5) + 1] = vy;
glGenVertexArrays(1, &vertexArrayObject);
glGenBuffers(1, &vertexBufferObject);
glGenBuffers(1, &elementBufferObject);
glBindVertexArray(vertexArrayObject);
glBindBuffer(GL_ARRAY_BUFFER, vertexBufferObject);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, elementBufferObject);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(float), nullptr);
glEnableVertexAttribArray(0);
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 5 * sizeof(float), reinterpret_cast<void*>(3 * sizeof(float)));
glEnableVertexAttribArray(1);
glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_2D, texture);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1024, 1024, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
glGenerateMipmap(GL_TEXTURE_2D);
}
#ifndef ANIMECOMPONENT_H
#define ANIMECOMPONENT_H
#include <GL/glew.h>
#include "BoxComponent.h"
class AnimeComponent : public BoxComponent {
public:
AnimeComponent(const float rawX, const float rawY, const float rawWidth, const float rawHeight, const int windowWidth, const int windowHeight);
};
#endif
\ No newline at end of file
#include "TextRasterizerCache.h"
TextRasterizerCache *rasterizerCache=new TextRasterizerCache;
// reduces this:
// Updated DOM in: 6.787870 seconds
// to this:
// Updated DOM in: 6.104453 seconds
std::shared_ptr<TextRasterizer> TextRasterizerCache::loadFont(const int size, const bool bold) {
if (bold) {
if (fontSizes_bold.find(size) == fontSizes_bold.end()) {
fontSizes_bold[size]=std::make_shared<TextRasterizer>("DejaVuSerif.ttf", size, 72, bold);
}
return fontSizes_bold[size];
} else {
if (fontSizes_notbold.find(size) == fontSizes_notbold.end()) {
fontSizes_notbold[size]=std::make_shared<TextRasterizer>("DejaVuSerif.ttf", size, 72, bold);
}
return fontSizes_notbold[size];
}
}
\ No newline at end of file
#ifndef TEXTRASTERIZERCACHE_H
#define TEXTRASTERIZERCACHE_H
#include "TextRasterizer.h"
#include <map>
class TextRasterizerCache {
private:
std::map<unsigned int, std::shared_ptr<TextRasterizer> > fontSizes_bold;
std::map<unsigned int, std::shared_ptr<TextRasterizer> > fontSizes_notbold;
public:
std::shared_ptr<TextRasterizer> loadFont(const int size, const bool bold);
};
#endif
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment