- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试放置一个正方形作为我的文本的背景,它由 OpenGL 中的 FreeType 呈现。但是文字不知何故像这样穿过我的方 block :
看,我方 block 后面的弧线没问题。圆弧在 0.0 上,正方形在 1.0 上,文字在 Z 轴上在 2.0 上。
这就是我创建它们的方式:
auto arc2x = new OpenGL::Rendering::Models::Arc(
Container::Position(pos_x, pos_y, 0), Container::Color::GREEN, 50,
radius, 90, arc_degree);
arc2x->create();
arc2x->set_rotation(76, 0, 0, 1);
auto text1_back = new OpenGL::Rendering::Models::Quad(
Container::Position(pos_x, pos_y - radius, -0.1),
Container::Color::CYAN, 25, 25);
text1_back->create();
auto text1 = new OpenGL::Rendering::Models::Text(
"8", Container::Position(pos_x - 5, pos_y - radius / 1.5, 2), 22,
Container::Color::PINK);
text1->create();
我的文本类:
// Text.cpp
#include "Text.h"
using namespace OpenGL::Rendering::Models;
Text::Text(const std::string& text, OpenGL::Container::Position position,
int font_size, OpenGL::Container::Color color) {
m_font_size = font_size;
m_scale = 1.0;
m_text = text;
float angle = 0;
this->color.r = color.r;
this->color.g = color.g;
this->color.b = color.b;
this->color.a = color.a;
matrix.xx = (FT_Fixed)(cos(angle) * 0x10000L);
matrix.xy = (FT_Fixed)(-sin(angle) * 0x10000L);
matrix.yx = (FT_Fixed)(sin(angle) * 0x10000L);
matrix.yy = (FT_Fixed)(cos(angle) * 0x10000L);
this->position.x = position.x;
this->position.y = position.y;
this->position.z = position.z;
if (FT_Init_FreeType(&font)) {
Log()->critical("Could not initalize Freetype library for fonts.");
}
if (FT_New_Face(font, "/usr/share/fonts/truetype/ubuntu/Ubuntu-R.ttf", 0,
&face)) {
Log()->critical("Could not load font. File is missing maybe?");
}
FT_Set_Char_Size(face, 0, m_font_size * 64, 300, 300);
FT_Set_Pixel_Sizes(face, 0, m_font_size);
if (FT_Load_Char(face, 'X', FT_LOAD_RENDER)) {
Log()->critical(
"Could not load a test glyph. The font is corrupted maybe?");
}
for (GLubyte c = 0; c < 128; ++c) {
FT_Set_Transform(face, &matrix, 0);
if (FT_Load_Char(face, c, FT_LOAD_RENDER)) {
Log()->critical("Could not load glyph \"{}\"", c);
continue;
}
GLuint texture;
glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_2D, texture);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RED, face->glyph->bitmap.width,
face->glyph->bitmap.rows, 0, GL_RED, GL_UNSIGNED_BYTE,
face->glyph->bitmap.buffer);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
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_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
Character character = {
texture,
glm::ivec2(face->glyph->bitmap.width, face->glyph->bitmap.rows),
glm::ivec2(face->glyph->bitmap_left, face->glyph->bitmap_top),
face->glyph->advance.x};
characters.insert(std::pair<GLchar, Character>(c, character));
}
FT_Done_Face(face);
FT_Done_FreeType(font);
}
void Text::create() {
GLuint vao;
GLuint vbo;
glGenVertexArrays(1, &vao);
glGenBuffers(1, &vbo);
glBindVertexArray(vao);
glBindBuffer(GL_ARRAY_BUFFER, vbo);
glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat) * 6 * 4, NULL,
GL_DYNAMIC_DRAW);
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 4 * sizeof(GLfloat),
(void*)0);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindVertexArray(0);
this->vao = vao;
this->vbos.push_back(vbo);
this->set_program(OpenGL::Managers::ShaderManager::get_program("text"));
this->set_position(position.x, position.y, position.z);
}
void Text::draw() {
glUseProgram(this->program);
glUniformMatrix4fv(glGetUniformLocation(this->program, "model_matrix"), 1,
false, &model_matrix[0][0]);
glUniform4f(glGetUniformLocation(this->program, "text_color"), color.r,
color.g, color.b, color.a);
glActiveTexture(GL_TEXTURE0);
glBindVertexArray(this->vao);
GLfloat temp_x = 0;
GLfloat temp_y = 0;
std::string::const_iterator c;
for (c = m_text.begin(); c != m_text.end(); c++) {
Character ch = characters[*c];
GLfloat xpos = temp_x + ch.bearing.x * m_scale;
GLfloat ypos = temp_y - (ch.size.y - ch.bearing.y) * m_scale;
GLfloat w = ch.size.x * m_scale;
GLfloat h = ch.size.y * m_scale;
GLfloat vertices[6][4] = {
{xpos, ypos + h, 0.0, 0.0}, /**/
{xpos, ypos, 0.0, 1.0}, /**/
{xpos + w, ypos, 1.0, 1.0}, /**/
{xpos, ypos + h, 0.0, 0.0}, /**/
{xpos + w, ypos, 1.0, 1.0}, /**/
{xpos + w, ypos + h, 1.0, 0.0} /**/
};
glBindTexture(GL_TEXTURE_2D, ch.texture_id);
glBindBuffer(GL_ARRAY_BUFFER, this->vbos[0]);
glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(vertices), vertices);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glDrawArrays(GL_TRIANGLES, 0, 6);
temp_x += (ch.advance >> 6) * m_scale;
}
glBindVertexArray(0);
glBindTexture(GL_TEXTURE_2D, 0);
}
void Text::set_text(const std::string& a_text) {
if (!a_text.empty()) {
m_text = a_text;
} else {
Log()->info("Cannot set the text. Input seems to be empty.");
}
}
std::string Text::get_text() { return m_text; }
void Text::set_color(const Container::Color a_color) {
color.r = a_color.r;
color.g = a_color.g;
color.b = a_color.b;
color.a = a_color.a;
}
还有我的 Quad 类:
// Quad.cpp
#include "Quad.h"
using namespace OpenGL;
using namespace Rendering::Models;
Quad::Quad(Container::Position pos, Container::Color color, float width,
float height) {
position.x = pos.x;
position.y = pos.y;
position.z = pos.z;
this->color.x = color.r;
this->color.y = color.g;
this->color.z = color.b;
this->color.w = color.a;
this->width = width;
this->height = height;
}
Quad::~Quad() {}
void Quad::create() {
GLuint vao;
GLuint vbo;
glGenVertexArrays(1, &vao);
glBindVertexArray(vao);
std::vector<Container::Vertex> vertices;
vertices.push_back(
Container::Vertex(glm::vec3(-1, -1, 0.0), color));
vertices.push_back(
Container::Vertex(glm::vec3(-1, 1, 0.0), color));
vertices.push_back(
Container::Vertex(glm::vec3(1, -1, 0.0), color));
vertices.push_back(
Container::Vertex(glm::vec3(1, 1, 0.0), color));
glGenBuffers(1, &vbo);
glBindBuffer(GL_ARRAY_BUFFER, vbo);
glBufferData(GL_ARRAY_BUFFER, sizeof(Container::Vertex) * 4, &vertices[0],
GL_STATIC_DRAW);
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(Container::Vertex),
(void*)0);
glEnableVertexAttribArray(1);
glVertexAttribPointer(
1, 4, GL_FLOAT, GL_FALSE, sizeof(Container::Vertex),
(void*)(offsetof(Container::Vertex, Container::Vertex::m_color)));
glBindVertexArray(0);
this->vao = vao;
this->vbos.push_back(vbo);
this->set_program(OpenGL::Managers::ShaderManager::get_program("shape"));
this->set_scale(width / 2, height / 2, 1.0);
this->set_position(position.x, position.y, position.z);
}
void Quad::draw() {
glUseProgram(this->program);
glUniformMatrix4fv(glGetUniformLocation(this->program, "model_matrix"), 1,
false, &model_matrix[0][0]);
glBindVertexArray(vao);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
glBindVertexArray(0);
}
知道为什么会这样吗?如果您需要更多代码进行诊断,我会立即添加。非常感谢。
最佳答案
您正在使用 alpha 混合绘制四边形。 alpha 混合允许 8
周围的区域透明。然而,就 OpenGL 而言,这只是片段颜色的修改。透明片段仍会写入深度缓冲区。
您的抽奖顺序似乎未指定。从下面的评论来看,您正在使用 std::map
来保存您的模型。迭代该容器时获得的顺序不一定与插入顺序相同。这意味着您可能首先绘制一个“更近”的元素,导致其深度值写入深度缓冲区,从而防止任何后续“更远”的元素影响片段颜色。
在绝大多数情况下,无序绘图是好的(并且出于性能原因实际上是鼓励的)。但是,一旦您开始使用 alpha 混合透明度,顺序就变得很重要。
对于 alpha 混合 2D 元素,绘制的一般方法是:
关于c++ - 在 OpenGL 中自由类型文本后面的渲染正方形被裁剪,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51656993/
我试图使用 显示正方形(如元素符号正方形) .squares{ list-style-type: square; display:inline; } 但我希望它们是水
这是关于在作为 4 个 div 的一部分的 1 个 div 中嵌套 4 个 div(正方形)... 我在包装器中使用 display: flex 并用于包装的元素本身,否则它不会工作 对我来说,这感觉
这是图像,我想填充此矩形或正方形的边缘,以便可以使用轮廓对其进行裁剪。到目前为止,我所做的是我使用了canny边缘检测器来找到边缘,然后使用bitwise_or或将这个矩形填充了一点,但没有完全填充。
我希望能够在图片框内创建 X x Y 数量的框/圆圈/按钮。完全像 Windows 碎片整理工具。 我尝试创建一个布局并不断向其添加按钮或图片框,但速度非常慢,在添加 200 个左右的图片框后它崩溃,
我正在尝试从图像(肺部图像)中提取 3 个区域,这些区域在软组织中显示,每个区域都是具有特定高度和宽度的正方形,例如宽高各10mm,如下图, 如图所示,该区域也是均匀的,这意味着它只包含相同的颜色(在
在我左键单击它后,我试图让一个正方形跟随我的鼠标。当我右键单击时,方 block 应该停止跟随我的鼠标。 我的程序检测到我在方 block 内单击,但由于某种原因,它没有根据 Mouse.getDX/
已经花了几个小时在这上面了(因为我还在学习),所以也许你们可以帮忙。问题是我无法弄清楚如何将二维数组划分为所有可能的 nxn 正方形。 我正在随机化二维数组,可以说它是这样的: 1 0 1 0 2
使用 Graph API,我可以获得小型、大型、中型图片。或者我可以获得小方形图片。 但是我怎样才能得到大方形图片呢?有什么服务可以使用吗? 最佳答案 很简单,我刚发现这个。 例子, https://
我是 HTML 和 CSS 的新手。 尝试创建 3 x 3 正方形“图片”,使用 ,但无法找到将正方形放在页面中间的简单解决方案,例如中间有九个正方形。 如何把所有的方 block 都放在大边框的正方
我正在玩弄 CSS 动画以获得乐趣。我有限的经验阻碍了这一进程。 下面的脚本将圆形转换为三 Angular 形,再转换为正方形,然后反转。然而,圆形和三 Angular 形之间的动画有一个小错误。我希
我的标准布局(最小宽度 1024 像素)有 4 行。第一个和最后一个有 6 个正方形,中间有两个组合正方形。但是第三行的第一个方 block 不见了。我没有使用不同的 CSS 设置。我试过 clear
关闭。这个问题需要更多focused .它目前不接受答案。 想改进这个问题吗? 更新问题,使其只关注一个问题 editing this post . 关闭 7 年前。 Improve this q
我的网站上有 4 张图片,我试图对其进行定位,以便它们在我的 DIV 中形成一个相等的正方形,但它看起来像一条由 4 张图片组成的垂直线。我希望它看起来像 2 个图像的 2 条垂直线,彼此相邻,使其成
这是方 block 检测示例的输出我的问题是过滤这个方 block 第一个问题是它为同一区域绘制多条线; 第二个是我只需要检测对象而不是所有图像。 另一个问题是我必须只取除所有图像之外的最大对象。 检
我正在绘制一个带有移动立方体(正方形,因为它是 2d)算法的元球。一切都很好,但我想将其作为矢量对象获取。 到目前为止,我已经从每个事件方 block 中得到一两条矢量线,将它们保存在列表线中。换句话
实际上,我有一个适用于 Android 1.5 的应用程序,其中包含一个 GLSurfaceView 类,它在屏幕上显示一个简单的方形多边形。 我想学习如何添加一个新功能,即移动用手指触摸的方 blo
如果我有一个包含多个子组件的 JPanel,我该如何使 JPanel 保持正方形,而不管其父组件的大小如何调整?我尝试了以下代码的变体,但它不会导致子组件也变成正方形。 public void pai
我找到了 this answer ,它确保 ImageView 的宽高比得以保留。 我如何使用带有可绘制背景的 TextView 来做到这一点?我有这个 TextView: 这是我的背
这个问题在这里已经有了答案: Maintain aspect ratio of a div according to height [duplicate] (1 个回答) 关闭 8 年前。 是否可以
如何创建 div Logo ,如下图所示: 这是我在 JsFiddle 中创建的 主要问题是如何将两个形状如下图的盒子连接起来,有人可以提出建议吗? body,html { width: 100%
我是一名优秀的程序员,十分优秀!