Введенное значение не отображается на экране OpenGL [дубликат]C++

Программы на C++. Форум разработчиков
Ответить
Anonymous
 Введенное значение не отображается на экране OpenGL [дубликат]

Сообщение Anonymous »

Я написал следующий код opengl, отвечающий приведенным ниже требованиям:
  • От 0 до 9 в упрощенном файле шрифтов TrueType (times_font_partial.txt) ),
    Прочитайте общую информацию о A-Z и a-z.
  • Добавьте графический интерфейс

    Когда я получаю ввод текста из ImGui шрифт соответствующих символов отображается на экране
  • Измените цвет шрифта, добавив цветовую палитру
[*]Максимальное количество символов, рисуемых одновременно, — 5 символов.

[*]Если введенный в поле 2 символ представляет собой число от 0 до 9, нарисуйте контур символа в левом окне.

[*]Если символы, введенные в 2, представляют собой алфавиты между a и z, а также A и Z. , нарисуйте соответствующий алфавит


Текстовый файл, содержащий простую информацию о шрифте, организован следующим образом

Код: Выделить всё

NumGlyph # (number of texts)
Index 0
CharIndex # (text code)
BBOX Xmin Ymin Xmax Ymax // (text size range)
NumContours #(number of outlines)
Contour #(ContourID) #(number of Curve)
C P0.X, P0.Y P1.X P1.Y P2.X P2.Y //quadratic Bézier curve
L P0.X, P0.Y P1.X P1.Y //Bézier curve (Straight Line)
...
Index 1
CharIndex # (text code)
...
Это функция, которая считывает информацию о шрифте из txt-файла.

Код: Выделить всё

#include "imgui/imgui.h"
#include "imgui/imgui_impl_glfw.h"
#include "imgui/imgui_impl_opengl3.h"
#include "InitShader.h"
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 

using namespace std;

struct Outline {
std::vector points;
};

class FontLoader {
public:
std::map outlines;
float fontScale = 1.0f;

void LoadFont(const std::string& filename) {
std::ifstream file(filename);
if (!file.is_open()) {
std::cerr  index;

std::getline(file, line);
std::stringstream charIndexStream(line.substr(9));
charIndexStream >> charIndex;
char ch = static_cast(charIndex);

std::getline(file, line);
std::stringstream bboxStream(line.substr(5));
bboxStream >> bbox[0] >> bbox[1] >> bbox[2] >> bbox[3];

std::getline(file, line);
std::stringstream numContoursStream(line.substr(12));
numContoursStream >> numContours;

Outline outline;
for (int i = 0; i < numContours; i++) {
std::getline(file, line);
if (line.find("Contour") == 0) {
std::stringstream ss(line.substr(8));
int contourIndex, numPoints;
ss >> contourIndex >> numPoints;

for (int j = 0; j < numPoints; j++) {
std::getline(file, line);
char type;
float x, y;
std::stringstream pointStream(line);
pointStream >> type;

if (type == 'L') {
pointStream >> x >> y;
outline.points.push_back(glm::vec2(x, y));
}
}
}
}

outlines[ch] = outline;
}
}
file.close();
}

void SetFontScale(float scale) {
fontScale = scale;
}

Outline GetOutline(char ch) {
return outlines.count(ch) ? outlines[ch] : Outline();
}
};
Я объявил переменные глобальными

Код: Выделить всё

GLuint model_view, projection, color_loc;
float left = -1.0f, right = 1.0f, bottom = -1.0f, top = 1.0f;

// Declare FontLoader and OpenGL objects globally
FontLoader fontLoader;
GLuint vao, vbo;
glm::vec3 fontColor = { 1.0f, 1.0f, 1.0f };
char inputText[6] = "";
float fontSize = 1.0f;
Это функция рисования контура

Код: Выделить всё

// a function of drawing an outline
void RenderOutline(const Outline&  outline, glm::vec3 color, float scale, GLuint program, GLuint VAO, GLuint VBO) {
if (outline.points.empty()) return;

// Apply the scale
std::vector scaledPoints;
for (auto& point : outline.points) {
scaledPoints.push_back(point * scale);
}

// Vertex Array Object Binding
glBindVertexArray(VAO);

// Upload Scaled Point Data to the VBO
glBindBuffer(GL_ARRAY_BUFFER, VBO);
glBufferData(GL_ARRAY_BUFFER, scaledPoints.size() * sizeof(glm::vec2), scaledPoints.data(), GL_DYNAMIC_DRAW);

// Using Shader Programs
glUseProgram(program);

// Color Uniform Settings
GLint colorLoc = glGetUniformLocation(program, "color");
glUniform3f(colorLoc, color.r, color.g, color.b);

// Point Positioning
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, sizeof(glm::vec2), (void*)0);
glEnableVertexAttribArray(0);

// Draw an outline
glDrawArrays(GL_LINE_STRIP, 0, scaledPoints.size());

// Unbinding
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindVertexArray(0);
glUseProgram(0);
}
Это функция инициализации

Код: Выделить всё

// Initialization function
void init(FontLoader& fontLoader, GLuint& VAO, GLuint& VBO) {
fontLoader.LoadFont("times_font_partial.txt");

glGenVertexArrays(1, &VAO);
glGenBuffers(1, &VBO);

glEnable(GL_DEPTH_TEST);
glClearColor(1.0, 1.0, 1.0, 1.0);
}
Это функция отображения

Код: Выделить всё

// display function
void display(const std::string& text, FontLoader& fontLoader, glm::vec3 color, GLuint VAO, GLuint VBO, GLuint program) {
float xOffset = -0.5f * text.length() * fontLoader.fontScale;

for (char ch : text) {
Outline outline = fontLoader.GetOutline(ch);
if (outline.points.empty()) continue;

glm::mat4 model = glm::translate(glm::mat4(1.0f), glm::vec3(xOffset, 0.0f, 0.0f));
GLint modelLoc = glGetUniformLocation(program, "model");
glUniformMatrix4fv(modelLoc, 1, GL_FALSE, glm::value_ptr(model));

RenderOutline(outline, color, fontLoader.fontScale, program, VAO, VBO);

xOffset += fontLoader.fontScale * 1.2f;
}
}
Это основное

Код: Выделить всё

int main() {
// GLFW init
if (!glfwInit()) {
std::cerr 

Подробнее здесь: [url]https://stackoverflow.com/questions/79174836/the-input-value-does-not-appear-on-the-screen-opengl[/url]
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «C++»