You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

78 lines
3.3 KiB

преди 9 години
преди 9 години
преди 10 години
преди 10 години
преди 10 години
преди 10 години
преди 10 години
преди 10 години
преди 10 години
преди 10 години
преди 10 години
преди 10 години
  1. /*******************************************************************************************
  2. *
  3. * raylib [textures] example - Texture source and destination rectangles
  4. *
  5. * This example has been created using raylib 1.3 (www.raylib.com)
  6. * raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
  7. *
  8. * Copyright (c) 2015 Ramon Santamaria (@raysan5)
  9. *
  10. ********************************************************************************************/
  11. #include "raylib.h"
  12. int main()
  13. {
  14. // Initialization
  15. //--------------------------------------------------------------------------------------
  16. int screenWidth = 800;
  17. int screenHeight = 450;
  18. InitWindow(screenWidth, screenHeight, "raylib [textures] examples - texture source and destination rectangles");
  19. // NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required)
  20. Texture2D guybrush = LoadTexture("resources/guybrush.png"); // Texture loading
  21. int frameWidth = guybrush.width/7;
  22. int frameHeight = guybrush.height;
  23. // NOTE: Source rectangle (part of the texture to use for drawing)
  24. Rectangle sourceRec = { 0, 0, frameWidth, frameHeight };
  25. // NOTE: Destination rectangle (screen rectangle where drawing part of texture)
  26. Rectangle destRec = { screenWidth/2, screenHeight/2, frameWidth*2, frameHeight*2 };
  27. // NOTE: Origin of the texture (rotation/scale point), it's relative to destination rectangle size
  28. Vector2 origin = { frameWidth, frameHeight };
  29. int rotation = 0;
  30. SetTargetFPS(60);
  31. //--------------------------------------------------------------------------------------
  32. // Main game loop
  33. while (!WindowShouldClose()) // Detect window close button or ESC key
  34. {
  35. // Update
  36. //----------------------------------------------------------------------------------
  37. rotation++;
  38. //----------------------------------------------------------------------------------
  39. // Draw
  40. //----------------------------------------------------------------------------------
  41. BeginDrawing();
  42. ClearBackground(RAYWHITE);
  43. // NOTE: Using DrawTexturePro() we can easily rotate and scale the part of the texture we draw
  44. // sourceRec defines the part of the texture we use for drawing
  45. // destRec defines the rectangle where our texture part will fit (scaling it to fit)
  46. // origin defines the point of the texture used as reference for rotation and scaling
  47. // rotation defines the texture rotation (using origin as rotation point)
  48. DrawTexturePro(guybrush, sourceRec, destRec, origin, rotation, WHITE);
  49. DrawLine(destRec.x, 0, destRec.x, screenHeight, GRAY);
  50. DrawLine(0, destRec.y, screenWidth, destRec.y, GRAY);
  51. EndDrawing();
  52. //----------------------------------------------------------------------------------
  53. }
  54. // De-Initialization
  55. //--------------------------------------------------------------------------------------
  56. UnloadTexture(guybrush); // Texture unloading
  57. CloseWindow(); // Close window and OpenGL context
  58. //--------------------------------------------------------------------------------------
  59. return 0;
  60. }