Fixed font rectangles
This commit is contained in:
parent
d8be6fc06f
commit
ffe2764d29
|
@ -115,11 +115,11 @@ Renderer::Renderer()
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, m_vbo);
|
glBindBuffer(GL_ARRAY_BUFFER, m_vbo);
|
||||||
|
|
||||||
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, sizeof(Rect), (GLvoid*)0);
|
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, sizeof(Rect), (GLvoid*)0);
|
||||||
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(Rect), (GLvoid*)(2 * sizeof(float)));
|
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(Rect), (GLvoid*)offsetof(Rect, dst_p1_x));
|
||||||
glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, sizeof(Rect), (GLvoid*)(4 * sizeof(float)));
|
glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, sizeof(Rect), (GLvoid*)offsetof(Rect, src_p0_x));
|
||||||
glVertexAttribPointer(3, 2, GL_FLOAT, GL_FALSE, sizeof(Rect), (GLvoid*)(6 * sizeof(float)));
|
glVertexAttribPointer(3, 2, GL_FLOAT, GL_FALSE, sizeof(Rect), (GLvoid*)offsetof(Rect, src_p1_x));
|
||||||
glVertexAttribPointer(4, 4, GL_FLOAT, GL_FALSE, sizeof(Rect), (GLvoid*)(8 * sizeof(float)));
|
glVertexAttribPointer(4, 4, GL_FLOAT, GL_FALSE, sizeof(Rect), (GLvoid*)offsetof(Rect, r));
|
||||||
glVertexAttribPointer(5, 1, GL_INT, GL_FALSE, sizeof(Rect), (GLvoid*)(12 * sizeof(float)));
|
glVertexAttribIPointer(5, 1, GL_INT, sizeof(Rect), (GLvoid*)offsetof(Rect, expand_r));
|
||||||
glEnableVertexAttribArray(0);
|
glEnableVertexAttribArray(0);
|
||||||
glEnableVertexAttribArray(1);
|
glEnableVertexAttribArray(1);
|
||||||
glEnableVertexAttribArray(2);
|
glEnableVertexAttribArray(2);
|
||||||
|
@ -346,10 +346,7 @@ void Renderer::renderFrame(float width, float height)
|
||||||
m_draw_textures.clear();
|
m_draw_textures.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Renderer::getTextureSize(
|
void Renderer::getTextureSize(StringHandle texture, unsigned int* w, unsigned int* h)
|
||||||
StringHandle texture,
|
|
||||||
unsigned int* w,
|
|
||||||
unsigned int* h)
|
|
||||||
{
|
{
|
||||||
if (m_textures.find(texture) == m_textures.end()) {
|
if (m_textures.find(texture) == m_textures.end()) {
|
||||||
Texture tex;
|
Texture tex;
|
||||||
|
|
|
@ -38,6 +38,7 @@ Texture::Texture(unsigned int width, unsigned int height, const void* data, GLin
|
||||||
GL_RED,
|
GL_RED,
|
||||||
GL_UNSIGNED_BYTE,
|
GL_UNSIGNED_BYTE,
|
||||||
data);
|
data);
|
||||||
|
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
||||||
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_MIN_FILTER, GL_LINEAR);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||||
|
|
|
@ -90,6 +90,9 @@ int main()
|
||||||
// BEISPIELCODE
|
// BEISPIELCODE
|
||||||
Position smiley_pos = {512, 384};
|
Position smiley_pos = {512, 384};
|
||||||
StringHandle smiley = StringRepository::global->internString("smiley_PNG42.png");
|
StringHandle smiley = StringRepository::global->internString("smiley_PNG42.png");
|
||||||
|
StringHandle ttf = StringRepository::global->internString("Milky Honey.ttf");
|
||||||
|
FontData fd;
|
||||||
|
AssetManager::ptr->loadFontData("Milky Honey.ttf", 24.f, &fd);
|
||||||
// ENDE BEISPIELCODE
|
// ENDE BEISPIELCODE
|
||||||
|
|
||||||
glfwSwapInterval(1);
|
glfwSwapInterval(1);
|
||||||
|
@ -178,6 +181,29 @@ int main()
|
||||||
|
|
||||||
Renderer::ptr->addRect(100, 100, 500, 500, 0.3f, 0.3f, 0.3f, 1.f);
|
Renderer::ptr->addRect(100, 100, 500, 500, 0.3f, 0.3f, 0.3f, 1.f);
|
||||||
Renderer::ptr->addRect(smiley_pos.x, smiley_pos.y, 500, 500, 0.f, x * x, 1.f - x * x, 1.f, smiley);
|
Renderer::ptr->addRect(smiley_pos.x, smiley_pos.y, 500, 500, 0.f, x * x, 1.f - x * x, 1.f, smiley);
|
||||||
|
|
||||||
|
const char* text = "Hello, Sailor!";
|
||||||
|
float tx = 100, ty = 200;
|
||||||
|
while (*text) {
|
||||||
|
if (*text >= 32 && *text < 128) {
|
||||||
|
stbtt_aligned_quad q;
|
||||||
|
stbtt_GetBakedQuad(fd.char_data, 1024, 1024, *text - 32, &tx, &ty, &q, 1);
|
||||||
|
float w = q.x1 - q.x0, h = q.y1 - q.y0;
|
||||||
|
Renderer::ptr->addFontRect(q.x0,
|
||||||
|
q.y0,
|
||||||
|
w,
|
||||||
|
h,
|
||||||
|
fd.char_height,
|
||||||
|
ttf,
|
||||||
|
StringRepository::global->internString("1"),
|
||||||
|
q.s0,
|
||||||
|
q.t0,
|
||||||
|
q.s1,
|
||||||
|
q.t1);
|
||||||
|
}
|
||||||
|
++text;
|
||||||
|
}
|
||||||
|
|
||||||
// ENDE BEISPIELCODE
|
// ENDE BEISPIELCODE
|
||||||
|
|
||||||
Renderer::ptr->renderFrame(static_cast<float>(w), static_cast<float>(h));
|
Renderer::ptr->renderFrame(static_cast<float>(w), static_cast<float>(h));
|
||||||
|
|
Loading…
Reference in New Issue
Block a user