摘要:本文主要向大家介绍了C/C++知识点之mac 中 用 qt配置 SDL 2,通过具体的内容向大家展示,希望对大家学习C/C++知识点有所帮助。
本文主要向大家介绍了C/C++知识点之mac 中 用 qt配置 SDL 2,通过具体的内容向大家展示,希望对大家学习C/C++知识点有所帮助。
1.安装SDL 2
2.同样也是各种动态与静态问题。也可以直接用官网上的。
主要是他默认只能显示bmp格式的图片。同时要加上(SDL_Delay(2000000000000);//延时2000毫秒,2s后自动关闭)不然看不到
#-------------------------------------------------## Project created by QtCreator 2018-03-09T13:30:28##-------------------------------------------------QT += core gui greaterThan(QT_MAJOR_VERSION, 4): QT += widgets TARGET = testsdl TEMPLATE = app# The following define makes your compiler emit warnings if you use# any feature of Qt which as been marked as deprecated (the exact warnings# depend on your compiler). Please consult the documentation of the# deprecated API in order to know how to port your code away from it.DEFINES += QT_DEPRECATED_WARNINGS# You can also make your code fail to compile if you use deprecated APIs.# In order to do so, uncomment the following line.# You can also select to disable deprecated APIs only up to a certain version of Qt.#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0SOURCES += main.cpp\ mainwindow.cpp HEADERS += mainwindow.h FORMS += mainwindow.ui INCLUDEPATH+=/usr/local/include#INCLUDEPATH+=/usr/local/Cellar/sdl2/2.0.8/includeLIBS += -L/usr/local/Cellar/sdl2/2.0.8/lib -lSDL2_test -lSDL2 -lSDL2main
#include ""mainwindow.h""#include <QApplication>#include ""SDL2/SDL.h""#include <iostream>#undef mainusing namespace std;const int SCREEN_WIDTH = 640;const int SCREEN_HEIGHT = 480;int main(int argc, char *argv[]){ QApplication a(argc, argv); MainWindow w;// w.show(); //The window we'll be rendering to SDL_Window* gWindow = NULL; //The surface contained by the window SDL_Surface* gScreenSurface = NULL; //The image we will load and show on the screen SDL_Surface* gHelloWorld = NULL; //首先初始化 初始化SD视频子系统 if(SDL_Init(SDL_INIT_VIDEO)<0) { printf( ""Window could not be created! SDL_Error: %s\n"", SDL_GetError() ); return false; } //创建窗口 gWindow=SDL_CreateWindow(""SHOW BMP"",//窗口标题 SDL_WINDOWPOS_UNDEFINED,//窗口位置设置 SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH,//窗口的宽度 SCREEN_HEIGHT,//窗口的高度 SDL_WINDOW_SHOWN//显示窗口 ); if(gWindow==NULL) { printf( ""Window could not be created! SDL_Error: %s\n"", SDL_GetError() ); return false; } //Use this function to get the SDL surface associated with the window. //获取窗口对应的surface gScreenSurface=SDL_GetWindowSurface(gWindow); //加载图片 gHelloWorld = SDL_LoadBMP(""/Users/allenboy/Desktop/allen.bmp"");//加载图片 if( gHelloWorld == NULL ) { printf( ""Unable to load image %s! SDL Error: %s\n"", ""Hello_World.bmp"", SDL_GetError() ); return false; } //Use this function to perform a fast surface copy to a destination surface. //surface的快速复制 //下面函数的参数分别为: SDL_Surface* src ,const SDL_Rect* srcrect , SDL_Surface* dst , SDL_Rect* dstrect SDL_BlitSurface( gHelloWorld ,NULL,gScreenSurface,NULL); SDL_UpdateWindowSurface(gWindow);//更新显示copy the window surface to the screen SDL_Delay(2000000000000);//延时2000毫秒,2s后自动关闭 //释放内存 SDL_FreeSurface( gHelloWorld );//释放空间 gHelloWorld = NULL; SDL_DestroyWindow(gWindow);//销毁窗口 gWindow = NULL ; SDL_Quit();//退出SDL return 0; return a.exec(); }
本文由职坐标整理并发布,希望对同学们有所帮助。了解更多详情请关注职坐标编程语言C/C+频道!
您输入的评论内容中包含违禁敏感词
我知道了
请输入正确的手机号码
请输入正确的验证码
您今天的短信下发次数太多了,明天再试试吧!
我们会在第一时间安排职业规划师联系您!
您也可以联系我们的职业规划师咨询:
版权所有 职坐标-一站式IT培训就业服务领导者 沪ICP备13042190号-4
上海海同信息科技有限公司 Copyright ©2015 www.zhizuobiao.com,All Rights Reserved.
沪公网安备 31011502005948号