Jump to content
  • Advertisement


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



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

I''m thinking of starting on a simple little engine that can display bitmaps from one big tileset. My question is: How can I get my programming to recognize what it should take out? For example: I have an isometric tileset with about 20 or so tiles in it. When I tell my engine what file to use, I don''t know how it will pick a specific point out of the whole bitmap. Would I have to find out where all of the corners are in the specific tile that I wanted? How would I do something like this? Oh yeah, and if anyone here has any resturaunt menus in spanish, can you please send them to me? Thanks a lot. -jedis1000

Share this post

Link to post
Share on other sites
Guest Anonymous Poster
i havent yet done this myself but im starting an iso puzzle game and i will be using bitmaps in the fashion you described. the simple answer is to have each tile be a given dimension so you can just parse through the file and load each part of it into a data structure array. like have tilesets be 512 by 512 and have 8 tiles at 64x64 each or what ever size you need.

Share this post

Link to post
Share on other sites
A bitmap is basically one big 2D array of bytes, so a point within the bitmap can be specified as array subscripts. In the case of an actual 2D array, you can specify any pixel location like this:


Typically, you will pass your tile drawing function a pair of coordinates defining a rectangle within the bitmap.

A lot of the time, your bitmap is represented as a 1D array, so using array subscript notation (ie: Array[XCoord][YCoord]) will not work and you will have to mimic 2D indexing with 1D indexing.

unsigned char *BitmapArray; // Pointer to your bitmap data

int BitmapWidth, BitmapHeight; // Dimensions of bitmap array

int CoordX, CoordY; // A coordinate within the bitmap

unsigned char *Pixel = BitmapArray[CoordY * BitmapWidth + CoordX];

After the last statement, the pointer Pixel points to the location in the bitmap array of the given pixel.

Note that this assumes a bitmap in which each pixel is represented by a single byte (unsigned char). This is appropriate for indexed bitmaps that draw their colors from a 256-entry palette. For more detailed bitmaps in 16, 24, or 32 bit depths, you will need to take into account how many bytes comprise a pixel.

int BytesPerPixel; // 1, 2, 3 or 4 for 8 bit, 16 bit, 24 bit or 32 bit

unsigned char *Pixel=BitmapArray[CoordY * (BitmapWidth*BytesPerPixel) + (CoordX*BytesPerPixel)];

Now, Pixel points to the byte in the array where your pixel begins. In an 16 bit image, that byte and the following are the 2 bytes (16 bits) representing your pixel. In 24 bit, the next three represent your Red, Green, and Blue values of the pixel.

At the simplest, blitting from here is straightforward. If you are doing it by hand, you would start at your rectangle's top left corner, and loop on X and Y, calculating the pixel offset at each step as just described, and copying that pixel's bytes from the bitmap to the screen.

Note that if all the tiles in the bitmap are the same size, this makes calculating the corners of your rectangle easier than if they are not.

For instance, say you have a bitmap, and each tile in the bitmap is 32x32 pixels, and there are 4 rows of 4 tiles (128x128 pixel bitmap). You want to draw the 2nd tile in the second row (Row=1, Col=1). To get the top,left/bottom,right corners of the rectangle defining this bitmap:


For the 2nd tile in the 2nd row:


So, the rectangle defining the tile is (32,32) -> (63,63). Pretty simple.

Now, drawing by hand is a pretty braindead way of doing things, as it does not take into account any acceleration provided by hardware. Typically, graphics APIs that support acceleration will handle the blitting details for you.

You can either use a vanilla 2D API such as DirectDraw or SDL, or mimic 2D using the 3D capabilities of the video card and Direct3D or OpenGL. Most 2D APIs specify a Blit or Blt function of some sort, which allows you to provide a surface (with a bitmap loaded on it) and a rectangle within that surface to draw from. Research your API of choice to find the specifics. (For an example, check this reference page for the SDL_BlitSurface() function of the SDL library. As you can see, it requires the surface bitmap, the source rectangle, the screen surface, and a destination rectangle).

If you use a 3D API such as Direct3D or OpenGL, you can mimic 2D functionality (and enjoy the benefits of a lot of features hard to duplicate in vanilla 2D) through, for example, the use of textures. In OpenGL, you can load a bitmap, set it as a texture, then draw specific pieces of the bitmap by specifying texture coordinates. In this case, specifying the rectangle is a little different as texture coordinates are generally specified in the range of 0 to 1, rather than discrete pixels.

When using a 3D API in this manner, you will need to ensure that you set up the environment for orthogonal projection. (for reference, see the function glOrtho(), which is part of the OpenGL spec.).

Some topics you may want to research to learn more: DirectX, OpenGL, SDL (Simple DirectMedia Layer, found here), blitting, etc...

Hope this helps.

vertexnormal AT linuxmail DOT org

Check out Golem: Lands of Shadow, an isometrically rendered hack-and-slash inspired equally by Nethack and Diablo.

[edited by - VertexNormal on October 13, 2003 7:49:46 PM]

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!