C/C++知识点之mac 中 用 qt配置 SDL 2
顾宇峰 2019-04-10 来源 : 阅读 1502 评论 0

摘要:本文主要向大家介绍了C/C++知识点之mac 中 用 qt配置 SDL 2,通过具体的内容向大家展示,希望对大家学习C/C++知识点有所帮助。

本文主要向大家介绍了C/C++知识点之mac 中 用 qt配置 SDL 2,通过具体的内容向大家展示,希望对大家学习C/C++知识点有所帮助。

C/C++知识点之mac 中 用 qt配置 SDL 2

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+频道!

本文由 @职坐标 发布于职坐标。未经许可,禁止转载。
喜欢 | 0 不喜欢 | 0
看完这篇文章有何感觉?已经有0人表态,0%的人喜欢 快给朋友分享吧~
评论(0)
后参与评论
本文作者 联系TA

2年研发与教育经验

  • 10
    文章
  • 2517
    人气
  • 0%
    受欢迎度

已有0人表明态度,0%喜欢该老师!

进入TA的空间
求职秘籍 直通车
  • 索取资料 索取资料 索取资料
  • 答疑解惑 答疑解惑 答疑解惑
  • 技术交流 技术交流 技术交流
  • 职业测评 职业测评 职业测评
  • 面试技巧 面试技巧 面试技巧
  • 高薪秘笈 高薪秘笈 高薪秘笈
TA的其他文章 更多>>
C/C++知识点之哈希表—位图
经验技巧 100% 的用户喜欢
C/C++知识点之哈希表详解
经验技巧 0% 的用户喜欢
C/C++知识点之container_of 和 offsetof宏
经验技巧 0% 的用户喜欢
C/C++知识点之平衡二叉树
经验技巧 0% 的用户喜欢
C/C++知识点之c++ 6种排序算法 源代码
经验技巧 0% 的用户喜欢
其他海同师资 更多>>
吕益平
吕益平 联系TA
熟悉企业软件开发的产品设计及开发
孔庆琦
孔庆琦 联系TA
对MVC模式和三层架构有深入的研究
周鸣君
周鸣君 联系TA
擅长Hadoop/Spark大数据技术
范佺菁
范佺菁 联系TA
擅长Java语言,只有合理的安排和管理时间你才能做得更多,行得更远!
金延鑫
金延鑫 联系TA
擅长与学生或家长及时有效沟通
经验技巧30天热搜词 更多>>

您输入的评论内容中包含违禁敏感词

我知道了

助您圆梦职场 匹配合适岗位
验证码手机号,获得海同独家IT培训资料
选择就业方向:
人工智能物联网
大数据开发/分析
人工智能Python
Java全栈开发
WEB前端+H5

请输入正确的手机号码

请输入正确的验证码

获取验证码

您今天的短信下发次数太多了,明天再试试吧!

提交

我们会在第一时间安排职业规划师联系您!

您也可以联系我们的职业规划师咨询:

小职老师的微信号:z_zhizuobiao
小职老师的微信号:z_zhizuobiao

版权所有 职坐标-一站式IT培训就业服务领导者 沪ICP备13042190号-4
上海海同信息科技有限公司 Copyright ©2015 www.zhizuobiao.com,All Rights Reserved.
 沪公网安备 31011502005948号    

©2015 www.zhizuobiao.com All Rights Reserved

208小时内训课程