- 本节课学习使用SDL2封装一个透明背景的window,并在window上使用SDL_Renderer和SDL_Texture进行绘图
- 圆形没有反走样
- 计算机几何算法B站有个
孔令德
老师讲课挺好的,建议看看
(我只看了两节课,后面工作不忙了再认真看,图论与网络流还没开始看,把SDL和GTK大致学一下再去看把,档期可能要排到明年才能开始看了)
-
在windows上要想让
SDL_Window
和linux不太一样(linux可以直接读取css设置)- 经过多次google终于在这个网址找到了做法
http://5.9.10.113/67609916/fully-transparent-window-with-opaque-elements-in-sdl-2
链接 - 以下为代码网址上copy的代码
#include <stdio.h> #include <SDL.h> #include <SDL_image.h> #include <SDL_syswm.h> #include <iostream> #include <Windows.h> #include <string> SDL_Window *window; SDL_Renderer *renderer; SDL_Texture *image; int imageWidth = 0; int imageHeight = 0; bool init() { //Initialize SDL if (SDL_Init(SDL_INIT_VIDEO) != 0) { printf("SDL could not initialize! SDL Error: %s\n", SDL_GetError()); return false; } //Set texture filtering to linear if (!SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "1")) { printf("Warning: Linear texture filtering not enabled!"); } //Create window window = SDL_CreateWindow("SDL Tutorial", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 500, 300, SDL_WINDOW_SHOWN | SDL_WINDOW_BORDERLESS); if (window == NULL) { printf("Window could not be created! SDL Error: %s\n", SDL_GetError()); return false; } //Create renderer for window renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC); if (renderer == NULL) { printf("Renderer could not be created! SDL Error: %s\n", SDL_GetError()); return false; } //Initialize renderer color SDL_SetRenderDrawColor(renderer, 255, 255, 0, 255); //Initialize PNG loading int imgFlags = IMG_INIT_PNG; if (!(IMG_Init(imgFlags) & imgFlags)) { printf("SDL_image could not initialize! SDL_image Error: %s\n", IMG_GetError()); return false; } return true; } bool loadImage(const std::string &path) { //The final texture SDL_Texture *newImage = NULL; //Load image at specified path SDL_Surface *loadedSurface = IMG_Load(path.c_str()); if (!loadedSurface) { printf("Unable to load image %s! SDL_image Error: %s\n", path.c_str(), IMG_GetError()); return false; } //Create texture from surface pixels newImage =
- 经过多次google终于在这个网址找到了做法