Archived

This topic is now archived and is closed to further replies.

Tga and DirectDraw problem .....

This topic is 5117 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi I have a stupid problem, I wrote a function to load Tga file but I don''t know how to copy my graph from my *m_piImageBuffer to DirectDraw Surface7 I left free space in place when copy stuff should be. My own do somethings wrong because when I draw this surface I see only garbage not corrent image. Maybe somebody can help me? Here is my class : class img_CTga //! Class name { public: static unsigned long m_iWidth; static unsigned long m_iHeight; static unsigned long *m_piImageBuffer; //! Constructor img_CTga(); //! Destructor ~img_CTga(); static bool LoadAndCreateSurface(LPDIRECTDRAWSURFACE7 &ddSurface, const char *fileName); }; // img_CTga - END And here is the function code : bool img_CTga::LoadAndCreateSurface(LPDIRECTDRAWSURFACE7 &ddSurface, const char *fileName) { HRESULT result; fstream kTarga; kTarga.open (fileName, ios::binary | ios::in); if (kTarga.is_open ()) { unsigned char iFieldDescSize; kTarga.read ((char *) &iFieldDescSize, sizeof (unsigned char)); kTarga.seekg (1, ios::cur); unsigned char iImageCode; kTarga.read ((char *) &iImageCode, sizeof (unsigned char)); if (2 != iImageCode) { return false; } kTarga.seekg (2, ios::cur); unsigned short iMapLength; kTarga.read ((char *) &iMapLength, sizeof (unsigned short)); kTarga.seekg (1, ios::cur); unsigned short iXStart; kTarga.read ((char *) &iXStart, sizeof (unsigned short)); unsigned short iYStart; kTarga.read ((char *) &iYStart, sizeof (unsigned short)); unsigned short iWidth; kTarga.read ((char *) &iWidth, sizeof (unsigned short)); unsigned short iHeight; kTarga.read ((char *) &iHeight, sizeof (unsigned short)); img_CTga::m_iWidth = iWidth; img_CTga::m_iHeight = iHeight; unsigned char iImageBits; kTarga.read ((char *) &iImageBits, sizeof (unsigned char)); if (32 != iImageBits) { return false; } unsigned char iImageDesc; kTarga.read ((char *) &iImageDesc, sizeof (unsigned char)); kTarga.seekg (iFieldDescSize, ios::cur); kTarga.seekg (iMapLength * 4, ios::cur); unsigned long *piBuffer = new unsigned long [m_iWidth * m_iHeight]; kTarga.read ((char *) piBuffer, m_iWidth * m_iHeight * 4 * sizeof (unsigned char)); if (NULL != m_piImageBuffer) { delete [] m_piImageBuffer; } m_piImageBuffer = new unsigned long [m_iWidth * m_iHeight]; unsigned char iRed, iGreen, iBlue, iAlpha; unsigned long iColor; unsigned long iX, iY; for (iY = 0; iY < m_iHeight; iY++) { for (iX = 0; iX < m_iWidth; iX++) { if ((iImageDesc & 1) << 4) { iColor = piBuffer [iX + (iY * m_iWidth)]; iAlpha = (unsigned char)((iColor & 0xFF000000) >> 24); iRed = (unsigned char)((iColor & 0x00FF0000) >> 16); iGreen = (unsigned char)((iColor & 0x0000FF00) >> 8); iBlue = (unsigned char)((iColor & 0x000000FF)); m_piImageBuffer [iX + (iY * m_iWidth)] = iAlpha << 0 | iBlue << 8 | iGreen << 16 | iRed << 24; } else { iColor = piBuffer [iX + (iY * m_iWidth)]; iAlpha = (unsigned char)((iColor & 0xFF000000) >> 24); iRed = (unsigned char)((iColor & 0x00FF0000) >> 16); iGreen = (unsigned char)((iColor & 0x0000FF00) >> 8); iBlue = (unsigned char)((iColor & 0x000000FF)); m_piImageBuffer [iX + (m_iHeight - 1 - iY) * (m_iWidth)] = iAlpha << 0 | iBlue << 8 | iGreen << 16 | iRed << 24; } } } if (NULL != piBuffer) { delete [] piBuffer; } kTarga.close (); } // targa open //+---------------------------------------------------------- //| CREATE DIRECT DRAW SURFACE | //+----------------------------+ if(FAILED(gx_CGraphEngine::CreateSurface(ddSurface,m_iWidth,m_iHeight,true,true))) { //! Break return false; } //------------------------------------------ // LOCK result = ddSurface->Lock(NULL,&ddsd,NULL,NULL); if (result != DD_OK) { return false; } // how to do this? //------------------------------------------ // UNLOCK result = ddSurface->Unlock(NULL); if (result != DD_OK) { return false; } return true; } // end //

Share this post


Link to post
Share on other sites