关闭

SDL1.3支持多个窗口 .

标签: accessnulldelay
1222人阅读 评论(0) 收藏 举报
分类:

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;
}

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:115042次
    • 积分:1603
    • 等级:
    • 排名:千里之外
    • 原创:25篇
    • 转载:143篇
    • 译文:0篇
    • 评论:10条
    文章分类
    最新评论