SDL1.3支持多个窗口 .

转载 2012年03月23日 14:31:03

http://blog.csdn.net/happyweb/article/details/6201655

在SDL1.2中是不支持多窗口的,而还没有正式发布的、非稳定状态下的SDL1.3是完全支持多窗口的。  

   下面是笔者写的一个简单的程序,其中创建2个视频窗口并在每一个窗口中显示不同位图:

 

#include <stdlib.h>
#include <math.h>
#include <stdio.h>
#include <tchar.h>
#include "SDL.h"
#include "SDL_shape.h"

 

void renderBlue(SDL_Renderer *renderer,SDL_Texture *texture,SDL_Rect texture_dimensions)
{
    //Clear render-target to blue.
    SDL_SetRenderDrawColor(renderer,0x00,0x00,0xff,0xff);
    SDL_RenderClear(renderer);

    //Render the texture.
    SDL_RenderCopy(renderer,texture,&texture_dimensions,&texture_dimensions);

    SDL_RenderPresent(renderer);
}

void renderRed(SDL_Renderer *renderer,SDL_Texture *texture,SDL_Rect texture_dimensions)
{
    //Clear render-target to red.
    SDL_SetRenderDrawColor(renderer,0xff,0x00,0x00,0xff);
    SDL_RenderClear(renderer);

    //Render the texture.
    SDL_RenderCopy(renderer,texture,&texture_dimensions,&texture_dimensions);

    SDL_RenderPresent(renderer);
}

int _tmain(int argc,TCHAR** argv)
{
    SDL_Color black = {0,0,0,0xff};
    Uint32 pixelFormat = 0;
    int access = 0;
    SDL_Rect texture_dimensions;;
    char *szAnsiFile="e://hello.bmp";
    char *szAnsiFile2="e://hello2.bmp";

    if(SDL_VideoInit(NULL) == -1) {
        printf("Could not initialize SDL video./n");
        exit(-2);
    }
   
    SDL_PixelFormat* pixformat = NULL;
    SDL_Window * win1 = SDL_CreateWindow("TEST1", 10, 10, 640,480, SDL_WINDOW_RESIZABLE | SDL_WINDOW_SHOWN);
    SDL_Renderer *render1 = SDL_CreateRenderer(win1,-1,0);
    SDL_Surface *imgSurface1 = SDL_LoadBMP(szAnsiFile);
    SDL_Texture *texture1 = SDL_CreateTextureFromSurface(render1,imgSurface1);
    SDL_QueryTexture(texture1,(Uint32 *)&pixelFormat,(int *)&access,&texture_dimensions.w,&texture_dimensions.h);
    SDL_SetWindowSize(win1,texture_dimensions.w,texture_dimensions.h);
    SDL_WindowShapeMode shapeMode1;
    pixformat = imgSurface1->format;
    if(pixformat->Amask != 0) {
        shapeMode1.mode = ShapeModeBinarizeAlpha;
        shapeMode1.parameters.binarizationCutoff = 255;
    }
    else {
        shapeMode1.mode = ShapeModeColorKey;
        shapeMode1.parameters.colorKey = black;
    }
    SDL_SetWindowShape(win1,imgSurface1,&shapeMode1);

    texture_dimensions.x = 0;
    texture_dimensions.y = 0;
    texture_dimensions.w = 640;
    texture_dimensions.h = 480;
    renderBlue(render1,texture1,texture_dimensions);    

    SDL_Window * win2 = SDL_CreateWindow("TEST2", 650, 10, 640,480, SDL_WINDOW_RESIZABLE | SDL_WINDOW_SHOWN);
    SDL_Renderer *render2 = SDL_CreateRenderer(win2,-1,0);
    SDL_Surface *imgSurface2 = SDL_LoadBMP(szAnsiFile2);
    SDL_Texture *texture2 = SDL_CreateTextureFromSurface(render2,imgSurface2);
    SDL_QueryTexture(texture2,(Uint32 *)&pixelFormat,(int *)&access,&texture_dimensions.w,&texture_dimensions.h);
    SDL_SetWindowSize(win2,texture_dimensions.w,texture_dimensions.h);
    SDL_WindowShapeMode shapeMode2;
   
    pixformat = imgSurface2->format;
    if(pixformat->Amask != 0) {
        shapeMode2.mode = ShapeModeBinarizeAlpha;
        shapeMode2.parameters.binarizationCutoff = 255;
    }
    else {
        shapeMode2.mode = ShapeModeColorKey;
        shapeMode2.parameters.colorKey = black;
    }
    SDL_SetWindowShape(win2,imgSurface2,&shapeMode2);

    texture_dimensions.x = 0;
    texture_dimensions.y = 0;
    texture_dimensions.w = 640;
    texture_dimensions.h = 480;
    renderRed(render2,texture2,texture_dimensions);       
    
    SDL_Delay(5000);

    SDL_DestroyTexture(texture1);
    SDL_DestroyRenderer(render1);
    SDL_DestroyWindow(win1);
    SDL_FreeSurface(imgSurface1);

    SDL_DestroyTexture(texture2);
    SDL_DestroyRenderer(render2);
    SDL_DestroyWindow(win2);
    SDL_FreeSurface(imgSurface2);

    //Call SDL_VideoQuit() before quitting.
    SDL_VideoQuit();

    return 0;
}

相关文章推荐

SDL1.3支持多个窗口

SDL1.3 视频双窗口 多窗口 多媒体

qt中用SDL 1.3实现播放视频双窗口

思路: 1。跳过由sdl直接创建弹出窗口,那么它的窗口应该是QT指定的窗口。 2。给SDL传递窗口Handle,由SDL_getenv("SDL_WINDOWID")来实现 3。在SDL调用系统...

【C语言探索之旅】 第三部分第二课:SDL开发游戏之创建窗口和画布

SDL程序在开始处需要使用SDL_Init函数来加载,在结尾处要使用SDL_Quit函数来卸载。 flag(标记)是一些常量,这些常量可以用按位或操作符“|”来连接,就好像相加一般,使多个特性可以同时...

SDL-1.3源码

  • 2012-12-27 16:43
  • 9.07MB
  • 下载

SDL-1.3.zip

  • 2015-11-03 19:47
  • 5.22MB
  • 下载

SDL2.0显示图形窗口

SDL2.0基础学习。填充Surface全白色,并弹出Window显示2秒钟。

android ndk 移植的sdl-1.3

  • 2013-02-17 11:41
  • 11.32MB
  • 下载

用SDL创建一个窗口

 原文来自:http://www.aaroncox.net/tutorials/2dtutorials/sdlwindow.html 注意:这里我们想当然你已经知道怎么在你的IDE集成开发环境...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

(最多只允许输入30个字)