allegtest.c
Upload User: wmy0603
Upload Date: 2022-05-02
Package Size: 1808k
Code Size: 1k
Development Platform:

Visual C++

  1. // Almost identical to Allegro's ex15.c
  2. #include <IL/il.h>
  3. #include <IL/ilu.h>
  4. #include <IL/ilut.h>
  5. #include <allegro.h>
  6. #include <stdlib.h>
  7. #include <stdio.h>
  8. int main(int argc, char *argv[])
  9. {
  10.   BITMAP *Image;
  11.   PALETTE Pal;
  12.   ILuint Id;
  13.   if (argc != 2) {
  14.      printf("Please specify a filename.n");
  15.      return 1;
  16.   }
  17.   ilInit();
  18.   ilGenImages(1, &Id);
  19.   ilBindImage(Id);
  20.   ilLoadImage(argv[1]);
  21. //  if (ilGetInteger(IL_IMAGE_FORMAT) == GL_BGR ||
  22. //      ilGetInteger(IL_IMAGE_FORMAT) == GL_BGRA)
  23.         ilSwapColours();
  24.   Image = (BITMAP*)ilutConvertToAlleg(Pal);
  25.   allegro_init();
  26.   install_keyboard();
  27.   if (ilGetInteger(IL_IMAGE_BYTES_PER_PIXEL) == 8) {
  28.      set_color_depth(8);
  29.      set_palette(Pal);
  30.   }
  31.   else
  32.      set_color_depth(32);
  33.   set_gfx_mode(GFX_AUTODETECT, 640, 480, 0, 0);
  34.   blit(Image, screen, 0, 0, (SCREEN_W - Image->w) / 2,
  35.         (SCREEN_H - Image->h) / 2, Image->w, Image->h);
  36.   destroy_bitmap(Image);
  37.   readkey();
  38.   return 0;
  39. }