EditorWindow.cpp
Код: Выделить всё
#include "EditorWindow.h"
EditorWindow::EditorWindow(GLFWwindow *window)
{
glfwGetWindowSize(window, &width, &height);
EditorWindow::graphInit(width, height);
EditorWindow::gridDotInit();
}
float EditorWindow::gridNormal(float x, float max)
{
x = 2 * x;
x = x / max;
x = x - 1;
return x;
}
void EditorWindow::graphInit(int resWidth, int resHeight)
{
int logx = 0;
int logy = 0;
for (int i = gridSize; i < resWidth; i += gridSize)
{
float x = gridNormal(i, resWidth);
vertacies.push_back(x);
vertacies.push_back(1);
vertacies.push_back(0);
vertacies.push_back(x);
vertacies.push_back(-1);
vertacies.push_back(0);
}
for (int i = gridSize; i < resHeight; i += gridSize)
{
float x = gridNormal(i, resHeight);
vertacies.push_back(1);
vertacies.push_back(x);
vertacies.push_back(0);
vertacies.push_back(-1);
vertacies.push_back(x);
vertacies.push_back(0);
}
glGenVertexArrays(1, &VAO);
glGenBuffers(1, &VBO);
glBindBuffer(GL_ARRAY_BUFFER, VBO);
glBufferData(GL_ARRAY_BUFFER, vertacies.size() * sizeof(float), vertacies.data(), GL_STATIC_DRAW);
glBindVertexArray(VAO);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), (void*)0);
glEnableVertexAttribArray(0);
}
void EditorWindow::drawGraph(Shader &shader)
{
//shader.setVec4("FragColor", glm::vec4(0.2, 0.2, 0.2, 1.0));
shader.use();
glBindBuffer(GL_ARRAY_BUFFER, VBO);
glBindVertexArray(VAO);
glDrawArrays(GL_LINES, 0, vertacies.size()/2);
}
void EditorWindow::mousePos(GLFWwindow* window)
{
glfwGetCursorPos(window, &mouseX, &mouseY);
//std::cout
Подробнее здесь: [url]https://stackoverflow.com/questions/78388383/i-cant-get-opengl-to-draw-a-line-on-user-input[/url]