// sdl2_win32.cpp : Defines the entry point for the console application.
//
// 假定SDL的库文件和头文件和VC的工程文件在一起.
#include "stdafx.h"
#include "SDL2-2.0.4/include/SDL.h"
#pragma comment(lib, "SDL2-2.0.4/lib/x86/sdl2.lib")

#include <iostream>

void pressESCtoQuit();

int _tmain(int argc, _TCHAR* argv[])
{
    try {
        if ( SDL_Init(SDL_INIT_VIDEO) != 0 )
            throw SDL_GetError();
    }
    catch ( const char* s ) {
        std::cerr << "SDL_Init() failed!\n" << s << std::endl;
        return -1;
    }

const int SCREEN_WIDTH = 640;    // 0 means use current width.
    const int SCREEN_HEIGHT = 480;    // 0 means use current height.
    const int SCREEN_BPP = 32;        // 0 means use current bpp.
    const Uint32 SCREEN_FLAGS = SDL_SWSURFACE;    // SDL_SWSURFACE == 0,surface in system memory.

SDL_Surface* pScreen = 0;
    SDL_Window* win = SDL_CreateWindow("title", 0,0,SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_FLAGS); // SDL1.X叫SDL_SetVideoMode()
    pScreen = SDL_GetWindowSurface(win); // 相比SDL1.X多一步
    try {
        if ( pScreen == 0 )
            throw SDL_GetError();
    }
    catch ( const char* s ) {
        std::cerr << "SDL_SetVideoMode() failed!\n" << s << std::endl;
        SDL_Quit();
        return -1;
    }

SDL_Surface* pShownBMP = 0;
    pShownBMP = SDL_LoadBMP("hello.bmp"); // Load a BMP file, and convert it as a surface.
    try {
        if ( pShownBMP == 0 )
            throw SDL_GetError();
    }
    catch ( const char* s ) {
        std::cerr << "SDL_LoadBMP() failed!\n" << s << std::endl;
        SDL_Quit();
        return -1;
    }

SDL_Rect* pSrcRect = 0;    // If pSrcRect is NULL, the entire source surface is copied.

SDL_Rect* pDstRect = 0;    // If pDstRect is NULL, then the destination position (upper left corner) is (0, 0).
    try {
        if ( SDL_BlitSurface(pShownBMP, pSrcRect, pScreen, pDstRect) != 0 )    // Put the BMP's surface on the SDL window's surface.
            throw SDL_GetError();
    }
    catch ( const char* s ) {
        std::cerr << "SDL_BlitSurface() failed!\n" << s << std::endl;
        SDL_Quit();
        return -1;
    }
    
    try {
        if ( SDL_UpdateWindowSurface(win) != 0 )    // Show the SDL window's surface. SDL1.X叫SDL_Flip
          throw SDL_GetError();
    }
    catch ( const char* s ) {
        std::cerr << "SDL_Flip() failed!\n" << s << std::endl;
        SDL_Quit();
        return -1;
    }

pressESCtoQuit();
    SDL_Quit();

return 0;
}

void pressESCtoQuit()
{
    bool gameOver = false;
    while( gameOver == false ){
        SDL_Event gameEvent;
        while ( SDL_PollEvent(&gameEvent) != 0 ){
            if ( gameEvent.type == SDL_QUIT ){
                gameOver = true;
            }
            if ( gameEvent.type == SDL_KEYUP ){
                if ( gameEvent.key.keysym.sym == SDLK_ESCAPE ){
                    gameOver = true;
                }
            }
        }
    }
    return;
}

