Ejemplo n.º 1
0
////////////////////////////////////////////////////////////////////////////////
// A helper function for loading an Allegro dat file where bitmaps are
// supposed to be stored.
MAS::Error MAS::Skin::LoadData(ALLEGRO_PATH *dir, ALLEGRO_CONFIG *config) {
   if (!dir || !al_is_path_present(dir) || !al_get_path_filename(dir)) {
      return Error(Error::SKIN_DAT);
   }

   // load the datafile
   int i;
   char tmp[256];
   const char *str;

   // Look for each bitmap inside and load it if it exists
   for (i=0; i<nBitmaps; i++) {
      al_set_path_filename(dir, bitmapName[i]);
	  al_set_path_extension(dir, ".png");
      const char *fullPath = al_path_cstr(dir, ALLEGRO_NATIVE_PATH_SEP);
      Bitmap bmp;
      if (bmp.Load(fullPath, Bitmap::MEMORY) == Error::NONE) {
         bmpList[i]->Set(bmp, true, MAS::Settings::useVideoMemory ? Bitmap::VIDEO : Bitmap::MEMORY);

         snprintf(tmp, 256, "%s_TCKX", bitmapName[i]);
         bmpList[i]->ThickX((str = al_get_config_value(config, "TILING", tmp)) ? strtol(str, NULL, 10) : -1);
         snprintf(tmp, 256, "%s_TCKY", bitmapName[i]);
         bmpList[i]->ThickY((str = al_get_config_value(config, "TILING", tmp)) ? strtol(str, NULL, 10) : -1);
      }
   }

   al_set_path_filename(dir, "");

   return Error(Error::NONE);
}
Ejemplo n.º 2
0
void Texture::Load(std::string a)
{
	name = a;

	Bitmap* b = new Bitmap();
	b->Load(a);
	textureId = GenerateOpenglBitmap(*b, false, false);
	height = b->GetHeight();
	width = b->GetWidth();
	b->Free();
}
Ejemplo n.º 3
0
static void
Main()
{
  Bitmap bitmap;
  bool success =
#ifdef USE_GDI
    id.IsDefined()
    ? bitmap.Load(id)
    :
#endif
    bitmap.LoadFile(path);
  if (!success)
    fprintf(stderr, "Failed to load image\n");
}
Ejemplo n.º 4
0
////////////////////////////////////////////////////////////////////////////////
// A helper function for loading an Allegro dat file where cursors are
// supposed to be stored.
MAS::Error MAS::Skin::LoadCursors(ALLEGRO_PATH *dir, ALLEGRO_CONFIG *config) {
   if (!dir || !al_is_path_present(dir)) {
      return Error(Error::NO_FILE);
   }

   MAS::Cursor::ReadSkinData(config);

   al_set_path_filename(dir, al_get_path_component(dir, -1));
   al_set_path_extension(dir, ".ini");
   const char *config_path_t = al_path_cstr(dir, ALLEGRO_NATIVE_PATH_SEP);
   ALLEGRO_CONFIG *mouse_config = al_load_config_file(config_path_t);

   int i;
   char tmp[256];
   char *config_path = strdup(config_path_t);
   int x, y, frames, interval;
   const char *str;

   // Look for each bitmap inside the dat file and load it if it exists
   for (i=0; i<nCursors; i++) {
      al_set_path_filename(dir, cursorName[i]);
      al_set_path_extension(dir, ".png");
      const char *fullPath = al_path_cstr(dir, ALLEGRO_NATIVE_PATH_SEP);
      Bitmap bmp;
      if (bmp.Load(fullPath, Bitmap::MEMORY) == Error::NONE) {
         snprintf(tmp, 256, "%s_FCSX", cursorName[i]);
         x = (str = al_get_config_value(mouse_config, "HOTSPOTS", tmp)) ? strtol(str, NULL, 10) : 0;

         snprintf(tmp, 256, "%s_FCSY", cursorName[i]);
         y = (str = al_get_config_value(mouse_config, "HOTSPOTS", tmp)) ? strtol(str, NULL, 10) : 0;

         snprintf(tmp, 256, "%s_FRMS", cursorName[i]);
         frames = (str = al_get_config_value(mouse_config, "HOTSPOTS", tmp)) ? strtol(str, NULL, 10) : 1;

         snprintf(tmp, 256, "%s_FDUR", cursorName[i]);
         interval = (str = al_get_config_value(mouse_config, "HOTSPOTS", tmp)) ? strtol(str, NULL, 10) : 20;

         curList[i]->Create(bmp, frames);
         curList[i]->SetFocus(x, y);
         curList[i]->SetAnimationInterval(interval);
      }
   }

   al_set_path_filename(dir, "");
   free(config_path);
   al_destroy_config(mouse_config);

   return Error(Error::NONE);
}
Ejemplo n.º 5
0
int main() {
   // SETUP //

   // Set up the program with all possible drivers //
   Setup::SetupProgram();

   LOCK_VARIABLE( global_pressed );
   LOCK_VARIABLE( global_released );
   LOCK_FUNCTION( mouse_function );

	mouse_callback = mouse_function;

   // Set up the screen in windowed mode with the window size of 800 x 600 //
   Setup::SetupScreen( 800, 600, WINDOWED );

   // Load a bitmap //
   Bitmap pointer;
   pointer.Load( "Gfx/PointerAlpha.png", "Gfx/PointerAlpha.bmp" );

   // Test if the bitmap was really loaded (maybe it didn't exist) //
   if( !pointer ) {
      allegro_message( "Couldn't load the bitmap!" );
      exit( -1 );
   }


   // RENDERING //

   // Draw the bitmap to the screen with the top-left coordinates of x = 200.0, y = 100.0 //

	Circle cPointer( Vec2D( 10,10 ), 10 );
	mousePointerLoop( cPointer );
	while( keypressed())
		readkey();

	Rect rPointer( 0.0, 0.0, 20.0, 15.0 );
	mousePointerLoop( rPointer );
	while( keypressed())
		readkey();

	ol::Ellipse ePointer( 20.0, 10.0, 20.0, 10.0 );
	mousePointerLoop( ePointer );
	while( keypressed())
		readkey();

	polygonLoop( pointer );

   return 0;
}
Ejemplo n.º 6
0
////////////////////////////////////////////////////////////////////////////////
// For loading a cursor from disk into the cursor array
MAS::Error MAS::Skin::LoadCursor(const char *filename, int i, int n, int interval) {
   if (i<0 || i>=nCursorsEx) {
      return Error(Error::INDEX);
   }

   Bitmap bmp;
   Error er = bmp.Load(filename);
   if (er != Error::NONE) {
      return er;
   }

   curList[i]->Create(bmp, n);
   curList[i]->SetAnimationInterval(interval);

   return Error(Error::NONE);
}
Ejemplo n.º 7
0
	/**
	 * Takes the pixel data from the Bitmap class and generates a vertices array with the Y value as the pixel value.
	 * @param		Renderer*				The renderer to use
	 * @param		std::string				The file name of the BMP file to load
	 * @param		float					The scaling of each pixel
	 * @param		unsigned long			The number of smoothing iteration to do
	 * @return		void
	 */
	void Heightmap::SetupVertices(Renderer* argPRenderer, std::string argMapFileName, float argPixelScale, unsigned long argSmoothing)
	{
		// Load the bitmap
		Bitmap* pBitmap					= new Bitmap();
		pBitmap->Load(argMapFileName);

		// Fetch the bitmap data, width and height
		unsigned char* pixelData		= pBitmap->GetPixelData();
		this->width						= pBitmap->GetImageWidth();
		this->height					= pBitmap->GetImageHeight();

		// Delete the bitmap
		delete pBitmap;

		this->offsetX					= -(((float)(this->width * argPixelScale)) / 2);
		this->offsetY					= 0;
		this->offsetZ					= -(((float)(this->height * argPixelScale)) / 2);
		
		// --- Create the vertex array ---
		this->numVertices				= this->width * this->height;
		this->numPrimitives				= this->numVertices * 2;
		unsigned long vertexArraySize	= this->numVertices * sizeof(TexturedVector3);
		this->vertices					= new TexturedVector3[this->numVertices];

		for(long z = 0; z < this->height; z++)
		{
			for(long x = 0; x < this->width; x++)
			{
				long vIndex						= (z * this->width) + x;
				float pixelX					= x * argPixelScale;
				float pixelY					= pixelData[vIndex] / 15.0f;
				float pixelZ					= z * argPixelScale;

				this->vertices[vIndex].x		= this->offsetX + pixelX;
				this->vertices[vIndex].y		= this->offsetY + pixelY;
				this->vertices[vIndex].z		= this->offsetZ + pixelZ;

				this->vertices[vIndex].normal	= D3DXVECTOR3(0.0f, 1.0f, 0.0f);

				this->vertices[vIndex].u		= pixelX / ((float)(this->width * argPixelScale));
				this->vertices[vIndex].v		= 1 - (pixelZ / ((float)(this->height * argPixelScale)));
			}
		}


		// Smooth the map
		this->SmoothMap(argSmoothing);
		// Calculate the normals
		this->CalculateNormals();

		
		// --- Create the index array ---
		unsigned long numIndices		= this->numPrimitives * 3;
		unsigned long indexArraySize	= numIndices * sizeof(short);

		short* indices					= new short[numIndices];
		
		int index						= 0;
		for(long z = 0; z < (this->height - 1); z++)
		{
			for(long x = 0; x < (this->width - 1); x++)
			{
				// Top Left
				indices[index]			= (short)((z * this->width) + x);
				index++;
				// Bottom Left
				indices[index]			= (short)(((z + 1) * this->width) + x);
				index++;
				// Top Right
				indices[index]			= (short)((z * this->width) + (x + 1));
				index++;
				
				// Bottom Right
				indices[index]			= (short)(((z + 1) * this->width) + (x + 1));
				index++;
				// Top Right
				indices[index]			= (short)((z * this->width) + (x + 1));
				index++;
				// Bottom Left
				indices[index]			= (short)(((z + 1) * this->width) + x);
				index++;
			}
		}

		
		// Create the vertex buffer.
		argPRenderer->CreateVertexBuffer(&this->pVertexBuffer, vertexArraySize, D3DFVFTexturedVector3, this->vertices);
		
		// Create the index buffer.
		argPRenderer->CreateIndexBuffer(&this->pIndexBuffer, indexArraySize, indices);
	}
