| 14 | #include "raylib-cpp.hpp" |
| 15 | |
| 16 | int main(void) { |
| 17 | // Initialization |
| 18 | //-------------------------------------------------------------------------------------- |
| 19 | const int screenWidth = 800; |
| 20 | const int screenHeight = 450; |
| 21 | |
| 22 | raylib::Window window(screenWidth, screenHeight, "raylib [textures] example - image drawing"); |
| 23 | raylib::Color darkGray = DARKGRAY; |
| 24 | |
| 25 | // NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required) |
| 26 | raylib::Image cat("resources/cat.png"); // Load image in CPU memory (RAM) |
| 27 | cat.Crop(raylib::Rectangle(100, 10, 280, 380)) // Crop an image piece |
| 28 | .FlipHorizontal() // Flip cropped image horizontally |
| 29 | .Resize(150, 200); // Resize flipped-cropped image |
| 30 | |
| 31 | raylib::Image parrots("resources/parrots.png"); // Load image in CPU memory (RAM) |
| 32 | |
| 33 | // Draw one image over the other with a scaling of 1.5f |
| 34 | parrots |
| 35 | .Draw(cat, |
| 36 | raylib::Rectangle(0, 0, cat.GetWidth(), cat.GetHeight()), |
| 37 | raylib::Rectangle(30, 40, cat.GetWidth() * 1.5f, cat.GetHeight() * 1.5f)); |
| 38 | parrots.Crop(raylib::Rectangle(0, 50, parrots.GetWidth(), parrots.GetHeight() - 100)); // Crop resulting image |
| 39 | |
| 40 | // Load custom font for frawing on image |
| 41 | raylib::Font font("resources/custom_jupiter_crash.png"); |
| 42 | |
| 43 | // Draw over image using custom font |
| 44 | parrots.DrawText(font, "PARROTS & CAT", raylib::Vector2(300, 230), font.baseSize, -2); |
| 45 | |
| 46 | raylib::Texture2D texture(parrots); // Image converted to texture, uploaded to GPU memory (VRAM) |
| 47 | |
| 48 | SetTargetFPS(60); |
| 49 | //--------------------------------------------------------------------------------------- |
| 50 | |
| 51 | // Main game loop |
| 52 | while (!window.ShouldClose()) { // Detect window close button or ESC key |
| 53 | // Update |
| 54 | //---------------------------------------------------------------------------------- |
| 55 | // Update your variables here |
| 56 | //---------------------------------------------------------------------------------- |
| 57 | |
| 58 | // Draw |
| 59 | //---------------------------------------------------------------------------------- |
| 60 | BeginDrawing(); |
| 61 | { |
| 62 | window.ClearBackground(RAYWHITE); |
| 63 | |
| 64 | texture.Draw(screenWidth / 2 - texture.width / 2, |
| 65 | screenHeight / 2 - texture.height / 2 - 40); |
| 66 | darkGray.DrawRectangleLines(screenWidth / 2 - texture.width / 2, |
| 67 | screenHeight / 2 - texture.height / 2 - 40, |
| 68 | texture.width, texture.height); |
| 69 | |
| 70 | darkGray.DrawText("We are drawing only one texture from various images composed!", |
| 71 | 240, 350, 10); |
| 72 | darkGray.DrawText("Source images have been cropped, scaled, flipped and copied one over the other.", |
| 73 | 190, 370, 10); |