examples_template.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /*
  2. WELCOME raylib EXAMPLES CONTRIBUTOR!
  3. This is a basic template to anyone ready to contribute with some code example for the library,
  4. here there are some guidelines on how to create an example to be included in raylib
  5. 1. File naming: <module>_<description> - Lower case filename, words separated by underscore,
  6. no more than 3-4 words in total to describe the example. <module> referes to the primary
  7. raylib module the example is more related with (code, shapes, textures, models, shaders, raudio)
  8. i.e: core_input_multitouch, shapes_lines_bezier, shaders_palette_switch
  9. 2. Follow below template structure, example info should list the module, the short description
  10. and the author of the example, twitter or github info could be also provided for the author
  11. Short description should also be used on the title of the window
  12. 3. Code should be organized by sections:[Initialization]- [Update] - [Draw] - [De-Initialization]
  13. Place your code between the dotted lines for every section, please don't mix update logic with drawing
  14. and remember to unload all loaded resources
  15. 4. Code should follow raylib conventions: https://github.com/raysan5/raylib/wiki/raylib-coding-conventions
  16. Try to be very organized, using line-breaks appropiately
  17. 5. Add comments to the specific parts of code the example is focus on
  18. Don't abuse with comments, try to be clear and impersonal on the comments
  19. 6. Try to keep the example simple, under 300 code lines if possible. Try to avoid external dependencies
  20. Try to avoid defining functions outside the main(). Example should be as self-contained as possible
  21. 7. About external resources, they should be placed in a [resources] folder and those resources
  22. should be open and free for use and distribution. Avoid propietary content
  23. 8. Try to keep the example simple but with a creative touch
  24. Simple but beautiful examples are more appealing to users!
  25. 9. In case of additional information is required, just come to raylib Discord channel: example-contributions
  26. 10. Have fun!
  27. The following files must be updated when adding a new example,
  28. but it can be automatically done using the raylib provided tool: rexm
  29. So, no worries if just the .c/.png are provided when adding the example.
  30. - raylib/examples/<category>/<category>_example_name.c
  31. - raylib/examples/<category>/<category>_example_name.png
  32. - raylib/examples/<category>/resources/..
  33. - raylib/examples/Makefile
  34. - raylib/examples/Makefile.Web
  35. - raylib/examples/README.md
  36. - raylib/projects/VS2022/examples/<category>_example_name.vcxproj
  37. - raylib/projects/VS2022/raylib.sln
  38. - raylib.com/common/examples.js
  39. - raylib.com/examples/<category>/<category>_example_name.html
  40. - raylib.com/examples/<category>/<category>_example_name.data
  41. - raylib.com/examples/<category>/<category>_example_name.wasm
  42. - raylib.com/examples/<category>/<category>_example_name.js
  43. */
  44. /*******************************************************************************************
  45. *
  46. * raylib [<module>] example - <name/short description>
  47. *
  48. * Example complexity rating: [★☆☆☆] 1/4
  49. *
  50. * Example originally created with raylib 5.5, last time updated with raylib 5.6
  51. *
  52. * Example contributed by <author_name> (@<user_github>) and reviewed by Ramon Santamaria (@raysan5)
  53. *
  54. * Example licensed under an unmodified zlib/libpng license, which is an OSI-certified,
  55. * BSD-like license that allows static linking with closed source software
  56. *
  57. * Copyright (c) <year_created>-<year_updated> <author_name> (@<user_github>)
  58. *
  59. ********************************************************************************************/
  60. #include "raylib.h"
  61. //------------------------------------------------------------------------------------
  62. // Program main entry point
  63. //------------------------------------------------------------------------------------
  64. int main(void)
  65. {
  66. // Initialization
  67. //--------------------------------------------------------------------------------------
  68. const int screenWidth = 800;
  69. const int screenHeight = 450;
  70. InitWindow(screenWidth, screenHeight, "raylib [<module>] example - <name>");
  71. // TODO: Load resources / Initialize variables at this point
  72. SetTargetFPS(60);
  73. //--------------------------------------------------------------------------------------
  74. // Main game loop
  75. while (!WindowShouldClose()) // Detect window close button or ESC key
  76. {
  77. // Update
  78. //----------------------------------------------------------------------------------
  79. // TODO: Update variables / Implement example logic at this point
  80. //----------------------------------------------------------------------------------
  81. // Draw
  82. //----------------------------------------------------------------------------------
  83. BeginDrawing();
  84. ClearBackground(RAYWHITE);
  85. // TODO: Draw everything that requires to be drawn at this point
  86. DrawLineEx((Vector2){ 0, 0 }, (Vector2){ screenWidth, screenHeight }, 2.0f, RED);
  87. DrawLineEx((Vector2){ 0, screenHeight }, (Vector2){ screenWidth, 0 }, 2.0f, RED);
  88. DrawText("example base code template", 260, 400, 20, LIGHTGRAY);
  89. EndDrawing();
  90. //----------------------------------------------------------------------------------
  91. }
  92. // De-Initialization
  93. //--------------------------------------------------------------------------------------
  94. // TODO: Unload all loaded resources at this point
  95. CloseWindow(); // Close window and OpenGL context
  96. //--------------------------------------------------------------------------------------
  97. return 0;
  98. }