Example of rendering a a triangle under the UI
This commit is contained in:
parent
982aa18b0c
commit
5b1b7227f8
|
@ -60,10 +60,51 @@ int main(int argc, char** argv)
|
||||||
|
|
||||||
int height = 0, width = 0;
|
int height = 0, width = 0;
|
||||||
ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f);
|
ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f);
|
||||||
|
|
||||||
|
// Triangle example
|
||||||
|
// @see http://www.opengl-tutorial.org/beginners-tutorials/tutorial-2-the-first-triangle/
|
||||||
|
GLuint VertexArrayID;
|
||||||
|
glGenVertexArrays(1, &VertexArrayID);
|
||||||
|
glBindVertexArray(VertexArrayID);
|
||||||
|
GLuint vertexbuffer;
|
||||||
|
// An array of 3 vectors which represents 3 vertices
|
||||||
|
static const GLfloat g_vertex_buffer_data[] = {
|
||||||
|
-1.0f, -1.0f, 0.0f,
|
||||||
|
1.0f, -1.0f, 0.0f,
|
||||||
|
0.0f, 1.0f, 0.0f,
|
||||||
|
};
|
||||||
|
glGenBuffers(1, &vertexbuffer);
|
||||||
|
glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer);
|
||||||
|
glBufferData(GL_ARRAY_BUFFER, sizeof(g_vertex_buffer_data),
|
||||||
|
g_vertex_buffer_data, GL_STATIC_DRAW);
|
||||||
while(!glfwWindowShouldClose(window)) {
|
while(!glfwWindowShouldClose(window)) {
|
||||||
glfwPollEvents();
|
glfwPollEvents();
|
||||||
// Process input.
|
// Process input.
|
||||||
|
|
||||||
|
// @TODO Game tick
|
||||||
|
|
||||||
|
|
||||||
|
// Clear GL buffers
|
||||||
|
glClearColor(clear_color.x, clear_color.y, clear_color.z, clear_color.w);
|
||||||
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
|
|
||||||
|
// Render game geometries
|
||||||
|
// @see https://blog.conan.io/2019/06/26/An-introduction-to-the-Dear-ImGui-library.html
|
||||||
|
// 1st attribute buffer : vertices
|
||||||
|
glEnableVertexAttribArray(0);
|
||||||
|
glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer);
|
||||||
|
glVertexAttribPointer(
|
||||||
|
0, // attribute 0. No particular reason for 0, but must match the layout in the shader.
|
||||||
|
3, // size
|
||||||
|
GL_FLOAT, // type
|
||||||
|
GL_FALSE, // normalized?
|
||||||
|
0, // stride
|
||||||
|
(void*)0 // array buffer offset
|
||||||
|
);
|
||||||
|
// Draw the triangle !
|
||||||
|
glDrawArrays(GL_TRIANGLES, 0, 3); // Starting from vertex 0; 3 vertices total -> 1 triangle
|
||||||
|
glDisableVertexAttribArray(0);
|
||||||
|
|
||||||
// Start the Dear ImGui frame
|
// Start the Dear ImGui frame
|
||||||
ImGui_ImplOpenGL3_NewFrame();
|
ImGui_ImplOpenGL3_NewFrame();
|
||||||
ImGui_ImplGlfw_NewFrame();
|
ImGui_ImplGlfw_NewFrame();
|
||||||
|
@ -89,16 +130,15 @@ int main(int argc, char** argv)
|
||||||
ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate);
|
ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate);
|
||||||
ImGui::End();
|
ImGui::End();
|
||||||
}
|
}
|
||||||
// @TODO Game tick
|
|
||||||
|
|
||||||
// Rendering
|
// Finalise rendering
|
||||||
ImGui::Render();
|
ImGui::Render();
|
||||||
|
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
|
||||||
|
|
||||||
|
// Swap buffers
|
||||||
int display_w, display_h;
|
int display_w, display_h;
|
||||||
glfwGetFramebufferSize(window, &display_w, &display_h);
|
glfwGetFramebufferSize(window, &display_w, &display_h);
|
||||||
glViewport(0, 0, display_w, display_h);
|
glViewport(0, 0, display_w, display_h);
|
||||||
glClearColor(clear_color.x, clear_color.y, clear_color.z, clear_color.w);
|
|
||||||
glClear(GL_COLOR_BUFFER_BIT);
|
|
||||||
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
|
|
||||||
glfwSwapBuffers(window);
|
glfwSwapBuffers(window);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue