Skip to main content
gamedev.net
🔒 Locked

Displaying a single tile help

Started by Zeke Dec 7, 2000 at 6:40 AM 8 replies 300+ views
Original Post
Zeke
Zeke
Can anyone explain how to, or point me in the direction of something to help me, display a single 32*32 pixel tile on the screen? I can display full screen bitmaps on the screen but when i try and get a single tile it goes wrong and exits the program without displaying anything. a tiling tutorial form the ground up would be good. Thanks for any help "People spend too much time thinking about the past, whatever else it is, its gone"-Mel Gibson, Man Without A Face
Just my thoughts take them as you will. "People spend too much time thinking about the past, whatever else it is, its gone"-Mel Gibson, Man Without A Face
NewDeal
NewDeal
You should probably be a little more specific. It sounds to me like you need to read up on your blt funtions. Maybe you are getting the coordinates wrong and bltting outside the screen?
acraig
acraig
You have to think about 3 main things:

  1. Source location of the tile ( source RECT ).
    • If you are trying to blt from the wrong place on the surface you won''t get anything. Make sure you give the right RECT location.


  2. Destination location of tile ( dest RECT )
    • Same thing here. If you are trying to blt to an invalid location nothing will happen.

  3. Clipping.
    • Some DX blt functions will NOT prefrom autoclipping so that if the tile is not totaly on the screen it won''t be displayed at all. Other blt functions do clip so read up on the ones you are using.


Take a look at CDX''s map class to see how you can have smooth scrolling maps.



-------
Andrew
Zeke
Zeke
Thanks for the response guys.
I have no idea why it doesnt work. Im using the blt() function. the destination rect is 0,0 to 32,32 the source rectangle is 0,0 to 32,32. But when i execute this the program just exits. I put a messagebox function to display and error if the blt function fails and it does. So i know it is the blt function that is going wrong i just dont know why.

"People spend too much time thinking about the past, whatever else it is, its gone"-Mel Gibson, Man Without A Face
Just my thoughts take them as you will. "People spend too much time thinking about the past, whatever else it is, its gone"-Mel Gibson, Man Without A Face
NewDeal
NewDeal
I ve had some problems with Blt() in the past. Try using Bitblt instead.
Zeke
Zeke
It didn''t work. i must be doing something fundamentally wrong, but i don''t know what

"People spend too much time thinking about the past, whatever else it is, its gone"-Mel Gibson, Man Without A Face
Just my thoughts take them as you will. "People spend too much time thinking about the past, whatever else it is, its gone"-Mel Gibson, Man Without A Face
acraig
acraig
A few things to check:

  • Is the tile actually loaded correctly onto your source surface?
  • What is the error from the blt?
  • Make sure that the source and dest rects are in the right place in the function call.
  • If it just exits ( unexpectantly ) then there may be problems elsewhere ( like null pointer )


Could also try BltFast().



-------
Andrew
Zeke
Zeke
i think i might have found the problem. is it possible to put a 32*32 pixel bitmap onto the primary surface from a file. i.e. i am loading the bitmap and then trying to put it straight onto the primary surface. is this the problem? I know how to create offscreen surfaces but i didnt want to bother setting any up until i could actually load and display a single tile.


"People spend too much time thinking about the past, whatever else it is, its gone"-Mel Gibson, Man Without A Face
Just my thoughts take them as you will. "People spend too much time thinking about the past, whatever else it is, its gone"-Mel Gibson, Man Without A Face
acraig
acraig
quote:
Original post by Zeke
i am loading the bitmap and then trying to put it straight onto the primary surface. is this the problem?




I didn''t think that you can do that. I thought blt used two surfaces. How are you loading the bitmap?


I usually have the primary surface, the back buffer and a surface with all my tiles on it. I then blt from my tile surface to the back buffer and then flip().

