   Sprite Loader SOLVED
  Hi all,I made a function that loads a Part of a Surface and stores it in a new Surface.But it don't work. The new created Surface is always full of black and some white pixels.NOTE: I use 8BPP Modebool LoadSprite(LPDIRECTDRAWSURFACE7& rpDDSImage, LPDIRECTDRAWSURFACE7& rpDDSSprite,int nSpriteWidth, int nSpriteHeight, int nSpriteX, int nSpriteY){// Struktur vorbereitenDDSURFACEDESC2 ddsd;memset(&ddsd, 0, sizeof(ddsd));ddsd.dwWidth = sizeof(ddsd);// Image lockenif(rpDDSImage->Lock(NULL, &ddsd, DDLOCK_WAIT | DDLOCK_SURFACEMEMORYPTR, NULL))return(false);int nImageWidth= (int)ddsd.dwWidth;int nImageHeight= (int)ddsd.dwHeight;int nImagePitch= (int)ddsd.lPitch;int nStartX= nSpriteX*nSpriteWidth;int nStartY= nSpriteY*nSpriteHeight;BYTE* pbyImage= (BYTE*)ddsd.lpSurface;// Bild ist groß genug?if(nSpriteWidth*nSpriteX > nImageWidth || nSpriteHeight*nSpriteY > nImageHeight){rpDDSImage->Unlock(NULL);return(false);}// Speicher für das Sprite bereitstellenBYTE* pbyTemp = new BYTE[nSpriteWidth*nSpriteHeight];for(int nY=nStartY;nY<nSpriteHeight+nStartY; nY++){for(int nX=nStartX;nX<nSpriteWidth+nStartX;nX++){pbyTemp[nX + (nY * nSpriteWidth)] = pbyImage[nX + (nY * nImagePitch)];}}// Image freigebenif(rpDDSImage->Unlock(NULL))return(false);// Struktur vorbereitenmemset(&ddsd, 0, sizeof(ddsd));ddsd.dwSize = sizeof(ddsd);// Sprite Surface lockenif(rpDDSSprite->Lock(NULL, &ddsd, DDLOCK_WAIT |DDLOCK_SURFACEMEMORYPTR, NULL))return(false);intnSpritePitch= (int)ddsd.lPitch;BYTE* pbySprite= (BYTE*)ddsd.lpSurface;// Daten umkopierenfor(int nY=0;nY<nSpriteHeight; nY++){for(int nX=0;nX<nSpriteWidth;nX++){pbySprite[nX + (nY * nSpritePitch)] = pbyTemp[nX + (nY * nSpriteWidth)];}}// Surface freigebenif(rpDDSSprite->Unlock(NULL))return(false);// Speicher freigebendelete pbyTemp;pbyTemp =NULL;return(true);}Please help, otherwise my project will never finish [tears][Edited by - m4ster on January 14, 2007 12:42:07 PM]
  This doesn't realy answer your question - But why don't you lock both surfaces and just copy directly between them? You should be able to copy a row at a time (width_of_the_sprite bytes) too, which would save you the inner loop.   ;  I don't lock both surfaces the same time, because I don't like it. I tryed to make clean and easy code and in my opinion locking 2 surfaces the same time seems to be too complex. [lol]   ;  Hey,I found the mistake by myself.It's pretty easy and very very very stupid [lol].// Struktur vorbereitenDDSURFACEDESC2 ddsd;memset(&ddsd, 0, sizeof(ddsd));ddsd.dwWidth = sizeof(ddsd);// Has to be: ddsd.dwSize [Edited by - m4ster on January 14, 2007 12:24:27 PM]