Archived

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

Loading BMP as a D3DIM Texture does not work

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

Guest Anonymous Poster
Try using BitBlt instead of StretchBlt, scence you are not stretching the bitmap anyhow. (The old D3D tutorials used BitBlt)

Share this post


Link to post
Share on other sites
Hi !!

I have a problem loading a bitmap into a Direct3D Immediate Mode Texture, well it seems to be so. I don't get any error, but my cube is not textured. Using the D3DFramework and loading the Texture works fine.
I am using DirectX 6 and MSVC 6 !

This is my code to load the bmp:


BOOL CTexture::LoadBMP(char *strFilename)
{
HBITMAP hBm = NULL;
BITMAP Bm;

extern HINSTANCE ghInstance;
extern CRenderer Renderer;
extern HWND hWndMain;

hBm = (HBITMAP)LoadImage(ghInstance,strFilename,IMAGE_BITMAP,0,0,LR_LOADFROMFILE|LR_CREATEDIBSECTION);
if (hBm == NULL) {
MessageBox(hWndMain,"Loading Bitmap failed","3D Engine",0);
return FALSE;
}

GetObject(hBm,sizeof(Bm),&Bm);

DDSURFACEDESC2 ddsd;
ZeroMemory(&ddsd, sizeof(ddsd));
ddsd.dwSize = sizeof(ddsd);
ddsd.dwFlags = DDSD_CAPS|DDSD_HEIGHT|DDSD_WIDTH|DDSD_TEXTURESTAGE;
ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
ddsd.ddsCaps.dwCaps2 = DDSCAPS2_TEXTUREMANAGE;
ddsd.dwWidth = Bm.bmWidth;
ddsd.dwHeight = Bm.bmHeight;
ddsd.dwTextureStage = 0;

if (Renderer.pDD4->CreateSurface(&ddsd, &pDDSurface, NULL) != DD_OK) {
DeleteObject(hBm);
MessageBox(hWndMain,"Texture Surface Creation failed","3D Engine",0);
return NULL;
}

HDC hdcImage;
HDC hdc;
HRESULT hr;
int x,y,dx,dy;
dx = dy = x = y = 0;

hdcImage = CreateCompatibleDC(NULL);
SelectObject(hdcImage, hBm);

GetObject(hBm, sizeof(Bm), &Bm); // get size of bitmap

ZeroMemory(&ddsd, sizeof(ddsd));
ddsd.dwSize = sizeof(ddsd);
ddsd.dwFlags = DDSD_HEIGHT | DDSD_WIDTH;
pDDSurface->GetSurfaceDesc(&ddsd);

if ((hr = pDDSurface->GetDC(&hdc)) == DD_OK) {
StretchBlt(hdc, 0, 0, Bm.bmWidth, Bm.bmHeight, hdcImage, 0, 0, Bm.bmWidth, Bm.bmHeight, SRCCOPY);
pDDSurface->ReleaseDC(hdc);
} else {
MessageBox(hWndMain,"Texture GetDC failed","3D Engine",0);
}

DeleteDC(hdcImage);
DeleteObject(hBm);

if (pDDSurface->QueryInterface(IID_IDirect3DTexture2, (LPVOID *)&pDDTexture) != S_OK) {
MessageBox(hWndMain,"Texture Query Interface failed","3D Engine",0);
return FALSE;
}

return TRUE;
}

My Renderer uses the pDDTexture member variable for:


pD3DDevice->SetTexture(0,pWorld->texture.pDDTexture);

I have used the D3DFrameworks support for textures and loading the same bitmap without changing the renderer works fine. So there must be an error in my BMP-Loading Routine.

What's wrong with my code ?????

Phillip

Share this post


Link to post
Share on other sites