Hello everybody, I try to draw a little figure where my mouse cursor is, here are some information:
GLfloat Renderer::mouseVertices[] = {
0.0f, 0.0f, 0.0f,
0.0f, 0.5f, 0.0f,
0.5f, 0.0f, 0.0f,
0.0f, -0.5f, 0.0f,
-0.5f, 0.0f, 0.0f
};
GLuint Renderer::mouseIndices[] = {
0, 1, 2,
0, 2, 3,
0, 3, 4,
0, 4, 1
};
glGenVertexArrays(1, &mouse.VAO);
glGenBuffers(1, &mouse.VBO);
glGenBuffers(1, &mouse.EBO);
glBindVertexArray(mouse.VAO);
glBindBuffer(GL_ARRAY_BUFFER, mouse.VBO);
glBufferData(GL_ARRAY_BUFFER, sizeof(mouseVertices), mouseVertices, GL_STATIC_DRAW);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, mouse.EBO);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(mouseIndices), mouseIndices, GL_STATIC_DRAW);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(GLfloat), (GLvoid*)0);
glEnableVertexAttribArray(0);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindVertexArray(0);
the actual rendering:
glfwGetCursorPos(window, &mousePosX, &mousePosY);
glUseProgram(shaderProgramMouse);
std::cout << mousePosX << "|" << mousePosY << std::endl;
glm::mat4 projection;
glm::mat4 model;
projection = glm::ortho(0.0f, (float) Game::WIDTH, 0.0f, (float) Game::HEIGHT);
//(float) mousePosX, (float) mousePosY,
model = glm::translate(model, glm::vec3((float) mousePosX, (float) mousePosY, 1.0f));
glUniformMatrix4fv(glGetUniformLocation(shaderProgramMouse, "projection"), 1, GL_FALSE, glm::value_ptr(projection));
glUniformMatrix4fv(glGetUniformLocation(shaderProgramMouse, "model"), 1, GL_FALSE, glm::value_ptr(model));
glBindVertexArray(mouse.VAO);
glDrawElements(GL_TRIANGLES, 12, GL_UNSIGNED_INT, 0);
glBindVertexArray(0);
glUseProgram(0);
All other things were correctly rendered… am I overseeing something?