I've been working with SDL2 for a long time and now I wanted to switch to GLFW with Dear ImGui. So I downloaded GLFW and integrated it into the project. The simple GLFW window works without problems. Then I integrated ImGui and I get these errors all the time:
Failed to initialize OpenGL loader!
Assertion failed: (bd != __null && "Did you call ImGui_ImplOpenGL3_Init()?"), function ImGui_ImplOpenGL3_NewFrame, file imgui_impl_opengl3.cpp, line 337.
although I'm on line 33:
ImGui_ImplOpenGL3_Init();
I have never worked with ImGui before and would be really happy if you could help me
My code:
int main() {
//init glfw
if (!glfwInit()) {
std::cout << "Failed to initialize GLFW" << std::endl;
return -1;
}
//create window
GLFWwindow* window = glfwCreateWindow(640, 480, "Text Editor", NULL, NULL);
if (!window) {
std::cout << "Failed to create window" << std::endl;
glfwTerminate();
return -1;
}
glfwMakeContextCurrent(window);
//init glew
if (glewInit() != GLEW_OK) {
std::cout << "Failed to initialize GLEW" << std::endl;
return -1;
}
ImGui::CreateContext();
ImGuiIO& io = ImGui::GetIO(); (void)io;
ImGui_ImplGlfw_InitForOpenGL(window, true);
ImGui::StyleColorsDark();
ImGui_ImplOpenGL3_Init();
//main loop
while (!glfwWindowShouldClose(window)) {
glfwPollEvents();
ImGui_ImplOpenGL3_NewFrame();
ImGui_ImplGlfw_NewFrame();
ImGui::Render();
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
glfwSwapBuffers(window);
glfwPollEvents();
}
return 0;
}
And my includes:
#include "GL/glew.h"
#include "GLFW/glfw3.h"
#include "imgui/imgui.h"
#include "imgui/imgui_impl_glfw.h"
#include "imgui/imgui_impl_opengl3.h"
Thank you for your answer :)