SDL2.0_03_SDL_image Library
来源:互联网 发布:java中super的作用 编辑:程序博客网 时间:2024/05/18 03:52
扩展库SDL_Image,运行的时候需要把zlib1.dll,libjpeg-9.dll,libpng16-16.dll一同拷到目录里,不然不会报错,但就是运行没显示结果。
代码是在上一课的基础上略加修改的。
#include <iostream>#include <windows.h>#include <string>using namespace std;#include <SDL.h>#include <SDL_image.h>const int SCREEN_WIDTH = 640;const int SCREEN_HEIGHT = 480;SDL_Window *win = nullptr;SDL_Renderer *ren = nullptr;SDL_Texture * LoadImage(string file) {SDL_Texture *tex = nullptr;tex = IMG_LoadTexture(ren, file.c_str());if (tex == nullptr) {cout << "Fail to load image in function LoadImage()!" << endl;}return tex;}void ApplySurface(int x, int y, SDL_Texture *tex, SDL_Renderer *ren){SDL_Rect pos;pos.x = x;pos.y = y;SDL_QueryTexture(tex, NULL, NULL, &pos.w, &pos.h);SDL_RenderCopy(ren, tex, NULL, &pos);}int main(int argc, char** argv){if (SDL_Init(SDL_INIT_EVERYTHING) == -1) {cout << SDL_GetError() << endl;return 0;}win = SDL_CreateWindow("02:", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_RESIZABLE);if (win == nullptr) {cout << SDL_GetError() << endl;return 0;}ren = SDL_CreateRenderer(win, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);if (ren == nullptr) {cout << SDL_GetError() << endl;return 0;}SDL_Texture *bg = LoadImage("f:/material/giantShadowFlash.jpg");SDL_Texture *fg = LoadImage("F:/material/bubble.png");if (bg == nullptr || fg == nullptr) {cout << "Could not load one of the images!" << endl;return 0;}SDL_RenderClear(ren);int bw, bh;SDL_QueryTexture(bg, NULL, NULL, &bw, &bh);ApplySurface(0, 0, bg, ren);ApplySurface(bw, 0, bg, ren);ApplySurface(0, bh, bg, ren);ApplySurface(bw, bh, bg, ren);SDL_QueryTexture(fg, NULL, NULL, &bw, &bh);ApplySurface(SCREEN_WIDTH / 2 - bw / 2, SCREEN_HEIGHT / 2 - bh / 2, fg, ren);SDL_RenderPresent(ren);SDL_Delay(2000);SDL_DestroyTexture(bg);SDL_DestroyTexture(fg);SDL_DestroyRenderer(ren);SDL_DestroyWindow(win);SDL_Quit();cout << "Success!" << endl;return 0;}
0 0
- SDL2.0_03_SDL_image Library
- SDL2.0
- SDL2.0 ubuntu complie
- SDL2.0上手试用
- ffmpeg and SDL2.0
- SDL2.0上手试用
- SDL2.0 播放YUV
- sdl2.0示例
- sdl2.0_opencv
- SDL2.0+ffmpeg2.3
- SDL2.0_01_hello world!
- SDL2.0_02_functions
- SDL2.0_04_event
- SDL2.0_05_sprite sheet
- SDL2.0_06_text
- SDL2.0_07_classes
- SDL2.0_08_timer
- SDL2.0多分屏显示
- JMS消息中间件原理图
- 利用PL/SQL Developer工具导入excel数据
- 简述计算机网络和互联网的定义
- 第9周项目6年龄几何
- 第9周项目6穷举法解决组合问题(3换分币)
- SDL2.0_03_SDL_image Library
- C++ 使用Jsoncpp解析Json
- Python核心编程 练习 第七章
- 什么是ADSL?它有哪些特点
- LeetCode 题解(58): Integer to Roman
- Java 导出EXCEL
- 第九周项目二——分数的累加
- 第九周项目 6 穷举法解决组合问题(换分币)
- PopupWindow杂谈