Porting DirectDraw to SDL
Hello, all. A few years ago I wrote a game using this tutorial
http://www.gamedev.net/reference/articles/article608.asp
Of course, it's been a few years and now Mac OS X is my favourite platform, not Windows. I would like to port my code to SDL, so that I could port it to Mac OS X. Has anybody attempted this? Is there a tutorial anywhere on converting DirectDraw code to SDL? Thank you for any pointers.
Here's a quick and dirty tutorial I whipped up based on the snippets of code I saw as I browsed through.
Initing: Call SDL_Init. That's all.
Create primary surface: Call SDL_SetVideoMode. That's all.
Loading a bitmap: IMG_Load if using the SDL_img library (recommended)
Palettes: I've never used palettes since the 486 days... dunno
Color keying: SDL_SetColorKey on a surface.
Blitting: SDL_BlitSurface
Page flipping: SDL_UpdateRect
Cleaning up: SDL_Quit
That's should serve as a useful starting point for browsing the SDL docs.
Initing: Call SDL_Init. That's all.
Create primary surface: Call SDL_SetVideoMode. That's all.
Loading a bitmap: IMG_Load if using the SDL_img library (recommended)
Palettes: I've never used palettes since the 486 days... dunno
Color keying: SDL_SetColorKey on a surface.
Blitting: SDL_BlitSurface
Page flipping: SDL_UpdateRect
Cleaning up: SDL_Quit
That's should serve as a useful starting point for browsing the SDL docs.
Hi! Thanks bunches for that reply, it really is very helpful!
If i paste some of my code here, would you mind telling me what the equivalent SDL functions are? I would greatly appreciate it.
Thanks!
Jiro-
If i paste some of my code here, would you mind telling me what the equivalent SDL functions are? I would greatly appreciate it.
Thanks!
Jiro-
Quote:Original post by C-Junkie
Page flipping: SDL_UpdateRect
Use SDL_Flip(). If the surface isn't double buffered it will call SDL_UpdateRect().
Here is a section of my code if you want to help...It was written almost 5 years ago so yes it looks like junk...
I would really like to find a way to do it in SDL... :(
I would really like to find a way to do it in SDL... :(
IDirectDrawSurface7 * CSprite::_pMakeSpriteSurface(){ IDirectDrawSurface7 * pdds4; HDC hDC; WORD * wp; m_bOnCriticalSection = TRUE; if( m_stBrush == NULL ) return NULL; CMyDib mydib(m_cPakFileName, m_dwBitmapFileStartLoc); m_wBitmapSizeX = mydib.m_wWidthX; m_wBitmapSizeY = mydib.m_wWidthY; pdds4 = m_pDDraw->pCreateOffScreenSurface(m_wBitmapSizeX, m_wBitmapSizeY); if (pdds4 == NULL) return NULL; pdds4->GetDC(&hDC); mydib.PaintImage(hDC); pdds4->ReleaseDC(hDC); DDSURFACEDESC2 ddsd; ddsd.dwSize = 124; if (pdds4->Lock(NULL, &ddsd, DDLOCK_WAIT, NULL) != DD_OK) return NULL; pdds4->Unlock(NULL); wp = (WORD *)ddsd.lpSurface; m_wColorKey = *wp; m_bOnCriticalSection = FALSE; return pdds4;}void CSprite::PutSpriteFast(int sX, int sY, int sFrame, DWORD dwTime, int iInPvX, int iInPvY){ short dX,dY,sx,sy,szx,szy,pvx,pvy; RECT rcRect; if( this == NULL ) return; if( m_stBrush == NULL ) return; if ((m_iTotalFrame-1 < sFrame) || (sFrame < 0)) return; m_bOnCriticalSection = TRUE; sx = m_stBrush[sFrame].sx; sy = m_stBrush[sFrame].sy; szx = m_stBrush[sFrame].szx; szy = m_stBrush[sFrame].szy; pvx = m_stBrush[sFrame].pvx + iInPvX; pvy = m_stBrush[sFrame].pvy + iInPvY; dX = sX + pvx; // if(bIsGate) // dY = sY + pvy -32;// else dY = sY + pvy; if (dX < m_pDDraw->m_rcClipArea.left) { sx = sx + (m_pDDraw->m_rcClipArea.left - dX); szx = szx - (m_pDDraw->m_rcClipArea.left - dX); if (szx <= 0) { m_rcBound.top = -1; return; } dX = (short)m_pDDraw->m_rcClipArea.left; } else if (dX+szx > m_pDDraw->m_rcClipArea.right) { szx = szx - ((dX+szx) - (short)m_pDDraw->m_rcClipArea.right); if (szx <= 0) { m_rcBound.top = -1; return; } } if (dY < m_pDDraw->m_rcClipArea.top) { sy = sy + (m_pDDraw->m_rcClipArea.top - dY); szy = szy - (m_pDDraw->m_rcClipArea.top - dY); if (szy <= 0) { m_rcBound.top = -1; return; } dY = (short)m_pDDraw->m_rcClipArea.top; } else if (dY+szy > m_pDDraw->m_rcClipArea.bottom) { szy = szy - ((dY+szy) - (short)m_pDDraw->m_rcClipArea.bottom); if (szy <= 0) { m_rcBound.top = -1; return; } } m_dwRefTime = dwTime; if (m_bIsSurfaceEmpty == TRUE) { if( _iOpenSprite() == FALSE ) return; } else { if (m_bAlphaEffect && (m_cAlphaDegree != G_cSpriteAlphaDegree)) { if (G_cSpriteAlphaDegree == 2) { _SetAlphaDegree(); } else { _iCloseSprite(); if( _iOpenSprite() == FALSE ) return; } } } rcRect.left = sx; rcRect.top = sy; rcRect.right = sx + szx; rcRect.bottom = sy + szy; m_rcBound.left = dX; m_rcBound.top = dY; m_rcBound.right = dX + szx; m_rcBound.bottom = dY + szy; m_pDDraw->m_lpBackB4->BltFast( dX, dY, m_lpSurface, &rcRect, DDBLTFAST_SRCCOLORKEY | DDBLTFAST_WAIT ); m_bOnCriticalSection = FALSE;}
Quote:Original post by Jiroh
Here is a section of my code if you want to help...It was written almost 5 years ago so yes it looks like junk...
I would really like to find a way to do it in SDL... :(
Here's Some new code for Making a Surface in SDL
(replaces IDirectDrawSurface7 * CSprite::_pMakeSpriteSurface() )
// Load in an image and convert it to the display format// for faster blitting.SDL_Surface * Image_Load(char *file){ SDL_Surface *temp1, *temp2; temp1 = IMG_Load(file); temp2 = SDL_DisplayFormat(temp1); SDL_FreeSurface(temp1); return temp2;}
(This next function replaces PutSpriteFast() )
// Blit an image on the screen surfacevoid Draw_IMG(SDL_Surface *img, int x, int y){ SDL_Rect dest; dest.x = x; dest.y = y; dest.h = img->h; dest.w = img->w; SDL_BlitSurface(img,//the image to blit NULL, //portion to blit - NULL blits entire imeage screen, //surface create from SDL_SetVideoMode &dest);// where the image will end up on screen}
Its a lot less code with SDL than DD7.
Did I understand your code correctly, one loads an image and the other draws it, right?
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement