2
0

ex04b_texture_rectangle.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*******************************************************************************************
  2. *
  3. * raylib example 04b - Texture loading and drawing a part defined by a rectangle
  4. *
  5. * This example has been created using raylib 1.0 (www.raylib.com)
  6. * raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
  7. *
  8. * Copyright (c) 2013 Ramon Santamaria (Ray San - [email protected])
  9. *
  10. ********************************************************************************************/
  11. #include "raylib.h"
  12. int main()
  13. {
  14. // Initialization
  15. //--------------------------------------------------------------------------------------
  16. int screenWidth = 800;
  17. int screenHeight = 450;
  18. const char textLine1[] = "Lena image is a standard test image which has been in use since 1973.";
  19. const char textLine2[] = "It comprises 512x512 pixels, and was originally cropped from the centerfold";
  20. const char textLine3[] = "of November 1972 issue of Playboy magazine. The image is probably the most";
  21. const char textLine4[] = "widely used test image for all sorts of image processing algorithms.";
  22. InitWindow(screenWidth, screenHeight, "raylib example 04b - texture rectangle");
  23. // NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required)
  24. Texture2D texture = LoadTexture("resources/lena.png"); // Texture loading
  25. Color halfTrans = WHITE;
  26. halfTrans.a = 30;
  27. Rectangle eyesRec = { 225, 240, 155, 50 };
  28. Vector2 position = { 369, 241 };
  29. //--------------------------------------------------------------------------------------
  30. // Main game loop
  31. while (!WindowShouldClose()) // Detect window close button or ESC key
  32. {
  33. // Update
  34. //----------------------------------------------------------------------------------
  35. // TODO: Update your variables here
  36. //----------------------------------------------------------------------------------
  37. // Draw
  38. //----------------------------------------------------------------------------------
  39. BeginDrawing();
  40. ClearBackground(RAYWHITE);
  41. DrawText("LENA", 220, 100, 20, PINK);
  42. DrawTexture(texture, screenWidth/2 - 256, 0, halfTrans); // Draw background image
  43. DrawTextureRec(texture, eyesRec, position, WHITE); // Draw eyes part of image
  44. DrawText(textLine1, 220, 140, 10, DARKGRAY);
  45. DrawText(textLine2, 220, 160, 10, DARKGRAY);
  46. DrawText(textLine3, 220, 180, 10, DARKGRAY);
  47. DrawText(textLine4, 220, 200, 10, DARKGRAY);
  48. EndDrawing();
  49. //----------------------------------------------------------------------------------
  50. }
  51. // De-Initialization
  52. //--------------------------------------------------------------------------------------
  53. UnloadTexture(texture); // Texture unloading
  54. CloseWindow(); // Close window and OpenGL context
  55. //--------------------------------------------------------------------------------------
  56. return 0;
  57. }