Jump to content

  • Log In with Google      Sign In   
  • Create Account

MaxFire

Member Since 09 Jun 2011
Offline Last Active Today, 04:15 PM

Posts I've Made

In Topic: C++ Serialize OpengGL pixel data in bitmap formatted byte array

Today, 04:14 PM

Sorry for yet another post, after 6 hours I'm pulling my hair out.. So everything seemed to work fine until I started looking at the bitmap file/buffer generated. The colour is different from what is actually rendered. I have searched high and low for Bitmap Headerfile examples but can't find any example that are hugely different from my implementation. Here is the code I use to save to a file and a screenshot.

 

Capture_zps7d44b0ed.jpg

MyBitmap::MyBitmap( int iWidth, int iHeight, int iNoOfBits, BYTE* pPixelData, size_t sPixelDataSize  )
{
	_header.bfType = 0x4d42;
	_header.bfSize = sizeof( BITMAPFILEHEADER ) + sizeof( BITMAPINFOHEADER ) + sPixelDataSize;
	_header.bfReserved1 = 0;
	_header.bfReserved2 = 0;
	_header.bfOffBits = sizeof( BITMAPFILEHEADER ) + sizeof( BITMAPINFOHEADER );

	_info.biSize = sizeof( _info );
	_info.biWidth = iWidth;
	_info.biHeight = iHeight;
	_info.biPlanes = 1;
	_info.biBitCount = 24;//iNoOfBits;
	_info.biCompression = BI_RGB;
	_info.biSizeImage = iWidth* iHeight * 3;
	_info.biXPelsPerMeter = 0;
	_info.biYPelsPerMeter = 0;
	_info.biClrUsed = 0;
	_info.biClrImportant = 0;
	_info.biXPelsPerMeter = 0;
	_info.biYPelsPerMeter = 0;

	_pPixelData = pPixelData;
	_sPixelDataSize = sPixelDataSize;
}

MyBitmap::~MyBitmap()
{
	if ( _pPixelData ) delete _pPixelData;
}

void MyBitmap::WriteToFile( std::string sFileName )
{
	std::ofstream file;
	file.open( sFileName.c_str(), std::ios::binary );

	//write headers
	file.write( ( char* ) ( &_header ), sizeof( _header ) );
	file.write( ( char* ) ( &_info ), sizeof( _info ) );

	//write pixel data
	file.write( reinterpret_cast<char*>( &_pPixelData[0] ), _sPixelDataSize );

	file.close();
}

And here is how its used

		glReadPixels( 0, 0, g_iScreenWidth, g_iScreenHeight, GL_RGB, GL_UNSIGNED_BYTE, g_pixels );

		MyBitmap bitmap( g_iScreenWidth, g_iScreenHeight, 24, g_pixels, 3 * g_iScreenWidth * g_iScreenHeight );

		bitmap.WriteToFile( "test.bmp" );

The only thing I can think of is that I need to specify an RGB colour mask but that would require switching to BITMAPV4HEADER structure, which I have yet to see anyone recommend to use. 

 

I am missing something painfully obvious?


In Topic: C++ Serialize OpengGL pixel data in bitmap formatted byte array

Today, 08:00 AM

Ahh I though that I would have to convert to CLI. I decided to create Header and info structures then write them to a buffer manually. Thanks for the additional knowledge guys :)


In Topic: C++ Serialize OpengGL pixel data in bitmap formatted byte array

Yesterday, 01:50 PM

Sorry for the such a basic question (I very rarely use visual c++) but how do I use the .Net classes if I have a c++ console app in visual studio?


In Topic: C++ Serialize OpengGL pixel data in bitmap formatted byte array

14 October 2014 - 03:43 PM

What's the cleanest way to do what im trying to achieve?, Atm im thinking of making my own bitmap class and using boost to serialize it but it seems a little overkill


In Topic: Unity CG Custom Sader for Texture Layering using Passes

28 October 2013 - 06:25 AM

Ok solved this problem, it was the unity cubes Normal deforming under a specific rotation. When I created a flat plane it worked perfectly


PARTNERS