| 19 | } |
| 20 | |
| 21 | void TileAtlas::initialize(unsigned int* ptex, int frames_wide, int frames_high, |
| 22 | int frame_width, int frame_height) |
| 23 | { |
| 24 | if (frames_wide <= 0) |
| 25 | frames_wide = 1; |
| 26 | if (frames_high <= 0) |
| 27 | frames_high = 1; |
| 28 | if (frame_width <= 0) |
| 29 | frame_width = 1; |
| 30 | if (frame_height <= 0) |
| 31 | frame_height = 1; |
| 32 | |
| 33 | texture = ptex; |
| 34 | totalFrames = frames_wide * frames_high; |
| 35 | frames = Point(frames_wide, frames_high); |
| 36 | imageSize = Point(frame_width * frames_wide, frame_height * frames_high); |
| 37 | imageFrameSize = Point(frame_width, frame_height); |
| 38 | texel = Vector2(1.0f / imageSize.x, 1.0f / imageSize.y); |
| 39 | textureFrameSize = Vector2(1.0f / frames.x, 1.0f / frames.y); |
| 40 | |
| 41 | sourceRectangles = new ScreenRect[totalFrames]; |
| 42 | |
| 43 | int currentFrame = 0; |
| 44 | for (int y = 0; y < frames.y; y++) |
| 45 | { |
| 46 | for (int x = 0; x < frames.x; x++) |
| 47 | { |
| 48 | sourceRectangles[currentFrame].x = x * textureFrameSize.x; |
| 49 | sourceRectangles[currentFrame].y = 1.0f - y * textureFrameSize.y; |
| 50 | sourceRectangles[currentFrame].w = textureFrameSize.x; |
| 51 | sourceRectangles[currentFrame].h = -textureFrameSize.y; |
| 52 | currentFrame++; |
| 53 | } |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | unsigned int loadBMPTexture_ARGB(const char* filename) |
| 58 | { |