QB / QB64 Discussion Forum      Other Subforums, Links and Downloads      Archived Pascal Resources    Search
Respond to this messageReturn to Index
Original Message
  • Textures.cpp
    • (Login ComputerGhost)
      R
      Posted Jan 8, 2007 9:23 PM

      #include <fstream>
      #include "Textures.h"

      using namespace std;

      //***********************************************
      //** LoadTexture
      //** Loads a texture from a file and stores it in buffer
      //***********************************************
      void LoadTexture( PIXEL *buffer, const char *file, int width, int height )
      {
      int size = width * height * 3; //Size in bytes of the image

      //open file
      ifstream texFile;
      texFile.open( file, ios::binary );

      //If the file is okay
      if( texFile.is_open() )
      {
      texFile.seekg( 18, ios_base::beg ); //Skip the header
      texFile.read( (char*)buffer, size ); //Read the data

      texFile.close();
      }

      //If the file is not okay
      else {
      int l = size >> 2, i;
      for( i = 0; i < l; i++ )
      ((long*)buffer)[i] = 0;
      l = size % 4;
      if( l )
      {
      l += (i *= 4);
      for( ; i < l; i++ )
      ((char*)buffer)[i] = 0;
      }
      }
      }
    Your Name
    Your Email
    (Optional)
    Message Title
    Message Text
    Options Also send responses to my email address