-------
Andrew
Zeke
Zeke
I am using the function from tricks of the window game programming guru''s:

  
int Load_Bitmap_File(BITMAP_FILE_PTR bitmap, char *filename)
{
// this function opens a bitmap file and loads the data into bitmap


int file_handle, // the file handle

index; // looping index


UCHAR *temp_buffer = NULL; // used to convert 24 bit images to 16 bit

OFSTRUCT file_data; // the file data information


// open the file if it exists

if ((file_handle = OpenFile(filename,&file_data,OF_READ))==-1)
return(0);

// now load the bitmap file header

_lread(file_handle, &bitmap->bitmapfileheader,sizeof(BITMAPFILEHEADER));

// test if this is a bitmap file

if (bitmap->bitmapfileheader.bfType!=BITMAP_ID)
{
// close the file

_lclose(file_handle);

// return error

return(0);
} // end if


// now we know this is a bitmap, so read in all the sections


// first the bitmap infoheader


// now load the bitmap file header

_lread(file_handle, &bitmap->bitmapinfoheader,sizeof(BITMAPINFOHEADER));

// now load the color palette if there is one

if (bitmap->bitmapinfoheader.biBitCount == 8)
{
_lread(file_handle, &bitmap->palette,MAX_COLORS_PALETTE*sizeof(PALETTEENTRY));

// now set all the flags in the palette correctly and fix the reversed

// BGR RGBQUAD data format

for (index=0; index < MAX_COLORS_PALETTE; index++)
{
// reverse the red and green fields

int temp_color = bitmap->palette[index].peRed;
bitmap->palette[index].peRed = bitmap->palette[index].peBlue;
bitmap->palette[index].peBlue = temp_color;

// always set the flags word to this

bitmap->palette[index].peFlags = PC_NOCOLLAPSE;
} // end for index


} // end if


// finally the image data itself

_lseek(file_handle,-(int)(bitmap->bitmapinfoheader.biSizeImage),SEEK_END);

// now read in the image, if the image is 8 or 16 bit then simply read it

// but if its 24 bit then read it into a temporary area and then convert

// it to a 16 bit image


if (bitmap->bitmapinfoheader.biBitCount==8 || bitmap->bitmapinfoheader.biBitCount==16 ||
bitmap->bitmapinfoheader.biBitCount==24)
{
// delete the last image if there was one

if (bitmap->buffer)
free(bitmap->buffer);

// allocate the memory for the image

if (!(bitmap->buffer = (UCHAR *)malloc(bitmap->bitmapinfoheader.biSizeImage)))
{
// close the file

_lclose(file_handle);

// return error

return(0);
} // end if


// now read it in

_lread(file_handle,bitmap->buffer,bitmap->bitmapinfoheader.biSizeImage);

} // end if

else
{
// serious problem

return(0);

} // end else


#if 0
// write the file info out

printf("\nfilename:%s \nsize=%d \nwidth=%d \nheight=%d \nbitsperpixel=%d \ncolors=%d \nimpcolors=%d",
filename,
bitmap->bitmapinfoheader.biSizeImage,
bitmap->bitmapinfoheader.biWidth,
bitmap->bitmapinfoheader.biHeight,
bitmap->bitmapinfoheader.biBitCount,
bitmap->bitmapinfoheader.biClrUsed,
bitmap->bitmapinfoheader.biClrImportant);
#endif

// close the file

_lclose(file_handle);

// flip the bitmap

Flip_Bitmap(bitmap->buffer,
bitmap->bitmapinfoheader.biWidth*(bitmap->bitmapinfoheader.biBitCount/8),
bitmap->bitmapinfoheader.biHeight);

// return success

return(1);

} // end Load_Bitmap_File







"People spend too much time thinking about the past, whatever else it is, its gone"-Mel Gibson, Man Without A Face
Just my thoughts take them as you will. "People spend too much time thinking about the past, whatever else it is, its gone"-Mel Gibson, Man Without A Face

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.