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.

85 lines
3.2 KiB

  1. /*******************************************************************************************
  2. *
  3. * raylib [models] example - Load and draw a 3d model (OBJ)
  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) 2014 Ramon Santamaria (Ray San - raysan@raysanweb.com)
  9. *
  10. ********************************************************************************************/
  11. #include "raylib.h"
  12. int main()
  13. {
  14. // Initialization
  15. //--------------------------------------------------------------------------------------
  16. int screenWidth = 1280;
  17. int screenHeight = 720;
  18. InitWindow(screenWidth, screenHeight, "raylib [models] example - custom shader");
  19. // Define the camera to look into our 3d world
  20. Camera camera = {{ 10.0, 8.0, 10.0 }, { 0.0, 0.0, 0.0 }, { 0.0, 1.0, 0.0 }};
  21. Texture2D texture = LoadTexture("resources/catsham.png"); // Load model texture
  22. Shader shader = LoadShader("resources/shaders/custom.vs", "resources/shaders/custom.fs");
  23. //Shader poste = LoadShader("resources/shaders/custom.vs", "resources/shaders/pixel.fs");
  24. Model cat = LoadModel("resources/cat.obj"); // Load OBJ model
  25. SetModelTexture(&cat, texture); // Bind texture to model
  26. //SetModelShader(&cat, poste);
  27. Vector3 catPosition = { 0.0, 0.0, 0.0 }; // Set model position
  28. SetPostproShader(shader);
  29. SetTargetFPS(60); // Set our game to run at 60 frames-per-second
  30. //--------------------------------------------------------------------------------------
  31. // Main game loop
  32. while (!WindowShouldClose()) // Detect window close button or ESC key
  33. {
  34. // Update
  35. //----------------------------------------------------------------------------------
  36. if (IsKeyDown(KEY_LEFT)) catPosition.x -= 0.2;
  37. if (IsKeyDown(KEY_RIGHT)) catPosition.x += 0.2;
  38. if (IsKeyDown(KEY_UP)) catPosition.z -= 0.2;
  39. if (IsKeyDown(KEY_DOWN)) catPosition.z += 0.2;
  40. //----------------------------------------------------------------------------------
  41. // Draw
  42. //----------------------------------------------------------------------------------
  43. BeginDrawing();
  44. ClearBackground(RAYWHITE);
  45. Begin3dMode(camera);
  46. DrawModel(cat, catPosition, 0.1f, WHITE); // Draw 3d model with texture
  47. DrawGrid(10.0, 1.0); // Draw a grid
  48. DrawGizmo(catPosition); // Draw gizmo
  49. End3dMode();
  50. DrawFPS(10, 10);
  51. EndDrawing();
  52. //----------------------------------------------------------------------------------
  53. }
  54. // De-Initialization
  55. //--------------------------------------------------------------------------------------
  56. UnloadTexture(texture); // Unload texture
  57. UnloadModel(cat); // Unload model
  58. UnloadShader(shader);
  59. //UnloadShader(poste);
  60. CloseWindow(); // Close window and OpenGL context
  61. //--------------------------------------------------------------------------------------
  62. return 0;
  63. }