Ejemplo n.º 8
0
int main () {

   rs = bs = gs =.5;

	TheKeyBoard->Install (); //install the keyboard driver

	//clip is set by default to 0,0 - 319, 199
	//ScreenClip->Set (50,50, 319-50,199-50);

	TheScreen->SetMode13h(); //set mode13h (don't forget)
   ScreenPal->Load("animdemo.vpl", "animdemo.pal");
	ScreenPal->PutToScreen();

	char * myfiles [] = { "1.vbm", "2.vbm", "3.vbm", "4.vbm", "5.vbm", "6.vbm", "7.vbm",
      "8.vbm","9.vbm","10.vbm" };

	int mydurs [] = {
      10,10,10,10,10,10,10,10,10,10
	};

   MasterAnim->AddAll(10, myfiles, mydurs);

	Bitmap * MyBitmap = new Bitmap;
	MyBitmap->Load("back.vbm");

	InitCreatures();

	ScreenPal->PrepareFadeIn();
	MyBuffer->Clear();
	MyBitmap->PutRegular18bit(0,0,MyBuffer->Memory);
	DrawCreatures();
	MyBuffer->CopyToScreen();
	ScreenPal->FadeIn(1500);

   float cinc = .1;
	do {
		//MyBuffer->Clear();
		MoveCreatures ();
		MyBitmap->PutRegular18bit(0,0,MyBuffer->Memory);
      rs += cinc;
      if (rs >= 1) {
         rs= 1;
         cinc = -cinc;
      }
      if (rs <= 0) {
         rs= 0;
         cinc = -cinc;
      }
      gs = bs = rs;

      DrawCreatures();
      //MasterAnim->Advance();
      //MasterAnim->PutTransparent18bit(MyCreatures[0].x, MyCreatures[0].y,
      //      MyBuffer->Memory);

		TheScreen->WaitVerticalRetraceStart();
		//TheScreen->WaitVerticalRetraceStart();
		//TheScreen->WaitVerticalRetraceStart();

		MyBuffer->CopyToScreen();
		//delay(1000);

	} while (!TheKeyBoard->GetKeyState(KEY_ESC) );

	ScreenPal->FadeOut(1500);

	TheKeyBoard->Remove(); //remove keyboard driver (SUPERLY important!!!)
	TheScreen->SetTextMode(); //set text mode (important!!!)
	delete MasterAnim;
	delete MyBitmap;

	return 0;
}
Ejemplo n.º 9
0
OlLoadResult PendingFileLoad::
ExecuteLoading( Bitmap &bmp ) {
   return bmp.Load( filename )? OL_LR_SUCCESS : OL_LR_FAILURE;
}
Ejemplo n.º 10
0
OlLoadResult PendingFunctorLoad <Type>::
ExecuteLoading( Bitmap &bmp ) {
   return bmp.Load( width, height, functor )? OL_LR_SUCCESS : OL_LR_FAILURE;
}