Ejemplo n.º 1
0
AGSurface &AVItem::getSurface()
{
    CTRACE;
    if(!inited)
        init();
    inited=true;

    // filter surface

    int x,y;
    SDL_Surface *s=mSurface.surface();

    //  SDL_SaveBMP(s,"getSurface1.bmp");

    Uint32 trans=SDL_MapRGB(s->format,255,255,255);
    Uint32 shadow=SDL_MapRGB(s->format,191,191,191);
    Uint32 ntrans=SDL_MapRGBA(s->format,0,0,0,0);
    Uint32 nshadow=SDL_MapRGBA(s->format,0,0,0,0x7f);

    for(x=0; x<mSurface.width(); x++)
        for(y=0; y<mSurface.height(); y++)
        {
            Uint32 c=sge_GetPixel(s,x,y);
            if(c==trans)
                sge_PutPixel(s,x,y,ntrans);
            else if(c==shadow)
                sge_PutPixel(s,x,y,nshadow);

        }

    //  SDL_SaveBMP(s,"getSurface2.bmp");



    return mSurface;
}
Ejemplo n.º 2
0
void VoxelView::init()
{
  VOXELHEIGHT=h;
  int x,y;
  Color c;

  calcShadow();

  for(x=0;x<w;x++)
    for(y=0;y<h;y++)
      {
        Pos2D p2(x,y);
        c=trace(p2);
        if(c.a>=0)
          {
            sge_PutPixel(s,x,y,c.toColor(s));

          }
      }
  mSurface=getSurfaceManager()->fromSDL(s);
  mTexture=new AGTexture(getTextureManager()->makeTexture(mSurface));
  return;
}
Ejemplo n.º 3
0
void FastVoxelView::init()
{
  //  VOXELHEIGHT=w;

  std::map<Pos2D,std::pair<int,Voxel*> >::iterator i=viewSpace.mViewSpace.begin();

  Color c;
  Pos2D p(0,0);
  for(;i!=viewSpace.mViewSpace.end();i++)
    {
      p=i->first;
      c=viewSpace.get(p);
      p.x*=mZoom;
      p.y*=mZoom;
      if(mZoom==1)
        sge_PutPixel(s,(int)p.x,(int)p.y,c.toColor(s));
      else
        sge_FilledRect(s,(int)p.x,(int)p.y,(int)(p.x+mZoom),(int)(p.y+mZoom),c.toColor(s));
    }
  //  SDL_SaveBMP(s,"myfile.bmp");

  mSurface=getSurfaceManager()->fromSDL(s);
  return;
}
Ejemplo n.º 4
0
int main(int argc,char *argv[])
{
  AGMain main;
  MyApp app;

  AntargisView *av=new AntargisView(0,AGRect(0,0,100,100),Pos3D(0,0,0));

  int x,y,z;

  int w=64;
  int s=0;

  Terrain t(16,16);

  AGSurface ms;

  int test=4;

  if(argc>1)
    test=atoi(argv[1]);

  if(test==1)
    {
      ms=test1();
      av->insert(new VoxelImage(ms,Pos3D(0,0,0)));
    }
  if(test==2)
    {
      ms=ball();
      av->insert(new VoxelImage(ms,Pos3D(0,0,0)));
    }
  else if(test==3)
    {
      ms=getTerrain(t.getInfo(2,0));
      av->insert(new VoxelImage(ms,Pos3D(0,0,0)));
    }
  else if(test==4)
    {
      ms=getTerrain(t.getInfo(1,0));
      av->insert(new VoxelImage(ms,Pos3D(0,0,0)));


      ms=getTerrain(t.getInfo(2,0));
      av->insert(new VoxelImage(ms,Pos3D(64,0,0)));


      ms=getTerrain(t.getInfo(1,1));
      av->insert(new VoxelImage(ms,Pos3D(32,0,-32)));

      ms=getTerrain(t.getInfo(2,1));
      av->insert(new VoxelImage(ms,Pos3D(64+32,0,-32)));
    }
  else if(test==5)
    {
      int x,y;
      for(int x=0;x<4;x++)
        for(int y=0;y<4;y++)
          {
            ms=getTerrain(t.getInfo(x,y));
            av->insert(new VoxelImage(ms,Pos3D(x*64+(y%2)*32,0,-y*32)));
          }
    }
  else if(test==6)
    {
      SplineMap<float> m(16,16,50);
      SplineMap<float> gm(16,16,20);
      int w=64;
      VoxelView v(w,w*2,Pos3D(0,0,0),true);

      for(int x=0;x<w;x++)
        for(int z=0;z<w;z++)
          {
            float mx=x/16.0;
            float mz=z/16.0;

            float h=m.get(mx,mz);
            for(int y=0;y<h;y++)
              {
                float a=std::min(1.0f,h-y);
                //    cdebug(a);
                v.set(Pos3D(x,y,z),Color(0xAA,0xAA,0,a));
              }

            // grass above

            float gh=rand()%int(gm.get(mx,mz));
            if(gh>0)
              for(int y=0;y<gh;y++)
                {
                  float a=1.0f-(y/gh);
                  //    cdebug(a);
                  v.set(Pos3D(x,y+h,z),Color(0,0xAA,0,a));
                }

          }

      /*



      // small ball above

      for(int x=0;x<8;x++)
      for(int y=0;y<8;y++)
      for(int z=0;z<8;z++)
      {
       int mx=x-4;
       int my=y-4;
       int mz=z-4;
       if(sqrt(mx*mx+my*my+mz*mz)<4)
      v.set(Pos3D(x+10,y+40,z+20),Color(0xAA,0,0));
      }

      */
      av->insert(new VoxelImage(v.getSurface(),Pos3D(0,0,0)));

    }

  else if(test==7)
    {
      float v0=-20;
      float v1=60;
      float v2=60;
      float v3=-20;
      float v4=0;
      float v5=0;
      float v6=0;
      int x;

      SDL_Surface *s=getScreen().surface();
      Color c(0,0,1);
      for(x=0;x<32;x++)
        {
          int y=spline2(x/32.0,v0,v1,v2);//,v3);
          sge_PutPixel(s,x,y+50,c.toColor(s));
        }
      for(x=0;x<32;x++)
        {
          int y=spline2(x/32.0,v1,v2,v3);//,v4);
          sge_PutPixel(s,x+32,y+50,c.toColor(s));
        }
      for(x=0;x<32;x++)
        {
          int y=spline2(x/32.0,v2,v3,v4);//,v5);
          sge_PutPixel(s,x+64,y+50,c.toColor(s));
        }
      for(x=0;x<32;x++)
        {
          int y=spline2(x/32.0,v3,v4,v5);//,v6);
          sge_PutPixel(s,x+96,y+50,c.toColor(s));
        }
      SDL_Flip(s);
      //      SDL_Delay(1000);
    }
  else if(test==8)
    {
      float v0=-20;
      float v1=60;
      float v2=60;
      float v3=-20;
      float v4=0;
      float v5=0;
      float v6=0;
      int x;

      SDL_Surface *s=getScreen().surface();
      Color c(1,0,1);
      for(x=0;x<32;x++)
        {
          int y=spline3(x/32.0,v0,v1,v2,v3);
          sge_PutPixel(s,x,y+50,c.toColor(s));
        }
      for(x=0;x<32;x++)
        {
          int y=spline3(x/32.0,v1,v2,v3,v4);
          sge_PutPixel(s,x+32,y+50,c.toColor(s));
        }
      for(x=0;x<32;x++)
        {
          int y=spline3(x/32.0,v2,v3,v4,v5);
          sge_PutPixel(s,x+64,y+50,c.toColor(s));
        }
      for(x=0;x<32;x++)
        {
          int y=spline3(x/32.0,v3,v4,v5,v6);
          sge_PutPixel(s,x+96,y+50,c.toColor(s));
        }
      SDL_Flip(s);
      //      SDL_Delay(1000);
    }
  else if(test==9)
    {
      SplineMap<float> m(64,64,50);
      int w=64;
      VoxelView v(w,w*2,Pos3D(0,0,0),false);

      int z=0;
      for(int x=0;x<w;x++)
        {
          float h=20+x/16.0;
          for(int y=0;y<h;y++)
            {
              float a=std::min(1.0f,h-y);
              //      if(a<1)
              if(a>0)
                {
                  cdebug(a);
                  v.set(Pos3D(x,y,z),Color(0xFF,0xFF,0xFF,a));//Color(0xAA*a,0xAA*a,0));//,a));
                }
            }
        }

      av->insert(new VoxelImage(v.getSurface(),Pos3D(0,0,0)));

    }
  else if(test==10)
    {
      SDL_Surface *s=getScreen().surface();
      for(int x=0;x<100;x++)
        {
          float h=20+x/16.0;
          for(int y=0;y<h;y++)
            {
              float a=std::min(1.0f,h-y);
              if(a>0)
                {
                  sge_PutPixelAlpha(s,x,100-y,SDL_MapRGBA(s->format,0xFF,0xFF,0xFF,a*0xFF),a*0xFF);
                }
            }
        }
      SDL_Flip(s);
      SDL_Delay(1000);
    }
  else if(test==11 || test==12)
    {
      int w=8;
      SplineMap<float> m(POINTS_PER_TILE*(w+2),POINTS_PER_TILE*(w+2),40);
      SplineMap<float> gm(POINTS_PER_TILE*(w+2),POINTS_PER_TILE*(w+2),10);

      if(test==12)
        w=2;

      for(int y=0;y<w;y++)
        for(int x=0;x<w;x++)
          {
            int mx=x*(POINTS_PER_TILE);
            int my=y*(POINTS_PER_TILE/2);
            if(y&1)
              mx+=(POINTS_PER_TILE/2);

            av->insert(new VoxelImage(makeTerrainTile(m,gm,mx,my),Pos3D(mx*TILE_WIDTH/POINTS_PER_TILE,0,my*TILE_WIDTH/POINTS_PER_TILE)));
          }
    }
  else if(test==13)
    {
      AGSurface s=makeWaterTile();
      av->insert(new VoxelImage(s,Pos3D(64,0,0)));
      av->insert(new VoxelImage(s,Pos3D(0,0,0)));
      av->insert(new VoxelImage(s,Pos3D(64+32,0,32)));
      av->insert(new VoxelImage(s,Pos3D(32,0,32)));
      av->insert(new VoxelImage(s,Pos3D(64+32,0,-32)));
      av->insert(new VoxelImage(s,Pos3D(32,0,-32)));
    }
  else if(test==14)
    {
      AGSurface s=makeWaterTile();
      std::string ms=toPNG(s.surface());
      s=fromPNG(ms);
      av->insert(new VoxelImage(s,Pos3D(64,0,0)));
    }

  app.setMainWidget(av);

  app.run();
}
Ejemplo n.º 5
0
SDL_Surface* LoadBackground( const char* a_pcFilename, int a_iNumColors, int a_iPaletteOffset, bool a_bTransparent )
{
	char acFilepath[FILENAME_MAX+1];
	strcpy( acFilepath, DATADIR );
	strcat( acFilepath, "/gfx/" );
	strcat( acFilepath, a_pcFilename );

	SDL_Surface* poBackground = IMG_Load( acFilepath );
	if (!poBackground)
	{
		debug( "Can't load file: %s\n", acFilepath );
		return NULL;
	}
	
	SDL_Palette* pal = poBackground->format->palette;
	if ( pal && gamescreen->format->palette )
	{
		int ncolors = pal->ncolors;
		if (ncolors>a_iNumColors) ncolors = a_iNumColors;
		if (ncolors+a_iPaletteOffset > 255) ncolors = 255 - a_iPaletteOffset;
		SDL_SetColors( gamescreen, pal->colors, a_iPaletteOffset, ncolors );
	}
		
	SDL_Surface* poRetval = SDL_DisplayFormat( poBackground );
	SDL_FreeSurface( poBackground );
	
	// 2. TRY TO LOAD AN IMAGE MASK
	// This means trying to load a .png file which acts as a mask for the
	// original [jpg] image.
	// If the original file is <Basename>.jpg, the mask is <Basename>.mask.png
	
	int iLength = strlen( acFilepath );
	char acMaskFilename[FILENAME_MAX+1];
	strncpy( acMaskFilename, acFilepath, iLength-4 );
	acMaskFilename[iLength-4] = 0;
	strcat( acMaskFilename, ".mask.png" );
	
	SDL_Surface* poMask = IMG_Load( acMaskFilename );
	if ( !poMask )
	{
		// No mask.
		return poRetval;
	}
	
	if ( poMask->w < poRetval->w
		|| poMask->h < poRetval->h )
	{
		debug( "Error loading mask for %s: mask is too small.\n", acFilepath );
		SDL_FreeSurface( poMask );
		return poRetval;
	}
	
	debug( "Loading mask for %s.\n", acFilepath );
	
	Uint32 iTransparent = SDL_MapRGB( gamescreen->format, 255, 217, 0 ); // an unlikely color in openmortal..
	Uint32 iMask = sge_GetPixel( poMask, 0, 0 );
	Uint32 iPixel;
	
	for ( int y = 0; y < poRetval->h; ++y ) {
		for ( int x=0; x< poRetval->w; ++x ) {
			iPixel = sge_GetPixel( poMask, x, y );
//			debug( "%d ", iPixel );
			if ( iPixel == iMask ) { 
				sge_PutPixel( poRetval, x, y, iTransparent );
			}
		}
//		debug( "\n" );
	}
	
	SDL_FreeSurface( poMask );
	
	SDL_SetColorKey( poRetval, SDL_SRCCOLORKEY, iTransparent );
	
	return poRetval;
}