Imgui implementation with SDL2 and OpenGL 3.3


#1

Hello guys,

I’m trying to implement Imgui in a personal engine where I use SDL2 and opengl(version 3.3.0) but the may , but I keep getting this errors:

WARNING: 1:2: ‘’ : #version directive missing
WARNING: 1:8: ‘function’ : is not available in current GLSL version texture

which I think are related to glsl version, I am using the last version of imgui, if this is the issue, I would really appreciate knowing what is the most optimal version of OpenGL to use.

In addition, this is the code I use from the opengl3 example (main.cpp):

#include “InmediateUI.h”
#include
InmediateUI::InmediateUI()
{
}
InmediateUI::InmediateUI(SDL_Window * window_, SDL_GLContext context_) : window(window_), context(context_)
{
if (window == nullptr || context == nullptr) {
std::cout << “issue in window or context maybe both” << std::endl;
}

ImGui::CreateContext();
// Setup Platform/Renderer bindings
ImGui_ImplSDL2_InitForOpenGL(window, context);


ImGui::StyleColorsDark();

}

InmediateUI::~InmediateUI()
{
}

void InmediateUI::ShutDown()
{
// Cleanup
ImGui_ImplOpenGL3_Shutdown();
ImGui_ImplSDL2_Shutdown();
ImGui::DestroyContext();
}

void InmediateUI::imGuiDefaultScene()
{
bool show_demo_window = true;
bool show_another_window = false;
clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f);

///ImGui::StyleColorsDark();

ImGui_ImplOpenGL3_NewFrame();
//ImGui_ImplGlfw_NewFrame();
ImGui_ImplSDL2_NewFrame(window);
ImGui::NewFrame();

static float f = 0.0f;
static int counter = 0;

ImGui::Begin("Hello, world!");                          // Create a window called "Hello, world!" and append into it.

ImGui::Text("This is some useful text.");               // Display some text (you can use a format strings too)
ImGui::Checkbox("Demo Window", &show_demo_window);      // Edit bools storing our window open/close state
ImGui::Checkbox("Another Window", &show_another_window);

ImGui::SliderFloat("float", &f, 0.0f, 1.0f);            // Edit 1 float using a slider from 0.0f to 1.0f
ImGui::ColorEdit3("clear color", (float*)&clear_color); // Edit 3 floats representing a color

if (ImGui::Button("Button"))                            // Buttons return true when clicked (most widgets return true when edited/activated)
	counter++;
ImGui::SameLine();
ImGui::Text("counter = %d", counter);

ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / ImGui::GetIO().Framerate, 
    ImGui::GetIO().Framerate);
ImGui::End();

}

void InmediateUI::Update(const float deltaTime_)
{
imGuiDefaultScene();
}

void InmediateUI::Render()
{
// Rendering

ImGui::Render();
SDL_GL_MakeCurrent(window, context);
glClearColor(clear_color.x, clear_color.y, clear_color.z, clear_color.w);
glClear(GL_COLOR_BUFFER_BIT);
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());//key
SDL_GL_SwapWindow(window);

}

Thanks a lot :slight_smile:


#2

There’s no call to ImGui_ImplOpenGL3_Init() in your pasted code, meaning the pasted code is probably incomplete.


#3

Well thas embarrassing, thanks a lot for the quick response