sdl2-2.04 读取位图并显示的更多相关文章

  1. opencv从txt文本读取像素点并显示

    opencv从txt文本读取像素点并显示 文本储存格式为每行一个像素点,排列为RGB.每帧图像的帧头为65535.  如下图所示 废话不多说,代码如下: // #include <iostrea ...

  2. 从多个XML文档中读取数据用于显示webapi帮助文档

    前言: 你先得知道HelpPageConfig文件,不知道说明你现在不需要这个,所以下文就不用看了,等知道了再看也不急.当然如果你很知道这个,下文也不用看了,因为你会了. 方法一: new XmlDo ...

  3. MFC中位图的显示

    分析: 首先,我们要明确一点,窗口的绘制包括两个步骤,首先:擦除窗口背景,然后再对窗口重新进行绘制:当擦除窗口背景时,程序会发生一个WM_ERASEBKGND消息,因此可以在此响应函数中完成位图的显示 ...

  4. [问题解决]Fresco设置占位图不显示的问题

    [问题解决]Fresco设置占位图不显示的问题 /** * Created by diql on 2017/02/15. */ 问题说明 本来设置占位图是通过以下方法: public void set ...

  5. 【WPF学习笔记】之如何把数据库里的值读取出来然后显示在页面上:动画系列之(六)(评论处有学习资料及源码)

    (应博友们的需要,在文章评论处有源码链接地址,以及WPF学习资料.工具等,希望对大家有所帮助) ...... 承接系列五 上一节讲了,已经把数据保存到数据库并且删除数据,本讲是把已经存在的数据从数据库 ...

  6. Ext.net自动保存读取GrdPanel列显示状态

    //layout保存 function SaveLayOut() { let colVisibleArray = []; for (var i = 0; i < mcp_gridlist.col ...

  7. shell-bash学习04读取输入、分隔符、流程控制

    读入输出 输入通常是通过stdin或参数传递给命令; 输出出现在stderr或stdout; 管道,过滤器,管道操作符: cmd1 | cmd2 | cmd3; //最后还有输出 ls | cat - ...

  8. android从资源文件中读取文件流显示

    在android中,假如有的文本文件,比如TXT放在raw下,要直接读取出来,放到屏幕中显示,可以这样:代码区: private void doRaw(){ InputStream is = this ...

  9. ubuntu10.04编译内核不显示grub菜单解决

    问题描述:        ubuntu10.04 内核版本2.6.32.28编译内核之后版本2.6.37.6,系统在编译完内核之后,不显示grub菜单 参考资料:            http:// ...

随机推荐

  1. C#实现大数据量TXT文本数据快速高效去重

    原文 C#实现大数据量TXT文本数据快速高效去重 对几千万的TXT文本数据进行去重处理,查找其中重复的数据,并移除.尝试了各种方法,下属方法是目前尝试到最快的方法.以下代码将重复和不重复数据进行分文件 ...

  2. HDU 5919 Sequence II(可持久化线段树)

    [题目链接]http://acm.hdu.edu.cn/showproblem.php?pid=5919 [题目大意] 给出一个数列,每次查询数列中,区间非重元素的下标的中位数.查询操作强制在线. [ ...

  3. How do I pull a native DOM element from a jQuery object? | jQuery Learning Center

    How do I pull a native DOM element from a jQuery object? | jQuery Learning Center How do I pull a na ...

  4. 套接字socket 的地址族和类型、工作原理、创建过程

    注:本分类下文章大多整理自<深入分析linux内核源代码>一书,另有参考其他一些资料如<linux内核完全剖析>.<linux c 编程一站式学习>等,只是为了更好 ...

  5. Docker之dockerfile

    一.什么是dockerfile Docker通过对于在dockerfile中的一系列指令的顺序解析实现自动的Image的构建: 通过使用build命令,根据dockerfile的描述来构建镜像: bu ...

  6. VS EF Error: Configuration Error extension=".edmx" type="System.Data.Entity.Design.AspNet.EntityDesignerBuildProvider"

    错误截图: Configuration Error :<add extension=".edmx" type="System.Data.Entity.Design. ...

  7. Jquery $.extend的重载方法详述

    1 $.extend(result,item1,item2,item3,........)  -这个重载方法主要是用来合并,将所有的参数都合并到result中,并返回result,但是这样会破坏res ...

  8. 用jersey + spring 实现rest服务及单元测试

    jersey提供了强大的rest功能,可以通过简洁的标注和编码实现业务的需求,架构会透明的把你的pojo对象转化为客户端可以接受的json/xml文件模式,当然也可以用它做一些基于ajax的表单提交和 ...

  9. Unity UGUI在鼠标位置不同时 图片浮动效果

    /// <summary> /// 在鼠标位置不同时 图片浮动效果 /// </summary> public class TiltWindow : MonoBehaviour ...

  10. 关于php支持的协议与封装协议

    <?php /* * php://stdin 标准输入流 * php://stdout 标准输入流 * php://stderr 标准错误流 * php://output 只写的数据流 * ph ...