Jump to content

  • Log In with Google      Sign In   
  • Create Account

Loading BMP as a D3DIM Texture does not work


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
1 reply to this topic

#1 Phillip Schuster   Members   -  Reputation: 122

Like
Likes
Like

Posted 06 October 1999 - 09:25 AM

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


Sponsor:

#2 Anonymous Poster_Anonymous Poster_*   Guests   -  Reputation:

Likes

Posted 06 October 1999 - 09:25 AM

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





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS