| @ -0,0 +1,79 @@ | |||
| /******************************************************************************************* | |||
| * | |||
| * raylib test - Load and draw a 3d model (OBJ) | |||
| * | |||
| * This test has been created using raylib 1.1 (www.raylib.com) | |||
| * raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) | |||
| * | |||
| * Copyright (c) 2014 Ramon Santamaria (Ray San - raysan@raysanweb.com) | |||
| * | |||
| ********************************************************************************************/ | |||
| #include "raylib.h" | |||
| int main() | |||
| { | |||
| // Initialization | |||
| //-------------------------------------------------------------------------------------- | |||
| int screenWidth = 800; | |||
| int screenHeight = 450; | |||
| Vector3 position = { 0.0, 0.0, 0.0 }; | |||
| // Define the camera to look into our 3d world | |||
| Camera camera = {{ 10.0, 8.0, 10.0 }, { 0.0, 0.0, 0.0 }, { 0.0, 1.0, 0.0 }}; | |||
| InitWindow(screenWidth, screenHeight, "raylib test - 3d models in OpenGL 3.3+"); | |||
| Texture2D texture = LoadTexture("resources/catwhite.png"); | |||
| Model cat = LoadModel("resources/cat.obj"); | |||
| SetModelTexture(&cat, texture); | |||
| SetTargetFPS(60); // Set our game to run at 60 frames-per-second | |||
| //-------------------------------------------------------------------------------------- | |||
| // Main game loop | |||
| while (!WindowShouldClose()) // Detect window close button or ESC key | |||
| { | |||
| // Update | |||
| //---------------------------------------------------------------------------------- | |||
| if (IsKeyDown(KEY_LEFT)) position.x -= 0.2; | |||
| if (IsKeyDown(KEY_RIGHT)) position.x += 0.2; | |||
| if (IsKeyDown(KEY_UP)) position.z -= 0.2; | |||
| if (IsKeyDown(KEY_DOWN)) position.z += 0.2; | |||
| //---------------------------------------------------------------------------------- | |||
| // Draw | |||
| //---------------------------------------------------------------------------------- | |||
| BeginDrawing(); | |||
| ClearBackground(RAYWHITE); | |||
| Begin3dMode(camera); | |||
| DrawModel(cat, position, 0.1f, BEIGE); // OK_GL11, OK_GL33 | |||
| //DrawModelWires(cat, position, 0.1f, RED); // OK_GL11, OK_GL33 | |||
| DrawGrid(10.0, 1.0); // Draw a grid | |||
| DrawGizmo(position); | |||
| End3dMode(); | |||
| DrawFPS(10, 10); | |||
| EndDrawing(); | |||
| //---------------------------------------------------------------------------------- | |||
| } | |||
| // De-Initialization | |||
| //-------------------------------------------------------------------------------------- | |||
| UnloadTexture(texture); // Unload texture | |||
| UnloadModel(cat); // Unload model | |||
| CloseWindow(); // Close window and OpenGL context | |||
| //-------------------------------------------------------------------------------------- | |||
| return 0; | |||
| } | |||
| @ -0,0 +1,86 @@ | |||
| /******************************************************************************************* | |||
| * | |||
| * raylib test - Music playing (streaming) | |||
| * | |||
| * NOTE: This test requires OpenAL32 dll installed (or in the same folder) | |||
| * | |||
| * This test has been created using raylib 1.1 (www.raylib.com) | |||
| * raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) | |||
| * | |||
| * Copyright (c) 2014 Ramon Santamaria (Ray San - raysan@raysanweb.com) | |||
| * | |||
| ********************************************************************************************/ | |||
| #include "raylib.h" | |||
| int main() | |||
| { | |||
| // Initialization | |||
| //-------------------------------------------------------------------------------------- | |||
| int screenWidth = 800; | |||
| int screenHeight = 450; | |||
| InitWindow(screenWidth, screenHeight, "raylib test - music playing (streaming)"); | |||
| InitAudioDevice(); // Initialize audio device | |||
| PlayMusicStream("resources/audio/deserve_to_be_loved.ogg"); // Load Music file | |||
| int framesCounter = 0; | |||
| float volume = 1.0; | |||
| float timePlayed = 0; | |||
| SetTargetFPS(60); | |||
| //-------------------------------------------------------------------------------------- | |||
| // Main game loop | |||
| while (!WindowShouldClose()) // Detect window close button or ESC key | |||
| { | |||
| // Update | |||
| //---------------------------------------------------------------------------------- | |||
| framesCounter++; | |||
| // Testing music fading | |||
| /* | |||
| if (framesCounter > 600) | |||
| { | |||
| volume -= 0.01; | |||
| if (volume <= 0) | |||
| { | |||
| volume = 1.0; | |||
| framesCounter = -600; | |||
| PlayMusicStream("resources/audio/destiny.ogg"); | |||
| } | |||
| SetMusicVolume(volume); | |||
| } | |||
| */ | |||
| timePlayed = GetMusicTimePlayed() / GetMusicTimeLength() * 100 * 4; // We scale by 4 to fit 400 pixels | |||
| //---------------------------------------------------------------------------------- | |||
| // Draw | |||
| //---------------------------------------------------------------------------------- | |||
| BeginDrawing(); | |||
| ClearBackground(RAYWHITE); | |||
| DrawText("MUSIC SHOULD BE PLAYING!", 255, 200, 20, LIGHTGRAY); | |||
| DrawRectangle(200, 250, 400, 12, LIGHTGRAY); | |||
| DrawRectangle(200, 250, (int)timePlayed, 12, MAROON); | |||
| EndDrawing(); | |||
| //---------------------------------------------------------------------------------- | |||
| } | |||
| // De-Initialization | |||
| //-------------------------------------------------------------------------------------- | |||
| CloseAudioDevice(); // Close audio device (music streaming is automatically stopped) | |||
| CloseWindow(); // Close window and OpenGL context | |||
| //-------------------------------------------------------------------------------------- | |||
| return 0; | |||
| } | |||
| @ -0,0 +1,60 @@ | |||
| /******************************************************************************************* | |||
| * | |||
| * raylib test - OGG audio loading and playing | |||
| * | |||
| * NOTE: This test requires OpenAL32 dll installed (or in the same folder) | |||
| * | |||
| * This test has been created using raylib 1.1 (www.raylib.com) | |||
| * raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) | |||
| * | |||
| * Copyright (c) 2014 Ramon Santamaria (Ray San - raysan@raysanweb.com) | |||
| * | |||
| ********************************************************************************************/ | |||
| #include "raylib.h" | |||
| int main() | |||
| { | |||
| // Initialization | |||
| //-------------------------------------------------------------------------------------- | |||
| int screenWidth = 800; | |||
| int screenHeight = 450; | |||
| InitWindow(screenWidth, screenHeight, "raylib test - ogg audio loading and playing"); | |||
| InitAudioDevice(); // Initialize audio device | |||
| Sound fx = LoadSound("resources/audio/0564.ogg"); // Load audio file | |||
| //-------------------------------------------------------------------------------------- | |||
| // Main game loop | |||
| while (!WindowShouldClose()) // Detect window close button or ESC key | |||
| { | |||
| // Update | |||
| //---------------------------------------------------------------------------------- | |||
| if (IsKeyPressed(KEY_SPACE)) PlaySound(fx); // Play the sound! | |||
| //---------------------------------------------------------------------------------- | |||
| // Draw | |||
| //---------------------------------------------------------------------------------- | |||
| BeginDrawing(); | |||
| ClearBackground(RAYWHITE); | |||
| DrawText("Press SPACE to PLAY the SOUND!", 240, 200, 20, LIGHTGRAY); | |||
| EndDrawing(); | |||
| //---------------------------------------------------------------------------------- | |||
| } | |||
| // De-Initialization | |||
| //-------------------------------------------------------------------------------------- | |||
| UnloadSound(fx); // Unload sound data | |||
| CloseAudioDevice(); // Close audio device | |||
| CloseWindow(); // Close window and OpenGL context | |||
| //-------------------------------------------------------------------------------------- | |||
| return 0; | |||
| } | |||
| @ -0,0 +1,59 @@ | |||
| /******************************************************************************************* | |||
| * | |||
| * raylib test - Texture loading with mipmaps, mipmaps generation | |||
| * | |||
| * This test has been created using raylib 1.1 (www.raylib.com) | |||
| * raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) | |||
| * | |||
| * Copyright (c) 2014 Ramon Santamaria (Ray San - raysan@raysanweb.com) | |||
| * | |||
| ********************************************************************************************/ | |||
| #include "raylib.h" | |||
| int main() | |||
| { | |||
| // Initialization | |||
| //-------------------------------------------------------------------------------------- | |||
| int screenWidth = 800; | |||
| int screenHeight = 450; | |||
| InitWindow(screenWidth, screenHeight, "raylib test - texture mipmaps"); | |||
| Image image = LoadImage("resources/raylib_logo.png"); | |||
| Texture2D texture = CreateTexture(image, true); | |||
| // NOTE: With OpenGL 3.3 mipmaps generation works great (automatic generation) | |||
| // NOTE: With OpenGL 1.1 mipmaps generation works great too! (manual generation) | |||
| //-------------------------------------------------------------------------------------- | |||
| // Main game loop | |||
| while (!WindowShouldClose()) // Detect window close button or ESC key | |||
| { | |||
| // Update | |||
| //---------------------------------------------------------------------------------- | |||
| // TODO: Update your variables here | |||
| //---------------------------------------------------------------------------------- | |||
| // Draw | |||
| //---------------------------------------------------------------------------------- | |||
| BeginDrawing(); | |||
| ClearBackground(RAYWHITE); | |||
| DrawTexture(texture, 0, 0, WHITE); | |||
| EndDrawing(); | |||
| //---------------------------------------------------------------------------------- | |||
| } | |||
| // De-Initialization | |||
| //-------------------------------------------------------------------------------------- | |||
| UnloadTexture(texture); // Texture unloading | |||
| CloseWindow(); // Close window and OpenGL context | |||
| //-------------------------------------------------------------------------------------- | |||
| return 0; | |||
| } | |||
| @ -0,0 +1,66 @@ | |||
| /******************************************************************************************* | |||
| * | |||
| * raylib test - Texture loading and drawing with pro parameters (rotation, origin, scale...) | |||
| * | |||
| * This test has been created using raylib 1.1 (www.raylib.com) | |||
| * raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) | |||
| * | |||
| * Copyright (c) 2014 Ramon Santamaria (Ray San - raysan@raysanweb.com) | |||
| * | |||
| ********************************************************************************************/ | |||
| #include "raylib.h" | |||
| int main() | |||
| { | |||
| // Initialization | |||
| //-------------------------------------------------------------------------------------- | |||
| int screenWidth = 800; | |||
| int screenHeight = 450; | |||
| InitWindow(screenWidth, screenHeight, "raylib test - texture pro"); | |||
| // NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required) | |||
| Texture2D texture = LoadTexture("resources/raylib_logo.png"); // Texture loading | |||
| Vector2 position = { 200, 100 }; | |||
| Rectangle sourceRec = { 128, 128, 128, 128 }; | |||
| Rectangle destRec = { 128, 128, 128, 128 }; | |||
| Vector2 origin = { 64, 64 }; // NOTE: origin is relative to destRec size | |||
| //-------------------------------------------------------------------------------------- | |||
| // Main game loop | |||
| while (!WindowShouldClose()) // Detect window close button or ESC key | |||
| { | |||
| // Update | |||
| //---------------------------------------------------------------------------------- | |||
| // TODO: Update your variables here | |||
| //---------------------------------------------------------------------------------- | |||
| // Draw | |||
| //---------------------------------------------------------------------------------- | |||
| BeginDrawing(); | |||
| ClearBackground(RAYWHITE); | |||
| //DrawTextureEx(texture, position, 45, 1, MAROON); | |||
| DrawTexturePro(texture, sourceRec, destRec, origin, 45, GREEN); | |||
| DrawLine(destRec.x, 0, destRec.x, screenHeight, RED); | |||
| DrawLine(0, destRec.y, screenWidth, destRec.y, RED); | |||
| EndDrawing(); | |||
| //---------------------------------------------------------------------------------- | |||
| } | |||
| // De-Initialization | |||
| //-------------------------------------------------------------------------------------- | |||
| UnloadTexture(texture); // Texture unloading | |||
| CloseWindow(); // Close window and OpenGL context | |||
| //-------------------------------------------------------------------------------------- | |||
| return 0; | |||
| } | |||
| @ -0,0 +1,66 @@ | |||
| /******************************************************************************************* | |||
| * | |||
| * raylib test - DDS Texture loading and drawing (compressed and uncompressed) | |||
| * | |||
| * This test has been created using raylib 1.1 (www.raylib.com) | |||
| * raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) | |||
| * | |||
| * Copyright (c) 2014 Ramon Santamaria (Ray San - raysan@raysanweb.com) | |||
| * | |||
| ********************************************************************************************/ | |||
| #include "raylib.h" | |||
| int main() | |||
| { | |||
| // Initialization | |||
| //-------------------------------------------------------------------------------------- | |||
| int screenWidth = 800; | |||
| int screenHeight = 450; | |||
| InitWindow(screenWidth, screenHeight, "raylib test - DDS texture loading and drawing"); | |||
| // NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required) | |||
| //Texture2D texture = LoadTexture("resources/raylib_logo.dds"); // Texture loading | |||
| //Texture2D texture = LoadTexture("resources/raylib_logo_uncompressed.dds"); // Texture loading | |||
| Image image = LoadImage("resources/raylib_logo_uncompressed.dds"); | |||
| Texture2D texture = CreateTexture(image, false); | |||
| // NOTE: With OpenGL 3.3 mipmaps generation works great | |||
| SetTargetFPS(60); | |||
| //--------------------------------------------------------------------------------------- | |||
| // Main game loop | |||
| while (!WindowShouldClose()) // Detect window close button or ESC key | |||
| { | |||
| // Update | |||
| //---------------------------------------------------------------------------------- | |||
| // TODO: Update your variables here | |||
| //---------------------------------------------------------------------------------- | |||
| // Draw | |||
| //---------------------------------------------------------------------------------- | |||
| BeginDrawing(); | |||
| ClearBackground(RAYWHITE); | |||
| DrawTexture(texture, screenWidth/2 - texture.width/2, screenHeight/2 - texture.height/2, WHITE); | |||
| DrawText("this IS a texture!", 360, 370, 10, GRAY); | |||
| EndDrawing(); | |||
| //---------------------------------------------------------------------------------- | |||
| } | |||
| // De-Initialization | |||
| //-------------------------------------------------------------------------------------- | |||
| //UnloadTexture(texture); // Texture unloading | |||
| CloseWindow(); // Close window and OpenGL context | |||
| //-------------------------------------------------------------------------------------- | |||
| return 0; | |||
| } | |||