   DirectDraw Surfaces, what Dx8 equivelant?
  I'm looking at the source code for a DirectX 6 game (Aliens Vs Predator, a game that uses D3D) which has numerous uses of DirectDraw Surfaces and DirectDraw surface descriptors.If someone was to go about porting such old rendering code to a newer directx version such as 8 or 9, then which would be the better choice to replace a DirectDraw surface...a Direct3D Surface or a Direct3D Texture?Am I right or wrong in thinking that the D3DPRESENT_PARAMETERS are the new equivelant of a DirectDraw surface descriptor?D3DFORMAT now does the work of DDPIXELFORMAT?   
  It's not quite as simple as replacing each type with a new type, unfortunately.D3DPRESENT_PARAMETERS specify how you swap between the back buffer and the front buffer. As the name suggests, they're parameters to 'Present()'. The two buffers are pretty much like the front and back buffer surfaces in DirectDraw, but they're nothing to do with sprite or texture graphics.And surfaces in Direct3D have subtly different uses to those in DirectDraw.Generally speaking you need to load your graphics in as textures. You may find the D3DX functions make this easier, as they provide a sprite interface that makes D3D9 more like DirectDraw.   ;  Thanks, that's cleared things up in my mind quite a bit :);  Need to bump this again as I have another question..In the game, special effects and whatnot for the menu system (font drawing, text glow etc) was done with a directdraw surface, which would get locked, and then each pixel in the specified screen area would get "updated"In the Linux port, which uses SDL and OpenGL, there's an extern surface global defined extern SDL_Surface *surface;the backbuffer I assume.. this was locked, and the pixel operations were performed on it. I was wondering how you go about this with Direct3D. Would I create a surface, use GetBackBuffer() to retrieve the back buffer and then use LockRect with that?I keep reading that using LockRect is *bad* but in the case of a menu system, I can't see performance being an issue.Still, I am a little unsure :)Here's one of the menu drawing functions. LockSurfaceAndGetBufferPointer(); sets the global variable 'ScreenBuffer' to point to the back buffer. [source code="cpp"]extern void DrawAvPMenuGlowyBar_Clipped(int topleftX, int topleftY, int alpha, int length, int topY, int bottomY){enum AVPMENUGFX_ID menuGfxID = AVPMENUGFX_GLOWY_MIDDLE;LockSurfaceAndGetBufferPointer();DDSURFACEDESC ddsdimage;   unsigned short *destPtr;unsigned short *srcPtr;AVPMENUGFX *gfxPtr;LPDIRECTDRAWSURFACE surface;GLOBALASSERT(menuGfxID < MAX_NO_OF_AVPMENUGFXS);gfxPtr = &AvPMenuGfxStorage[menuGfxID];surface = gfxPtr->ImagePtr;memset(&ddsdimage, 0, sizeof(ddsdimage));ddsdimage.dwSize = sizeof(ddsdimage);/* lock the image */while (surface->Lock(NULL, &ddsdimage, DDLOCK_WAIT, NULL) == DDERR_WASSTILLDRAWING);srcPtr = (unsigned short *)ddsdimage.lpSurface;if (length<0) length = 0;if (alpha>ONE_FIXED){int x,y;for (y=topleftY; y<gfxPtr->Height+topleftY; y++){if(y>=topY && y<=bottomY){destPtr = (unsigned short *)(ScreenBuffer + topleftX*2 + y*BackBufferPitch);for (x=0; x<length; x++){*destPtr = *srcPtr;destPtr++;}srcPtr += (ddsdimage.lPitch/2); }}}else{int x,y;for (y=topleftY; y<gfxPtr->Height+topleftY; y++){if(y>=topY && y<=bottomY){destPtr = (unsigned short *)(ScreenBuffer + topleftX*2 + y*BackBufferPitch);for (x=0; x<length; x++){if (*srcPtr){unsigned int srcR,srcG,srcB;unsigned int destR,destG,destB;destR = (int)(*destPtr) & DisplayPixelFormat.dwRBitMask;destG = (int)(*destPtr) & DisplayPixelFormat.dwGBitMask;destB = (int)(*destPtr) & DisplayPixelFormat.dwBBitMask;srcR = (int)(*srcPtr) & DisplayPixelFormat.dwRBitMask;srcG = (int)(*srcPtr) & DisplayPixelFormat.dwGBitMask;srcB = (int)(*srcPtr) & DisplayPixelFormat.dwBBitMask;destR += MUL_FIXED(alpha,srcR);if (destR>DisplayPixelFormat.dwRBitMask) destR = DisplayPixelFormat.dwRBitMask;else destR &= DisplayPixelFormat.dwRBitMask;destG += MUL_FIXED(alpha,srcG);if (destG>DisplayPixelFormat.dwGBitMask) destG = DisplayPixelFormat.dwGBitMask;else destG &= DisplayPixelFormat.dwGBitMask;destB += MUL_FIXED(alpha,srcB);if (destB>DisplayPixelFormat.dwBBitMask) destB = DisplayPixelFormat.dwBBitMask;else destB &= DisplayPixelFormat.dwBBitMask;*destPtr = (short)(destR|destG|destB);}destPtr++;}}srcPtr += (ddsdimage.lPitch/2); }} surface->Unlock((LPVOID)ddsdimage.lpSurface);UnlockSurface();}And here's the linux port equivelant:the D3DTexture struct is a redefined version of DIRECT3DTEXTUREtypedef struct DIRECT3DTEXTURE{unsigned char *buf;int id; int w;int h; int filter;} DIRECT3DTEXTURE;[source code="cpp"]static void DrawAvPMenuGlowyBar(int topleftX, int topleftY, int alpha, int length){enum AVPMENUGFX_ID menuGfxID = AVPMENUGFX_GLOWY_MIDDLE;unsigned char *srcPtr;unsigned short *destPtr;AVPMENUGFX *gfxPtr;D3DTexture *image;gfxPtr = &AvPMenuGfxStorage[menuGfxID];image = gfxPtr->ImagePtr;srcPtr = image->buf;if (ScreenDescriptorBlock.SDB_Width - topleftX < length) {length = ScreenDescriptorBlock.SDB_Width - topleftX;}if (length<0) length = 0;if (SDL_MUSTLOCK(surface)) {if (SDL_LockSurface(surface) < 0) {return; /* ... */}}if (alpha>ONE_FIXED) {int x, y;for (y=topleftY; y<gfxPtr->Height+topleftY; y++) {destPtr = (unsigned short *)(((unsigned char *)surface->pixels) + y*surface->pitch) + topleftX;for (x=0; x<length; x++) {*destPtr =((srcPtr[0]>>3)<<11) |((srcPtr[1]>>2)<<5 ) |((srcPtr[2]>>3));destPtr++;}srcPtr += image->w * 4;}} else {int x, y;for (y=topleftY; y<gfxPtr->Height+topleftY; y++) {destPtr = ((unsigned short *)(((unsigned char *)surface->pixels) + y*surface->pitch)) + topleftX;for (x=0; x<length; x++) {if (srcPtr[0] || srcPtr[1] || srcPtr[2]) {unsigned int destR, destG, destB;destR = (*destPtr & 0xF800)>>8;destG = (*destPtr & 0x07E0)>>3;destB = (*destPtr & 0x001F)<<3;destR += MUL_FIXED(alpha, srcPtr[0]);destG += MUL_FIXED(alpha, srcPtr[1]);destB += MUL_FIXED(alpha, srcPtr[2]);if (destR > 0x00FF) destR = 0x00FF;if (destG > 0x00FF) destG = 0x00FF;if (destB > 0x00FF) destB = 0x00FF;*destPtr =((destR>>3)<<11) |((destG>>2)<<5 ) |((destB>>3));}destPtr++;}srcPtr += image->w * 4;}}if (SDL_MUSTLOCK(surface)) {SDL_UnlockSurface(surface);}};Quote:Original post by sirlemonheadIn the game, special effects and whatnot for the menu system (font drawing, text glow etc) was done with a directdraw surface, which would get locked, and then each pixel in the specified screen area would get "updated"...I was wondering how you go about this with Direct3D. Would I create a surface, use GetBackBuffer() to retrieve the back buffer and then use LockRect with that?I keep reading that using LockRect is *bad* but in the case of a menu system, I can't see performance being an issue.3D rendering these days is done on a separate processor to your CPU - this means that relatively speaking, it's actually very slow to read and write individual pixels as the data has to be communicated back and forth. Therefore typically you wouldn't ever write directly to a buffer in real time like that any more.It is probably still possible, but you're discouraged from doing it, both by the interface and by the performance implications. Perhaps someone on the DirectX forum could give you a more useful answer though.;  As Kylotan said, locking surfaces isn't usually a good idea. I'd be tempted to use a dynamic texture for your UI (If it's not going to be fullscreen, and just a simple menu system), then you can lock that without too much of a performance penalty. Then just render a quad with that texture applied to it.Alternatively (and preferably), I'd rewrite the UI system to use sprites (See ID3DXSprite) to handle the UI elements, and ID3DXFont for the text.Also, I wouldn't bother with DX8, you're just as well going for DX9 - there's more people using it, the D3DX library has better performance, DX8 isn't being developed any more, and some things are easier to do in DX9.   