资源简介
两张png图片叠加在一起,使用SDL让前景色透明
代码片段和文件信息
#include “stdafx.h“
#include “include/SDL.h“
#include “SDL2_image/include/SDL_image.h“
#pragma comment(lib “lib/x86/SDL2.lib“)
#pragma comment(lib “SDL2_image/lib/x86/SDL2_image.lib“)
int _tmain(int argc _TCHAR* argv[])
{
SDL_Init(SDL_INIT_EVERYTHING);//SDL初始化
SDL_Window *Screen = SDL_CreateWindow(“title“ 100 100 640 480 SDL_WINDOW_RESIZABLE);//创建窗口
SDL_Renderer *render = SDL_CreateRenderer(Screen -1 0);//创建渲染器
SDL_Surface *bk = IMG_Load(“F:\\background.png“);//SDL IMAGE扩展库读取tga图片
SDL_Surface *foo = IMG_Load(“F:\\foo.png“);//SDL IMAGE扩展库读取tga图片
//Use this function to map an RGB triple to an opaque pixel value for a given pixel format
//format:an SDL_PixelFormat structure describing the format of the pixel
Uint32 colorkey = SDL_MapRGB(foo->format 0x00 0xff 0xff);//用画图工具提取foo.png的背景颜色发现foo.png的背景色是0x00ffff
//surface:the SDL_Surface structure to update
//flag:SDL_TRUE to enable color key SDL_FALSE to disable color key
//key:the transparent pixel
//Returns 0 on success or a negative error code on failure; call SDL_GetError() for more information.
SDL_SetColorKey(foo 1 colorkey);//Use this function to set the color key (transparent pixel) in a surface.
SDL_Texture *texture = SDL_CreateTextureFromSurface(render bk);//创建纹理
SDL_Texture *texture1 = SDL_CreateTextureFromSurface(render foo);//创建纹理
SDL_RenderClear(render);
SDL_RenderCopy(render texture NULL NULL);//拷贝数据显示
SDL_Rect rect;
rect.x = 50;
rect.y = 125;
rect.w = foo->w;
rect.h = foo->h;
SDL_RenderCopy(render texture1 NULL &rect);//拷贝数据显示
SDL_RenderPresent(render);
SDL_Event event;
while (1){
SDL_PollEvent(&event);
if (event.type == SDL_QUIT){
break;
}
}
SDL_FreeSurface(bk);//是否图片资源
SDL_DestroyTexture(texture);//释放纹理
SDL_DestroyRenderer(render);//释放渲染器
SDL_DestroyWindow(Screen);//销毁窗口
SDL_Quit();//退出
return 0;
}
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 3718 2005-06-17 19:30 SDL_Lesson1\Debug\bk.png
文件 548 2005-06-17 19:30 SDL_Lesson1\Debug\foo.png
文件 223232 2016-01-02 21:52 SDL_Lesson1\Debug\libjpeg-9.dll
文件 200704 2016-01-02 21:52 SDL_Lesson1\Debug\libpng16-16.dll
文件 436224 2016-01-02 21:52 SDL_Lesson1\Debug\libtiff-5.dll
文件 271872 2016-01-02 21:52 SDL_Lesson1\Debug\libwebp-4.dll
文件 1068544 2016-10-19 20:58 SDL_Lesson1\Debug\SDL2.dll
文件 93184 2016-01-02 21:52 SDL_Lesson1\Debug\SDL2_image.dll
文件 32768 2017-06-22 13:38 SDL_Lesson1\Debug\SDL_Lesson1.exe
文件 123904 2016-01-02 21:52 SDL_Lesson1\Debug\zlib1.dll
文件 4182 2016-10-19 20:59 SDL_Lesson1\SDL_Lesson1\include\begin_code.h
文件 1417 2016-10-19 20:59 SDL_Lesson1\SDL_Lesson1\include\close_code.h
文件 4101 2016-10-19 20:59 SDL_Lesson1\SDL_Lesson1\include\SDL.h
文件 10860 2016-10-19 20:59 SDL_Lesson1\SDL_Lesson1\include\SDL_assert.h
文件 9458 2016-10-19 20:59 SDL_Lesson1\SDL_Lesson1\include\SDL_atomic.h
文件 28133 2016-10-19 20:59 SDL_Lesson1\SDL_Lesson1\include\SDL_audio.h
文件 2527 2016-10-19 20:59 SDL_Lesson1\SDL_Lesson1\include\SDL_bits.h
文件 2252 2016-10-19 20:59 SDL_Lesson1\SDL_Lesson1\include\SDL_blendmode.h
文件 1966 2016-10-19 20:59 SDL_Lesson1\SDL_Lesson1\include\SDL_clipboard.h
文件 5722 2016-10-19 20:59 SDL_Lesson1\SDL_Lesson1\include\SDL_config.h
文件 4181 2016-10-19 20:59 SDL_Lesson1\SDL_Lesson1\include\SDL_cpuinfo.h
文件 73519 2016-10-19 20:59 SDL_Lesson1\SDL_Lesson1\include\SDL_egl.h
文件 5944 2016-10-19 20:59 SDL_Lesson1\SDL_Lesson1\include\SDL_endian.h
文件 2271 2016-10-19 20:59 SDL_Lesson1\SDL_Lesson1\include\SDL_error.h
文件 28067 2016-10-19 20:59 SDL_Lesson1\SDL_Lesson1\include\SDL_events.h
文件 5255 2016-10-19 20:59 SDL_Lesson1\SDL_Lesson1\include\SDL_filesystem.h
文件 10824 2016-10-19 20:59 SDL_Lesson1\SDL_Lesson1\include\SDL_gamecontroller.h
文件 2157 2016-10-19 20:59 SDL_Lesson1\SDL_Lesson1\include\SDL_gesture.h
文件 38621 2016-10-19 20:59 SDL_Lesson1\SDL_Lesson1\include\SDL_haptic.h
文件 32393 2016-10-19 20:59 SDL_Lesson1\SDL_Lesson1\include\SDL_hints.h
............此处省略110个文件信息
- 上一篇:libcurl 以JSON模式post
- 下一篇:快递包裹代收系统
评论
共有 条评论