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
🔒 Locked
Doesn't show rectangular bitmaps right
Advertisement
Original Post
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:
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
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
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/
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
- WitchLord
Edited by - WitchLord on 4/23/00 12:51:05 PM
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
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
Here is the BITMAP_FILE struct, as from LaMothe:
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
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
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/
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.
The_Minister
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
Okay I looked it up in the help file.
Width is 250, and height is 200, as it should be.
Printed right after the bitmap was loaded.
Any takers?
The_Minister
Width is 250, and height is 200, as it should be.
Printed right after the bitmap was loaded.
Any takers?
The_Minister
Is there a pitch value in the BITMAPINFOHEADER structure?
lntakitopi@aol.com
http://geocities.com/guanajam/
lntakitopi@aol.com
http://geocities.com/guanajam/
SHilbert: No there isn''t, and I don''t think there needs to be.
goir: Good idea, but one of the bitmaps in the screenshot is 300x300, not divisable by eight
. Are you saying that maybe DirectDraw can''t blit surfaces that are not divisable by eight? Or maybe it''s divisable by four, not eight, as that would work with 300? Intriguing notion... But still that is a bit of a restriction.
Did your bitmap get spliced up like mine? BTW is that screenie even coming through, because I think xoom.com is messing me around again...
Also there is no mention of this in the SDK that I have seen... still I will try it... 200x400 sounds fair enough.
The_Minister
goir: Good idea, but one of the bitmaps in the screenshot is 300x300, not divisable by eight
Did your bitmap get spliced up like mine? BTW is that screenie even coming through, because I think xoom.com is messing me around again...
Also there is no mention of this in the SDK that I have seen... still I will try it... 200x400 sounds fair enough.
The_Minister
Holy Cr@p it works
. /me smothers goir in kisses.. wait... no
.
Thanks guys
The_Minister
Thanks guys
The_Minister
What happed to my bitmaps was that they looked like every row was pushed a bit to the left (or right, I don''t remember). Kina like what I mad below
/ / / / /
/ / / / /
/ / / / /
/ / / / /
/ / / / /
/ / / / /
Also the colors was messed up and looked a little like black and white (but there were other colors aswell).
and I can''t see that ''screenie'' all I see is an xoom logo.
I think you can solve the problem by making the surface in a multiple of 8 and then only use part of the surface when you blit, but I haven''t tried.
/ / / / /
/ / / / /
/ / / / /
/ / / / /
/ / / / /
/ / / / /
Also the colors was messed up and looked a little like black and white (but there were other colors aswell).
and I can''t see that ''screenie'' all I see is an xoom logo.
I think you can solve the problem by making the surface in a multiple of 8 and then only use part of the surface when you blit, but I haven''t tried.
Yeah that''s exactly what I got, thanks. I will have to do a bit of el hacko to get this right.
The_Minister
The_Minister
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement