Exemple #1
0
//Perform frame by frame updates and blits. Set the stream
//state to STOP if there are no more frames to update.
void RenderToSurface(BITMAP *vscreen) {
    //update each frame
    if (g_pSample->Update(0, NULL, NULL, 0) != S_OK) {
        g_bAppactive = FALSE;
        g_pMMStream->SetState(STREAMSTATE_STOP);
    }
    else {
        g_bAppactive = TRUE;
        acquire_screen();
        // Because vscreen is a DX Video Bitmap, it can be stretched
        // onto the screen (also a Video Bmp) but not onto a memory
        // bitmap (which is what "screen" is when using gfx filters)
        if (is_video_bitmap(screen))
        {
            stretch_blit(vscreen, screen, 0, 0, vscreen->w, vscreen->h,
                         screen->w / 2 - newWidth / 2,
                         screen->h / 2 - newHeight / 2,
                         newWidth, newHeight);
        }
        else
        {
            blit(vscreen, vsMemory, 0, 0, 0, 0, vscreen->w, vscreen->h);
            stretch_blit(vsMemory, screen, 0, 0, vscreen->w, vscreen->h,
                         screen->w / 2 - newWidth / 2,
                         screen->h / 2 - newHeight / 2,
                         newWidth, newHeight);
        }
        release_screen();

        render_to_screen(screen, 0, 0);
        // if we're not playing AVI sound, poll the game MP3
        if (!useSound)
            update_polled_stuff_and_crossfade();
    }
}
Exemple #2
0
static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods) {
    if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS) {
        glfwSetWindowShouldClose(window, GL_TRUE);
    }
    if (key == GLFW_KEY_SPACE && action == GLFW_PRESS) {
        render_to_screen();
    }
    if (key == GLFW_KEY_S && action == GLFW_PRESS) {
        save_to_png(NULL);
        // render_to_png(NULL);
    }
}
Exemple #3
0
int theora_playing_callback(BITMAP *theoraBuffer)
{
  if (theoraBuffer == NULL)
  {
    // No video, only sound
    return check_if_user_input_should_cancel_video();
  }

  int drawAtX = 0, drawAtY = 0;
  if (fli_ddb == NULL)
  {
    fli_ddb = gfxDriver->CreateDDBFromBitmap(theoraBuffer, false, true);
  }
  if (stretch_flc) 
  {
    drawAtX = scrnwid / 2 - fliTargetWidth / 2;
    drawAtY = scrnhit / 2 - fliTargetHeight / 2;
    if (!gfxDriver->HasAcceleratedStretchAndFlip())
    {
      stretch_blit(theoraBuffer, fli_target, 0, 0, BMP_W(theoraBuffer), BMP_H(theoraBuffer), 
                   drawAtX, drawAtY, fliTargetWidth, fliTargetHeight);
      gfxDriver->UpdateDDBFromBitmap(fli_ddb, fli_target, false);
      drawAtX = 0;
      drawAtY = 0;
    }
    else
    {
      gfxDriver->UpdateDDBFromBitmap(fli_ddb, theoraBuffer, false);
      fli_ddb->SetStretch(fliTargetWidth, fliTargetHeight);
    }
  }
  else
  {
    gfxDriver->UpdateDDBFromBitmap(fli_ddb, theoraBuffer, false);
    drawAtX = scrnwid / 2 - BMP_W(theoraBuffer) / 2;
    drawAtY = scrnhit / 2 - BMP_H(theoraBuffer) / 2;
  }

  gfxDriver->DrawSprite(drawAtX, drawAtY, fli_ddb);
  render_to_screen(virtual_screen, 0, 0);
  update_polled_stuff_and_crossfade ();

  return check_if_user_input_should_cancel_video();
}
Exemple #4
0
int __cdecl fli_callback() {
#else
int fli_callback(...) {
#endif
  block usebuf = fli_buffer;

  update_polled_stuff_and_crossfade ();

  if (game.color_depth > 1) {
    blit(fli_buffer,hicol_buf,0,0,0,0,fliwidth,fliheight);
    usebuf=hicol_buf;
  }
  if (stretch_flc == 0)
    blit(usebuf, fli_target, 0,0,scrnwid/2-fliwidth/2,scrnhit/2-fliheight/2,scrnwid,scrnhit);
  else 
    stretch_blit(usebuf, fli_target, 0,0,fliwidth,fliheight,0,0,scrnwid,scrnhit);

  gfxDriver->UpdateDDBFromBitmap(fli_ddb, fli_target, false);
  gfxDriver->DrawSprite(0, 0, fli_ddb);
  render_to_screen(fli_target, 0, 0);

  return check_if_user_input_should_cancel_video();
}
Exemple #5
0
/* *** SCRIPT SYMBOL: [Multimedia] PlayFlic *** */
void play_flc_file(int numb,int playflags) {
  color oldpal[256];

  if (play.fast_forward)
    return;

  wreadpalette(0,255,oldpal);

  int clearScreenAtStart = 1;
  canabort = playflags % 10;
  playflags -= canabort;

  if (canabort == 2) // convert to PlayVideo-compatible setting
    canabort = 3;

  if (playflags % 100 == 0)
    stretch_flc = 1;
  else
    stretch_flc = 0;

  if (playflags / 100)
    clearScreenAtStart = 0;

  char flicnam[20]; sprintf(flicnam,"flic%d.flc",numb);
  FILE*iii=clibfopen(flicnam,"rb");
  if (iii==NULL) { sprintf(flicnam,"flic%d.fli",numb);
    iii=clibfopen(flicnam,"rb"); }
  if (iii==NULL) {
    debug_log("FLIC animation FLIC%d.FLC not found",numb);
    return;
    }
  fseek(iii,8,SEEK_CUR);
  fread(&fliwidth,2,1,iii);
  fread(&fliheight,2,1,iii);
  fclose(iii);
  if (game.color_depth > 1) {
    hicol_buf=create_bitmap_ex(final_col_dep,fliwidth,fliheight);
    clear(hicol_buf);
    }
  // override the stretch option if necessary
  if ((fliwidth==scrnwid) && (fliheight==scrnhit))
    stretch_flc = 0;
  else if ((fliwidth > scrnwid) || (fliheight > scrnhit))
    stretch_flc = 1;
  fli_buffer=create_bitmap_ex(8,fliwidth,fliheight); //640,400); //scrnwid,scrnhit);
  if (fli_buffer==NULL) quit("Not enough memory to play animation");
  clear(fli_buffer);

  if (clearScreenAtStart) {
    clear(screen);
    render_to_screen(screen, 0, 0);
  }

  fli_target = create_bitmap_ex(final_col_dep, BMP_W(screen), BMP_H(screen));
  fli_ddb = gfxDriver->CreateDDBFromBitmap(fli_target, false, true);

  if (play_fli(flicnam,fli_buffer,0,fli_callback)==FLI_ERROR)
    quit("FLI/FLC animation play error");

  wfreeblock(fli_buffer);
  clear(screen);
  wsetpalette(0,255,oldpal);
  render_to_screen(screen, 0, 0);

  destroy_bitmap(fli_target);
  gfxDriver->DestroyDDB(fli_ddb);
  fli_ddb = NULL;

  if (hicol_buf!=NULL) {
    wfreeblock(hicol_buf);
    hicol_buf=NULL; }
//  wsetscreen(screen); wputblock(0,0,backbuffer,0);
  while (ac_mgetbutton()!=NONE) ;
  invalidate_screen();
}
Exemple #6
0
int main(int argc, char **argv) {
    
    int i;
    int filecount = 0;
    char* filename = NULL;
    
    {
        int c, option_index = 0;
        static struct option long_options[] = {
            {"help", 0, 0, 0},
            {"output", 2, 0, 0},
            {"size", 1, 0, 0},
            {NULL, 0, NULL, 0}
        };
        char* endptr = NULL;
        bool opt_fail = false;
        bool help = false;
        while ((c = getopt_long(argc, argv, "ho::s:",
                long_options, &option_index)) != -1) {
            switch (c) {
                case 0:
                    switch(option_index) {
                    case 0: // help
                        goto help;
                    case 1: // output
                        goto output;
                    case 2: // size
                        goto size;
                    default:
                        goto unknown;
                    }
                    break;
                help:
                case 'h':   // help
                    help = true;
                    break;
                output:
                case 'o':   // output
                    filecount = 1;
                    // avoid leakiness if the user provided multiple --output
                    // free(NULL) is a no-op, so this should be safe:
                    free(filename);
                    filename = NULL;
                    if(optarg != NULL) {
                        int tmp = strtol(optarg, &endptr, 10);
                        if (endptr == optarg || (endptr != NULL && *endptr != '\0')) {
                            int len = strlen(optarg);
                            filename = malloc(len + 1);
                            strcpy(filename, optarg);
                            filename[len] = '\0';
                        } else {
                            filecount = tmp;
                        }
                    }
                    break;
                size:
                case 's':
                    i = 0;
                    while(optarg[i] != '*' && optarg[i] != '\0') i++;
                    if(optarg[i] == '\0') {
                        goto size_fail;
                    }
                    optarg[i] = '\0';
                    width = strtol(optarg, &endptr, 10);
                    if (endptr == optarg || (endptr != NULL && *endptr != '\0')) {
                        goto size_fail;
                    }
                    height = strtol(optarg + i + 1, &endptr, 10);
                    if (endptr == optarg || (endptr != NULL && *endptr != '\0')) {
                        goto size_fail;
                    }
                    printf("width: %d, height: %d\n", width, height);
                    break;
                size_fail:
                    fprintf(stderr, "Invalid size string '%s'\n", optarg);
                    print_help(1);
                    break;
                unknown:
                case '?':
                    opt_fail = true;
                    break;
                default:
                    fprintf(stderr, "?? getopt returned character code 0%o ??\n", c);
            }
        }
        if(opt_fail) {
            print_help(1);
        }
        if(optind < argc) {
            fprintf(stderr, "%s: unrecognized option '%s'\n", argv[0], argv[optind]);
            print_help(1);
        }
        if(help) {
            print_help(0);
        }
    }
    
    scale = max(width, height);
    srand(get_time_us());

    GLFWwindow* window;

    glfwSetErrorCallback(error_callback);

    // Initialize the library
    if (!glfwInit())
        return -1;

    glfwWindowHint(GLFW_SAMPLES, 4);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
    glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);


    // Create a windowed mode window and its OpenGL context
    if(filecount) {
        glfwWindowHint(GLFW_VISIBLE, false);
        window = glfwCreateWindow(1, 1, "SpaceScape", NULL, NULL);
    } else {
        window = glfwCreateWindow(width, height, "SpaceScape", NULL, NULL);
    }
    if (!window) {
        glfwTerminate();
        return -1;
    }

    // Make the window's context current
    glfwMakeContextCurrent(window);

    glfwSetKeyCallback(window, key_callback);

    // Init GLEW
    glewExperimental = true;
    GLenum err = glewInit();
    if (GLEW_OK != err) {
        fprintf(stderr, "Error: %s\n", glewGetErrorString(err));
    }
    fprintf(stderr, "Using GLEW %s\n", glewGetString(GLEW_VERSION));
    if (!GLEW_ARB_vertex_buffer_object) {
        fputs("VBO not supported\n", stderr);
        exit(1);
    }

    render_init();

    if(filename) {
        render_to_png(filename);
    } else if(filecount) {
        for(i = 0; i < filecount; i++) {
            render_to_png(NULL);
        }
    } else {
        // Render to our framebuffer
        render_to_screen();

        while (!glfwWindowShouldClose(window)) {

            // Clear the screen
            glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

            // 1rst attribute buffer : vertices
            glEnableVertexAttribArray(0);
            glBindBuffer(GL_ARRAY_BUFFER, quad_vertexbuffer);
            glVertexAttribPointer(
                    0, // attribute 0. No particular reason for 0, but must match the layout in the shader.
                    3, // size
                    GL_FLOAT, // type
                    GL_FALSE, // normalized?
                    0, // stride
                    (void*) 0 // array buffer offset
                    );

            // Draw the triangles !
            glDrawArrays(GL_TRIANGLES, 0, 6); // 2*3 indices starting at 0 -> 2 triangles

            glDisableVertexAttribArray(0);

            // Swap buffers
            glfwSwapBuffers(window);
            glfwPollEvents();
        }
    }

    render_cleanup();

    // Close OpenGL window and terminate GLFW
    glfwTerminate();

    return 0;
}