当前位置: 首页>>代码示例>>C++>>正文


C++ Image::BlitTo方法代码示例

本文整理汇总了C++中Image::BlitTo方法的典型用法代码示例。如果您正苦于以下问题:C++ Image::BlitTo方法的具体用法?C++ Image::BlitTo怎么用?C++ Image::BlitTo使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Image的用法示例。


在下文中一共展示了Image::BlitTo方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main

int main(int argc, char *argv[])
{
    int width = 640;
    int height = 480;

    int t_time = 0;

    Image *source = NULL;
    std::string basename = "noname";
    std::string workfilename;

    if (SDL_Init(SDL_INIT_VIDEO) < 0) {
        std::cerr << "Unable to initialize SDL!\n";
        return -1;
    }

    atexit(SDL_Quit);

    if (argc >= 2) {
        try {
            source = new Image(argv[1]);
        }
        catch (const std::string &err) {
            std::cerr << "Error in image creation: " << err << "\n";
            return -1;
        }

        width = source->Width();
        height = source->Height();
        basename = argv[1];

        if (argc == 3)
            workfilename = argv[2];
    }
    else {
        std::cerr << "**** IMAGE NOT SPECIFIED ****!\n";
        return -1;
    }

    SDL_Surface *video = SDL_SetVideoMode(width * 2, height, 32, SDL_SWSURFACE);

    source->BlitTo(video, width, 0);
    SDL_UpdateRect(video, width, 0, width, height);

    if (!video) {
        std::cerr << "Unable to open window!\n";
        return -1;
    }

    Settings::ScreenHeight = source->Height();
    Settings::ScreenWidth = source->Width();

    uint64_t counter = 0;
    time_t start = ::time(NULL);
    bool running = true;
    time_t last = start;
    ::srand(start);

    /* Set time measure */
    struct timeval t_start, t_stop;
    unsigned long t_elapsed;
    gettimeofday(&t_start, NULL);

    GeneticTest gen(*source);

    if (!workfilename.empty()) {
        std::cerr << "Loading progresses from <" << workfilename << ">...\n";
        if (FILE *f = ::fopen(workfilename.c_str(), "rb")) {
            SerialLoader l(f);
            l & gen;
            ::fclose(f);
            gen.Display(video);
        }
    }

    while (running) {
        if (gen.Step()) {
            time_t now = time(NULL);

            if (now > last) {
                gen.Display(video);
                last = now;
            }
        }

        counter++;

        if ((counter % 100) == 0) {
            SDL_Event e;
            while (SDL_PollEvent(&e)) {
                if (e.type == SDL_QUIT )
                    running = false;
                else if (e.type == SDL_KEYDOWN) {
                    if (e.key.keysym.sym == SDLK_q)
                        running = false;
                    else if (e.key.keysym.sym == SDLK_s) {
                        if (FILE *f = fopen((basename + ".idx").c_str(), "wb")) {
                            SerialSaver s(f);
                            s & gen;
                            fclose(f);
//.........这里部分代码省略.........
开发者ID:isadorasophia,项目名称:genetic_cu,代码行数:101,代码来源:genetic.cpp

示例2: Display

 void Display(SDL_Surface *video) {
     drawing_.Render(dest_);
     dest_.BlitTo(video);
     SDL_UpdateRect(video, 0, 0, dest_.Width(), dest_.Height());
 }
开发者ID:isadorasophia,项目名称:genetic_cu,代码行数:5,代码来源:genetic.cpp


注:本文中的Image::BlitTo方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。