Jump to content
  • Advertisement


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



This topic is 6233 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

Ever seen that guy''s article about how to use Direct3D to render isometric 2D tiles? well, i spent all day today converting his code from some earlier version to version 7 (which is pretty cool because i know hardly any Direct3D). It works fine, in wireframe mode, but when i try to load textures i get this wierd message from the flipping code. This flips the back buffers... int clsGraphicsStuff::Flip(void) { HRESULT ddrval; ddrval = lpPrimaryBuffer->Flip(NULL, DDFLIP_WAIT); if FAILED(ddrval) { DebugStuff.OutputLog("Couldn''t flip!"); DebugStuff.OutputLog(ddrval); } return(1); } but when i try to load some textures, not changing ANYTHING else, just loading some textures onto some surfaces, i get a DDERR_NOTFLIPPABLE error from the flipping code. Heres the code i''m using to load a bitmap onto a surface and create a texture.... LPDIRECTDRAWSURFACE7 lsDirect3DStuff::CreateTextureFromBitmap( LPDIRECT3DDEVICE7 pd3dDevice, char *Filename ) { HBITMAP hbm = (HBITMAP)LoadImage( GetModuleHandle(NULL), Filename, IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION ); if( NULL == hbm ) { // If not in the resource, try to load the bitmap as a file. Real code // would try to find the bitmap among many file paths. hbm = (HBITMAP)LoadImage( NULL, Filename, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE|LR_CREATEDIBSECTION ); if( NULL == hbm ) { DebugStuff.OutputLog("Failed at Place #1"); return NULL; } } LPDIRECTDRAWSURFACE7 pddsTexture; HRESULT hr; // Get the device caps so we can check if the device has any constraints // when using textures D3DDEVICEDESC7 ddDesc; if( FAILED( pd3dDevice->GetCaps( &ddDesc ) ) ) return NULL; // Get the bitmap structure (to extract width, height, and bpp) BITMAP bm; GetObject( hbm, sizeof(BITMAP), &bm ); DWORD dwWidth = (DWORD)bm.bmWidth; DWORD dwHeight = (DWORD)bm.bmHeight; // Setup the new surface desc for the texture. Note how we are using the // texture manage attribute, so Direct3D does alot of dirty work for us DDSURFACEDESC2 ddsd; ZeroMemory( &ddsd, sizeof(DDSURFACEDESC2) ); ddsd.dwSize = sizeof(DDSURFACEDESC2); ddsd.dwFlags = DDSD_CAPS|DDSD_HEIGHT|DDSD_WIDTH| DDSD_PIXELFORMAT|DDSD_TEXTURESTAGE; ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE; ddsd.dwWidth = dwWidth; ddsd.dwHeight = dwHeight; // Turn on texture management for hardware devices if( ddDesc.deviceGUID == IID_IDirect3DHALDevice ) ddsd.ddsCaps.dwCaps2 = DDSCAPS2_TEXTUREMANAGE; else if( ddDesc.deviceGUID == IID_IDirect3DTnLHalDevice ) ddsd.ddsCaps.dwCaps2 = DDSCAPS2_TEXTUREMANAGE; else ddsd.ddsCaps.dwCaps |= DDSCAPS_SYSTEMMEMORY; // Adjust width and height, if the driver requires it if( ddDesc.dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2 ) { for( ddsd.dwWidth=1; dwWidth>ddsd.dwWidth; ddsd.dwWidth<<=1 ); for( ddsd.dwHeight=1; dwHeight>ddsd.dwHeight; ddsd.dwHeight<<=1 ); } if( ddDesc.dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_SQUAREONLY ) { if( ddsd.dwWidth > ddsd.dwHeight ) ddsd.dwHeight = ddsd.dwWidth; else ddsd.dwWidth = ddsd.dwHeight; } // Enumerate the texture formats, and find the closest device-supported // texture pixel format. The TextureSearchCallback function for this // tutorial is simply looking for a 16-bit texture. Real apps may be // interested in other formats, for alpha textures, bumpmaps, etc.. pd3dDevice->EnumTextureFormats( TextureSearchCallback, &ddsd.ddpfPixelFormat ); if( 0L == ddsd.ddpfPixelFormat.dwRGBBitCount ) return NULL; // Get the device''s render target, so we can then use the render target to // get a ptr to a DDraw object. We need the DirectDraw interface for // creating surfaces. LPDIRECTDRAWSURFACE7 pddsRender; LPDIRECTDRAW7 pDD; pd3dDevice->GetRenderTarget( &pddsRender ); pddsRender->GetDDInterface( (VOID**)&pDD ); pddsRender->Release(); // Create a new surface for the texture if( FAILED( hr = pDD->CreateSurface( &ddsd, &pddsTexture, NULL ) ) ) { pDD->Release(); return NULL; } // Done with DDraw pDD->Release(); // Now, copy the bitmap to the texture surface. To do this, we are creating // a DC for the bitmap and a DC for the surface, so we can use the BitBlt() // call to copy the actual bits. // Get a DC for the bitmap HDC hdcBitmap = CreateCompatibleDC( NULL ); if( NULL == hdcBitmap ) { pddsTexture->Release(); return NULL; } SelectObject( hdcBitmap, hbm ); // Get a DC for the surface HDC hdcTexture; if( SUCCEEDED( pddsTexture->GetDC( &hdcTexture ) ) ) { // Copy the bitmap image to the surface. BitBlt( hdcTexture, 0, 0, bm.bmWidth, bm.bmHeight, hdcBitmap, 0, 0, SRCCOPY ); pddsTexture->ReleaseDC( hdcTexture ); } DeleteDC( hdcBitmap ); // Return the newly created texture return pddsTexture; } sorry that was so long. anyway, do yall have ANY ideas what is wrong?! i haven''t changed ANY code from the wireframe rendering version to this one, except adding the call to the function that loads all the textures! and incase its important, i''m calling that texture creating thing like this: lpSomeTextureSurface = CreateTextureFromBitmap(lpDevice, "c:\somefolder\someimage");

Share this post

Link to post
Share on other sites
Im not sure this is the problem but maybe you should try using


instead of



Thats what I dislike about DirectX, the return calls dont tell you exactly what the problem is, and as a result, you waste loads of time trying to solve the problem blindfolded.

DX8 is even worse, most functions only return D3DERR_INVALIDCALL.

  Game Download  ZeroOne Realm

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!