able to comple with tex inspect

This commit is contained in:
2024-06-12 10:03:06 -04:00
parent 803d1e17ec
commit 913a0429bd
6 changed files with 2438 additions and 3 deletions

View File

@ -28,14 +28,53 @@
#include <SDL2/SDL_opengl.h>
#endif
#else
#include <SDL.h>
#include <SDL2/SDL.h>
#if defined(IMGUI_IMPL_OPENGL_ES2)
#include <SDL_opengles2.h>
#include <SDL2/SDL_opengles2.h>
#else
#include <SDL_opengl.h>
#include <SDL2/SDL_opengl.h>
#endif
#endif
#include "lib/imgui_tex_inspect.h"
#include "lib/backends/tex_inspect_opengl.h"
struct Texture
{
ImTextureID texture;
ImVec2 size;
};
Texture LoadTexture(const char * path)
{
const int channelCount = 4;
int imageFileChannelCount;
int width, height;
uint8_t *image = (uint8_t *)stbi_load(path, &width, &height, &imageFileChannelCount, channelCount);
if (image == NULL)
{
fprintf(stderr, "%s\nFailed to open %s\n", stbi_failure_reason(), path);
return {nullptr,{0,0}};
}
GLenum dataFormat = GL_RGBA;
GLuint textureHandle;
glGenTextures(1, &textureHandle);
glBindTexture(GL_TEXTURE_2D, textureHandle);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, dataFormat, GL_UNSIGNED_BYTE, image);
Texture t;
t.texture = (void*)(uintptr_t)(textureHandle);
t.size = ImVec2((float)width,(float)height);
stbi_image_free(image);
return t;
}
static bool init = true;
// Main code
@ -110,6 +149,10 @@ int main(int, char **) {
// Platform Windows
// io.ConfigViewportsNoAutoMerge = true;
// io.ConfigViewportsNoTaskBarIcon = true;
//
ImGuiTexInspect::ImplOpenGL3_Init(); // Or DirectX 11 equivalent (check your chosen backend header file)
ImGuiTexInspect::Init();
ImGuiTexInspect::CreateContext();
// Setup Dear ImGui style
ImGui::StyleColorsDark();
@ -129,6 +172,8 @@ int main(int, char **) {
ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f);
Texture t;
// Main loop
bool done = false;
while (!done)
@ -185,6 +230,7 @@ int main(int, char **) {
ImGui::DockBuilderSetNodeSize(dockspace_id, viewport->Size);
ImGui::DockBuilderDockWindow("Editor", dockspace_id);
ImGui::DockBuilderFinish(dockspace_id);
t = LoadTexture("/home/dubey/Pictures/DSC03199.JPG");
}
if (ImGui::BeginMainMenuBar()) {