Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to display the same texture with different scale modes? #7616

Open
achabense opened this issue May 23, 2024 · 1 comment
Open

How to display the same texture with different scale modes? #7616

achabense opened this issue May 23, 2024 · 1 comment

Comments

@achabense
Copy link

Version/Branch of Dear ImGui:

Version 1.90.6

Back-ends:

imgui_impl_sdl2.cpp + imgui_impl_sdlrenderer2.cpp

Compiler, OS:

Windows 10 + MSVC 2022

Full config/build information:

No response

Details:

I want to display the same texture in different scale modes. The screenshot shows the effect of test_fn below. Can I achieve the same effect without creating multiple textures?

Screenshots/Video:

image

Minimal, Complete and Verifiable Example code:

static void test_fn(SDL_Renderer* renderer) {
    static SDL_Texture *nearest = nullptr, *linear = nullptr;
    const int w = 33, h = 25;
    const int zoom = 4;

    if (!nearest) {
        nearest = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_ABGR8888, SDL_TEXTUREACCESS_STATIC, w, h);
        SDL_SetTextureScaleMode(nearest, SDL_ScaleModeNearest);
        linear = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_ABGR8888, SDL_TEXTUREACCESS_STATIC, w, h);
        SDL_SetTextureScaleMode(linear, SDL_ScaleModeLinear);
        Uint32 pixels[h][w];
        bool b = false;
        for (auto& line : pixels) {
            for (Uint32& p : line) {
                p = b ? 0 : -1;
                b = !b;
            }
        }
        SDL_UpdateTexture(nearest, nullptr, pixels, w * sizeof(Uint32));
        SDL_UpdateTexture(linear, nullptr, pixels, w * sizeof(Uint32));
    }

    if (ImGui::Begin("Test", nullptr, ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoCollapse)) {
        ImGui::Image(nearest, ImVec2(w * zoom, h * zoom));
        ImGui::SameLine();
        ImGui::Image(linear, ImVec2(w * zoom, h * zoom));
    }
    ImGui::End();
}
@achabense
Copy link
Author

achabense commented May 26, 2024

Here is the background of this issue: I wanted to display a zoom window in nearest scale mode for a texture shown in linear mode. The problem was worked around by making a new texture with different scale mode, but I think the solution is wasteful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants