Jump to content
  • Advertisement

Bj

Member
  • Content Count

    19
  • Joined

  • Last visited

Everything posted by Bj

  1. It appears i had the wrong version of Windows Media Feature pack installed. Downloading this one fixed the problem: https://www.microsoft.com/en-US/download/details.aspx?id=49919
  2. Hello, I'm trying to add audio to my game, and to load audio files I want to use the Media Foundation, however when i try to initialize it with this line:   MFStartup(MF_VERSION);   it crashes, before the program even loads with the following error:   "Unable to activate Windows Store App '031...'. The process started but failed with error 'The App didn't start'."   If I uncomment this line the game starts, but I need it to use audio, what am I doing wrong? :O   /Björn
  3. Ah, this was supposed to go into 'For beginners' :O
  4. I am having some troubles when generating a .bmp file, from the code below i expected it to come out in shades of red, but as you'll see from the included picture it becomes both blue and green instead. Any ideas why this is happening? struct Pixel { unsigned char r;  unsigned char g; unsigned char b; }; The main function generates the vector that holds all the pixel data, the color depends on the height of the image. int main() { std::vector<Pixel> ImageData; unsigned int Width = 640; unsigned int Height = 480;   for (unsigned int i = 0; i < Height; i++) { for (unsigned int j = 0; j < Width; j++) { Pixel temp; temp.r = i % 255; temp.g = 0; temp.b = 0; ImageData.push_back(temp); } }   WriteBitMap("raytracer.bmp", Width, Height, ImageData);   return 0; }   Writes the 2 headers needed for BMP files and then the image data. bool WriteBitMap(std::string Filename, const unsigned int Width, const unsigned int Height, std::vector<Pixel> ImageData) { //Create fileformat headers   BitmapFileHeader fh; BitmapInfoHeader ih;   fh.bmtype[0] = 'B'; fh.bmtype[1] = 'M'; fh.iFileSize = sizeof(BitmapFileHeader) + sizeof(BitmapInfoHeader) + (Width*Height * 3); fh.iOffsetBits = sizeof(BitmapFileHeader) + sizeof(BitmapInfoHeader);   ih.iSizeHeader = 40; ih.iWidth = Width; ih.iHeight = Height; ih.iPlanes = 1; ih.iBitCount = 24; ih.Compression = 0;   //Open file for writing   std::ofstream file; file.open(Filename, std::ios::out);   file.write(reinterpret_cast<char*>(&fh), sizeof(BitmapFileHeader)); file.write(reinterpret_cast<char*>(&ih), sizeof(BitmapInfoHeader));   for (auto it = ImageData.begin(); it != ImageData.end(); ++it) { char red = it->r; char green = 0; char blue = 0; file.write(&blue, sizeof(char)); file.write(&green, sizeof(char)); file.write(&red, sizeof(char)); }   file.close(); return false; }   Edit: See solution further down   File needed to be opened in binary mode.
  5. The problem was a simple one,    file.open(Filename, std::ios::out)   needed to be   file.open(Filename, std::ios::out | std::ios::binary);   since it needs to write the data in binary mode.
  6. Thank you for your answers. =)     I do store them that way: for (auto it = ImageData.begin(); it != ImageData.end(); ++it) {    char red = it->r;    char green = 0;    char blue = 0;    file.write(&blue, sizeof(char));    file.write(&green, sizeof(char));    file.write(&red, sizeof(char)); }     I thought using a width of 640 would be aligned since: 640 pixels * 3 chars = 1920bytes   1920 bytes % 4 = 0 Isnt this correct?   Edit: If I change to constant values it works, and generates a red picture as expected       temp.r = i % 255; to    temp.r = 255;
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!