Hey ,
i am back with new troubles .
So i am past the point of integrating SDL2 alongside with OpenGL (and a variaty of other opensource libs such as assimp/glm/glew e.t.c) and i moved forward to put ImGUI on the game too .
For starters, what i did was create a .lib file out of ImGUI alongside with
imgui_impl_sdl_gl3.cpp and imgui_impl_sdl_gl3.h which are the example files for ImGUI + SDL2 + OpenGL in github -> https://github.com/ocornut/imgui/tree/master/examples/sdl_opengl3_example .
I got the examples working fine (http://prntscr.com/bi9lzz) as you can see in the screenshot and ImGUI looks really cool indeed , but now i want to render also my cube inside the window .
According to the little documentation of ImGUi (most of it inside of imgui.cpp) this is a typical application skeleton :
// Application init
ImGuiIO& io = ImGui::GetIO();
io.DisplaySize.x = 1920.0f;
io.DisplaySize.y = 1280.0f;
io.IniFilename = "imgui.ini";
io.RenderDrawListsFn = my_render_function; // Setup a render function, or set to NULL and call GetDrawData() after Render() to access the render data.
// TODO: Fill others settings of the io structure
// Load texture atlas
// There is a default font so you don't need to care about choosing a font yet
unsigned char* pixels;
int width, height;
io.Fonts->GetTexDataAsRGBA32(pixels, &width, &height);
// TODO: At this points you've got a texture pointed to by 'pixels' and you need to upload that your your graphic system
// TODO: Store your texture pointer/identifier (whatever your engine uses) in 'io.Fonts->TexID'
// Application main loop
while (true)
{
// 1) get low-level inputs (e.g. on Win32, GetKeyboardState(), or poll your events, etc.)
// TODO: fill all fields of IO structure and call NewFrame
ImGuiIO& io = ImGui::GetIO();
io.DeltaTime = 1.0f/60.0f;
io.MousePos = mouse_pos;
io.MouseDown[0] = mouse_button_0;
io.MouseDown[1] = mouse_button_1;
io.KeysDown[i] = ...
// 2) call NewFrame(), after this point you can use ImGui::* functions anytime
ImGui::NewFrame();
// 3) most of your application code here
ImGui::Begin("My window");
ImGui::Text("Hello, world.");
ImGui::End();
MyGameUpdate(); // may use ImGui functions
MyGameRender(); // may use ImGui functions
// 4) render & swap video buffers
ImGui::Render();
SwapBuffers();
}
Considering it, i have created my main function :
int main(int, char**)
{
int running = true;
if (init() == false)
{
std::cout << "Init failed !!!" << std::endl;
exit(EXIT_FAILURE);
}
initCube();
// Setup ImGui binding
ImGui_ImplSdlGL3_Init(gWindow);
ImVec4 clear_color = ImColor(114, 144, 154);
// Main loop
bool done = false;
while (!done)
{
SDL_Event event;
while (SDL_PollEvent(&event))
{
ImGui_ImplSdlGL3_ProcessEvent(&event);
if (event.type == SDL_QUIT)
done = true;
}
ImGui_ImplSdlGL3_NewFrame(gWindow);
// 1. Show a simple window
// Tip: if we don't call ImGui::Begin()/ImGui::End() the widgets appears in a window automatically called "Debug"
ImGui::SetNextWindowSize(ImVec2(100,100), ImGuiSetCond_FirstUseEver);
ImGui::Begin("basicCube GUI");
static float f = 0.0f;
ImGui::Text("Hello, world!");
ImGui::SliderFloat("float", &f, 0.0f, 1.0f);
ImGui::ColorEdit3("clear color", (float*)&clear_color);
ImGui::Button("Test button");
ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate);
ImGui::End();
// Rendering
glViewport(0, 0, (int)ImGui::GetIO().DisplaySize.x, (int)ImGui::GetIO().DisplaySize.y);
glClearColor(clear_color.x, clear_color.y, clear_color.z, clear_color.w);
glClear(GL_COLOR_BUFFER_BIT);
displayCube();
ImGui::Render();
SDL_GL_SwapWindow(gWindow);
}
close(); //Shuts down every little thing...
return 0;
}
My problem is that there is no cube in my screen , just what you saw in the screen shot above .
If i try to render the cube alone it works fine , the problem seems to be when i mix ImGUI functions with mine .
Anybody got any ideas or has faced anything similar?
Thanks in advance .