resolve conflict

This commit is contained in:
Tanishq Dubey 2024-06-14 19:28:07 -04:00
parent e34e38778e
commit 844d23b3fd
2 changed files with 76 additions and 28 deletions

View File

@ -1,24 +0,0 @@
[Window][Debug##Default]
Pos=341,6
Size=400,400
Collapsed=0
[Window][viewport_container]
Size=1101,598
Collapsed=0
[Window][Editor]
Pos=33,52
Size=1118,634
Collapsed=0
[Window][Main]
Pos=0,0
Size=2560,1532
Collapsed=0
[Window][Help]
Pos=136,255
Size=177,114
Collapsed=0

View File

@ -17,6 +17,7 @@
#include "lib/backends/imgui_impl_sdl2.h"
#include "lib/imgui.h"
#include "lib/imgui_internal.h"
#include <cstdint>
#include <iostream>
#include <stdexcept>
#include <stdio.h>
@ -52,14 +53,17 @@ struct Texture
{
ImTextureID texture;
ImVec2 size;
int channels;
};
static uint8_t* image = nullptr;
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);
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);
@ -78,11 +82,62 @@ Texture LoadTexture(const char * path)
Texture t;
t.texture = (void*)(uintptr_t)(textureHandle);
t.size = ImVec2((float)width,(float)height);
t.channels = channelCount;
stbi_image_free(image);
return t;
}
Texture ReloadTexture(ImTextureID id, int width, int height) {
GLuint tid = (GLuint)(uintptr_t)id;
glDeleteTextures((GLsizei)1, &tid);
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);
return t;
}
void rotate90()
{
}
void RotateImage(Texture t) {
int height = t.size.y;
int width = t.size.x;
int channels = t.channels;
const unsigned int sizeBuffer = width * height * channels;
unsigned char *tempBuffer = new unsigned char[sizeBuffer];
int nidx = 0;
for (int x = 0; x < width; x++)
{
for (int y = height - 1; y >= 0; y--)
{
int idx = (x + y * width) * channels;
for (int i = 0; i < channels; i++)
tempBuffer[nidx + i] = image[idx + i];
nidx = nidx + 4;
}
}
// Copy rotated pixels
memcpy(image, tempBuffer, sizeBuffer);
delete[] tempBuffer;
}
static bool init = true;
static bool showHelp = false;
@ -99,7 +154,7 @@ int main(int argc, char* argv[]) {
}
bool TOOLTIP_ENABLED = false;
bool GRID_ENABLED = true;
bool GRID_ENABLED = false;
bool AA_ENABLED = true;
// Decide GL+GLSL versions
@ -222,6 +277,10 @@ int main(int argc, char* argv[]) {
case SDL_SCANCODE_D:
mode = (mode + 1) % 5;
break;
case SDL_SCANCODE_R:
RotateImage(t);
t = ReloadTexture(t.texture, t.size.y, t.size.x);
break;
case SDL_SCANCODE_Q:
done = true;
break;
@ -317,12 +376,21 @@ int main(int argc, char* argv[]) {
if (ImGui::BeginPopup("HelpPopup")) {
ImGui::Text("tview Help");
ImGui::Separator();
ImGui::Text("r - rotate 90 deg clockwise");
ImGui::Text("g - toggle grid");
ImGui::Text("a - toggle filtering");
ImGui::Text("t - toggle tooltip");
ImGui::Text("d - cycle pixel detail mode");
ImGui::Text("q - quit");
ImGui::Separator();
ImGui::Text("modes:");
ImGui::Text("\tOff");
ImGui::Text("\tGradient Arrow");
ImGui::Text("\tHex Code");
ImGui::Text("\tRGB Values");
ImGui::Text("\tFloat Values");
ImGui::Separator();
ImGui::Text("h - show help popup");
ImGui::Text("q - quit");
ImGui::Separator();
ImGui::Text("click anywhere to continue");
ImGui::EndPopup();
@ -339,6 +407,10 @@ int main(int argc, char* argv[]) {
SDL_GL_SwapWindow(window);
}
if (image != nullptr) {
stbi_image_free(image);
}
// Cleanup
ImGui_ImplOpenGL3_Shutdown();
ImGui_ImplSDL2_Shutdown();