スキャンラインのソースを発見

ousttrue2009-02-18

http://www.lysator.liu.se/~mikaelk/doc/perspectivetexture/
一番下にあるサンプルソースの線形補間のものを動かしてみた。
やってみると簡単ではあるのだがそのままではコンパイルできないので
ちょっと困った。
どうせならそのままで動くものか、もう少しコメント書くなりしてくれれば
よいものをw


補ったソース。

// 先頭に

#include <vector>
#include <fstream>
#include <iostream>
static char *screen;

//////////////////////////////////////////
// 最後に
void loadTexture(char *texture)
{
  std::ifstream io("check16x16.pgm", std::ios::binary);
  std::string line;

  for(int i=0; i<3; ){
    std::getline(io, line);
    if(line[0]!='#'){
      std::cout << line << std::endl;
      ++i;
    }
  }

  io.read(texture, 256 * 256);

  std::cout << "load texture" << std::endl;
}

int main(int argc, char **argv)
{
  // screen 320 x 320
  std::vector<char> Screen(320 * 320, 0x00);
  screen=&Screen[0];

  // texture 256 x 256
  std::vector<char> Texture(256 * 256, 0x00);
  loadTexture(&Texture[0]);

  TPolytri poly={
    20, 20, 30,
    20, 280, 30,
    280, 280, 30,
    0, 0,
    0, 256,
    256, 256,
    &Texture[0]
  };
  drawtpolysubtri(&poly);

  std::ofstream io("tmp.ppm", std::ios::binary);
  io << "P5\n320 320\n255\n";
  io.write(&Screen[0], Screen.size());
}

これにgimpで作った
256x256のグレイスケールのテクスチャ(check16x16.pgm)を読ませてみた。


コードはちゃんと読んでないが、
ブレゼンハムアルゴリズムの縦横判定のような準備コードが半分くらいを
占めていて本体が
drawtpolysubtriseg
関数らしい。
他にパース補正のサンプルもあるのでぼちぼち解読予定。

lucilleコンパイルしてみた

http://d.hatena.ne.jp/tueda_wolf/20090214/p1
でちょうどgitのリポジトリが紹介されていたので
それならば早いということでやってみた。
環境はGentoo Linux


scons0.97だと AddOption is not defined とかエラーがでるので1.00に
sconsをアップグレード


gcc-4.3だとerror: 'memset' was not declared in this scope
とエラーが出るので(他のソフトでもよくある。OpenEXRとか)
src/testrbed/GLView.cppに
#include
を追加する。


以上でビルド完了。

$ ./bin/testbed 
[0][0] = 1.000000
[0][1] = 1.000000
[0][2] = 2.000000
[0][3] = 3.000000
[1][0] = 4.000000
[1][1] = 4.000000
[1][2] = 2.000000
[1][3] = 4.000000
[2][0] = 6.000000
[2][1] = 6.000000
[2][2] = 8.000000
[2][3] = 3.000000
[3][0] = 6.000000
[3][1] = 6.000000
[3][2] = 9.000000
[3][3] = 12.000000
can't open file [ conf.dat ]

今はここまで。