fileImage.cpp
  0
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
/*
*  Image.cpp
*
*  Created by Daisuke Nogami on Sep, 05.
*  opyright 2005 Daisuke Nogami [null-null.net]. Some rights reserved.
*/
 
#include "stdafx.h"
#include "Image.h"
 
Image::Image( char* file, int width, int height ){
  this->width = width;
  this->height = height;
 
  data = new GLubyte[height*width*4];
  
  FILE *fp;
  int x, y;
   
  // texture file open
  if( ( fp = fopen( file, "rb" ) ) == NULL ){
    fprintf( stderr, "texture file cannot open\n" );
    return;
  }
  fseek(fp, 18, SEEK_SET);
  for( y = 0; y < height; y++ ){
    for( x = 0; x < width; x++ ){
      data[(x+y*width)*4+2] = fgetc(fp);  /* B */
      data[(x+y*width)*4+1] = fgetc(fp);  /* G */
      data[(x+y*width)*4] = fgetc(fp);  /* R */
      data[(x+y*width)*4+3] = fgetc(fp);  /* alpha */
    }
  }
  fclose(fp);
}
 
Image::~Image(){
  delete []this->data;
  this->data = 0;
}
[トップ] [一覧] [最終更新] [検索] [バックアップ]