filenlTGA32ImageLoader.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
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
/*
 *  nlTGA32ImageLoader.cpp
 *
 *  Created by Daisuke Nogami.
 *  Copyright 2005 Daisuke Nogami [null-null.net]. All rights reserved.
 */
 
#include "stdafx.h"
#include "nlTGA32ImageLoader.h"
 
nlTGA32ImageLoader::nlTGA32ImageLoader(){
}
 
nlTGA32ImageLoader::~nlTGA32ImageLoader(){
  delete []this->btmp;
  this->btmp = 0;
}
 
void nlTGA32ImageLoader::load( char* filename, int width, int height ){
  if( width < 0 || height < 0 ){
    fprintf( stderr, "texture size error\n" );
    return;
  }
  this->width = width;
  this->height = height;
 
  if( btmp != NULL ){
    delete []this->btmp;
    this->btmp = 0;
  }
  btmp = new GLubyte[height*width*4];
  
  FILE *fp;
  int x, y;
   
  // file open
  if( ( fp = fopen( filename, "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++ ){
      btmp[(x+y*width)*4+2] = fgetc(fp);  /* B */
      btmp[(x+y*width)*4+1] = fgetc(fp);  /* G */
      btmp[(x+y*width)*4] = fgetc(fp);  /* R */
      btmp[(x+y*width)*4+3] = fgetc(fp);  /* alpha */
    }
  }
  fclose(fp);
}
[トップ] [一覧] [最終更新] [検索] [バックアップ]