Beginners_-_DrawTexturePro_RectsScaleOrigin.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #include "raylib.h"
  2. int main(void)
  3. {
  4. // Initialization
  5. //--------------------------------------------------------------------------------------
  6. const int screenWidth = 800;
  7. const int screenHeight = 400;
  8. InitWindow(screenWidth,screenHeight, "raylib example.");
  9. // Create a Image in memory
  10. RenderTexture2D target = LoadRenderTexture(320,200);
  11. // Clear our texture(image) before entering the game loop
  12. BeginTextureMode(target);
  13. ClearBackground(BLUE);
  14. // Draw something on it.
  15. DrawRectangle(10,10,300,180,BLACK);
  16. EndTextureMode(); // This needs to be called after every different draw command used. Do not forget to use begintexture also..
  17. SetTargetFPS(60); // Set our game to run at 60 frames-per-second
  18. //--------------------------------------------------------------------------------------
  19. // Main game loop
  20. while (!WindowShouldClose()) // Detect window close button or ESC key
  21. {
  22. // Update
  23. //----------------------------------------------------------------------------------
  24. //----------------------------------------------------------------------------------
  25. // Draw
  26. //----------------------------------------------------------------------------------
  27. BeginDrawing();
  28. ClearBackground(RAYWHITE);
  29. // Draw a texture from rectangle to target rectangle. Note we use the - for opengl reasons!
  30. DrawTexturePro(target.texture, (Rectangle){0,0,target.texture.width,-target.texture.height},
  31. (Rectangle){0,0,screenWidth,screenHeight},
  32. (Vector2){0,0},0,WHITE);
  33. EndDrawing();
  34. //----------------------------------------------------------------------------------
  35. }
  36. // De-Initialization
  37. //--------------------------------------------------------------------------------------
  38. UnloadRenderTexture(target); // Unload render texture
  39. CloseWindow(); // Close window and OpenGL context
  40. //--------------------------------------------------------------------------------------
  41. return 0;
  42. }