c++ - Set transparent SDL window background - Stack Overflow

Having the following simple PNG image rendering example:#include <Windows.h>#include <stdlib

Having the following simple PNG image rendering example:

#include <Windows.h>
#include <stdlib.h>
#include <SDL.h>
#include <SDL_image.h>
#include <iostream>

char g_buffer[100];

int WINAPI WinMain(HINSTANCE hThisInst, HINSTANCE hPrevInst, LPSTR str, int nWinMode) {

    SDL_Event event;
    SDL_Renderer* renderer = NULL;
    SDL_Texture* texture = NULL;
    SDL_Texture* texture2 = NULL;
    SDL_Window* window = NULL;

    SDL_Init(SDL_INIT_TIMER | SDL_INIT_VIDEO);
    SDL_CreateWindowAndRenderer(
        400, 400,
        0, &window, &renderer
    );

    IMG_Init(IMG_INIT_PNG);

    texture = IMG_LoadTexture(renderer, "D:/Pobrane_2/flower.png");
    if (!texture)
    {
        sprintf(g_buffer, "IMG_LoadTexture error: %s\n", SDL_GetError());
        MessageBox(NULL, g_buffer, "Error!", MB_OK | MB_ICONINFORMATION);
        g_buffer[0] = 0;
        return 1;
    }

    while (1) {
        // Select the color for drawing. It is set to red here.
        SDL_SetRenderDrawColor(renderer, 255, 0, 0, 255);
        // Clear the entire screen to our selected color.
        SDL_RenderClear(renderer);
        SDL_RenderCopy(renderer, texture, NULL, NULL);
        SDL_RenderPresent(renderer);
        if (SDL_PollEvent(&event) && event.type == SDL_QUIT)
            break;
    }
    SDL_DestroyTexture(texture);
    IMG_Quit();
    SDL_DestroyRenderer(renderer);
    SDL_DestroyWindow(window);
    SDL_Quit();
    return EXIT_SUCCESS;
}

How can one make the window background color transparent instead of solid red just to see what's behind the app window (for e.g. windows desktop)? I'd prefer platform independent code if possible.

Note: this is not a duplicate of my previous question: Making window background transparent

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742328204a4423177.html

相关推荐

  • c++ - Set transparent SDL window background - Stack Overflow

    Having the following simple PNG image rendering example:#include <Windows.h>#include <stdlib

    9小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信