You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am trying to render a simple triangle and a simple imgui Window,but when i try to render it just shows a black window without any triangle or imgui window(sometimes also crashes).I am Unbinding my VertexBuffer but it still doesnot let the traingle and imgui window render(my driver has s deafult white color shader so i am not writing it) and whenever i comment glBindBuffer(GL_ARRAY_BUFFER,VBO); it works.So,its a problem with the VertexBuffer
But how to fix it??.I think i am doing all of the procedures right(I am a beginner so i dont know how to fix it even after trying for many hours).
My Code:
#include "GL/glew.h"
#include "GLFW/glfw3.h"
#include "imgui_impl_opengl2.h"
#include "imgui_impl_glfw.h"
#include "imgui.h"
#include <vector>
std::vector<float> Vertices = {
-0.5,0.5,
0.5,0.0,
0.5,-0.5
};
int main()
{
glfwInit();
GLFWwindow* window = glfwCreateWindow(900,500,"WWW",NULL,NULL);
glfwMakeContextCurrent(window);
glewInit();
unsigned int VBO;
glGenBuffers(1,&VBO);
glBindBuffer(GL_ARRAY_BUFFER,VBO);
glBufferData(GL_ARRAY_BUFFER,6 * sizeof(float),&Vertices[0],GL_STATIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER,0);
IMGUI_CHECKVERSION();
ImGui::CreateContext();
ImGuiIO& io = ImGui::GetIO(); (void)io;
ImGui::StyleColorsDark();
bool show_another_window = true;
ImGui_ImplGlfw_InitForOpenGL(window, true);
ImGui_ImplOpenGL2_Init();
while (!glfwWindowShouldClose(window))
{
glfwPollEvents();
// Start the Dear ImGui frame
ImGui_ImplOpenGL2_NewFrame();
ImGui_ImplGlfw_NewFrame();
ImGui::NewFrame();
glBindBuffer(GL_ARRAY_BUFFER,VBO);
glEnableVertexAttribArray(0);
glVertexAttribPointer(0,2,GL_FLOAT,GL_FALSE,2* sizeof(float),0);
glDrawArrays(GL_TRIANGLES,0,3);
glBindBuffer(GL_ARRAY_BUFFER,0);
if (show_another_window)
{
ImGui::Begin("Another Window", &show_another_window); // Pass a pointer to our bool variable (the window will have a closing button that will clear the bool when clicked)
ImGui::Text("Hello from another window!");
if (ImGui::Button("Close Me"))
show_another_window = false;
ImGui::End();
}
// Rendering
ImGui::Render();
int display_w, display_h;
glfwGetFramebufferSize(window, &display_w, &display_h);
glViewport(0, 0, display_w, display_h);
glClearColor(0.2f,0.2f,0.2f,1.0f);
glClear(GL_COLOR_BUFFER_BIT);
ImGui_ImplOpenGL2_RenderDrawData(ImGui::GetDrawData());
glfwMakeContextCurrent(window);
glfwSwapBuffers(window);
}
// Cleanup
ImGui_ImplOpenGL2_Shutdown();
ImGui_ImplGlfw_Shutdown();
ImGui::DestroyContext();
glfwDestroyWindow(window);glfwTerminate();
return 0;
}
You have access to examples/example_glfw_opengl2 you can compare your code to it and see the difference and track your issue from there. If examples/example_glfw_opengl2/ unmodified works and your code doesn't, then your added code is the culprit, however confusing OpenGL states are this becomes an OpenGL problem not a Dear ImGui problem.
I suggest you use the imgui_impl_opengl3 backend which is more in line with your coding style. Its not guaranteed that OpenGL driver handle both old and new style perfectly.
I am trying to render a simple triangle and a simple imgui Window,but when i try to render it just shows a black window without any triangle or imgui window(sometimes also crashes).I am Unbinding my VertexBuffer but it still doesnot let the traingle and imgui window render(my driver has s deafult white color shader so i am not writing it) and whenever i comment glBindBuffer(GL_ARRAY_BUFFER,VBO); it works.So,its a problem with the VertexBuffer
But how to fix it??.I think i am doing all of the procedures right(I am a beginner so i dont know how to fix it even after trying for many hours).
My Code:
my Compiler Settings:
The text was updated successfully, but these errors were encountered: