Doesn't show rectangular bitmaps right

Started by
15 comments, last by The_Minister 24 years ago
Yo guys, this problem is frying my brain. I am writing an API based on DirectX for my game, and I have just finished displaying bitmaps, with my own load functions etc. So I load the bitmap, make a surface for it and copy it, pixel by pixel, to the surface. Then I ditch the bitmap''s old buffer. This works great for square bitmaps, but not for rectangular ones. When I blit a rectangular one, it appears heavily distorted. I first thought this was some stupid mistake when I was using Width instead of height, and because they are square it didn''t matter, but I went through the code over and over and I can''t find a single place that I did this in. I suspect the function that copies the buffer to the surface, shown here: int Bitmap::CopyBitmapToSurface (BITMAP_FILE_PTR bitmap, LPDDSURFACEDESC2 ddsd) { UCHAR *Surface = (UCHAR *)ddsd->lpSurface; // the drawing surface // copy pixel by pixel for (int index_y = 0; index_y < bitmap->InfoHeader.biHeight; index_y++) for (int index_x = 0; index_x < bitmap->InfoHeader.biWidth; index_x++) Surface[index_x + index_y * int(ddsd->lPitch)] = bitmap->buffer[index_x + index_y * bitmap->InfoHeader.biWidth]; return 1; } If this seems perfect, like it does to me, then the problem must be somewhere else... Anyways thanks for your time, and if you can help me, well that''s even better. The_Minister
[email=mwronen@mweb.co.za" onmouseOver="window.status='Mail The_Minister'; return true" onmouseOut="window.status=' '; return true]The_Minister[/email]1C3-D3M0N Interactive
Advertisement
What kind of "distorted"? Stretched? Garbled? Skewed?

http://geocities.com/guanajam/
Here is a screenshot, followed by what the bitmap is supposed to look like.




Note that I have converted the to .gif for quicker download.


The_Minister

Edited by - The_Minister on 4/23/00 12:15:49 PM
[email=mwronen@mweb.co.za" onmouseOver="window.status='Mail The_Minister'; return true" onmouseOut="window.status=' '; return true]The_Minister[/email]1C3-D3M0N Interactive
It''s getting skewed. I think that
bitmap->InfoHeader.biWidth
is not the bitmap''s real width, for some reason. (From my estimate, it looks like it''s 2 pixels over the real value.) You might want to try getting the width from some other location.

lntakitopi@aol.com
http://geocities.com/guanajam/
I haven't studied the bitmap structure in detail so I'm not sure that this is true. But each row in the image may infact be longer than the actual width of the image in pixels. They are usually padded for 32 bit alignment. I see that you use lPitch on the DDSurface, isn't there something similar in the bitmap structure?


- WitchLord




Edited by - WitchLord on 4/23/00 12:51:05 PM

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

It works for the other bitmaps?
Crazy idea but: Maybe, for some reason, biWidth is the same as biHeight?

Ok I''ve been putting this off for a while now, but it looks like I''m going to need it. How do you print numbers using TextOut, or add them to char*''s? Gee I feel stupid asking that, but I have to learn too

I need this because, as said by someone else before, I can''t use the debugger line-by-line after I hit the lock.

Any help whatsoever would be appreciated, thanks again.


The_Minister
[email=mwronen@mweb.co.za" onmouseOver="window.status='Mail The_Minister'; return true" onmouseOut="window.status=' '; return true]The_Minister[/email]1C3-D3M0N Interactive
You print numbers in a string by using sprintf()

char Str[256];
sprintf(Str,"Number: %d\n", 128);

This creates the string: "Number: 128", that you may then use in TextOut.

- WitchLord

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

Here is the BITMAP_FILE struct, as from LaMothe:


typedef struct
{
BITMAPFILEHEADER FileHeader; // file header is stored here
BITMAPINFOHEADER InfoHeader; // infoheader is stored here

PALETTEENTRY palette[256]; // palette is translated from BGR to RGB and stored here

UCHAR *buffer; // image is stored here
} BITMAP_FILE, *BITMAP_FILE_PTR;


I examined BITMAPINFOHEADER and the only thing denoting width in pixels, is biWidth.

Also the bitmaps are all 8-bit, with a palette, and the display is 8-bit. LOL I JUST ENDED OFF A SENTENCE WITH A SEMI-COLON. Hmm I need to get some air...


The_Minister
[email=mwronen@mweb.co.za" onmouseOver="window.status='Mail The_Minister'; return true" onmouseOut="window.status=' '; return true]The_Minister[/email]1C3-D3M0N Interactive
Here''s my code for using TextOut (It prints green text w/ a black shadow.)

HRESULT DebugOut(int x, int y, char *szText)
{
// Get the device context of the screen
HDC hDC;
g_pBackBuffer->GetDC(&hDC);

// Make sure it prints transparently
SetBkMode( hDC, TRANSPARENT );

// Set an appropriate color
SetTextColor(hDC, RGB(0,0,0));
ExtTextOut( hDC, x+1, y+1, 0, NULL, szText, strlen(szText), NULL );
SetTextColor(hDC, RGB(0,255,0));
ExtTextOut( hDC, x, y, 0, NULL, szText, strlen(szText), NULL );

// Release the DC
g_pBackBuffer->ReleaseDC(hDC);

// Return OK
return DD_OK;
}

lntakitopi@aol.com
http://geocities.com/guanajam/
It says ''sprintf - undeclared identifier''. The weird thing is that when I hover the mouse over it, it tells me it''s definition line, and it shows the parameter list when I open the paranthesis. Do I need to include something?
At the moment I just have ddraw.h, windows.h and windowsx.h, excluding my api includes.


char *Msg;

sprintf(Msg, "Bitmap Width: %d Bitmap Height: %d\n", bitmap->InfoHeader.biWidth, bitmap->InfoHeader.biHeight);
ShowMessage (Msg, 50);



The_Minister
[email=mwronen@mweb.co.za" onmouseOver="window.status='Mail The_Minister'; return true" onmouseOut="window.status=' '; return true]The_Minister[/email]1C3-D3M0N Interactive

This topic is closed to new replies.

Advertisement