mirror of
https://github.com/raylib-cs/raylib-cs
synced 2025-04-11 14:34:44 -04:00
Fixed trailing whitespace
- Removed trailing whitespace from bindings and examples.
This commit is contained in:
parent
01ec64945c
commit
527bf58521
Bindings
Examples
audio
core
core_2d_camera.cscore_3d_camera_first_person.cscore_3d_camera_free.cscore_3d_mode.cscore_3d_picking.cscore_basic_window.cscore_basic_window_web.cscore_color_select.cscore_custom_logging.cscore_drop_files.cscore_gestures_detection.cscore_input_gamepad.cscore_input_keys.cscore_input_mouse.cscore_mouse_wheel.cscore_random_values.cscore_storage_values.cscore_vr_simulator.cscore_world_screen.cs
models
models_billboard.csmodels_box_collisions.csmodels_cubicmap.csmodels_geometric_shapes.csmodels_heightmap.csmodels_mesh_generation.csmodels_mesh_picking.csmodels_obj_loading.csmodels_orthographic_projection.csmodels_skybox.csmodels_yaw_pitch_roll.cs
others
physac
shaders
shapes
shapes_basic_shapes.csshapes_colors_palette.csshapes_lines_bezier.csshapes_logo_raylib.csshapes_logo_raylib_anim.cs
text
text_bmfont_ttf.cstext_bmfont_unordered.cstext_font_sdf.cstext_format_text.cstext_input_box.cstext_raylib_fonts.cstext_sprite_fonts.cstext_ttf_loading.cstext_writing_anim.cs
textures
@ -1,9 +1,4 @@
|
||||
/**********************************************************************************************
|
||||
*
|
||||
* Raylib easings bindings
|
||||
* Original - https://github.com/raysan5/raylib/blob/master/src/easings.h
|
||||
*
|
||||
**********************************************************************************************/
|
||||
// Easings - https://github.com/raysan5/raylib/blob/master/src/easings.h
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
@ -13,94 +8,94 @@ namespace Raylib
|
||||
public static partial class Raylib
|
||||
{
|
||||
#region Raylib-cs Functions
|
||||
|
||||
|
||||
// Linear Easing functions
|
||||
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern float EaseLinearNone(float t, float b, float c, float d);
|
||||
|
||||
|
||||
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern float EaseLinearIn(float t, float b, float c, float d);
|
||||
|
||||
|
||||
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern float EaseLinearOut(float t, float b, float c, float d);
|
||||
|
||||
|
||||
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern float EaseLinearInOut(float t, float b, float c, float d);
|
||||
|
||||
|
||||
// Sine Easing functions
|
||||
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern float EaseSineIn(float t, float b, float c, float d);
|
||||
|
||||
|
||||
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern float EaseSineOut(float t, float b, float c, float d);
|
||||
|
||||
|
||||
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern float EaseSineInOut(float t, float b, float c, float d);
|
||||
|
||||
|
||||
// Circular Easing functions
|
||||
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern float EaseCircIn(float t, float b, float c, float d);
|
||||
|
||||
|
||||
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern float EaseCircOut(float t, float b, float c, float d);
|
||||
|
||||
|
||||
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern float EaseCircInOut(float t, float b, float c, float d);
|
||||
|
||||
|
||||
// Cubic Easing functions
|
||||
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern float EaseCubicIn(float t, float b, float c, float d);
|
||||
|
||||
|
||||
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern float EaseCubicOut(float t, float b, float c, float d);
|
||||
|
||||
|
||||
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern float EaseCubicInOut(float t, float b, float c, float d);
|
||||
|
||||
|
||||
// Quadratic Easing functions
|
||||
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern float EaseQuadIn(float t, float b, float c, float d);
|
||||
|
||||
|
||||
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern float EaseQuadOut(float t, float b, float c, float d);
|
||||
|
||||
|
||||
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern float EaseQuadInOut(float t, float b, float c, float d);
|
||||
|
||||
|
||||
// Exponential Easing functions
|
||||
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern float EaseExpoIn(float t, float b, float c, float d);
|
||||
|
||||
|
||||
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern float EaseExpoOut(float t, float b, float c, float d);
|
||||
|
||||
|
||||
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern float EaseExpoInOut(float t, float b, float c, float d);
|
||||
|
||||
|
||||
// Back Easing functions
|
||||
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern float EaseBackIn(float t, float b, float c, float d);
|
||||
|
||||
|
||||
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern float EaseBackOut(float t, float b, float c, float d);
|
||||
|
||||
|
||||
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern float EaseBackInOut(float t, float b, float c, float d);
|
||||
|
||||
|
||||
// Bounce Easing functions
|
||||
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern float EaseBounceOut(float t, float b, float c, float d);
|
||||
|
||||
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern float EaseBounceIn(float t, float b, float c, float d);
|
||||
|
||||
|
||||
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern float EaseBounceInOut(float t, float b, float c, float d);
|
||||
|
||||
|
||||
// Elastic Easing functions
|
||||
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern float EaseElasticIn(float t, float b, float c, float d);
|
||||
|
||||
|
||||
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern float EaseElasticOut(float t, float b, float c, float d);
|
||||
|
||||
@ -108,6 +103,5 @@ namespace Raylib
|
||||
public static extern float EaseElasticInOut(float t, float b, float c, float d);
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,4 @@
|
||||
/**********************************************************************************************
|
||||
*
|
||||
* Physac
|
||||
* Original -https://github.com/raysan5/raylib/blob/master/src/physac.h
|
||||
*
|
||||
**********************************************************************************************/
|
||||
// Physac - https://github.com/raysan5/raylib/blob/master/src/physac.h
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
@ -37,11 +32,13 @@ namespace Raylib
|
||||
{
|
||||
public uint vertexCount; // Current used vertex and normals count
|
||||
|
||||
[MarshalAs(UnmanagedType.ByValArray, ArraySubType = UnmanagedType.Struct, SizeConst = Raylib.PHYSAC_MAX_VERTICES)]
|
||||
public Vector2[] positions; // Polygon vertex positions vectors
|
||||
|
||||
[MarshalAs(UnmanagedType.ByValArray, ArraySubType = UnmanagedType.Struct, SizeConst = Raylib.PHYSAC_MAX_VERTICES)]
|
||||
public Vector2[] normals; // Polygon vertex normals vectors
|
||||
//[MarshalAs(UnmanagedType.ByValArray, ArraySubType = UnmanagedType.Struct, SizeConst = Raylib.PHYSAC_MAX_VERTICES)]
|
||||
//public Vector2[] positions; // Polygon vertex positions vectors
|
||||
public unsafe Vector2* positions;
|
||||
|
||||
//[MarshalAs(UnmanagedType.ByValArray, ArraySubType = UnmanagedType.Struct, SizeConst = Raylib.PHYSAC_MAX_VERTICES)]
|
||||
//public Vector2[] normals; // Polygon vertex normals vectors
|
||||
public unsafe Vector2* normals;
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
|
||||
@ -79,17 +76,18 @@ namespace Raylib
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
|
||||
public struct PhysicsManifoldData
|
||||
public unsafe struct PhysicsManifoldData
|
||||
{
|
||||
public uint id; // Reference unique identifier
|
||||
public PhysicsBodyData bodyA; // Manifold first physics body reference
|
||||
public PhysicsBodyData bodyB; // Manifold second physics body reference
|
||||
public float penetration; // Depth of penetration from collision
|
||||
public Vector2 normal; // Normal direction vector from 'a' to 'b'
|
||||
|
||||
[MarshalAs(UnmanagedType.ByValArray, ArraySubType = UnmanagedType.Struct, SizeConst = 2)]
|
||||
public Vector2[] contacts; // Points of contact during collision
|
||||
|
||||
|
||||
//[MarshalAs(UnmanagedType.ByValArray, ArraySubType = UnmanagedType.Struct, SizeConst = 2)]
|
||||
// public fixed Vector2[] contacts; // Points of contact during collision
|
||||
public unsafe Vector2* contacts;
|
||||
|
||||
public uint contactsCount; // Current collision number of contacts
|
||||
public float restitution; // Mixed restitution during collision
|
||||
public float dynamicFriction; // Mixed dynamic friction during collision
|
||||
@ -120,19 +118,23 @@ namespace Raylib
|
||||
|
||||
#endregion
|
||||
|
||||
#region Raylib-cs Functions
|
||||
#region Raylib-cs Functions
|
||||
|
||||
// Initializes physics values, pointers and creates physics loop thread
|
||||
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void InitPhysics();
|
||||
public static extern void InitPhysics();
|
||||
|
||||
// Run physics step, to be used if PHYSICS_NO_THREADS is set in your main loop
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void RunPhysicsStep();
|
||||
|
||||
// Returns true if physics thread is currently enabled
|
||||
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern bool IsPhysicsEnabled();
|
||||
public static extern bool IsPhysicsEnabled();
|
||||
|
||||
// Sets physics global gravity force
|
||||
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void SetPhysicsGravity(float x, float y);
|
||||
public static extern void SetPhysicsGravity(float x, float y);
|
||||
|
||||
// Creates a new circle physics body with generic parameters
|
||||
[DllImport(nativeLibName, EntryPoint = "CreatePhysicsBodyCircle")]
|
||||
@ -167,23 +169,23 @@ namespace Raylib
|
||||
|
||||
// Adds a force to a physics body
|
||||
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void PhysicsAddForce(PhysicsBodyData body, Vector2 force);
|
||||
public static extern void PhysicsAddForce(PhysicsBodyData body, Vector2 force);
|
||||
|
||||
// Adds an angular force to a physics body
|
||||
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void PhysicsAddTorque(PhysicsBodyData body, float amount);
|
||||
|
||||
public static extern void PhysicsAddTorque(PhysicsBodyData body, float amount);
|
||||
|
||||
// Shatters a polygon shape physics body to little physics bodies with explosion force
|
||||
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void PhysicsShatter(PhysicsBodyData body, Vector2 position, float force);
|
||||
public static extern void PhysicsShatter(PhysicsBodyData body, Vector2 position, float force);
|
||||
|
||||
// Returns the current amount of created physics bodies
|
||||
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern int GetPhysicsBodiesCount();
|
||||
public static extern int GetPhysicsBodiesCount();
|
||||
|
||||
// Returns a physics body of the bodies pool at a specific index
|
||||
[DllImport(nativeLibName, EntryPoint = "GetPhysicsBody")]
|
||||
public static extern IntPtr GetPhysicsBodyImport(int index);
|
||||
public static extern IntPtr GetPhysicsBodyImport(int index);
|
||||
public static PhysicsBodyData GetPhysicsBody(int index)
|
||||
{
|
||||
var body = GetPhysicsBodyImport(index);
|
||||
@ -193,33 +195,32 @@ namespace Raylib
|
||||
|
||||
// Returns the physics body shape type (PHYSICS_CIRCLE or PHYSICS_POLYGON)
|
||||
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern int GetPhysicsShapeType(int index);
|
||||
public static extern int GetPhysicsShapeType(int index);
|
||||
|
||||
// Returns the amount of vertices of a physics body shape
|
||||
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern int GetPhysicsShapeVerticesCount(int index);
|
||||
public static extern int GetPhysicsShapeVerticesCount(int index);
|
||||
|
||||
// Returns transformed position of a body shape (body position + vertex transformed position)
|
||||
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern Vector2 GetPhysicsShapeVertex(PhysicsBodyData body, int vertex);
|
||||
public static extern Vector2 GetPhysicsShapeVertex(PhysicsBodyData body, int vertex);
|
||||
|
||||
// Sets physics body shape transform based on radians parameter
|
||||
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void SetPhysicsBodyRotation(PhysicsBodyData body, float radians);
|
||||
public static extern void SetPhysicsBodyRotation(PhysicsBodyData body, float radians);
|
||||
|
||||
// Unitializes and destroy a physics body
|
||||
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void DestroyPhysicsBody(PhysicsBodyData body);
|
||||
public static extern void DestroyPhysicsBody(PhysicsBodyData body);
|
||||
|
||||
// Destroys created physics bodies and manifolds and resets global values
|
||||
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void ResetPhysics();
|
||||
public static extern void ResetPhysics();
|
||||
|
||||
// Unitializes physics pointers and closes physics loop thread
|
||||
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void ClosePhysics();
|
||||
public static extern void ClosePhysics();
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,4 @@
|
||||
/**********************************************************************************************
|
||||
*
|
||||
* Raygui
|
||||
* Original - https://github.com/raysan5/raygui/blob/master/src/raygui.h
|
||||
*
|
||||
**********************************************************************************************/
|
||||
// Raygui - https://github.com/raysan5/raygui/blob/master/src/raygui.h
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
@ -1,9 +1,5 @@
|
||||
/**********************************************************************************************
|
||||
*
|
||||
* Raylib - A simple and easy-to-use library to learn videogames programming (www.raylib.com)
|
||||
* Original - https://github.com/raysan5/raylib/blob/master/src/raylib.h
|
||||
*
|
||||
**********************************************************************************************/
|
||||
// Raylib - https://github.com/raysan5/raylib/blob/master/src/raylib.h
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Runtime.InteropServices;
|
||||
@ -186,7 +182,7 @@ namespace Raylib
|
||||
NPT_9PATCH = 0, // 3x3
|
||||
NPT_3PATCH_VERTICAL, // 1x3
|
||||
NPT_3PATCH_HORIZONTAL // 3x1
|
||||
}
|
||||
}
|
||||
|
||||
// enum extension for constants
|
||||
// Keyboard Function Keys
|
||||
@ -933,7 +929,7 @@ namespace Raylib
|
||||
|
||||
#endregion
|
||||
|
||||
#region Raylib-cs Functions
|
||||
#region Raylib-cs Functions
|
||||
|
||||
//------------------------------------------------------------------------------------
|
||||
// Window and Graphics Device Functions (Module: core)
|
||||
@ -1354,7 +1350,7 @@ namespace Raylib
|
||||
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern int GetTouchPointsCount();
|
||||
|
||||
// Get gesture hold time in milliseconds
|
||||
// Get gesture hold time in milliseconds
|
||||
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern float GetGestureHoldDuration();
|
||||
|
||||
@ -2396,7 +2392,7 @@ namespace Raylib
|
||||
// Set pitch for audio stream (1.0 is base level)
|
||||
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void SetAudioStreamPitch(AudioStream stream, float pitch);
|
||||
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,4 @@
|
||||
/**********************************************************************************************
|
||||
*
|
||||
* Raymath v1.2 bindings - Math functions to work with Vector3, Matrix and Quaternions
|
||||
* Original - https://github.com/raysan5/raylib/blob/master/src/raymath.h
|
||||
*
|
||||
**********************************************************************************************/
|
||||
// Raymath - https://github.com/raysan5/raylib/blob/master/src/raymath.h
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
@ -1,9 +1,4 @@
|
||||
/**********************************************************************************************
|
||||
*
|
||||
* Rlgl
|
||||
* Original - https://github.com/raysan5/raylib/blob/master/src/rlgl.h
|
||||
*
|
||||
**********************************************************************************************/
|
||||
// Rlgl - https://github.com/raysan5/raylib/blob/master/src/rlgl.h
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
@ -28,6 +23,5 @@ namespace Raylib
|
||||
#region Raylib-cs Functions
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -15,8 +15,7 @@ public partial class audio_module_playing
|
||||
* Copyright (c) 2016 Ramon Santamaria (@raysan5)
|
||||
*
|
||||
********************************************************************************************/
|
||||
|
||||
|
||||
|
||||
public const int MAX_CIRCLES = 64;
|
||||
|
||||
struct CircleWave
|
||||
@ -27,26 +26,26 @@ public partial class audio_module_playing
|
||||
public float speed;
|
||||
public Color color;
|
||||
}
|
||||
|
||||
|
||||
public static int Main()
|
||||
{
|
||||
// Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
int screenWidth = 800;
|
||||
int screenHeight = 450;
|
||||
|
||||
|
||||
SetConfigFlags(FLAG_MSAA_4X_HINT); // NOTE: Try to enable MSAA 4X
|
||||
|
||||
|
||||
InitWindow(screenWidth, screenHeight, "raylib [audio] example - module playing (streaming)");
|
||||
|
||||
|
||||
InitAudioDevice(); // Initialize audio device
|
||||
|
||||
|
||||
Color[] colors = new Color[14] { ORANGE, RED, GOLD, LIME, BLUE, VIOLET, BROWN, LIGHTGRAY, PINK,
|
||||
YELLOW, GREEN, SKYBLUE, PURPLE, BEIGE };
|
||||
|
||||
|
||||
// Creates ome circles for visual effect
|
||||
CircleWave[] circles = new CircleWave[MAX_CIRCLES];
|
||||
|
||||
|
||||
for (int i = MAX_CIRCLES - 1; i >= 0; i--)
|
||||
{
|
||||
circles[i].alpha = 0.0f;
|
||||
@ -56,51 +55,51 @@ public partial class audio_module_playing
|
||||
circles[i].speed = (float)GetRandomValue(1, 100)/20000.0f;
|
||||
circles[i].color = colors[GetRandomValue(0, 13)];
|
||||
}
|
||||
|
||||
|
||||
var xm = LoadMusicStream("resources/mini1111.xm");
|
||||
|
||||
|
||||
PlayMusicStream(xm);
|
||||
|
||||
|
||||
float timePlayed = 0.0f;
|
||||
bool pause = false;
|
||||
|
||||
|
||||
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
|
||||
//----------------------------------------------------------------------------------
|
||||
UpdateMusicStream(xm); // Update music buffer with new stream data
|
||||
|
||||
|
||||
// Restart music playing (stop and play)
|
||||
if (IsKeyPressed(KEY_SPACE))
|
||||
if (IsKeyPressed(KEY_SPACE))
|
||||
{
|
||||
StopMusicStream(xm);
|
||||
PlayMusicStream(xm);
|
||||
}
|
||||
|
||||
// Pause/Resume music playing
|
||||
|
||||
// Pause/Resume music playing
|
||||
if (IsKeyPressed(KEY_P))
|
||||
{
|
||||
pause = !pause;
|
||||
|
||||
|
||||
if (pause) PauseMusicStream(xm);
|
||||
else ResumeMusicStream(xm);
|
||||
}
|
||||
|
||||
|
||||
// Get timePlayed scaled to bar dimensions
|
||||
timePlayed = GetMusicTimePlayed(xm)/GetMusicTimeLength(xm)*(screenWidth - 40);
|
||||
|
||||
|
||||
// Color circles animation
|
||||
for (int i = MAX_CIRCLES - 1; (i >= 0) && !pause; i--)
|
||||
{
|
||||
circles[i].alpha += circles[i].speed;
|
||||
circles[i].radius += circles[i].speed*10.0f;
|
||||
|
||||
|
||||
if (circles[i].alpha > 1.0f) circles[i].speed *= -1;
|
||||
|
||||
|
||||
if (circles[i].alpha <= 0.0f)
|
||||
{
|
||||
circles[i].alpha = 0.0f;
|
||||
@ -112,36 +111,36 @@ public partial class audio_module_playing
|
||||
}
|
||||
}
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
BeginDrawing();
|
||||
|
||||
|
||||
ClearBackground(RAYWHITE);
|
||||
|
||||
|
||||
for (int i = MAX_CIRCLES - 1; i >= 0; i--)
|
||||
{
|
||||
DrawCircleV(circles[i].position, circles[i].radius, Fade(circles[i].color, circles[i].alpha));
|
||||
}
|
||||
|
||||
|
||||
// Draw time bar
|
||||
DrawRectangle(20, screenHeight - 20 - 12, screenWidth - 40, 12, LIGHTGRAY);
|
||||
DrawRectangle(20, screenHeight - 20 - 12, (int)timePlayed, 12, MAROON);
|
||||
DrawRectangleLines(20, screenHeight - 20 - 12, screenWidth - 40, 12, GRAY);
|
||||
|
||||
|
||||
EndDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
|
||||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
UnloadMusicStream(xm); // Unload music stream buffers from RAM
|
||||
|
||||
|
||||
CloseAudioDevice(); // Close audio device (music streaming is automatically stopped)
|
||||
|
||||
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -15,84 +15,84 @@ public partial class audio_music_stream
|
||||
* Copyright (c) 2015 Ramon Santamaria (@raysan5)
|
||||
*
|
||||
********************************************************************************************/
|
||||
|
||||
|
||||
|
||||
|
||||
public static int Main()
|
||||
{
|
||||
// Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
int screenWidth = 800;
|
||||
int screenHeight = 450;
|
||||
|
||||
|
||||
InitWindow(screenWidth, screenHeight, "raylib [audio] example - music playing (streaming)");
|
||||
|
||||
|
||||
InitAudioDevice(); // Initialize audio device
|
||||
|
||||
|
||||
var music = LoadMusicStream("resources/guitar_noodling.ogg");
|
||||
|
||||
|
||||
PlayMusicStream(music);
|
||||
|
||||
|
||||
float timePlayed = 0.0f;
|
||||
bool pause = false;
|
||||
|
||||
|
||||
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
|
||||
//----------------------------------------------------------------------------------
|
||||
UpdateMusicStream(music); // Update music buffer with new stream data
|
||||
|
||||
|
||||
// Restart music playing (stop and play)
|
||||
if (IsKeyPressed(KEY_SPACE))
|
||||
if (IsKeyPressed(KEY_SPACE))
|
||||
{
|
||||
StopMusicStream(music);
|
||||
PlayMusicStream(music);
|
||||
}
|
||||
|
||||
// Pause/Resume music playing
|
||||
|
||||
// Pause/Resume music playing
|
||||
if (IsKeyPressed(KEY_P))
|
||||
{
|
||||
pause = !pause;
|
||||
|
||||
|
||||
if (pause) PauseMusicStream(music);
|
||||
else ResumeMusicStream(music);
|
||||
}
|
||||
|
||||
|
||||
// Get timePlayed scaled to bar dimensions (400 pixels)
|
||||
timePlayed = GetMusicTimePlayed(music)/GetMusicTimeLength(music)*400;
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
BeginDrawing();
|
||||
|
||||
|
||||
ClearBackground(RAYWHITE);
|
||||
|
||||
|
||||
DrawText("MUSIC SHOULD BE PLAYING!", 255, 150, 20, LIGHTGRAY);
|
||||
|
||||
|
||||
DrawRectangle(200, 200, 400, 12, LIGHTGRAY);
|
||||
DrawRectangle(200, 200, (int)timePlayed, 12, MAROON);
|
||||
DrawRectangleLines(200, 200, 400, 12, GRAY);
|
||||
|
||||
|
||||
DrawText("PRESS SPACE TO RESTART MUSIC", 215, 250, 20, LIGHTGRAY);
|
||||
DrawText("PRESS P TO PAUSE/RESUME MUSIC", 208, 280, 20, LIGHTGRAY);
|
||||
|
||||
|
||||
EndDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
|
||||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
UnloadMusicStream(music); // Unload music stream buffers from RAM
|
||||
|
||||
|
||||
CloseAudioDevice(); // Close audio device (music streaming is automatically stopped)
|
||||
|
||||
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -16,104 +16,104 @@ public partial class audio_raw_stream
|
||||
* Copyright (c) 2015 Ramon Santamaria (@raysan5)
|
||||
*
|
||||
********************************************************************************************/
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public const int MAX_SAMPLES = 22050;
|
||||
public const int MAX_SAMPLES_PER_UPDATE = 4096;
|
||||
|
||||
|
||||
public static int Main()
|
||||
{
|
||||
// Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
int screenWidth = 800;
|
||||
int screenHeight = 450;
|
||||
|
||||
|
||||
InitWindow(screenWidth, screenHeight, "raylib [audio] example - raw audio streaming");
|
||||
|
||||
|
||||
InitAudioDevice(); // Initialize audio device
|
||||
|
||||
|
||||
// Init raw audio stream (sample rate: 22050, sample size: 16bit-short, channels: 1-mono)
|
||||
AudioStream stream = InitAudioStream(22050, 16, 1);
|
||||
|
||||
// Generate samples data from sine wave
|
||||
short[] data = new short[MAX_SAMPLES];
|
||||
//short *data = (short *)malloc(sizeof(short)*MAX_SAMPLES);
|
||||
|
||||
|
||||
// TODO: Review data generation, it seems data is discontinued for loop,
|
||||
// for that reason, there is a clip everytime audio stream is looped...
|
||||
for (int i = 0; i < MAX_SAMPLES; i++)
|
||||
{
|
||||
data[i] = (short)(Math.Sin(((2*Math.PI*(float)i)/2)*DEG2RAD)*32000);
|
||||
}
|
||||
|
||||
|
||||
PlayAudioStream(stream); // Start processing stream buffer (no data loaded currently)
|
||||
|
||||
|
||||
int totalSamples = MAX_SAMPLES;
|
||||
int samplesLeft = totalSamples;
|
||||
|
||||
|
||||
Vector2 position = new Vector2( 0, 0 );
|
||||
|
||||
|
||||
SetTargetFPS(30); // Set our game to run at 30 frames-per-second
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Main game loop
|
||||
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||
{
|
||||
// Update
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Refill audio stream if required
|
||||
// NOTE: Every update we check if stream data has been already consumed and we update
|
||||
// buffer with new data from the generated samples, we upload data at a rate (MAX_SAMPLES_PER_UPDATE),
|
||||
// but notice that at some point we update < MAX_SAMPLES_PER_UPDATE data...
|
||||
if (IsAudioBufferProcessed(stream))
|
||||
if (IsAudioBufferProcessed(stream))
|
||||
{
|
||||
int numSamples = 0;
|
||||
if (samplesLeft >= MAX_SAMPLES_PER_UPDATE) numSamples = MAX_SAMPLES_PER_UPDATE;
|
||||
else numSamples = samplesLeft;
|
||||
|
||||
|
||||
// UpdateAudioStream(stream, data + (totalSamples - samplesLeft), numSamples);
|
||||
|
||||
|
||||
samplesLeft -= numSamples;
|
||||
|
||||
|
||||
// Reset samples feeding (loop audio)
|
||||
if (samplesLeft <= 0) samplesLeft = totalSamples;
|
||||
}
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
BeginDrawing();
|
||||
|
||||
|
||||
ClearBackground(RAYWHITE);
|
||||
|
||||
|
||||
DrawText("SINE WAVE SHOULD BE PLAYING!", 240, 140, 20, LIGHTGRAY);
|
||||
|
||||
|
||||
// NOTE: Draw a part of the sine wave (only screen width, proportional values)
|
||||
for (int i = 0; i < GetScreenWidth(); i++)
|
||||
{
|
||||
position.x = i;
|
||||
position.y = 250 + 50*data[i]/32000;
|
||||
|
||||
|
||||
DrawPixelV(position, RED);
|
||||
}
|
||||
|
||||
|
||||
EndDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
|
||||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
// free(data); // Unload sine wave data
|
||||
|
||||
|
||||
CloseAudioStream(stream); // Close raw audio stream and delete buffers from RAM
|
||||
|
||||
|
||||
CloseAudioDevice(); // Close audio device (music streaming is automatically stopped)
|
||||
|
||||
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -15,25 +15,25 @@ public partial class audio_sound_loading
|
||||
* Copyright (c) 2014 Ramon Santamaria (@raysan5)
|
||||
*
|
||||
********************************************************************************************/
|
||||
|
||||
|
||||
|
||||
|
||||
public static int Main()
|
||||
{
|
||||
// Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
int screenWidth = 800;
|
||||
int screenHeight = 450;
|
||||
|
||||
|
||||
InitWindow(screenWidth, screenHeight, "raylib [audio] example - sound loading and playing");
|
||||
|
||||
|
||||
InitAudioDevice(); // Initialize audio device
|
||||
|
||||
|
||||
Sound fxWav = LoadSound("resources/sound.wav"); // Load WAV audio file
|
||||
Sound fxOgg = LoadSound("resources/tanatana.ogg"); // Load OGG audio file
|
||||
|
||||
|
||||
SetTargetFPS(60);
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Main game loop
|
||||
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||
{
|
||||
@ -42,31 +42,31 @@ public partial class audio_sound_loading
|
||||
if (IsKeyPressed(KEY_SPACE)) PlaySound(fxWav); // Play WAV sound
|
||||
if (IsKeyPressed(KEY_ENTER)) PlaySound(fxOgg); // Play OGG sound
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
BeginDrawing();
|
||||
|
||||
|
||||
ClearBackground(RAYWHITE);
|
||||
|
||||
|
||||
DrawText("Press SPACE to PLAY the WAV sound!", 200, 180, 20, LIGHTGRAY);
|
||||
|
||||
|
||||
DrawText("Press ENTER to PLAY the OGG sound!", 200, 220, 20, LIGHTGRAY);
|
||||
|
||||
|
||||
EndDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
|
||||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
UnloadSound(fxWav); // Unload sound data
|
||||
UnloadSound(fxOgg); // Unload sound data
|
||||
|
||||
|
||||
CloseAudioDevice(); // Close audio device
|
||||
|
||||
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -134,7 +134,7 @@ public partial class core_2d_camera
|
||||
}
|
||||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
//--------------------------------------------------------------------------------------
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
@ -15,19 +15,19 @@ public partial class core_3d_camera_first_person
|
||||
* Copyright (c) 2015 Ramon Santamaria (@raysan5)
|
||||
*
|
||||
********************************************************************************************/
|
||||
|
||||
|
||||
|
||||
|
||||
public const int MAX_COLUMNS = 20;
|
||||
|
||||
|
||||
public static int Main()
|
||||
{
|
||||
// Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
int screenWidth = 800;
|
||||
int screenHeight = 450;
|
||||
|
||||
|
||||
InitWindow(screenWidth, screenHeight, "raylib [core] example - 3d camera first person");
|
||||
|
||||
|
||||
// Define the camera to look into our 3d world (position, target, up vector)
|
||||
Camera3D camera = new Camera3D();
|
||||
camera.position = new Vector3( 4.0f, 2.0f, 4.0f );
|
||||
@ -35,24 +35,24 @@ public partial class core_3d_camera_first_person
|
||||
camera.up = new Vector3( 0.0f, 1.0f, 0.0f );
|
||||
camera.fovy = 60.0f;
|
||||
camera.type = (int)CAMERA_PERSPECTIVE;
|
||||
|
||||
|
||||
// Generates some random columns
|
||||
float[] heights = new float[MAX_COLUMNS];
|
||||
Vector3[] positions = new Vector3[MAX_COLUMNS];
|
||||
Color[] colors = new Color[MAX_COLUMNS];
|
||||
|
||||
|
||||
for (int i = 0; i < MAX_COLUMNS; i++)
|
||||
{
|
||||
heights[i] = (float)GetRandomValue(1, 12);
|
||||
positions[i] = new Vector3( GetRandomValue(-15, 15), heights[i]/2, GetRandomValue(-15, 15) );
|
||||
colors[i] = new Color( GetRandomValue(20, 255), GetRandomValue(10, 55), 30, 255 );
|
||||
}
|
||||
|
||||
|
||||
SetCameraMode(camera, (int)CAMERA_FIRST_PERSON); // Set a first person camera mode
|
||||
|
||||
|
||||
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Main game loop
|
||||
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||
{
|
||||
@ -60,45 +60,45 @@ public partial class core_3d_camera_first_person
|
||||
//----------------------------------------------------------------------------------
|
||||
UpdateCamera(ref camera); // Update camera
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
BeginDrawing();
|
||||
|
||||
|
||||
ClearBackground(RAYWHITE);
|
||||
|
||||
|
||||
BeginMode3D(camera);
|
||||
|
||||
|
||||
DrawPlane(new Vector3( 0.0f, 0.0f, 0.0f ), new Vector2( 32.0f, 32.0f ), LIGHTGRAY); // Draw ground
|
||||
DrawCube(new Vector3( -16.0f, 2.5f, 0.0f ), 1.0f, 5.0f, 32.0f, BLUE); // Draw a blue wall
|
||||
DrawCube(new Vector3( 16.0f, 2.5f, 0.0f ), 1.0f, 5.0f, 32.0f, LIME); // Draw a green wall
|
||||
DrawCube(new Vector3( 0.0f, 2.5f, 16.0f ), 32.0f, 5.0f, 1.0f, GOLD); // Draw a yellow wall
|
||||
|
||||
|
||||
// Draw some cubes around
|
||||
for (int i = 0; i < MAX_COLUMNS; i++)
|
||||
{
|
||||
DrawCube(positions[i], 2.0f, heights[i], 2.0f, colors[i]);
|
||||
DrawCubeWires(positions[i], 2.0f, heights[i], 2.0f, MAROON);
|
||||
}
|
||||
|
||||
|
||||
EndMode3D();
|
||||
|
||||
|
||||
DrawRectangle( 10, 10, 220, 70, Fade(SKYBLUE, 0.5f));
|
||||
DrawRectangleLines( 10, 10, 220, 70, BLUE);
|
||||
|
||||
|
||||
DrawText("First person camera default controls:", 20, 20, 10, BLACK);
|
||||
DrawText("- Move with keys: W, A, S, D", 40, 40, 10, DARKGRAY);
|
||||
DrawText("- Mouse move to look around", 40, 60, 10, DARKGRAY);
|
||||
|
||||
|
||||
EndDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
|
||||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
//--------------------------------------------------------------------------------------
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -15,17 +15,17 @@ public partial class core_3d_camera_free
|
||||
* Copyright (c) 2015 Ramon Santamaria (@raysan5)
|
||||
*
|
||||
********************************************************************************************/
|
||||
|
||||
|
||||
|
||||
|
||||
public static int Main()
|
||||
{
|
||||
// Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
int screenWidth = 800;
|
||||
int screenHeight = 450;
|
||||
|
||||
|
||||
InitWindow(screenWidth, screenHeight, "raylib [core] example - 3d camera free");
|
||||
|
||||
|
||||
// Define the camera to look into our 3d world
|
||||
Camera3D camera;
|
||||
camera.position = new Vector3( 10.0f, 10.0f, 10.0f ); // Camera3D position
|
||||
@ -33,58 +33,58 @@ public partial class core_3d_camera_free
|
||||
camera.up = new Vector3( 0.0f, 1.0f, 0.0f ); // Camera3D up vector (rotation towards target)
|
||||
camera.fovy = 45.0f; // Camera3D field-of-view Y
|
||||
camera.type = (int)CAMERA_PERSPECTIVE; // Camera3D mode type
|
||||
|
||||
|
||||
Vector3 cubePosition = new Vector3( 0.0f, 0.0f, 0.0f );
|
||||
|
||||
|
||||
SetCameraMode(camera, (int)CAMERA_FREE); // Set a free camera mode
|
||||
|
||||
|
||||
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
|
||||
//----------------------------------------------------------------------------------
|
||||
UpdateCamera(ref camera); // Update camera
|
||||
|
||||
|
||||
if (IsKeyDown('Z')) camera.target = new Vector3( 0.0f, 0.0f, 0.0f );
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
BeginDrawing();
|
||||
|
||||
|
||||
ClearBackground(RAYWHITE);
|
||||
|
||||
|
||||
BeginMode3D(camera);
|
||||
|
||||
|
||||
DrawCube(cubePosition, 2.0f, 2.0f, 2.0f, RED);
|
||||
DrawCubeWires(cubePosition, 2.0f, 2.0f, 2.0f, MAROON);
|
||||
|
||||
|
||||
DrawGrid(10, 1.0f);
|
||||
|
||||
|
||||
EndMode3D();
|
||||
|
||||
|
||||
DrawRectangle( 10, 10, 320, 133, Fade(SKYBLUE, 0.5f));
|
||||
DrawRectangleLines( 10, 10, 320, 133, BLUE);
|
||||
|
||||
|
||||
DrawText("Free camera default controls:", 20, 20, 10, BLACK);
|
||||
DrawText("- Mouse Wheel to Zoom in-out", 40, 40, 10, DARKGRAY);
|
||||
DrawText("- Mouse Wheel Pressed to Pan", 40, 60, 10, DARKGRAY);
|
||||
DrawText("- Alt + Mouse Wheel Pressed to Rotate", 40, 80, 10, DARKGRAY);
|
||||
DrawText("- Alt + Ctrl + Mouse Wheel Pressed for Smooth Zoom", 40, 100, 10, DARKGRAY);
|
||||
DrawText("- Z to zoom to (0, 0, 0)", 40, 120, 10, DARKGRAY);
|
||||
|
||||
|
||||
EndDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
|
||||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -14,17 +14,17 @@ public partial class core_3d_mode
|
||||
* Copyright (c) 2014 Ramon Santamaria (@raysan5)
|
||||
*
|
||||
********************************************************************************************/
|
||||
|
||||
|
||||
|
||||
|
||||
public static int Main()
|
||||
{
|
||||
// Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
int screenWidth = 800;
|
||||
int screenHeight = 450;
|
||||
|
||||
|
||||
InitWindow(screenWidth, screenHeight, "raylib [core] example - 3d mode");
|
||||
|
||||
|
||||
// Define the camera to look into our 3d world
|
||||
Camera3D camera;
|
||||
camera.position = new Vector3( 0.0f, 10.0f, 10.0f ); // Camera3D position
|
||||
@ -32,12 +32,12 @@ public partial class core_3d_mode
|
||||
camera.up = new Vector3( 0.0f, 1.0f, 0.0f ); // Camera3D up vector (rotation towards target)
|
||||
camera.fovy = 45.0f; // Camera3D field-of-view Y
|
||||
camera.type = CAMERA_PERSPECTIVE; // Camera3D mode type
|
||||
|
||||
|
||||
Vector3 cubePosition = new Vector3( 0.0f, 0.0f, 0.0f );
|
||||
|
||||
|
||||
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Main game loop
|
||||
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||
{
|
||||
@ -45,35 +45,35 @@ public partial class core_3d_mode
|
||||
//----------------------------------------------------------------------------------
|
||||
// TODO: Update your variables here
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
BeginDrawing();
|
||||
|
||||
|
||||
ClearBackground(RAYWHITE);
|
||||
|
||||
|
||||
BeginMode3D(camera);
|
||||
|
||||
|
||||
DrawCube(cubePosition, 2.0f, 2.0f, 2.0f, RED);
|
||||
DrawCubeWires(cubePosition, 2.0f, 2.0f, 2.0f, MAROON);
|
||||
|
||||
|
||||
DrawGrid(10, 1.0f);
|
||||
|
||||
|
||||
EndMode3D();
|
||||
|
||||
|
||||
DrawText("Welcome to the third dimension!", 10, 40, 20, DARKGRAY);
|
||||
|
||||
|
||||
DrawFPS(10, 10);
|
||||
|
||||
|
||||
EndDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
|
||||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -15,17 +15,17 @@ public partial class core_3d_picking
|
||||
* Copyright (c) 2015 Ramon Santamaria (@raysan5)
|
||||
*
|
||||
********************************************************************************************/
|
||||
|
||||
|
||||
|
||||
|
||||
public static int Main()
|
||||
{
|
||||
// Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
int screenWidth = 800;
|
||||
int screenHeight = 450;
|
||||
|
||||
|
||||
InitWindow(screenWidth, screenHeight, "raylib [core] example - 3d picking");
|
||||
|
||||
|
||||
// Define the camera to look into our 3d world
|
||||
Camera3D camera;
|
||||
camera.position = new Vector3( 10.0f, 10.0f, 10.0f ); // Camera3D position
|
||||
@ -33,50 +33,50 @@ public partial class core_3d_picking
|
||||
camera.up = new Vector3( 0.0f, 1.0f, 0.0f ); // Camera3D up vector (rotation towards target)
|
||||
camera.fovy = 45.0f; // Camera3D field-of-view Y
|
||||
camera.type = (int)CAMERA_PERSPECTIVE; // Camera3D mode type
|
||||
|
||||
|
||||
Vector3 cubePosition = new Vector3( 0.0f, 1.0f, 0.0f );
|
||||
Vector3 cubeSize = new Vector3( 2.0f, 2.0f, 2.0f );
|
||||
|
||||
|
||||
Ray ray = new Ray(new Vector3(0.0f, 0.0f, 0.0f), Vector3.Zero); // Picking line ray
|
||||
|
||||
|
||||
bool collision = false;
|
||||
|
||||
|
||||
SetCameraMode(camera, (int)CAMERA_FREE); // Set a free camera mode
|
||||
|
||||
|
||||
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
|
||||
//----------------------------------------------------------------------------------
|
||||
UpdateCamera(ref camera); // Update camera
|
||||
|
||||
|
||||
if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON))
|
||||
{
|
||||
ray = GetMouseRay(GetMousePosition(), camera);
|
||||
|
||||
|
||||
// Check collision between ray and box
|
||||
collision = CheckCollisionRayBox(ray,
|
||||
new BoundingBox(new Vector3( cubePosition.x - cubeSize.x/2, cubePosition.y - cubeSize.y/2, cubePosition.z - cubeSize.z/2 ),
|
||||
new Vector3( cubePosition.x + cubeSize.x/2, cubePosition.y + cubeSize.y/2, cubePosition.z + cubeSize.z/2 )));
|
||||
}
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
BeginDrawing();
|
||||
|
||||
|
||||
ClearBackground(RAYWHITE);
|
||||
|
||||
|
||||
BeginMode3D(camera);
|
||||
|
||||
|
||||
if (collision)
|
||||
{
|
||||
DrawCube(cubePosition, cubeSize.x, cubeSize.y, cubeSize.z, RED);
|
||||
DrawCubeWires(cubePosition, cubeSize.x, cubeSize.y, cubeSize.z, MAROON);
|
||||
|
||||
|
||||
DrawCubeWires(cubePosition, cubeSize.x + 0.2f, cubeSize.y + 0.2f, cubeSize.z + 0.2f, GREEN);
|
||||
}
|
||||
else
|
||||
@ -84,27 +84,27 @@ public partial class core_3d_picking
|
||||
DrawCube(cubePosition, cubeSize.x, cubeSize.y, cubeSize.z, GRAY);
|
||||
DrawCubeWires(cubePosition, cubeSize.x, cubeSize.y, cubeSize.z, DARKGRAY);
|
||||
}
|
||||
|
||||
|
||||
DrawRay(ray, MAROON);
|
||||
DrawGrid(10, 1.0f);
|
||||
|
||||
|
||||
EndMode3D();
|
||||
|
||||
|
||||
DrawText("Try selecting the box with mouse!", 240, 10, 20, DARKGRAY);
|
||||
|
||||
|
||||
if(collision) DrawText("BOX SELECTED", (screenWidth - MeasureText("BOX SELECTED", 30)) / 2, (int)(screenHeight * 0.1f), 30, GREEN);
|
||||
|
||||
|
||||
DrawFPS(10, 10);
|
||||
|
||||
|
||||
EndDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
|
||||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -23,20 +23,20 @@ public partial class core_basic_window
|
||||
* Copyright (c) 2013-2016 Ramon Santamaria (@raysan5)
|
||||
*
|
||||
********************************************************************************************/
|
||||
|
||||
|
||||
|
||||
|
||||
public static int Main()
|
||||
{
|
||||
// Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
int screenWidth = 800;
|
||||
int screenHeight = 450;
|
||||
|
||||
|
||||
InitWindow(screenWidth, screenHeight, "raylib [core] example - basic window");
|
||||
|
||||
|
||||
SetTargetFPS(60);
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Main game loop
|
||||
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||
{
|
||||
@ -44,24 +44,24 @@ public partial class core_basic_window
|
||||
//----------------------------------------------------------------------------------
|
||||
// TODO: Update your variables here
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
BeginDrawing();
|
||||
|
||||
|
||||
ClearBackground(RAYWHITE);
|
||||
|
||||
|
||||
DrawText("Congrats! You created your first window!", 190, 200, 20, MAROON);
|
||||
|
||||
|
||||
EndDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
|
||||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
//--------------------------------------------------------------------------------------
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -17,23 +17,23 @@ public partial class Examples
|
||||
* Copyright (c) 2015 Ramon Santamaria (@raysan5)
|
||||
*
|
||||
********************************************************************************************/
|
||||
|
||||
|
||||
|
||||
|
||||
//#define PLATFORM_WEB
|
||||
|
||||
|
||||
#include <emscripten/emscripten.h>
|
||||
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Global Variables Definition
|
||||
//----------------------------------------------------------------------------------
|
||||
int screenWidth = 800;
|
||||
int screenHeight = 450;
|
||||
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Module Functions Declaration
|
||||
//----------------------------------------------------------------------------------
|
||||
void UpdateDrawFrame(void); // Update and Draw one frame
|
||||
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Main Enry Point
|
||||
//----------------------------------------------------------------------------------
|
||||
@ -42,26 +42,26 @@ public partial class Examples
|
||||
// Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
InitWindow(screenWidth, screenHeight, "raylib [core] example - basic window");
|
||||
|
||||
|
||||
emscripten_set_main_loop(UpdateDrawFrame, 0, 1);
|
||||
#else
|
||||
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Main game loop
|
||||
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||
{
|
||||
UpdateDrawFrame();
|
||||
}
|
||||
|
||||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Module Functions Definition
|
||||
//----------------------------------------------------------------------------------
|
||||
@ -71,16 +71,16 @@ public partial class Examples
|
||||
//----------------------------------------------------------------------------------
|
||||
// TODO: Update your variables here
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
BeginDrawing();
|
||||
|
||||
|
||||
ClearBackground(RAYWHITE);
|
||||
|
||||
|
||||
DrawText("Congrats! You created your first window!", 190, 200, 20, LIGHTGRAY);
|
||||
|
||||
|
||||
EndDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -13,23 +13,23 @@ public partial class core_color_select
|
||||
* Copyright (c) 2014 Ramon Santamaria (@raysan5)
|
||||
*
|
||||
********************************************************************************************/
|
||||
|
||||
|
||||
|
||||
|
||||
public static int Main()
|
||||
{
|
||||
// Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
int screenWidth = 800;
|
||||
int screenHeight = 450;
|
||||
|
||||
|
||||
InitWindow(screenWidth, screenHeight, "raylib [core] example - color selection (collision detection)");
|
||||
|
||||
|
||||
Color[] colors = new Color[21] { DARKGRAY, MAROON, ORANGE, DARKGREEN, DARKBLUE, DARKPURPLE, DARKBROWN,
|
||||
GRAY, RED, GOLD, LIME, BLUE, VIOLET, BROWN, LIGHTGRAY, PINK, YELLOW,
|
||||
GREEN, SKYBLUE, PURPLE, BEIGE };
|
||||
|
||||
|
||||
Rectangle[] colorsRecs = new Rectangle[21]; // Rectangles array
|
||||
|
||||
|
||||
// Fills colorsRecs data (for every rectangle)
|
||||
for (int i = 0; i < 21; i++)
|
||||
{
|
||||
@ -38,43 +38,43 @@ public partial class core_color_select
|
||||
colorsRecs[i].width = 100;
|
||||
colorsRecs[i].height = 100;
|
||||
}
|
||||
|
||||
|
||||
bool[] selected = new bool[21]; // Selected rectangles indicator
|
||||
|
||||
|
||||
Vector2 mousePoint;
|
||||
|
||||
|
||||
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
|
||||
//----------------------------------------------------------------------------------
|
||||
mousePoint = GetMousePosition();
|
||||
|
||||
|
||||
for (int i = 0; i < 21; i++) // Iterate along all the rectangles
|
||||
{
|
||||
if (CheckCollisionPointRec(mousePoint, colorsRecs[i]))
|
||||
{
|
||||
colors[i].a = 120;
|
||||
|
||||
|
||||
if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) selected[i] = !selected[i];
|
||||
}
|
||||
else colors[i].a = 255;
|
||||
}
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
BeginDrawing();
|
||||
|
||||
|
||||
ClearBackground(RAYWHITE);
|
||||
|
||||
|
||||
for (int i = 0; i < 21; i++) // Draw all rectangles
|
||||
{
|
||||
DrawRectangleRec(colorsRecs[i], colors[i]);
|
||||
|
||||
|
||||
// Draw four rectangles around selected rectangle
|
||||
if (selected[i])
|
||||
{
|
||||
@ -84,16 +84,16 @@ public partial class core_color_select
|
||||
DrawRectangle((int)colorsRecs[i].x, (int)colorsRecs[i].y + 90, 100, 10, RAYWHITE); // Square bottom rectangle
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
EndDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
|
||||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -13,19 +13,19 @@ public partial class Examples
|
||||
* Copyright (c) 2018 Ramon Santamaria (@raysan5) and Pablo Marcos Oltra (@pamarcos)
|
||||
*
|
||||
********************************************************************************************/
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// Custom logging funtion
|
||||
void LogCustom(int msgType, const char *text, va_list args)
|
||||
{
|
||||
char timeStr[64];
|
||||
time_t now = time(NULL);
|
||||
struct tm *tm_info = localtime(&now);
|
||||
|
||||
|
||||
strftime(timeStr, sizeof(timeStr), "%Y-%m-%d %H:%M:%S", tm_info);
|
||||
printf("[%s] ", timeStr);
|
||||
|
||||
|
||||
switch (msgType)
|
||||
{
|
||||
case LOG_INFO: printf("[INFO] : "); break;
|
||||
@ -34,27 +34,27 @@ public partial class Examples
|
||||
case LOG_DEBUG: printf("[DEBUG]: "); break;
|
||||
default: break;
|
||||
}
|
||||
|
||||
|
||||
vprintf(text, args);
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
|
||||
public static int core_custom_logging()
|
||||
{
|
||||
// Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
int screenWidth = 800;
|
||||
int screenHeight = 450;
|
||||
|
||||
|
||||
// First thing we do is setting our custom logger to ensure everything raylib logs
|
||||
// will use our own logger instead of its internal one
|
||||
SetTraceLogCallback(LogCustom);
|
||||
|
||||
|
||||
InitWindow(screenWidth, screenHeight, "raylib [core] example - custom logging");
|
||||
|
||||
|
||||
SetTargetFPS(60);
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Main game loop
|
||||
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||
{
|
||||
@ -62,25 +62,25 @@ public partial class Examples
|
||||
//----------------------------------------------------------------------------------
|
||||
// TODO: Update your variables here
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
BeginDrawing();
|
||||
|
||||
|
||||
ClearBackground(RAYWHITE);
|
||||
|
||||
|
||||
DrawText("Check out the console output to see the custom logger in action!", 60, 200, 20, LIGHTGRAY);
|
||||
|
||||
|
||||
EndDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
|
||||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -15,23 +15,23 @@ public partial class core_drop_files
|
||||
* Copyright (c) 2015 Ramon Santamaria (@raysan5)
|
||||
*
|
||||
********************************************************************************************/
|
||||
|
||||
|
||||
|
||||
|
||||
public static int Main()
|
||||
{
|
||||
// Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
int screenWidth = 800;
|
||||
int screenHeight = 450;
|
||||
|
||||
|
||||
InitWindow(screenWidth, screenHeight, "raylib [core] example - drop files");
|
||||
|
||||
|
||||
int count = 0;
|
||||
string[] droppedFiles = { };
|
||||
|
||||
|
||||
SetTargetFPS(60);
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Main game loop
|
||||
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||
{
|
||||
@ -42,40 +42,40 @@ public partial class core_drop_files
|
||||
droppedFiles = GetDroppedFiles(ref count);
|
||||
}
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
BeginDrawing();
|
||||
|
||||
|
||||
ClearBackground(RAYWHITE);
|
||||
|
||||
|
||||
if (count == 0) DrawText("Drop your files to this window!", 100, 40, 20, DARKGRAY);
|
||||
else
|
||||
{
|
||||
DrawText("Dropped files:", 100, 40, 20, DARKGRAY);
|
||||
|
||||
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
if (i%2 == 0) DrawRectangle(0, 85 + 40*i, screenWidth, 40, Fade(LIGHTGRAY, 0.5f));
|
||||
else DrawRectangle(0, 85 + 40*i, screenWidth, 40, Fade(LIGHTGRAY, 0.3f));
|
||||
|
||||
|
||||
DrawText(droppedFiles[i], 120, 100 + 40*i, 10, GRAY);
|
||||
}
|
||||
|
||||
|
||||
DrawText("Drop new files...", 100, 110 + 40*count, 20, DARKGRAY);
|
||||
}
|
||||
|
||||
|
||||
EndDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
|
||||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
ClearDroppedFiles(); // Clear internal buffers
|
||||
|
||||
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -14,33 +14,33 @@ public partial class core_gestures_detection
|
||||
* Copyright (c) 2016 Ramon Santamaria (@raysan5)
|
||||
*
|
||||
********************************************************************************************/
|
||||
|
||||
|
||||
|
||||
|
||||
public const int MAX_GESTURE_STRINGS = 20;
|
||||
|
||||
|
||||
public static int Main()
|
||||
{
|
||||
// Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
int screenWidth = 800;
|
||||
int screenHeight = 450;
|
||||
|
||||
|
||||
InitWindow(screenWidth, screenHeight, "raylib [core] example - gestures detection");
|
||||
|
||||
|
||||
Vector2 touchPosition = new Vector2( 0, 0 );
|
||||
Rectangle touchArea = new Rectangle( 220, 10, screenWidth - 230, screenHeight - 20 );
|
||||
|
||||
|
||||
int gesturesCount = 0;
|
||||
string[] gestureStrings = new string[MAX_GESTURE_STRINGS];
|
||||
|
||||
|
||||
int currentGesture = (int)GESTURE_NONE;
|
||||
int lastGesture = (int)GESTURE_NONE;
|
||||
|
||||
|
||||
//SetGesturesEnabled(0b0000000000001001); // Enable only some gestures to be detected
|
||||
|
||||
|
||||
SetTargetFPS(60);
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Main game loop
|
||||
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||
{
|
||||
@ -49,7 +49,7 @@ public partial class core_gestures_detection
|
||||
lastGesture = currentGesture;
|
||||
currentGesture = GetGestureDetected();
|
||||
touchPosition = GetTouchPosition(0);
|
||||
|
||||
|
||||
if (CheckCollisionPointRec(touchPosition, touchArea) && (currentGesture != (int)GESTURE_NONE))
|
||||
{
|
||||
if (currentGesture != lastGesture)
|
||||
@ -69,53 +69,53 @@ public partial class core_gestures_detection
|
||||
case (int)GESTURE_PINCH_OUT: gestureStrings[gesturesCount] = "GESTURE PINCH OUT"; break;
|
||||
default: break;
|
||||
}
|
||||
|
||||
|
||||
gesturesCount++;
|
||||
|
||||
|
||||
// Reset gestures strings
|
||||
if (gesturesCount >= MAX_GESTURE_STRINGS)
|
||||
{
|
||||
for (int i = 0; i < MAX_GESTURE_STRINGS; i++) gestureStrings[i] = " ";
|
||||
|
||||
|
||||
gesturesCount = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
BeginDrawing();
|
||||
|
||||
|
||||
ClearBackground(RAYWHITE);
|
||||
|
||||
|
||||
DrawRectangleRec(touchArea, GRAY);
|
||||
DrawRectangle(225, 15, screenWidth - 240, screenHeight - 30, RAYWHITE);
|
||||
|
||||
|
||||
DrawText("GESTURES TEST AREA", screenWidth - 270, screenHeight - 40, 20, Fade(GRAY, 0.5f));
|
||||
|
||||
|
||||
for (int i = 0; i < gesturesCount; i++)
|
||||
{
|
||||
if (i%2 == 0) DrawRectangle(10, 30 + 20*i, 200, 20, Fade(LIGHTGRAY, 0.5f));
|
||||
else DrawRectangle(10, 30 + 20*i, 200, 20, Fade(LIGHTGRAY, 0.3f));
|
||||
|
||||
|
||||
if (i < gesturesCount - 1) DrawText(gestureStrings[i], 35, 36 + 20*i, 10, DARKGRAY);
|
||||
else DrawText(gestureStrings[i], 35, 36 + 20*i, 10, MAROON);
|
||||
}
|
||||
|
||||
|
||||
DrawRectangleLines(10, 29, 200, screenHeight - 50, GRAY);
|
||||
DrawText("DETECTED GESTURES", 50, 15, 10, GRAY);
|
||||
|
||||
|
||||
if (currentGesture != (int)GESTURE_NONE) DrawCircleV(touchPosition, 30, MAROON);
|
||||
|
||||
|
||||
EndDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
|
||||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
//--------------------------------------------------------------------------------------
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -9,9 +9,9 @@ public partial class core_input_gamepad
|
||||
* raylib [core] example - Gamepad input
|
||||
*
|
||||
* NOTE: This example requires a Gamepad connected to the system
|
||||
* raylib is configured to work with the following gamepads:
|
||||
* raylib is configured to work with the following gamepads:
|
||||
* - Xbox 360 Controller (Xbox 360, Xbox One)
|
||||
* - PLAYSTATION(R)3 Controller
|
||||
* - PLAYSTATION(R)3 Controller
|
||||
* Check raylib.h for buttons configuration
|
||||
*
|
||||
* This example has been created using raylib 1.6 (www.raylib.com)
|
||||
@ -35,7 +35,7 @@ public partial class core_input_gamepad
|
||||
int screenWidth = 800;
|
||||
int screenHeight = 450;
|
||||
|
||||
SetConfigFlags(FLAG_MSAA_4X_HINT); // Set MSAA 4X hint before windows creation
|
||||
SetConfigFlags(FLAG_MSAA_4X_HINT); // Set MSAA 4X hint before windows creation
|
||||
|
||||
InitWindow(screenWidth, screenHeight, "raylib [core] example - gamepad input");
|
||||
|
||||
|
@ -13,22 +13,22 @@ public partial class core_input_keys
|
||||
* Copyright (c) 2014 Ramon Santamaria (@raysan5)
|
||||
*
|
||||
********************************************************************************************/
|
||||
|
||||
|
||||
|
||||
|
||||
public static int Main()
|
||||
{
|
||||
// Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
int screenWidth = 800;
|
||||
int screenHeight = 450;
|
||||
|
||||
|
||||
InitWindow(screenWidth, screenHeight, "raylib [core] example - keyboard input");
|
||||
|
||||
|
||||
Vector2 ballPosition = new Vector2( (float)screenWidth/2, (float)screenHeight/2 );
|
||||
|
||||
|
||||
SetTargetFPS(60); // Set target frames-per-second
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Main game loop
|
||||
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||
{
|
||||
@ -39,26 +39,26 @@ public partial class core_input_keys
|
||||
if (IsKeyDown(KEY_UP)) ballPosition.y -= 2.0f;
|
||||
if (IsKeyDown(KEY_DOWN)) ballPosition.y += 2.0f;
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
BeginDrawing();
|
||||
|
||||
|
||||
ClearBackground(RAYWHITE);
|
||||
|
||||
|
||||
DrawText("move the ball with arrow keys", 10, 10, 20, DARKGRAY);
|
||||
|
||||
|
||||
DrawCircleV(ballPosition, 50, MAROON);
|
||||
|
||||
|
||||
EndDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
|
||||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -13,54 +13,54 @@ public partial class core_input_mouse
|
||||
* Copyright (c) 2014 Ramon Santamaria (@raysan5)
|
||||
*
|
||||
********************************************************************************************/
|
||||
|
||||
|
||||
|
||||
|
||||
public static int Main()
|
||||
{
|
||||
// Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
int screenWidth = 800;
|
||||
int screenHeight = 450;
|
||||
|
||||
|
||||
InitWindow(screenWidth, screenHeight, "raylib [core] example - mouse input");
|
||||
|
||||
|
||||
Vector2 ballPosition = new Vector2( -100.0f, -100.0f );
|
||||
Color ballColor = DARKBLUE;
|
||||
|
||||
|
||||
SetTargetFPS(60);
|
||||
//---------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Main game loop
|
||||
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||
{
|
||||
// Update
|
||||
//----------------------------------------------------------------------------------
|
||||
ballPosition = GetMousePosition();
|
||||
|
||||
|
||||
if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) ballColor = MAROON;
|
||||
else if (IsMouseButtonPressed(MOUSE_MIDDLE_BUTTON)) ballColor = LIME;
|
||||
else if (IsMouseButtonPressed(MOUSE_RIGHT_BUTTON)) ballColor = DARKBLUE;
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
BeginDrawing();
|
||||
|
||||
|
||||
ClearBackground(RAYWHITE);
|
||||
|
||||
|
||||
DrawCircleV(ballPosition, 40, ballColor);
|
||||
|
||||
|
||||
DrawText("move ball with mouse and click mouse button to change color", 10, 10, 20, DARKGRAY);
|
||||
|
||||
|
||||
EndDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
|
||||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ public partial class core_mouse_wheel
|
||||
* Copyright (c) 2014 Ramon Santamaria (@raysan5)
|
||||
*
|
||||
********************************************************************************************/
|
||||
|
||||
|
||||
|
||||
public static int Main()
|
||||
{
|
||||
@ -21,15 +21,15 @@ public partial class core_mouse_wheel
|
||||
//--------------------------------------------------------------------------------------
|
||||
int screenWidth = 800;
|
||||
int screenHeight = 450;
|
||||
|
||||
|
||||
InitWindow(screenWidth, screenHeight, "raylib [core] example - mouse wheel");
|
||||
|
||||
|
||||
int boxPositionY = screenHeight/2 - 40;
|
||||
int scrollSpeed = 4; // Scrolling speed in pixels
|
||||
|
||||
|
||||
SetTargetFPS(60);
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Main game loop
|
||||
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||
{
|
||||
@ -37,15 +37,15 @@ public partial class core_mouse_wheel
|
||||
//----------------------------------------------------------------------------------
|
||||
boxPositionY -= (GetMouseWheelMove()*scrollSpeed);
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
BeginDrawing();
|
||||
|
||||
|
||||
ClearBackground(RAYWHITE);
|
||||
|
||||
|
||||
DrawRectangle(screenWidth/2 - 40, boxPositionY, 80, 80, MAROON);
|
||||
|
||||
|
||||
DrawText("Use mouse wheel to move the cube up and down!", 10, 10, 20, GRAY);
|
||||
//DrawText(FormatText("Box position Y: %03i", boxPositionY), 10, 40, 20, LIGHTGRAY);
|
||||
DrawText($"Box position Y: {boxPositionY}", 10, 40, 20, LIGHTGRAY);
|
||||
@ -53,12 +53,12 @@ public partial class core_mouse_wheel
|
||||
EndDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
|
||||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -13,31 +13,31 @@ public partial class core_random_values
|
||||
* Copyright (c) 2014 Ramon Santamaria (@raysan5)
|
||||
*
|
||||
********************************************************************************************/
|
||||
|
||||
|
||||
|
||||
|
||||
public static int Main()
|
||||
{
|
||||
// Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
int screenWidth = 800;
|
||||
int screenHeight = 450;
|
||||
|
||||
|
||||
InitWindow(screenWidth, screenHeight, "raylib [core] example - generate random values");
|
||||
|
||||
|
||||
int framesCounter = 0; // Variable used to count frames
|
||||
|
||||
|
||||
int randValue = GetRandomValue(-8, 5); // Get a random integer number between -8 and 5 (both included)
|
||||
|
||||
|
||||
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
|
||||
//----------------------------------------------------------------------------------
|
||||
framesCounter++;
|
||||
|
||||
|
||||
// Every two seconds (120 frames) a new random value is generated
|
||||
if (((framesCounter/120)%2) == 1)
|
||||
{
|
||||
@ -45,27 +45,27 @@ public partial class core_random_values
|
||||
framesCounter = 0;
|
||||
}
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
BeginDrawing();
|
||||
|
||||
|
||||
ClearBackground(RAYWHITE);
|
||||
|
||||
|
||||
DrawText("Every 2 seconds a new random value is generated:", 130, 100, 20, MAROON);
|
||||
|
||||
|
||||
//DrawText(FormatText("%i", randValue), 360, 180, 80, LIGHTGRAY);
|
||||
DrawText($"{randValue}", 360, 180, 80, LIGHTGRAY);
|
||||
|
||||
|
||||
EndDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
|
||||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ public partial class core_storage_values
|
||||
* Copyright (c) 2015 Ramon Santamaria (@raysan5)
|
||||
*
|
||||
********************************************************************************************/
|
||||
|
||||
|
||||
// NOTE: Storage positions must start with 0, directly related to file memory layout
|
||||
enum StorageData { STORAGE_SCORE = 0, STORAGE_HISCORE };
|
||||
|
||||
@ -23,17 +23,17 @@ public partial class core_storage_values
|
||||
//--------------------------------------------------------------------------------------
|
||||
int screenWidth = 800;
|
||||
int screenHeight = 450;
|
||||
|
||||
|
||||
InitWindow(screenWidth, screenHeight, "raylib [core] example - storage save/load values");
|
||||
|
||||
|
||||
int score = 0;
|
||||
int hiscore = 0;
|
||||
|
||||
|
||||
int framesCounter = 0;
|
||||
|
||||
|
||||
SetTargetFPS(60);
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Main game loop
|
||||
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||
{
|
||||
@ -44,7 +44,7 @@ public partial class core_storage_values
|
||||
score = GetRandomValue(1000, 2000);
|
||||
hiscore = GetRandomValue(2000, 4000);
|
||||
}
|
||||
|
||||
|
||||
if (IsKeyPressed(KEY_ENTER))
|
||||
{
|
||||
StorageSaveValue((int)StorageData.STORAGE_SCORE, score);
|
||||
@ -56,14 +56,14 @@ public partial class core_storage_values
|
||||
score = StorageLoadValue((int)StorageData.STORAGE_SCORE);
|
||||
hiscore = StorageLoadValue((int)StorageData.STORAGE_HISCORE);
|
||||
}
|
||||
|
||||
|
||||
framesCounter++;
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
BeginDrawing();
|
||||
|
||||
|
||||
ClearBackground(RAYWHITE);
|
||||
|
||||
// DrawText(FormatText("SCORE: %i", score), 280, 130, 40, MAROON);
|
||||
@ -77,16 +77,16 @@ public partial class core_storage_values
|
||||
DrawText("Press R to generate random numbers", 220, 40, 20, LIGHTGRAY);
|
||||
DrawText("Press ENTER to SAVE values", 250, 310, 20, LIGHTGRAY);
|
||||
DrawText("Press SPACE to LOAD values", 252, 350, 20, LIGHTGRAY);
|
||||
|
||||
|
||||
EndDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
|
||||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
//--------------------------------------------------------------------------------------
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -16,23 +16,23 @@ public partial class core_vr_simulator
|
||||
* Copyright (c) 2017 Ramon Santamaria (@raysan5)
|
||||
*
|
||||
********************************************************************************************/
|
||||
|
||||
|
||||
|
||||
|
||||
public static int Main()
|
||||
{
|
||||
// Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
int screenWidth = 1080;
|
||||
int screenHeight = 600;
|
||||
|
||||
|
||||
// NOTE: screenWidth/screenHeight should match VR device aspect ratio
|
||||
|
||||
|
||||
InitWindow(screenWidth, screenHeight, "raylib [core] example - vr simulator");
|
||||
|
||||
|
||||
// Init VR simulator (Oculus Rift CV1 parameters)
|
||||
// fails?
|
||||
InitVrSimulator(GetVrDeviceInfo((int)HMD_OCULUS_RIFT_CV1));
|
||||
|
||||
|
||||
// Define the camera to look into our 3d world
|
||||
Camera3D camera;
|
||||
camera.position = new Vector3( 5.0f, 2.0f, 5.0f ); // Camera3D position
|
||||
@ -40,56 +40,56 @@ public partial class core_vr_simulator
|
||||
camera.up = new Vector3( 0.0f, 1.0f, 0.0f ); // Camera3D up vector (rotation towards target)
|
||||
camera.fovy = 60.0f; // Camera3D field-of-view Y
|
||||
camera.type = (int)CAMERA_PERSPECTIVE; // Camera3D type
|
||||
|
||||
|
||||
Vector3 cubePosition = new Vector3( 0.0f, 0.0f, 0.0f );
|
||||
|
||||
|
||||
SetCameraMode(camera, (int)CAMERA_FIRST_PERSON); // Set first person camera mode
|
||||
|
||||
|
||||
SetTargetFPS(90); // Set our game to run at 90 frames-per-second
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Main game loop
|
||||
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||
{
|
||||
// Update
|
||||
//----------------------------------------------------------------------------------
|
||||
UpdateCamera(ref camera); // Update camera (simulator mode)
|
||||
|
||||
|
||||
if (IsKeyPressed(KEY_SPACE)) ToggleVrMode(); // Toggle VR mode
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
BeginDrawing();
|
||||
|
||||
|
||||
ClearBackground(RAYWHITE);
|
||||
|
||||
|
||||
BeginVrDrawing();
|
||||
|
||||
|
||||
BeginMode3D(camera);
|
||||
|
||||
|
||||
DrawCube(cubePosition, 2.0f, 2.0f, 2.0f, RED);
|
||||
DrawCubeWires(cubePosition, 2.0f, 2.0f, 2.0f, MAROON);
|
||||
|
||||
|
||||
DrawGrid(40, 1.0f);
|
||||
|
||||
|
||||
EndMode3D();
|
||||
|
||||
|
||||
EndVrDrawing();
|
||||
|
||||
|
||||
DrawFPS(10, 10);
|
||||
|
||||
|
||||
EndDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
|
||||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
CloseVrSimulator(); // Close VR simulator
|
||||
|
||||
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -15,17 +15,17 @@ public partial class core_world_screen
|
||||
* Copyright (c) 2015 Ramon Santamaria (@raysan5)
|
||||
*
|
||||
********************************************************************************************/
|
||||
|
||||
|
||||
|
||||
|
||||
public static int Main()
|
||||
{
|
||||
// Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
int screenWidth = 800;
|
||||
int screenHeight = 450;
|
||||
|
||||
|
||||
InitWindow(screenWidth, screenHeight, "raylib [core] example - 3d camera free");
|
||||
|
||||
|
||||
// Define the camera to look into our 3d world
|
||||
Camera3D camera = new Camera3D();
|
||||
camera.position = new Vector3( 10.0f, 10.0f, 10.0f );
|
||||
@ -33,54 +33,54 @@ public partial class core_world_screen
|
||||
camera.up = new Vector3( 0.0f, 1.0f, 0.0f );
|
||||
camera.fovy = 45.0f;
|
||||
camera.type = (int)CAMERA_PERSPECTIVE;
|
||||
|
||||
|
||||
Vector3 cubePosition = new Vector3( 0.0f, 0.0f, 0.0f );
|
||||
|
||||
|
||||
Vector2 cubeScreenPosition;
|
||||
|
||||
|
||||
SetCameraMode(camera, (int)CAMERA_FREE); // Set a free camera mode
|
||||
|
||||
|
||||
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
|
||||
//----------------------------------------------------------------------------------
|
||||
UpdateCamera(ref camera); // Update camera
|
||||
|
||||
|
||||
// Calculate cube screen space position (with a little offset to be in top)
|
||||
cubeScreenPosition = GetWorldToScreen(new Vector3(cubePosition.x, cubePosition.y + 2.5f, cubePosition.z), camera);
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
BeginDrawing();
|
||||
|
||||
|
||||
ClearBackground(RAYWHITE);
|
||||
|
||||
|
||||
BeginMode3D(camera);
|
||||
|
||||
|
||||
DrawCube(cubePosition, 2.0f, 2.0f, 2.0f, RED);
|
||||
DrawCubeWires(cubePosition, 2.0f, 2.0f, 2.0f, MAROON);
|
||||
|
||||
|
||||
DrawGrid(10, 1.0f);
|
||||
|
||||
|
||||
EndMode3D();
|
||||
|
||||
|
||||
DrawText("Enemy: 100 / 100", (int)cubeScreenPosition.x - MeasureText("Enemy: 100 / 100", 20) / 2, (int)cubeScreenPosition.y, 20, BLACK);
|
||||
DrawText("Text is always on top of the cube", (screenWidth - MeasureText("Text is always on top of the cube", 20)) / 2, 25, 20, GRAY);
|
||||
|
||||
|
||||
EndDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
|
||||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -15,17 +15,17 @@ public partial class models_billboard
|
||||
* Copyright (c) 2015 Ramon Santamaria (@raysan5)
|
||||
*
|
||||
********************************************************************************************/
|
||||
|
||||
|
||||
|
||||
|
||||
public static int Main()
|
||||
{
|
||||
// Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
int screenWidth = 800;
|
||||
int screenHeight = 450;
|
||||
|
||||
|
||||
InitWindow(screenWidth, screenHeight, "raylib [models] example - drawing billboards");
|
||||
|
||||
|
||||
// Define the camera to look into our 3d world
|
||||
Camera3D camera = new Camera3D();
|
||||
camera.position = new Vector3( 5.0f, 4.0f, 5.0f );
|
||||
@ -33,15 +33,15 @@ public partial class models_billboard
|
||||
camera.up = new Vector3( 0.0f, 1.0f, 0.0f );
|
||||
camera.fovy = 45.0f;
|
||||
camera.type = CAMERA_PERSPECTIVE;
|
||||
|
||||
|
||||
Texture2D bill = LoadTexture("resources/billboard.png"); // Our texture billboard
|
||||
Vector3 billPosition = new Vector3( 0.0f, 2.0f, 0.0f ); // Position where draw billboard
|
||||
|
||||
|
||||
SetCameraMode(camera, (int)CAMERA_ORBITAL); // Set an orbital camera mode
|
||||
|
||||
|
||||
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Main game loop
|
||||
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||
{
|
||||
@ -49,34 +49,34 @@ public partial class models_billboard
|
||||
//----------------------------------------------------------------------------------
|
||||
UpdateCamera(ref camera); // Update camera
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
BeginDrawing();
|
||||
|
||||
|
||||
ClearBackground(RAYWHITE);
|
||||
|
||||
|
||||
BeginMode3D(camera);
|
||||
|
||||
|
||||
DrawBillboard(camera, bill, billPosition, 2.0f, WHITE);
|
||||
|
||||
|
||||
DrawGrid(10, 1.0f); // Draw a grid
|
||||
|
||||
|
||||
EndMode3D();
|
||||
|
||||
|
||||
DrawFPS(10, 10);
|
||||
|
||||
|
||||
EndDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
|
||||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
UnloadTexture(bill); // Unload texture
|
||||
|
||||
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -13,114 +13,114 @@ public partial class models_box_collisions
|
||||
* Copyright (c) 2015 Ramon Santamaria (@raysan5)
|
||||
*
|
||||
********************************************************************************************/
|
||||
|
||||
|
||||
|
||||
|
||||
public static int Main()
|
||||
{
|
||||
// Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
int screenWidth = 800;
|
||||
int screenHeight = 450;
|
||||
|
||||
|
||||
InitWindow(screenWidth, screenHeight, "raylib [models] example - box collisions");
|
||||
|
||||
|
||||
// Define the camera to look into our 3d world
|
||||
Camera3D camera = new Camera3D(new Vector3( 0.0f, 10.0f, 10.0f ), new Vector3( 0.0f, 0.0f, 0.0f ), new Vector3( 0.0f, 1.0f, 0.0f ), 45.0f, 0 );
|
||||
|
||||
|
||||
Vector3 playerPosition = new Vector3( 0.0f, 1.0f, 2.0f );
|
||||
Vector3 playerSize = new Vector3( 1.0f, 2.0f, 1.0f );
|
||||
Color playerColor = GREEN;
|
||||
|
||||
|
||||
Vector3 enemyBoxPos = new Vector3( -4.0f, 1.0f, 0.0f );
|
||||
Vector3 enemyBoxSize = new Vector3( 2.0f, 2.0f, 2.0f );
|
||||
|
||||
|
||||
Vector3 enemySpherePos = new Vector3( 4.0f, 0.0f, 0.0f );
|
||||
float enemySphereSize = 1.5f;
|
||||
|
||||
|
||||
bool collision = false;
|
||||
|
||||
|
||||
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
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Move player
|
||||
if (IsKeyDown(KEY_RIGHT)) playerPosition.x += 0.2f;
|
||||
else if (IsKeyDown(KEY_LEFT)) playerPosition.x -= 0.2f;
|
||||
else if (IsKeyDown(KEY_DOWN)) playerPosition.z += 0.2f;
|
||||
else if (IsKeyDown(KEY_UP)) playerPosition.z -= 0.2f;
|
||||
|
||||
|
||||
collision = false;
|
||||
|
||||
|
||||
// Check collisions player vs enemy-box
|
||||
if (CheckCollisionBoxes(
|
||||
new BoundingBox(new Vector3( playerPosition.x - playerSize.x/2,
|
||||
playerPosition.y - playerSize.y/2,
|
||||
playerPosition.z - playerSize.z/2 ),
|
||||
new BoundingBox(new Vector3( playerPosition.x - playerSize.x/2,
|
||||
playerPosition.y - playerSize.y/2,
|
||||
playerPosition.z - playerSize.z/2 ),
|
||||
new Vector3( playerPosition.x + playerSize.x/2,
|
||||
playerPosition.y + playerSize.y/2,
|
||||
playerPosition.y + playerSize.y/2,
|
||||
playerPosition.z + playerSize.z/2 )),
|
||||
new BoundingBox(new Vector3( enemyBoxPos.x - enemyBoxSize.x/2,
|
||||
enemyBoxPos.y - enemyBoxSize.y/2,
|
||||
enemyBoxPos.z - enemyBoxSize.z/2 ),
|
||||
new BoundingBox(new Vector3( enemyBoxPos.x - enemyBoxSize.x/2,
|
||||
enemyBoxPos.y - enemyBoxSize.y/2,
|
||||
enemyBoxPos.z - enemyBoxSize.z/2 ),
|
||||
new Vector3( enemyBoxPos.x + enemyBoxSize.x/2,
|
||||
enemyBoxPos.y + enemyBoxSize.y/2,
|
||||
enemyBoxPos.y + enemyBoxSize.y/2,
|
||||
enemyBoxPos.z + enemyBoxSize.z/2 )))) collision = true;
|
||||
|
||||
|
||||
// Check collisions player vs enemy-sphere
|
||||
if (CheckCollisionBoxSphere(
|
||||
new BoundingBox(new Vector3( playerPosition.x - playerSize.x/2,
|
||||
playerPosition.y - playerSize.y/2,
|
||||
playerPosition.z - playerSize.z/2 ),
|
||||
new BoundingBox(new Vector3( playerPosition.x - playerSize.x/2,
|
||||
playerPosition.y - playerSize.y/2,
|
||||
playerPosition.z - playerSize.z/2 ),
|
||||
new Vector3( playerPosition.x + playerSize.x/2,
|
||||
playerPosition.y + playerSize.y/2,
|
||||
playerPosition.z + playerSize.z/2 )),
|
||||
playerPosition.y + playerSize.y/2,
|
||||
playerPosition.z + playerSize.z/2 )),
|
||||
enemySpherePos, enemySphereSize)) collision = true;
|
||||
|
||||
|
||||
if (collision) playerColor = RED;
|
||||
else playerColor = GREEN;
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
BeginDrawing();
|
||||
|
||||
|
||||
ClearBackground(RAYWHITE);
|
||||
|
||||
|
||||
BeginMode3D(camera);
|
||||
|
||||
|
||||
// Draw enemy-box
|
||||
DrawCube(enemyBoxPos, enemyBoxSize.x, enemyBoxSize.y, enemyBoxSize.z, GRAY);
|
||||
DrawCubeWires(enemyBoxPos, enemyBoxSize.x, enemyBoxSize.y, enemyBoxSize.z, DARKGRAY);
|
||||
|
||||
|
||||
// Draw enemy-sphere
|
||||
DrawSphere(enemySpherePos, enemySphereSize, GRAY);
|
||||
DrawSphereWires(enemySpherePos, enemySphereSize, 16, 16, DARKGRAY);
|
||||
|
||||
|
||||
// Draw player
|
||||
DrawCubeV(playerPosition, playerSize, playerColor);
|
||||
|
||||
|
||||
DrawGrid(10, 1.0f); // Draw a grid
|
||||
|
||||
|
||||
EndMode3D();
|
||||
|
||||
|
||||
DrawText("Move player with cursors to collide", 220, 40, 20, GRAY);
|
||||
|
||||
|
||||
DrawFPS(10, 10);
|
||||
|
||||
|
||||
EndDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
|
||||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -15,39 +15,39 @@ public partial class models_cubicmap
|
||||
* Copyright (c) 2015 Ramon Santamaria (@raysan5)
|
||||
*
|
||||
********************************************************************************************/
|
||||
|
||||
|
||||
|
||||
|
||||
public static int Main()
|
||||
{
|
||||
// Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
int screenWidth = 800;
|
||||
int screenHeight = 450;
|
||||
|
||||
|
||||
InitWindow(screenWidth, screenHeight, "raylib [models] example - cubesmap loading and drawing");
|
||||
|
||||
|
||||
// Define the camera to look into our 3d world
|
||||
Camera3D camera = new Camera3D(new Vector3( 16.0f, 14.0f, 16.0f ), new Vector3( 0.0f, 0.0f, 0.0f ), new Vector3( 0.0f, 1.0f, 0.0f ), 45.0f, 0 );
|
||||
|
||||
|
||||
Image image = LoadImage("resources/cubicmap.png"); // Load cubicmap image (RAM)
|
||||
Texture2D cubicmap = LoadTextureFromImage(image); // Convert image to texture to display (VRAM)
|
||||
|
||||
|
||||
Mesh mesh = GenMeshCubicmap(image, new Vector3( 1.0f, 1.0f, 1.0f ));
|
||||
Model model = LoadModelFromMesh(mesh);
|
||||
|
||||
|
||||
// NOTE: By default each cube is mapped to one part of texture atlas
|
||||
Texture2D texture = LoadTexture("resources/cubicmap_atlas.png"); // Load map texture
|
||||
model.material.maps[(int)MAP_ALBEDO].texture = texture; // Set map diffuse texture
|
||||
|
||||
|
||||
Vector3 mapPosition = new Vector3( -16.0f, 0.0f, -8.0f ); // Set model position
|
||||
|
||||
|
||||
UnloadImage(image); // Unload cubesmap image from RAM, already uploaded to VRAM
|
||||
|
||||
|
||||
SetCameraMode(camera, (int)CAMERA_ORBITAL); // Set an orbital camera mode
|
||||
|
||||
|
||||
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Main game loop
|
||||
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||
{
|
||||
@ -55,40 +55,40 @@ public partial class models_cubicmap
|
||||
//----------------------------------------------------------------------------------
|
||||
UpdateCamera(ref camera); // Update camera
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
BeginDrawing();
|
||||
|
||||
|
||||
ClearBackground(RAYWHITE);
|
||||
|
||||
|
||||
BeginMode3D(camera);
|
||||
|
||||
|
||||
DrawModel(model, mapPosition, 1.0f, WHITE);
|
||||
|
||||
|
||||
EndMode3D();
|
||||
|
||||
|
||||
DrawTextureEx(cubicmap, new Vector2( screenWidth - cubicmap.width*4 - 20, 20 ), 0.0f, 4.0f, WHITE);
|
||||
DrawRectangleLines(screenWidth - cubicmap.width*4 - 20, 20, cubicmap.width*4, cubicmap.height*4, GREEN);
|
||||
|
||||
|
||||
DrawText("cubicmap image used to", 658, 90, 10, GRAY);
|
||||
DrawText("generate map 3d model", 658, 104, 10, GRAY);
|
||||
|
||||
|
||||
DrawFPS(10, 10);
|
||||
|
||||
|
||||
EndDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
|
||||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
UnloadTexture(cubicmap); // Unload cubicmap texture
|
||||
UnloadTexture(texture); // Unload map texture
|
||||
UnloadModel(model); // Unload map model
|
||||
|
||||
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -14,17 +14,17 @@ public partial class models_geometric_shapes
|
||||
* Copyright (c) 2014 Ramon Santamaria (@raysan5)
|
||||
*
|
||||
********************************************************************************************/
|
||||
|
||||
|
||||
|
||||
|
||||
public static int Main()
|
||||
{
|
||||
// Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
int screenWidth = 800;
|
||||
int screenHeight = 450;
|
||||
|
||||
|
||||
InitWindow(screenWidth, screenHeight, "raylib [models] example - geometric shapes");
|
||||
|
||||
|
||||
// Define the camera to look into our 3d world
|
||||
Camera3D camera = new Camera3D();
|
||||
camera.position = new Vector3( 0.0f, 10.0f, 10.0f );
|
||||
@ -32,10 +32,10 @@ public partial class models_geometric_shapes
|
||||
camera.up = new Vector3( 0.0f, 1.0f, 0.0f );
|
||||
camera.fovy = 45.0f;
|
||||
camera.type = CAMERA_PERSPECTIVE;
|
||||
|
||||
|
||||
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Main game loop
|
||||
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||
{
|
||||
@ -43,44 +43,44 @@ public partial class models_geometric_shapes
|
||||
//----------------------------------------------------------------------------------
|
||||
// TODO: Update your variables here
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
BeginDrawing();
|
||||
|
||||
|
||||
ClearBackground(RAYWHITE);
|
||||
|
||||
|
||||
BeginMode3D(camera);
|
||||
|
||||
|
||||
DrawCube(new Vector3(-4.0f, 0.0f, 2.0f), 2.0f, 5.0f, 2.0f, RED);
|
||||
DrawCubeWires(new Vector3(-4.0f, 0.0f, 2.0f), 2.0f, 5.0f, 2.0f, GOLD);
|
||||
DrawCubeWires(new Vector3(-4.0f, 0.0f, -2.0f), 3.0f, 6.0f, 2.0f, MAROON);
|
||||
|
||||
|
||||
DrawSphere(new Vector3(-1.0f, 0.0f, -2.0f), 1.0f, GREEN);
|
||||
DrawSphereWires(new Vector3(1.0f, 0.0f, 2.0f), 2.0f, 16, 16, LIME);
|
||||
|
||||
|
||||
DrawCylinder(new Vector3(4.0f, 0.0f, -2.0f), 1.0f, 2.0f, 3.0f, 4, SKYBLUE);
|
||||
DrawCylinderWires(new Vector3(4.0f, 0.0f, -2.0f), 1.0f, 2.0f, 3.0f, 4, DARKBLUE);
|
||||
DrawCylinderWires(new Vector3(4.5f, -1.0f, 2.0f), 1.0f, 1.0f, 2.0f, 6, BROWN);
|
||||
|
||||
|
||||
DrawCylinder(new Vector3(1.0f, 0.0f, -4.0f), 0.0f, 1.5f, 3.0f, 8, GOLD);
|
||||
DrawCylinderWires(new Vector3(1.0f, 0.0f, -4.0f), 0.0f, 1.5f, 3.0f, 8, PINK);
|
||||
|
||||
|
||||
DrawGrid(10, 1.0f); // Draw a grid
|
||||
|
||||
|
||||
EndMode3D();
|
||||
|
||||
|
||||
DrawFPS(10, 10);
|
||||
|
||||
|
||||
EndDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
|
||||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -15,36 +15,36 @@ public partial class models_heightmap
|
||||
* Copyright (c) 2015 Ramon Santamaria (@raysan5)
|
||||
*
|
||||
********************************************************************************************/
|
||||
|
||||
|
||||
|
||||
|
||||
public static int Main()
|
||||
{
|
||||
// Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
int screenWidth = 800;
|
||||
int screenHeight = 450;
|
||||
|
||||
|
||||
InitWindow(screenWidth, screenHeight, "raylib [models] example - heightmap loading and drawing");
|
||||
|
||||
|
||||
// Define our custom camera to look into our 3d world
|
||||
Camera3D camera = new Camera3D(new Vector3( 18.0f, 16.0f, 18.0f ), new Vector3( 0.0f, 0.0f, 0.0f ), new Vector3( 0.0f, 1.0f, 0.0f ), 45.0f, 0 );
|
||||
|
||||
|
||||
Image image = LoadImage("resources/heightmap.png"); // Load heightmap image (RAM)
|
||||
Texture2D texture = LoadTextureFromImage(image); // Convert image to texture (VRAM)
|
||||
|
||||
|
||||
Mesh mesh = GenMeshHeightmap(image, new Vector3( 16, 8, 16 )); // Generate heightmap mesh (RAM and VRAM)
|
||||
Model model = LoadModelFromMesh(mesh); // Load model from generated mesh
|
||||
|
||||
|
||||
model.material.maps[(int)MAP_ALBEDO].texture = texture; // Set map diffuse texture
|
||||
Vector3 mapPosition = new Vector3( -8.0f, 0.0f, -8.0f ); // Define model position
|
||||
|
||||
|
||||
UnloadImage(image); // Unload heightmap image from RAM, already uploaded to VRAM
|
||||
|
||||
|
||||
SetCameraMode(camera, (int)CAMERA_ORBITAL); // Set an orbital camera mode
|
||||
|
||||
|
||||
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Main game loop
|
||||
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||
{
|
||||
@ -52,38 +52,38 @@ public partial class models_heightmap
|
||||
//----------------------------------------------------------------------------------
|
||||
UpdateCamera(ref camera); // Update camera
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
BeginDrawing();
|
||||
|
||||
|
||||
ClearBackground(RAYWHITE);
|
||||
|
||||
|
||||
BeginMode3D(camera);
|
||||
|
||||
|
||||
DrawModel(model, mapPosition, 1.0f, RED);
|
||||
|
||||
|
||||
DrawGrid(20, 1.0f);
|
||||
|
||||
|
||||
EndMode3D();
|
||||
|
||||
|
||||
DrawTexture(texture, screenWidth - texture.width - 20, 20, WHITE);
|
||||
DrawRectangleLines(screenWidth - texture.width - 20, 20, texture.width, texture.height, GREEN);
|
||||
|
||||
|
||||
DrawFPS(10, 10);
|
||||
|
||||
|
||||
EndDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
|
||||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
UnloadTexture(texture); // Unload texture
|
||||
UnloadModel(model); // Unload model
|
||||
|
||||
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -15,26 +15,26 @@ public partial class models_mesh_generation
|
||||
* Copyright (c) 2017 Ramon Santamaria (Ray San)
|
||||
*
|
||||
********************************************************************************************/
|
||||
|
||||
|
||||
|
||||
|
||||
public const int NUM_MODELS = 7;
|
||||
|
||||
|
||||
public static int Main()
|
||||
{
|
||||
// Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
int screenWidth = 800;
|
||||
int screenHeight = 450;
|
||||
|
||||
|
||||
InitWindow(screenWidth, screenHeight, "raylib [models] example - mesh generation");
|
||||
|
||||
|
||||
// We generate a isChecked image for texturing
|
||||
Image isChecked = GenImageChecked(2, 2, 1, 1, RED, GREEN);
|
||||
Texture2D texture = LoadTextureFromImage(isChecked);
|
||||
UnloadImage(isChecked);
|
||||
|
||||
|
||||
Model[] models = new Model[NUM_MODELS];
|
||||
|
||||
|
||||
models[0] = LoadModelFromMesh(GenMeshPlane(2, 2, 5, 5));
|
||||
models[1] = LoadModelFromMesh(GenMeshCube(2.0f, 1.0f, 2.0f));
|
||||
models[2] = LoadModelFromMesh(GenMeshSphere(2, 32, 32));
|
||||
@ -42,54 +42,54 @@ public partial class models_mesh_generation
|
||||
models[4] = LoadModelFromMesh(GenMeshCylinder(1, 2, 16));
|
||||
models[5] = LoadModelFromMesh(GenMeshTorus(0.25f, 4.0f, 16, 32));
|
||||
models[6] = LoadModelFromMesh(GenMeshKnot(1.0f, 2.0f, 16, 128));
|
||||
|
||||
|
||||
// Set isChecked texture as default diffuse component for all models material
|
||||
for (int i = 0; i < NUM_MODELS; i++) models[i].material.maps[(int)MAP_ALBEDO].texture = texture;
|
||||
|
||||
|
||||
// Define the camera to look into our 3d world
|
||||
Camera3D camera = new Camera3D(new Vector3( 5.0f, 5.0f, 5.0f ), new Vector3( 0.0f, 0.0f, 0.0f ), new Vector3( 0.0f, 1.0f, 0.0f ), 45.0f, 0 );
|
||||
|
||||
|
||||
// Model drawing position
|
||||
Vector3 position = new Vector3( 0.0f, 0.0f, 0.0f );
|
||||
|
||||
|
||||
int currentModel = 0;
|
||||
|
||||
|
||||
SetCameraMode(camera, (int)CAMERA_ORBITAL); // Set a orbital camera mode
|
||||
|
||||
|
||||
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
|
||||
//----------------------------------------------------------------------------------
|
||||
UpdateCamera(ref camera); // Update internal camera and our camera
|
||||
|
||||
|
||||
if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON))
|
||||
{
|
||||
currentModel = (currentModel + 1)%NUM_MODELS; // Cycle between the textures
|
||||
}
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
BeginDrawing();
|
||||
|
||||
|
||||
ClearBackground(RAYWHITE);
|
||||
|
||||
|
||||
BeginMode3D(camera);
|
||||
|
||||
|
||||
DrawModel(models[currentModel], position, 1.0f, WHITE);
|
||||
|
||||
|
||||
DrawGrid(10, 1.0f);
|
||||
|
||||
|
||||
EndMode3D();
|
||||
|
||||
|
||||
DrawRectangle(30, 400, 310, 30, Fade(SKYBLUE, 0.5f));
|
||||
DrawRectangleLines(30, 400, 310, 30, Fade(DARKBLUE, 0.5f));
|
||||
DrawText("MOUSE LEFT BUTTON to CYCLE PROCEDURAL MODELS", 40, 410, 10, BLUE);
|
||||
|
||||
|
||||
switch(currentModel)
|
||||
{
|
||||
case 0: DrawText("PLANE", 680, 10, 20, DARKBLUE); break;
|
||||
@ -101,20 +101,20 @@ public partial class models_mesh_generation
|
||||
case 6: DrawText("KNOT", 680, 10, 20, DARKBLUE); break;
|
||||
default: break;
|
||||
}
|
||||
|
||||
|
||||
EndDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
|
||||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Unload models data (GPU VRAM)
|
||||
for (int i = 0; i < NUM_MODELS; i++) UnloadModel(models[i]);
|
||||
|
||||
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -17,19 +17,19 @@ public partial class models_mesh_picking
|
||||
* Example contributed by Joel Davis (@joeld42)
|
||||
*
|
||||
********************************************************************************************/
|
||||
|
||||
|
||||
|
||||
|
||||
public const float FLT_MAX = 3.40282347E+38F;
|
||||
|
||||
|
||||
public static int Main()
|
||||
{
|
||||
// Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
int screenWidth = 800;
|
||||
int screenHeight = 450;
|
||||
|
||||
|
||||
InitWindow(screenWidth, screenHeight, "raylib [models] example - mesh picking");
|
||||
|
||||
|
||||
// Define the camera to look into our 3d world
|
||||
Camera3D camera;
|
||||
camera.position = new Vector3( 20.0f, 20.0f, 20.0f ); // Camera3D position
|
||||
@ -37,27 +37,27 @@ public partial class models_mesh_picking
|
||||
camera.up = new Vector3( 0.0f, 1.6f, 0.0f ); // Camera3D up vector (rotation towards target)
|
||||
camera.fovy = 45.0f; // Camera3D field-of-view Y
|
||||
camera.type = CAMERA_PERSPECTIVE; // Camera3D mode type
|
||||
|
||||
|
||||
Ray ray; // Picking ray
|
||||
|
||||
|
||||
Model tower = LoadModel("resources/models/turret.obj"); // Load OBJ model
|
||||
Texture2D texture = LoadTexture("resources/models/turret_diffuse.png"); // Load model texture
|
||||
tower.material.maps[(int)MAP_ALBEDO].texture = texture; // Set model diffuse texture
|
||||
|
||||
|
||||
Vector3 towerPos = new Vector3( 0.0f, 0.0f, 0.0f ); // Set model position
|
||||
BoundingBox towerBBox = MeshBoundingBox(tower.mesh); // Get mesh bounding box
|
||||
bool hitMeshBBox = false;
|
||||
bool hitTriangle = false;
|
||||
|
||||
|
||||
// Test triangle
|
||||
Vector3 ta = new Vector3( -25.0f, 0.5f, 0.0f );
|
||||
Vector3 ta = new Vector3( -25.0f, 0.5f, 0.0f );
|
||||
Vector3 tb = new Vector3( -4.0f, 2.5f, 1.0f );
|
||||
Vector3 tc = new Vector3( -8.0f, 6.5f, 0.0f );
|
||||
|
||||
Vector3 bary = new Vector3( 0.0f, 0.0f, 0.0f );
|
||||
|
||||
|
||||
Vector3 bary = new Vector3( 0.0f, 0.0f, 0.0f );
|
||||
|
||||
SetCameraMode(camera, (int)CAMERA_FREE); // Set a free camera mode
|
||||
|
||||
|
||||
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||
//--------------------------------------------------------------------------------------
|
||||
// Main game loop
|
||||
@ -66,143 +66,143 @@ public partial class models_mesh_picking
|
||||
// Update
|
||||
//----------------------------------------------------------------------------------
|
||||
UpdateCamera(ref camera); // Update camera
|
||||
|
||||
|
||||
// Display information about closest hit
|
||||
RayHitInfo nearestHit = new RayHitInfo();
|
||||
string hitObjectName = "None";
|
||||
nearestHit.distance = FLT_MAX;
|
||||
nearestHit.hit = false;
|
||||
Color cursorColor = WHITE;
|
||||
|
||||
|
||||
// Get ray and test against ground, triangle, and mesh
|
||||
ray = GetMouseRay(GetMousePosition(), camera);
|
||||
|
||||
|
||||
// Check ray collision aginst ground plane
|
||||
RayHitInfo groundHitInfo = GetCollisionRayGround(ray, 0.0f);
|
||||
|
||||
|
||||
if ((groundHitInfo.hit) && (groundHitInfo.distance < nearestHit.distance))
|
||||
{
|
||||
nearestHit = groundHitInfo;
|
||||
cursorColor = GREEN;
|
||||
hitObjectName = "Ground";
|
||||
}
|
||||
|
||||
|
||||
// Check ray collision against test triangle
|
||||
RayHitInfo triHitInfo = GetCollisionRayTriangle(ray, ta, tb, tc);
|
||||
|
||||
if ((triHitInfo.hit) && (triHitInfo.distance < nearestHit.distance))
|
||||
|
||||
if ((triHitInfo.hit) && (triHitInfo.distance < nearestHit.distance))
|
||||
{
|
||||
nearestHit = triHitInfo;
|
||||
cursorColor = PURPLE;
|
||||
hitObjectName = "Triangle";
|
||||
|
||||
|
||||
bary = Vector3Barycenter(nearestHit.position, ta, tb, tc);
|
||||
hitTriangle = true;
|
||||
}
|
||||
}
|
||||
else hitTriangle = false;
|
||||
|
||||
|
||||
RayHitInfo meshHitInfo;
|
||||
|
||||
|
||||
// Check ray collision against bounding box first, before trying the full ray-mesh test
|
||||
if (CheckCollisionRayBox(ray, towerBBox))
|
||||
if (CheckCollisionRayBox(ray, towerBBox))
|
||||
{
|
||||
hitMeshBBox = true;
|
||||
|
||||
|
||||
// Check ray collision against model
|
||||
// NOTE: It considers model.transform matrix!
|
||||
meshHitInfo = GetCollisionRayModel(ray, ref tower);
|
||||
|
||||
if ((meshHitInfo.hit) && (meshHitInfo.distance < nearestHit.distance))
|
||||
meshHitInfo = GetCollisionRayModel(ray, ref tower);
|
||||
|
||||
if ((meshHitInfo.hit) && (meshHitInfo.distance < nearestHit.distance))
|
||||
{
|
||||
nearestHit = meshHitInfo;
|
||||
cursorColor = ORANGE;
|
||||
hitObjectName = "Mesh";
|
||||
}
|
||||
|
||||
} hitMeshBBox = false;
|
||||
|
||||
} hitMeshBBox = false;
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
BeginDrawing();
|
||||
|
||||
|
||||
ClearBackground(RAYWHITE);
|
||||
|
||||
|
||||
BeginMode3D(camera);
|
||||
|
||||
|
||||
// Draw the tower
|
||||
// WARNING: If scale is different than 1.0f,
|
||||
// WARNING: If scale is different than 1.0f,
|
||||
// not considered by GetCollisionRayModel()
|
||||
DrawModel(tower, towerPos, 1.0f, WHITE);
|
||||
|
||||
|
||||
// Draw the test triangle
|
||||
DrawLine3D(ta, tb, PURPLE);
|
||||
DrawLine3D(tb, tc, PURPLE);
|
||||
DrawLine3D(tc, ta, PURPLE);
|
||||
|
||||
|
||||
// Draw the mesh bbox if we hit it
|
||||
if (hitMeshBBox) DrawBoundingBox(towerBBox, LIME);
|
||||
|
||||
|
||||
// If we hit something, draw the cursor at the hit point
|
||||
if (nearestHit.hit)
|
||||
if (nearestHit.hit)
|
||||
{
|
||||
DrawCube(nearestHit.position, 0.3f, 0.3f, 0.3f, cursorColor);
|
||||
DrawCubeWires(nearestHit.position, 0.3f, 0.3f, 0.3f, RED);
|
||||
|
||||
|
||||
Vector3 normalEnd;
|
||||
normalEnd.x = nearestHit.position.x + nearestHit.normal.x;
|
||||
normalEnd.y = nearestHit.position.y + nearestHit.normal.y;
|
||||
normalEnd.z = nearestHit.position.z + nearestHit.normal.z;
|
||||
|
||||
|
||||
DrawLine3D(nearestHit.position, normalEnd, RED);
|
||||
}
|
||||
|
||||
|
||||
DrawRay(ray, MAROON);
|
||||
|
||||
|
||||
DrawGrid(10, 10.0f);
|
||||
|
||||
|
||||
EndMode3D();
|
||||
|
||||
|
||||
// Draw some debug GUI text
|
||||
DrawText(FormatText("Hit Object: %s", hitObjectName), 10, 50, 10, BLACK);
|
||||
|
||||
if (nearestHit.hit)
|
||||
|
||||
if (nearestHit.hit)
|
||||
{
|
||||
int ypos = 70;
|
||||
|
||||
|
||||
DrawText(FormatText("Distance: %3.2f", nearestHit.distance), 10, ypos, 10, BLACK);
|
||||
|
||||
DrawText(FormatText("Hit Pos: %3.2f %3.2f %3.2f",
|
||||
nearestHit.position.x,
|
||||
nearestHit.position.y,
|
||||
|
||||
DrawText(FormatText("Hit Pos: %3.2f %3.2f %3.2f",
|
||||
nearestHit.position.x,
|
||||
nearestHit.position.y,
|
||||
nearestHit.position.z), 10, ypos + 15, 10, BLACK);
|
||||
|
||||
DrawText(FormatText("Hit Norm: %3.2f %3.2f %3.2f",
|
||||
nearestHit.normal.x,
|
||||
nearestHit.normal.y,
|
||||
|
||||
DrawText(FormatText("Hit Norm: %3.2f %3.2f %3.2f",
|
||||
nearestHit.normal.x,
|
||||
nearestHit.normal.y,
|
||||
nearestHit.normal.z), 10, ypos + 30, 10, BLACK);
|
||||
|
||||
|
||||
if (hitTriangle) DrawText(FormatText("Barycenter: %3.2f %3.2f %3.2f", bary.x, bary.y, bary.z), 10, ypos + 45, 10, BLACK);
|
||||
}
|
||||
|
||||
|
||||
DrawText("Use Mouse to Move Camera", 10, 430, 10, GRAY);
|
||||
|
||||
|
||||
DrawText("(c) Turret 3D model by Alberto Cano", screenWidth - 200, screenHeight - 20, 10, GRAY);
|
||||
|
||||
|
||||
DrawFPS(10, 10);
|
||||
|
||||
|
||||
EndDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
|
||||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
UnloadModel(tower); // Unload model
|
||||
UnloadTexture(texture); // Unload texture
|
||||
|
||||
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -15,17 +15,17 @@ public partial class models_obj_loading
|
||||
* Copyright (c) 2014 Ramon Santamaria (@raysan5)
|
||||
*
|
||||
********************************************************************************************/
|
||||
|
||||
|
||||
|
||||
|
||||
public static int Main()
|
||||
{
|
||||
// Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
int screenWidth = 800;
|
||||
int screenHeight = 450;
|
||||
|
||||
|
||||
InitWindow(screenWidth, screenHeight, "raylib [models] example - obj model loading");
|
||||
|
||||
|
||||
// Define the camera to look into our 3d world
|
||||
Camera3D camera = new Camera3D();
|
||||
camera.position = new Vector3( 8.0f, 8.0f, 8.0f ); // Camera3D position
|
||||
@ -33,15 +33,15 @@ public partial class models_obj_loading
|
||||
camera.up = new Vector3( 0.0f, 1.0f, 0.0f ); // Camera3D up vector (rotation towards target)
|
||||
camera.fovy = 45.0f; // Camera3D field-of-view Y
|
||||
camera.type = CAMERA_PERSPECTIVE; // Camera3D mode type
|
||||
|
||||
|
||||
Model model = LoadModel("resources/models/castle.obj"); // Load OBJ model
|
||||
Texture2D texture = LoadTexture("resources/models/castle_diffuse.png"); // Load model texture
|
||||
model.material.maps[(int)MAP_ALBEDO].texture = texture; // Set map diffuse texture
|
||||
Vector3 position = new Vector3( 0.0f, 0.0f, 0.0f ); // Set model position
|
||||
|
||||
|
||||
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Main game loop
|
||||
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||
{
|
||||
@ -49,39 +49,39 @@ public partial class models_obj_loading
|
||||
//----------------------------------------------------------------------------------
|
||||
//...
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
BeginDrawing();
|
||||
|
||||
|
||||
ClearBackground(RAYWHITE);
|
||||
|
||||
|
||||
BeginMode3D(camera);
|
||||
|
||||
|
||||
DrawModel(model, position, 0.2f, WHITE); // Draw 3d model with texture
|
||||
|
||||
|
||||
DrawGrid(10, 1.0f); // Draw a grid
|
||||
|
||||
|
||||
DrawGizmo(position); // Draw gizmo
|
||||
|
||||
|
||||
EndMode3D();
|
||||
|
||||
|
||||
DrawText("(c) Castle 3D model by Alberto Cano", screenWidth - 200, screenHeight - 20, 10, GRAY);
|
||||
|
||||
|
||||
DrawFPS(10, 10);
|
||||
|
||||
|
||||
EndDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
|
||||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
UnloadTexture(texture); // Unload texture
|
||||
UnloadModel(model); // Unload model
|
||||
|
||||
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -7,7 +7,7 @@ public partial class models_orthographic_projection
|
||||
{
|
||||
/*******************************************************************************************
|
||||
*
|
||||
* raylib [models] example - Show the difference between perspective and orthographic projection
|
||||
* raylib [models] example - Show the difference between perspective and orthographic projection
|
||||
*
|
||||
* This program is heavily based on the geometric objects example
|
||||
*
|
||||
@ -17,88 +17,88 @@ public partial class models_orthographic_projection
|
||||
* Copyright (c) 2018 Max Danielsson ref Ramon Santamaria (@raysan5)
|
||||
*
|
||||
********************************************************************************************/
|
||||
|
||||
|
||||
|
||||
|
||||
public const float FOVY_PERSPECTIVE = 45.0f;
|
||||
public const float WIDTH_ORTHOGRAPHIC = 10.0f;
|
||||
|
||||
|
||||
public static int Main()
|
||||
{
|
||||
// Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
int screenWidth = 800;
|
||||
int screenHeight = 450;
|
||||
|
||||
|
||||
InitWindow(screenWidth, screenHeight, "raylib [models] example - geometric shapes");
|
||||
|
||||
|
||||
// Define the camera to look into our 3d world
|
||||
Camera3D camera = new Camera3D(new Vector3( 0.0f, 10.0f, 10.0f ), new Vector3( 0.0f, 0.0f, 0.0f ), new Vector3( 0.0f, 1.0f, 0.0f ), FOVY_PERSPECTIVE, CAMERA_PERSPECTIVE );
|
||||
|
||||
|
||||
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 (IsKeyPressed(KEY_SPACE))
|
||||
if (IsKeyPressed(KEY_SPACE))
|
||||
{
|
||||
if (camera.type == CAMERA_PERSPECTIVE)
|
||||
if (camera.type == CAMERA_PERSPECTIVE)
|
||||
{
|
||||
camera.fovy = WIDTH_ORTHOGRAPHIC;
|
||||
camera.type = CAMERA_ORTHOGRAPHIC;
|
||||
}
|
||||
else
|
||||
}
|
||||
else
|
||||
{
|
||||
camera.fovy = FOVY_PERSPECTIVE;
|
||||
camera.type = CAMERA_PERSPECTIVE;
|
||||
}
|
||||
}
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
BeginDrawing();
|
||||
|
||||
|
||||
ClearBackground(RAYWHITE);
|
||||
|
||||
|
||||
BeginMode3D(camera);
|
||||
|
||||
|
||||
DrawCube(new Vector3(-4.0f, 0.0f, 2.0f), 2.0f, 5.0f, 2.0f, RED);
|
||||
DrawCubeWires(new Vector3(-4.0f, 0.0f, 2.0f), 2.0f, 5.0f, 2.0f, GOLD);
|
||||
DrawCubeWires(new Vector3(-4.0f, 0.0f, -2.0f), 3.0f, 6.0f, 2.0f, MAROON);
|
||||
|
||||
|
||||
DrawSphere(new Vector3(-1.0f, 0.0f, -2.0f), 1.0f, GREEN);
|
||||
DrawSphereWires(new Vector3(1.0f, 0.0f, 2.0f), 2.0f, 16, 16, LIME);
|
||||
|
||||
|
||||
DrawCylinder(new Vector3(4.0f, 0.0f, -2.0f), 1.0f, 2.0f, 3.0f, 4, SKYBLUE);
|
||||
DrawCylinderWires(new Vector3(4.0f, 0.0f, -2.0f), 1.0f, 2.0f, 3.0f, 4, DARKBLUE);
|
||||
DrawCylinderWires(new Vector3(4.5f, -1.0f, 2.0f), 1.0f, 1.0f, 2.0f, 6, BROWN);
|
||||
|
||||
|
||||
DrawCylinder(new Vector3(1.0f, 0.0f, -4.0f), 0.0f, 1.5f, 3.0f, 8, GOLD);
|
||||
DrawCylinderWires(new Vector3(1.0f, 0.0f, -4.0f), 0.0f, 1.5f, 3.0f, 8, PINK);
|
||||
|
||||
|
||||
DrawGrid(10, 1.0f); // Draw a grid
|
||||
|
||||
|
||||
EndMode3D();
|
||||
|
||||
|
||||
DrawText("Press Spacebar to switch camera type", 10, GetScreenHeight() - 30, 20, DARKGRAY);
|
||||
|
||||
|
||||
if (camera.type == CAMERA_ORTHOGRAPHIC) DrawText("ORTHOGRAPHIC", 10, 40, 20, BLACK);
|
||||
else if (camera.type == CAMERA_PERSPECTIVE) DrawText("PERSPECTIVE", 10, 40, 20, BLACK);
|
||||
|
||||
|
||||
DrawFPS(10, 10);
|
||||
|
||||
|
||||
EndDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
|
||||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -15,48 +15,48 @@ public partial class models_skybox
|
||||
* Copyright (c) 2017 Ramon Santamaria (@raysan5)
|
||||
*
|
||||
********************************************************************************************/
|
||||
|
||||
|
||||
|
||||
|
||||
public static int Main()
|
||||
{
|
||||
// Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
int screenWidth = 800;
|
||||
int screenHeight = 450;
|
||||
|
||||
|
||||
InitWindow(screenWidth, screenHeight, "raylib [models] example - skybox loading and drawing");
|
||||
|
||||
|
||||
// Define the camera to look into our 3d world
|
||||
Camera3D camera = new Camera3D(new Vector3( 1.0f, 1.0f, 1.0f ), new Vector3( 0.0f, 0.0f, 0.0f ), new Vector3( 0.0f, 1.0f, 0.0f ), 45.0f, 0 );
|
||||
|
||||
// Load skybox model
|
||||
|
||||
// Load skybox model
|
||||
Mesh cube = GenMeshCube(1.0f, 1.0f, 1.0f);
|
||||
Model skybox = LoadModelFromMesh(cube);
|
||||
|
||||
|
||||
// Load skybox shader and set required locations
|
||||
// NOTE: Some locations are automatically set at shader loading
|
||||
skybox.material.shader = LoadShader("resources/shaders/skybox.vs", "resources/shaders/skybox.fs");
|
||||
SetShaderValuei(skybox.material.shader, GetShaderLocation(skybox.material.shader, "environmentMap"), new int[]{ (int)MAP_CUBEMAP }, 1);
|
||||
|
||||
|
||||
// Load cubemap shader and setup required shader locations
|
||||
Shader shdrCubemap = LoadShader("resources/shaders/cubemap.vs", "resources/shaders/cubemap.fs");
|
||||
SetShaderValuei(shdrCubemap, GetShaderLocation(shdrCubemap, "equirectangularMap"), new int[]{ 0 }, 1);
|
||||
|
||||
|
||||
// Load HDR panorama (sphere) texture
|
||||
Texture2D texHDR = LoadTexture("resources/dresden_square.hdr");
|
||||
|
||||
|
||||
// Generate cubemap (texture with 6 quads-cube-mapping) from panorama HDR texture
|
||||
// NOTE: New texture is generated rendering to texture, shader computes the sphre->cube coordinates mapping
|
||||
skybox.material.maps[(int)MAP_CUBEMAP].texture = GenTextureCubemap(shdrCubemap, texHDR, 512);
|
||||
|
||||
|
||||
UnloadTexture(texHDR); // Texture not required anymore, cubemap already generated
|
||||
UnloadShader(shdrCubemap); // Unload cubemap generation shader, not required anymore
|
||||
|
||||
|
||||
SetCameraMode(camera, (int)CAMERA_FIRST_PERSON); // Set a first person camera mode
|
||||
|
||||
|
||||
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Main game loop
|
||||
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||
{
|
||||
@ -64,34 +64,34 @@ public partial class models_skybox
|
||||
//----------------------------------------------------------------------------------
|
||||
UpdateCamera(ref camera); // Update camera
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
BeginDrawing();
|
||||
|
||||
|
||||
ClearBackground(RAYWHITE);
|
||||
|
||||
|
||||
BeginMode3D(camera);
|
||||
|
||||
|
||||
DrawModel(skybox, new Vector3(0, 0, 0), 1.0f, WHITE);
|
||||
|
||||
|
||||
DrawGrid(10, 1.0f);
|
||||
|
||||
|
||||
EndMode3D();
|
||||
|
||||
|
||||
DrawFPS(10, 10);
|
||||
|
||||
|
||||
EndDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
|
||||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
UnloadModel(skybox); // Unload skybox model (and textures)
|
||||
|
||||
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -19,11 +19,11 @@ public partial class models_yaw_pitch_roll
|
||||
* Copyright (c) 2017 Ramon Santamaria (@raysan5)
|
||||
*
|
||||
********************************************************************************************/
|
||||
|
||||
|
||||
|
||||
|
||||
// Draw angle gauge controls
|
||||
//void DrawAngleGauge(Texture2D angleGauge, int x, int y, float angle, char title[], Color color);
|
||||
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Main entry point
|
||||
//----------------------------------------------------------------------------------
|
||||
@ -33,42 +33,42 @@ public partial class models_yaw_pitch_roll
|
||||
//--------------------------------------------------------------------------------------
|
||||
const int screenWidth = 800;
|
||||
const int screenHeight = 450;
|
||||
|
||||
|
||||
InitWindow(screenWidth, screenHeight, "raylib [models] example - plane rotations (yaw, pitch, roll)");
|
||||
|
||||
|
||||
Texture2D texAngleGauge = LoadTexture("resources/angle_gauge.png");
|
||||
Texture2D texBackground = LoadTexture("resources/background.png");
|
||||
Texture2D texPitch = LoadTexture("resources/pitch.png");
|
||||
Texture2D texPlane = LoadTexture("resources/plane.png");
|
||||
|
||||
|
||||
RenderTexture2D framebuffer = LoadRenderTexture(192, 192);
|
||||
|
||||
|
||||
// Model loading
|
||||
Model model = LoadModel("resources/plane.obj"); // Load OBJ model
|
||||
model.material.maps[(int)MAP_ALBEDO].texture = LoadTexture("resources/plane_diffuse.png"); // Set map diffuse texture
|
||||
|
||||
|
||||
GenTextureMipmaps(ref model.material.maps[(int)MAP_ALBEDO].texture);
|
||||
|
||||
|
||||
Camera3D camera = new Camera3D();
|
||||
camera.position = new Vector3( 0.0f, 60.0f, -120.0f );// Camera3D position perspective
|
||||
camera.target = new Vector3( 0.0f, 12.0f, 0.0f ); // Camera3D looking at point
|
||||
camera.up = new Vector3( 0.0f, 1.0f, 0.0f ); // Camera3D up vector (rotation towards target)
|
||||
camera.fovy = 30.0f; // Camera3D field-of-view Y
|
||||
camera.type = CAMERA_PERSPECTIVE; // Camera3D type
|
||||
|
||||
|
||||
float pitch = 0.0f;
|
||||
float roll = 0.0f;
|
||||
float yaw = 0.0f;
|
||||
|
||||
|
||||
SetTargetFPS(60);
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
|
||||
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||
{
|
||||
// Update
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Plane roll (x-axis) controls
|
||||
if (IsKeyDown(KEY_LEFT)) roll += 1.0f;
|
||||
else if (IsKeyDown(KEY_RIGHT)) roll -= 1.0f;
|
||||
@ -77,7 +77,7 @@ public partial class models_yaw_pitch_roll
|
||||
if (roll > 0.0f) roll -= 0.5f;
|
||||
else if (roll < 0.0f) roll += 0.5f;
|
||||
}
|
||||
|
||||
|
||||
// Plane yaw (y-axis) controls
|
||||
if (IsKeyDown(KEY_S)) yaw += 1.0f;
|
||||
else if (IsKeyDown(KEY_A)) yaw -= 1.0f;
|
||||
@ -86,7 +86,7 @@ public partial class models_yaw_pitch_roll
|
||||
if (yaw > 0.0f) yaw -= 0.5f;
|
||||
else if (yaw < 0.0f) yaw += 0.5f;
|
||||
}
|
||||
|
||||
|
||||
// Plane pitch (z-axis) controls
|
||||
if (IsKeyDown(KEY_DOWN)) pitch += 0.6f;
|
||||
else if (IsKeyDown(KEY_UP)) pitch -= 0.6f;
|
||||
@ -95,101 +95,101 @@ public partial class models_yaw_pitch_roll
|
||||
if (pitch > 0.3f) pitch -= 0.3f;
|
||||
else if (pitch < -0.3f) pitch += 0.3f;
|
||||
}
|
||||
|
||||
|
||||
// Wraps the phase of an angle to fit between -180 and +180 degrees
|
||||
int pitchOffset = (int)pitch;
|
||||
while (pitchOffset > 180) pitchOffset -= 360;
|
||||
while (pitchOffset < -180) pitchOffset += 360;
|
||||
pitchOffset *= 10;
|
||||
|
||||
|
||||
Matrix transform = MatrixIdentity();
|
||||
|
||||
|
||||
transform = MatrixMultiply(transform, MatrixRotateZ(DEG2RAD*roll));
|
||||
transform = MatrixMultiply(transform, MatrixRotateX(DEG2RAD*pitch));
|
||||
transform = MatrixMultiply(transform, MatrixRotateY(DEG2RAD*yaw));
|
||||
|
||||
|
||||
model.transform = transform;
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
BeginDrawing();
|
||||
|
||||
|
||||
ClearBackground(RAYWHITE);
|
||||
|
||||
|
||||
// Draw framebuffer texture (Ahrs Display)
|
||||
int centerX = framebuffer.texture.width/2;
|
||||
int centerY = framebuffer.texture.height/2;
|
||||
float scaleFactor = 0.5f;
|
||||
|
||||
|
||||
BeginTextureMode(framebuffer);
|
||||
|
||||
|
||||
BeginBlendMode((int)BLEND_ALPHA);
|
||||
|
||||
|
||||
DrawTexturePro(texBackground, new Rectangle( 0, 0, texBackground.width, texBackground.height ),
|
||||
new Rectangle( centerX, centerY, texBackground.width*scaleFactor, texBackground.height*scaleFactor),
|
||||
new Vector2( texBackground.width/2*scaleFactor, texBackground.height/2*scaleFactor + pitchOffset*scaleFactor ), roll, WHITE);
|
||||
|
||||
|
||||
DrawTexturePro(texPitch, new Rectangle( 0, 0, texPitch.width, texPitch.height ),
|
||||
new Rectangle( centerX, centerY, texPitch.width*scaleFactor, texPitch.height*scaleFactor ),
|
||||
new Vector2( texPitch.width/2*scaleFactor, texPitch.height/2*scaleFactor + pitchOffset*scaleFactor ), roll, WHITE);
|
||||
|
||||
|
||||
DrawTexturePro(texPlane, new Rectangle( 0, 0, texPlane.width, texPlane.height ),
|
||||
new Rectangle( centerX, centerY, texPlane.width*scaleFactor, texPlane.height*scaleFactor ),
|
||||
new Vector2( texPlane.width/2*scaleFactor, texPlane.height/2*scaleFactor ), 0, WHITE);
|
||||
|
||||
|
||||
EndBlendMode();
|
||||
|
||||
|
||||
EndTextureMode();
|
||||
|
||||
|
||||
// Draw 3D model (recomended to draw 3D always before 2D)
|
||||
BeginMode3D(camera);
|
||||
|
||||
|
||||
DrawModel(model, new Vector3( 0, 6.0f, 0 ), 1.0f, WHITE); // Draw 3d model with texture
|
||||
DrawGrid(10, 10.0f);
|
||||
|
||||
|
||||
EndMode3D();
|
||||
|
||||
|
||||
// Draw 2D GUI stuff
|
||||
DrawAngleGauge(texAngleGauge, 80, 70, roll, "roll", RED);
|
||||
DrawAngleGauge(texAngleGauge, 190, 70, pitch, "pitch", GREEN);
|
||||
DrawAngleGauge(texAngleGauge, 300, 70, yaw, "yaw", SKYBLUE);
|
||||
|
||||
|
||||
DrawRectangle(30, 360, 260, 70, Fade(SKYBLUE, 0.5f));
|
||||
DrawRectangleLines(30, 360, 260, 70, Fade(DARKBLUE, 0.5f));
|
||||
DrawText("Pitch controlled with: KEY_UP / KEY_DOWN", 40, 370, 10, DARKGRAY);
|
||||
DrawText("Roll controlled with: KEY_LEFT / KEY_RIGHT", 40, 390, 10, DARKGRAY);
|
||||
DrawText("Yaw controlled with: KEY_A / KEY_S", 40, 410, 10, DARKGRAY);
|
||||
|
||||
|
||||
// Draw framebuffer texture
|
||||
DrawTextureRec(framebuffer.texture, new Rectangle( 0, 0, framebuffer.texture.width, -framebuffer.texture.height ),
|
||||
new Vector2( screenWidth - framebuffer.texture.width - 20, 20 ), Fade(WHITE, 0.8f));
|
||||
|
||||
|
||||
DrawRectangleLines(screenWidth - framebuffer.texture.width - 20, 20, framebuffer.texture.width, framebuffer.texture.height, DARKGRAY);
|
||||
|
||||
|
||||
EndDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
|
||||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Unload all loaded data
|
||||
UnloadModel(model);
|
||||
|
||||
|
||||
UnloadRenderTexture(framebuffer);
|
||||
|
||||
|
||||
UnloadTexture(texAngleGauge);
|
||||
UnloadTexture(texBackground);
|
||||
UnloadTexture(texPitch);
|
||||
UnloadTexture(texPlane);
|
||||
|
||||
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
// Draw angle gauge controls
|
||||
static void DrawAngleGauge(Texture2D angleGauge, int x, int y, float angle, string title, Color color)
|
||||
{
|
||||
@ -197,10 +197,10 @@ public partial class models_yaw_pitch_roll
|
||||
Rectangle dstRec = new Rectangle( x, y, angleGauge.width, angleGauge.height );
|
||||
Vector2 origin = new Vector2( angleGauge.width/2, angleGauge.height/2);
|
||||
int textSize = 20;
|
||||
|
||||
|
||||
DrawTexturePro(angleGauge, srcRec, dstRec, origin, angle, color);
|
||||
|
||||
|
||||
DrawText(FormatText("%5.1f", angle), x - MeasureText(FormatText("%5.1f", angle), textSize) / 2, y + 10, textSize, DARKGRAY);
|
||||
DrawText(title, x - MeasureText(title, textSize) / 2, y + 60, textSize, DARKGRAY);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -13,8 +13,8 @@ public partial class bunnymark
|
||||
* Copyright (c) 2014 Ramon Santamaria (@raysan5)
|
||||
*
|
||||
********************************************************************************************/
|
||||
|
||||
|
||||
|
||||
|
||||
public const int MAX_BUNNIES = 100000;
|
||||
|
||||
struct Bunny
|
||||
@ -23,25 +23,25 @@ public partial class bunnymark
|
||||
public Vector2 speed;
|
||||
public Color color;
|
||||
}
|
||||
|
||||
|
||||
public static int Main()
|
||||
{
|
||||
// Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
int screenWidth = 1280;
|
||||
int screenHeight = 960;
|
||||
|
||||
|
||||
InitWindow(screenWidth, screenHeight, "raylib example - Bunnymark");
|
||||
|
||||
|
||||
Texture2D texBunny = LoadTexture("resources/wabbit_alpha.png");
|
||||
|
||||
|
||||
Bunny[] bunnies = new Bunny[MAX_BUNNIES]; // Bunnies array
|
||||
|
||||
|
||||
int bunniesCount = 0; // Bunnies counter
|
||||
|
||||
|
||||
SetTargetFPS(60);
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Main game loop
|
||||
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||
{
|
||||
@ -58,24 +58,24 @@ public partial class bunnymark
|
||||
bunniesCount++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Update bunnies
|
||||
for (int i = 0; i < bunniesCount; i++)
|
||||
{
|
||||
bunnies[i].position.x += bunnies[i].speed.x;
|
||||
bunnies[i].position.y += bunnies[i].speed.y;
|
||||
|
||||
|
||||
if ((bunnies[i].position.x > GetScreenWidth()) || (bunnies[i].position.x < 0)) bunnies[i].speed.x *= -1;
|
||||
if ((bunnies[i].position.y > GetScreenHeight()) || (bunnies[i].position.y < 0)) bunnies[i].speed.y *= -1;
|
||||
}
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
BeginDrawing();
|
||||
|
||||
|
||||
ClearBackground(RAYWHITE);
|
||||
|
||||
|
||||
for (int i = 0; i < bunniesCount; i++)
|
||||
{
|
||||
// NOTE: When internal QUADS batch limit is reached, a draw call is launched and
|
||||
@ -84,23 +84,23 @@ public partial class bunnymark
|
||||
// a stall and consequently a frame drop, limiting number of bunnies drawn at 60 fps
|
||||
DrawTexture(texBunny, (int)bunnies[i].position.x, (int)bunnies[i].position.y, RAYWHITE);
|
||||
}
|
||||
|
||||
|
||||
DrawRectangle(0, 0, screenWidth, 40, LIGHTGRAY);
|
||||
DrawText("raylib bunnymark", 10, 10, 20, DARKGRAY);
|
||||
// DrawText(FormatText("bunnies: %i", bunniesCount), 400, 10, 20, RED);
|
||||
DrawText($"bunnies: {bunniesCount}", 400, 10, 20, RED);
|
||||
DrawFPS(260, 10);
|
||||
|
||||
|
||||
EndDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
|
||||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -12,44 +12,44 @@ public partial class physics_demo
|
||||
*
|
||||
* Use the following line to compile:
|
||||
*
|
||||
* gcc -o $(NAME_PART).exe $(FILE_NAME) -s $(RAYLIB_DIR)\raylib\raylib.rc.o -static -lraylib -lpthread
|
||||
* gcc -o $(NAME_PART).exe $(FILE_NAME) -s $(RAYLIB_DIR)\raylib\raylib.rc.o -static -lraylib -lpthread
|
||||
* -lglfw3 -lopengl32 -lgdi32 -lopenal32 -lwinmm -std=c99 -Wl,--subsystem,windows -Wl,-allow-multiple-definition
|
||||
*
|
||||
*
|
||||
* Copyright (c) 2016-2018 Victor Fisac
|
||||
*
|
||||
********************************************************************************************/
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public static int Main()
|
||||
{
|
||||
// Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
int screenWidth = 800;
|
||||
int screenHeight = 450;
|
||||
|
||||
|
||||
SetConfigFlags(FLAG_MSAA_4X_HINT);
|
||||
InitWindow(screenWidth, screenHeight, "Physac [raylib] - Physics demo");
|
||||
|
||||
|
||||
// Physac logo drawing position
|
||||
int logoX = screenWidth - MeasureText("Physac", 30) - 10;
|
||||
int logoY = 15;
|
||||
bool needsReset = false;
|
||||
|
||||
|
||||
// Initialize physics and default physics bodies
|
||||
InitPhysics();
|
||||
|
||||
|
||||
// Create floor rectangle physics body
|
||||
var floor = CreatePhysicsBodyRectangle(new Vector2( screenWidth/2, screenHeight ), 500, 100, 10);
|
||||
floor.enabled = false; // Disable body state to convert it to static (no dynamics, but collisions)
|
||||
|
||||
|
||||
// Create obstacle circle physics body
|
||||
var circle = CreatePhysicsBodyCircle(new Vector2( screenWidth/2, screenHeight/2 ), 45, 10);
|
||||
circle.enabled = false; // Disable body state to convert it to static (no dynamics, but collisions)
|
||||
|
||||
|
||||
SetTargetFPS(60);
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Main game loop
|
||||
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||
{
|
||||
@ -60,22 +60,22 @@ public partial class physics_demo
|
||||
{
|
||||
floor = CreatePhysicsBodyRectangle(new Vector2( screenWidth/2, screenHeight ), 500, 100, 10);
|
||||
floor.enabled = false;
|
||||
|
||||
|
||||
circle = CreatePhysicsBodyCircle(new Vector2( screenWidth/2, screenHeight/2 ), 45, 10);
|
||||
circle.enabled = false;
|
||||
}
|
||||
|
||||
|
||||
// Reset physics input
|
||||
if (IsKeyPressed('R'))
|
||||
{
|
||||
ResetPhysics();
|
||||
needsReset = true;
|
||||
}
|
||||
|
||||
|
||||
// Physics body creation inputs
|
||||
if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) CreatePhysicsBodyPolygon(GetMousePosition(), GetRandomValue(20, 80), GetRandomValue(3, 8), 10);
|
||||
else if (IsMouseButtonPressed(MOUSE_RIGHT_BUTTON)) CreatePhysicsBodyCircle(GetMousePosition(), GetRandomValue(10, 45), 10);
|
||||
|
||||
|
||||
// Destroy falling physics bodies
|
||||
int bodiesCount = GetPhysicsBodiesCount();
|
||||
for (int i = bodiesCount - 1; i >= 0; i--)
|
||||
@ -84,21 +84,21 @@ public partial class physics_demo
|
||||
if (body.id != 0 && (body.position.y > screenHeight*2)) DestroyPhysicsBody(body);
|
||||
}
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
BeginDrawing();
|
||||
|
||||
|
||||
ClearBackground(BLACK);
|
||||
|
||||
|
||||
DrawFPS(screenWidth - 90, screenHeight - 30);
|
||||
|
||||
|
||||
// Draw created physics bodies
|
||||
bodiesCount = GetPhysicsBodiesCount();
|
||||
for (int i = 0; i < bodiesCount; i++)
|
||||
{
|
||||
var body = GetPhysicsBody(i);
|
||||
|
||||
|
||||
if (body.id != 0) // can't check struct for null
|
||||
{
|
||||
int vertexCount = GetPhysicsShapeVerticesCount(i);
|
||||
@ -107,33 +107,33 @@ public partial class physics_demo
|
||||
// Get physics bodies shape vertices to draw lines
|
||||
// Note: GetPhysicsShapeVertex() already calculates rotation transformations
|
||||
Vector2 vertexA = GetPhysicsShapeVertex(body, j);
|
||||
|
||||
|
||||
int jj = (((j + 1) < vertexCount) ? (j + 1) : 0); // Get next vertex or first to close the shape
|
||||
Vector2 vertexB = GetPhysicsShapeVertex(body, jj);
|
||||
|
||||
|
||||
DrawLineV(vertexA, vertexB, GREEN); // Draw a line between two vertex positions
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
DrawText("Left mouse button to create a polygon", 10, 10, 10, WHITE);
|
||||
DrawText("Right mouse button to create a circle", 10, 25, 10, WHITE);
|
||||
DrawText("Press 'R' to reset example", 10, 40, 10, WHITE);
|
||||
|
||||
|
||||
DrawText("Physac", logoX, logoY, 30, WHITE);
|
||||
DrawText("Powered by", logoX + 50, logoY - 7, 10, WHITE);
|
||||
|
||||
|
||||
EndDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
|
||||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
//--------------------------------------------------------------------------------------
|
||||
ClosePhysics(); // Unitialize physics
|
||||
|
||||
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -12,62 +12,62 @@ public partial class physics_friction
|
||||
*
|
||||
* Use the following line to compile:
|
||||
*
|
||||
* gcc -o $(NAME_PART).exe $(FILE_NAME) -s $(RAYLIB_DIR)\raylib\raylib.rc.o -static -lraylib -lpthread
|
||||
* gcc -o $(NAME_PART).exe $(FILE_NAME) -s $(RAYLIB_DIR)\raylib\raylib.rc.o -static -lraylib -lpthread
|
||||
* -lglfw3 -lopengl32 -lgdi32 -lopenal32 -lwinmm -std=c99 -Wl,--subsystem,windows -Wl,-allow-multiple-definition
|
||||
*
|
||||
*
|
||||
* Copyright (c) 2016-2018 Victor Fisac
|
||||
*
|
||||
********************************************************************************************/
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public static int Main()
|
||||
{
|
||||
// Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
int screenWidth = 800;
|
||||
int screenHeight = 450;
|
||||
|
||||
|
||||
SetConfigFlags(FLAG_MSAA_4X_HINT);
|
||||
InitWindow(screenWidth, screenHeight, "Physac [raylib] - Physics friction");
|
||||
|
||||
|
||||
// Physac logo drawing position
|
||||
int logoX = screenWidth - MeasureText("Physac", 30) - 10;
|
||||
int logoY = 15;
|
||||
|
||||
|
||||
// Initialize physics and default physics bodies
|
||||
InitPhysics();
|
||||
|
||||
|
||||
// Create floor rectangle physics body
|
||||
PhysicsBodyData floor = CreatePhysicsBodyRectangle(new Vector2( screenWidth/2, screenHeight ), screenWidth, 100, 10);
|
||||
floor.enabled = false; // Disable body state to convert it to static (no dynamics, but collisions)
|
||||
PhysicsBodyData wall = CreatePhysicsBodyRectangle(new Vector2( screenWidth/2, screenHeight*0.8f ), 10, 80, 10);
|
||||
wall.enabled = false; // Disable body state to convert it to static (no dynamics, but collisions)
|
||||
|
||||
|
||||
// Create left ramp physics body
|
||||
PhysicsBodyData rectLeft = CreatePhysicsBodyRectangle(new Vector2( 25, screenHeight - 5 ), 250, 250, 10);
|
||||
rectLeft.enabled = false; // Disable body state to convert it to static (no dynamics, but collisions)
|
||||
SetPhysicsBodyRotation(rectLeft, 30*DEG2RAD);
|
||||
|
||||
|
||||
// Create right ramp physics body
|
||||
PhysicsBodyData rectRight = CreatePhysicsBodyRectangle(new Vector2( screenWidth - 25, screenHeight - 5 ), 250, 250, 10);
|
||||
rectRight.enabled = false; // Disable body state to convert it to static (no dynamics, but collisions)
|
||||
SetPhysicsBodyRotation(rectRight, 330*DEG2RAD);
|
||||
|
||||
|
||||
// Create dynamic physics bodies
|
||||
PhysicsBodyData bodyA = CreatePhysicsBodyRectangle(new Vector2( 35, screenHeight*0.6f ), 40, 40, 10);
|
||||
bodyA.staticFriction = 0.1f;
|
||||
bodyA.dynamicFriction = 0.1f;
|
||||
SetPhysicsBodyRotation(bodyA, 30*DEG2RAD);
|
||||
|
||||
|
||||
PhysicsBodyData bodyB = CreatePhysicsBodyRectangle(new Vector2( screenWidth - 35, screenHeight*0.6f ), 40, 40, 10);
|
||||
bodyB.staticFriction = 1;
|
||||
bodyB.dynamicFriction = 1;
|
||||
SetPhysicsBodyRotation(bodyB, 330*DEG2RAD);
|
||||
|
||||
|
||||
SetTargetFPS(60);
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Main game loop
|
||||
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||
{
|
||||
@ -80,28 +80,28 @@ public partial class physics_friction
|
||||
bodyA.velocity = new Vector2( 0, 0 );
|
||||
bodyA.angularVelocity = 0;
|
||||
SetPhysicsBodyRotation(bodyA, 30*DEG2RAD);
|
||||
|
||||
|
||||
bodyB.position = new Vector2( screenWidth - 35, screenHeight*0.6f );
|
||||
bodyB.velocity = new Vector2( 0, 0 );
|
||||
bodyB.angularVelocity = 0;
|
||||
SetPhysicsBodyRotation(bodyB, 330*DEG2RAD);
|
||||
}
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
BeginDrawing();
|
||||
|
||||
|
||||
ClearBackground(BLACK);
|
||||
|
||||
|
||||
DrawFPS(screenWidth - 90, screenHeight - 30);
|
||||
|
||||
|
||||
// Draw created physics bodies
|
||||
int bodiesCount = GetPhysicsBodiesCount();
|
||||
for (int i = 0; i < bodiesCount; i++)
|
||||
{
|
||||
PhysicsBodyData body = GetPhysicsBody(i);
|
||||
|
||||
|
||||
if (body.id != 0) // check for null?
|
||||
{
|
||||
int vertexCount = GetPhysicsShapeVerticesCount(i);
|
||||
@ -110,39 +110,39 @@ public partial class physics_friction
|
||||
// Get physics bodies shape vertices to draw lines
|
||||
// Note: GetPhysicsShapeVertex() already calculates rotation transformations
|
||||
Vector2 vertexA = GetPhysicsShapeVertex(body, j);
|
||||
|
||||
|
||||
int jj = (((j + 1) < vertexCount) ? (j + 1) : 0); // Get next vertex or first to close the shape
|
||||
Vector2 vertexB = GetPhysicsShapeVertex(body, jj);
|
||||
|
||||
|
||||
DrawLineV(vertexA, vertexB, GREEN); // Draw a line between two vertex positions
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
DrawRectangle(0, screenHeight - 49, screenWidth, 49, BLACK);
|
||||
|
||||
|
||||
DrawText("Friction amount", (screenWidth - MeasureText("Friction amount", 30))/2, 75, 30, WHITE);
|
||||
DrawText("0.1", (int)bodyA.position.x - MeasureText("0.1", 20)/2, (int)bodyA.position.y - 7, 20, WHITE);
|
||||
DrawText("1", (int)bodyB.position.x - MeasureText("1", 20)/2, (int)bodyB.position.y - 7, 20, WHITE);
|
||||
|
||||
|
||||
DrawText("Press 'R' to reset example", 10, 10, 10, WHITE);
|
||||
|
||||
|
||||
DrawText("Physac", logoX, logoY, 30, WHITE);
|
||||
DrawText("Powered by", logoX + 50, logoY - 7, 10, WHITE);
|
||||
|
||||
|
||||
EndDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
|
||||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
//--------------------------------------------------------------------------------------
|
||||
ClosePhysics(); // Unitialize physics
|
||||
|
||||
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -12,37 +12,37 @@ public partial class physics_restitution
|
||||
*
|
||||
* Use the following line to compile:
|
||||
*
|
||||
* gcc -o $(NAME_PART).exe $(FILE_NAME) -s $(RAYLIB_DIR)\raylib\raylib.rc.o -static -lraylib -lpthread
|
||||
* gcc -o $(NAME_PART).exe $(FILE_NAME) -s $(RAYLIB_DIR)\raylib\raylib.rc.o -static -lraylib -lpthread
|
||||
* -lglfw3 -lopengl32 -lgdi32 -lopenal32 -lwinmm -std=c99 -Wl,--subsystem,windows -Wl,-allow-multiple-definition
|
||||
*
|
||||
*
|
||||
* Copyright (c) 2016-2018 Victor Fisac
|
||||
*
|
||||
********************************************************************************************/
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public static int Main()
|
||||
{
|
||||
// Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
int screenWidth = 800;
|
||||
int screenHeight = 450;
|
||||
|
||||
|
||||
SetConfigFlags(FLAG_MSAA_4X_HINT);
|
||||
InitWindow(screenWidth, screenHeight, "Physac [raylib] - Physics restitution");
|
||||
|
||||
|
||||
// Physac logo drawing position
|
||||
int logoX = screenWidth - MeasureText("Physac", 30) - 10;
|
||||
int logoY = 15;
|
||||
|
||||
|
||||
// Initialize physics and default physics bodies
|
||||
InitPhysics();
|
||||
|
||||
|
||||
// Create floor rectangle physics body
|
||||
PhysicsBodyData floor = CreatePhysicsBodyRectangle(new Vector2( screenWidth/2, screenHeight ), screenWidth, 100, 10);
|
||||
floor.enabled = false; // Disable body state to convert it to static (no dynamics, but collisions)
|
||||
floor.restitution = 1;
|
||||
|
||||
|
||||
// Create circles physics body
|
||||
PhysicsBodyData circleA = CreatePhysicsBodyCircle(new Vector2( screenWidth*0.25f, screenHeight/2 ), 30, 10);
|
||||
circleA.restitution = 0;
|
||||
@ -50,10 +50,10 @@ public partial class physics_restitution
|
||||
circleB.restitution = 0.5f;
|
||||
PhysicsBodyData circleC = CreatePhysicsBodyCircle(new Vector2( screenWidth*0.75f, screenHeight/2 ), 30, 10);
|
||||
circleC.restitution = 1;
|
||||
|
||||
|
||||
SetTargetFPS(60);
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Main game loop
|
||||
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||
{
|
||||
@ -72,58 +72,58 @@ public partial class physics_restitution
|
||||
circleC.velocity = new Vector2( 0, 0 );
|
||||
}
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
BeginDrawing();
|
||||
|
||||
|
||||
ClearBackground(BLACK);
|
||||
|
||||
|
||||
DrawFPS(screenWidth - 90, screenHeight - 30);
|
||||
|
||||
|
||||
// Draw created physics bodies
|
||||
int bodiesCount = GetPhysicsBodiesCount();
|
||||
for (int i = 0; i < bodiesCount; i++)
|
||||
{
|
||||
PhysicsBodyData body = GetPhysicsBody(i);
|
||||
|
||||
|
||||
int vertexCount = GetPhysicsShapeVerticesCount(i);
|
||||
for (int j = 0; j < vertexCount; j++)
|
||||
{
|
||||
// Get physics bodies shape vertices to draw lines
|
||||
// Note: GetPhysicsShapeVertex() already calculates rotation transformations
|
||||
Vector2 vertexA = GetPhysicsShapeVertex(body, j);
|
||||
|
||||
|
||||
int jj = (((j + 1) < vertexCount) ? (j + 1) : 0); // Get next vertex or first to close the shape
|
||||
Vector2 vertexB = GetPhysicsShapeVertex(body, jj);
|
||||
|
||||
|
||||
DrawLineV(vertexA, vertexB, GREEN); // Draw a line between two vertex positions
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
DrawText("Restitution amount", (screenWidth - MeasureText("Restitution amount", 30))/2, 75, 30, WHITE);
|
||||
DrawText("0", (int)circleA.position.x - MeasureText("0", 20)/2, (int)circleA.position.y - 7, 20, WHITE);
|
||||
DrawText("0.5", (int)circleB.position.x - MeasureText("0.5", 20)/2, (int)circleB.position.y - 7, 20, WHITE);
|
||||
DrawText("1", (int)circleC.position.x - MeasureText("1", 20)/2, (int)circleC.position.y - 7, 20, WHITE);
|
||||
|
||||
|
||||
DrawText("Press 'R' to reset example", 10, 10, 10, WHITE);
|
||||
|
||||
|
||||
DrawText("Physac", logoX, logoY, 30, WHITE);
|
||||
DrawText("Powered by", logoX + 50, logoY - 7, 10, WHITE);
|
||||
|
||||
|
||||
EndDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
|
||||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
//--------------------------------------------------------------------------------------
|
||||
ClosePhysics(); // Unitialize physics
|
||||
|
||||
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -12,40 +12,40 @@ public partial class physics_shatter
|
||||
*
|
||||
* Use the following line to compile:
|
||||
*
|
||||
* gcc -o $(NAME_PART).exe $(FILE_NAME) -s $(RAYLIB_DIR)\raylib\raylib.rc.o -static -lraylib -lpthread
|
||||
* gcc -o $(NAME_PART).exe $(FILE_NAME) -s $(RAYLIB_DIR)\raylib\raylib.rc.o -static -lraylib -lpthread
|
||||
* -lglfw3 -lopengl32 -lgdi32 -lopenal32 -lwinmm -std=c99 -Wl,--subsystem,windows -Wl,-allow-multiple-definition
|
||||
*
|
||||
*
|
||||
* Copyright (c) 2016-2018 Victor Fisac
|
||||
*
|
||||
********************************************************************************************/
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public static int Main()
|
||||
{
|
||||
// Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
int screenWidth = 800;
|
||||
int screenHeight = 450;
|
||||
|
||||
|
||||
SetConfigFlags(FLAG_MSAA_4X_HINT);
|
||||
InitWindow(screenWidth, screenHeight, "Physac [raylib] - Body shatter");
|
||||
|
||||
|
||||
// Physac logo drawing position
|
||||
int logoX = screenWidth - MeasureText("Physac", 30) - 10;
|
||||
int logoY = 15;
|
||||
bool needsReset = false;
|
||||
|
||||
|
||||
// Initialize physics and default physics bodies
|
||||
InitPhysics();
|
||||
SetPhysicsGravity(0, 0);
|
||||
|
||||
|
||||
// Create random polygon physics body to shatter
|
||||
CreatePhysicsBodyPolygon(new Vector2( screenWidth/2, screenHeight/2 ), GetRandomValue(80, 200), GetRandomValue(3, 8), 10);
|
||||
|
||||
|
||||
SetTargetFPS(60);
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Main game loop
|
||||
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||
{
|
||||
@ -59,13 +59,13 @@ public partial class physics_shatter
|
||||
// Create random polygon physics body to shatter
|
||||
CreatePhysicsBodyPolygon(new Vector2( screenWidth/2, screenHeight/2 ), GetRandomValue(80, 200), GetRandomValue(3, 8), 10);
|
||||
}
|
||||
|
||||
|
||||
if (IsKeyPressed('R')) // Reset physics input
|
||||
{
|
||||
ResetPhysics();
|
||||
needsReset = true;
|
||||
}
|
||||
|
||||
|
||||
if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) // Physics shatter input
|
||||
{
|
||||
// Note: some values need to be stored in variables due to asynchronous changes during main thread
|
||||
@ -77,51 +77,51 @@ public partial class physics_shatter
|
||||
}
|
||||
}
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
BeginDrawing();
|
||||
|
||||
|
||||
ClearBackground(BLACK);
|
||||
|
||||
|
||||
// Draw created physics bodies
|
||||
int bodiesCount = GetPhysicsBodiesCount();
|
||||
for (int i = 0; i < bodiesCount; i++)
|
||||
{
|
||||
PhysicsBodyData currentBody = GetPhysicsBody(i);
|
||||
|
||||
|
||||
int vertexCount = GetPhysicsShapeVerticesCount(i);
|
||||
for (int j = 0; j < vertexCount; j++)
|
||||
{
|
||||
// Get physics bodies shape vertices to draw lines
|
||||
// Note: GetPhysicsShapeVertex() already calculates rotation transformations
|
||||
Vector2 vertexA = GetPhysicsShapeVertex(currentBody, j);
|
||||
|
||||
|
||||
int jj = (((j + 1) < vertexCount) ? (j + 1) : 0); // Get next vertex or first to close the shape
|
||||
Vector2 vertexB = GetPhysicsShapeVertex(currentBody, jj);
|
||||
|
||||
|
||||
DrawLineV(vertexA, vertexB, GREEN); // Draw a line between two vertex positions
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
DrawText("Left mouse button in polygon area to shatter body\nPress 'R' to reset example", 10, 10, 10, WHITE);
|
||||
|
||||
|
||||
DrawText("Physac", logoX, logoY, 30, WHITE);
|
||||
DrawText("Powered by", logoX + 50, logoY - 7, 10, WHITE);
|
||||
|
||||
|
||||
EndDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
|
||||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
//--------------------------------------------------------------------------------------
|
||||
ClosePhysics(); // Unitialize physics
|
||||
|
||||
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -23,19 +23,19 @@ public partial class shaders_custom_uniform
|
||||
* Copyright (c) 2015 Ramon Santamaria (@raysan5)
|
||||
*
|
||||
********************************************************************************************/
|
||||
|
||||
|
||||
|
||||
|
||||
public static int Main()
|
||||
{
|
||||
// Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
int screenWidth = 800;
|
||||
int screenHeight = 450;
|
||||
|
||||
|
||||
SetConfigFlags(FLAG_MSAA_4X_HINT); // Enable Multi Sampling Anti Aliasing 4x (if available)
|
||||
|
||||
|
||||
InitWindow(screenWidth, screenHeight, "raylib [shaders] example - custom uniform variable");
|
||||
|
||||
|
||||
// Define the camera to look into our 3d world
|
||||
Camera3D camera = new Camera3D();
|
||||
camera.position = new Vector3( 8.0f, 8.0f, 8.0f );
|
||||
@ -43,92 +43,92 @@ public partial class shaders_custom_uniform
|
||||
camera.up = new Vector3( 0.0f, 1.0f, 0.0f );
|
||||
camera.fovy = 45.0f;
|
||||
camera.type = CAMERA_PERSPECTIVE;
|
||||
|
||||
|
||||
Model model = LoadModel("resources/models/barracks.obj"); // Load OBJ model
|
||||
Texture2D texture = LoadTexture("resources/models/barracks_diffuse.png"); // Load model texture (diffuse map)
|
||||
model.material.maps[(int)MAP_ALBEDO].texture = texture; // Set model diffuse texture
|
||||
|
||||
|
||||
Vector3 position = new Vector3( 0.0f, 0.0f, 0.0f ); // Set model position
|
||||
|
||||
Shader shader = LoadShader("resources/shaders/glsl330/base.vs",
|
||||
|
||||
Shader shader = LoadShader("resources/shaders/glsl330/base.vs",
|
||||
"resources/shaders/glsl330/swirl.fs"); // Load postpro shader
|
||||
|
||||
|
||||
// Get variable (uniform) location on the shader to connect with the program
|
||||
// NOTE: If uniform variable could not be found in the shader, function returns -1
|
||||
int swirlCenterLoc = GetShaderLocation(shader, "center");
|
||||
|
||||
|
||||
float[] swirlCenter = new float[2] { (float)screenWidth/2, (float)screenHeight/2 };
|
||||
|
||||
|
||||
// Create a RenderTexture2D to be used for render to texture
|
||||
RenderTexture2D target = LoadRenderTexture(screenWidth, screenHeight);
|
||||
|
||||
|
||||
// Setup orbital camera
|
||||
SetCameraMode(camera, (int)CAMERA_ORBITAL); // Set an orbital camera mode
|
||||
|
||||
|
||||
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
|
||||
//----------------------------------------------------------------------------------
|
||||
Vector2 mousePosition = GetMousePosition();
|
||||
|
||||
|
||||
swirlCenter[0] = mousePosition.x;
|
||||
swirlCenter[1] = screenHeight - mousePosition.y;
|
||||
|
||||
|
||||
// Send new value to the shader to be used on drawing
|
||||
SetShaderValue(shader, swirlCenterLoc, swirlCenter, 2);
|
||||
|
||||
|
||||
UpdateCamera(ref camera); // Update camera
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
BeginDrawing();
|
||||
|
||||
|
||||
ClearBackground(RAYWHITE);
|
||||
|
||||
|
||||
BeginTextureMode(target); // Enable drawing to texture
|
||||
|
||||
|
||||
BeginMode3D(camera);
|
||||
|
||||
|
||||
DrawModel(model, position, 0.5f, WHITE); // Draw 3d model with texture
|
||||
|
||||
|
||||
DrawGrid(10, 1.0f); // Draw a grid
|
||||
|
||||
|
||||
EndMode3D();
|
||||
|
||||
|
||||
DrawText("TEXT DRAWN IN RENDER TEXTURE", 200, 10, 30, RED);
|
||||
|
||||
|
||||
EndTextureMode(); // End drawing to texture (now we have a texture available for next passes)
|
||||
|
||||
|
||||
BeginShaderMode(shader);
|
||||
|
||||
|
||||
// NOTE: Render texture must be y-flipped due to default OpenGL coordinates (left-bottom)
|
||||
DrawTextureRec(target.texture, new Rectangle( 0, 0, target.texture.width, -target.texture.height ), new Vector2( 0, 0 ), WHITE);
|
||||
|
||||
|
||||
EndShaderMode();
|
||||
|
||||
|
||||
DrawText("(c) Barracks 3D model by Alberto Cano", screenWidth - 220, screenHeight - 20, 10, GRAY);
|
||||
|
||||
|
||||
DrawFPS(10, 10);
|
||||
|
||||
|
||||
EndDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
|
||||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
UnloadShader(shader); // Unload shader
|
||||
UnloadTexture(texture); // Unload texture
|
||||
UnloadModel(model); // Unload model
|
||||
UnloadRenderTexture(target); // Unload render texture
|
||||
|
||||
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -23,19 +23,19 @@ public partial class shaders_model_shader
|
||||
* Copyright (c) 2014 Ramon Santamaria (@raysan5)
|
||||
*
|
||||
********************************************************************************************/
|
||||
|
||||
|
||||
|
||||
|
||||
public static int Main()
|
||||
{
|
||||
// Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
int screenWidth = 800;
|
||||
int screenHeight = 450;
|
||||
|
||||
|
||||
SetConfigFlags(FLAG_MSAA_4X_HINT); // Enable Multi Sampling Anti Aliasing 4x (if available)
|
||||
|
||||
|
||||
InitWindow(screenWidth, screenHeight, "raylib [shaders] example - model shader");
|
||||
|
||||
|
||||
// Define the camera to look into our 3d world
|
||||
Camera3D camera = new Camera3D();
|
||||
camera.position = new Vector3( 4.0f, 4.0f, 4.0f );
|
||||
@ -43,22 +43,22 @@ public partial class shaders_model_shader
|
||||
camera.up = new Vector3( 0.0f, 1.0f, 0.0f );
|
||||
camera.fovy = 45.0f;
|
||||
camera.type = CAMERA_PERSPECTIVE;
|
||||
|
||||
|
||||
Model model = LoadModel("resources/models/watermill.obj"); // Load OBJ model
|
||||
Texture2D texture = LoadTexture("resources/models/watermill_diffuse.png"); // Load model texture
|
||||
Shader shader = LoadShader("resources/shaders/glsl330/base.vs",
|
||||
Shader shader = LoadShader("resources/shaders/glsl330/base.vs",
|
||||
"resources/shaders/glsl330/grayscale.fs"); // Load model shader
|
||||
|
||||
|
||||
model.material.shader = shader; // Set shader effect to 3d model
|
||||
model.material.maps[(int)MAP_ALBEDO].texture = texture; // Bind texture to model
|
||||
|
||||
|
||||
Vector3 position = new Vector3( 0.0f, 0.0f, 0.0f ); // Set model position
|
||||
|
||||
|
||||
SetCameraMode(camera, (int)CAMERA_FREE); // Set an orbital camera mode
|
||||
|
||||
|
||||
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Main game loop
|
||||
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||
{
|
||||
@ -66,41 +66,41 @@ public partial class shaders_model_shader
|
||||
//----------------------------------------------------------------------------------
|
||||
UpdateCamera(ref camera); // Update camera
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
BeginDrawing();
|
||||
|
||||
|
||||
ClearBackground(RAYWHITE);
|
||||
|
||||
|
||||
BeginMode3D(camera);
|
||||
|
||||
|
||||
DrawModel(model, position, 0.2f, WHITE); // Draw 3d model with texture
|
||||
|
||||
|
||||
DrawGrid(10, 1.0f); // Draw a grid
|
||||
|
||||
|
||||
EndMode3D();
|
||||
|
||||
|
||||
DrawText("(c) Watermill 3D model by Alberto Cano", screenWidth - 210, screenHeight - 20, 10, GRAY);
|
||||
|
||||
|
||||
DrawText(FormatText("Camera3D position: (%.2f, %.2f, %.2f)", camera.position.x, camera.position.y, camera.position.z), 600, 20, 10, BLACK);
|
||||
DrawText(FormatText("Camera3D target: (%.2f, %.2f, %.2f)", camera.target.x, camera.target.y, camera.target.z), 600, 40, 10, GRAY);
|
||||
|
||||
|
||||
DrawFPS(10, 10);
|
||||
|
||||
|
||||
EndDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
|
||||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
UnloadShader(shader); // Unload shader
|
||||
UnloadTexture(texture); // Unload texture
|
||||
UnloadModel(model); // Unload model
|
||||
|
||||
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -22,13 +22,13 @@ public partial class shaders_postprocessing
|
||||
* Copyright (c) 2015 Ramon Santamaria (@raysan5)
|
||||
*
|
||||
********************************************************************************************/
|
||||
|
||||
|
||||
|
||||
|
||||
public const int GLSL_VERSION = 330;
|
||||
// public const int GLSL_VERSION = 100;
|
||||
|
||||
|
||||
public const int MAX_POSTPRO_SHADERS = 12;
|
||||
|
||||
|
||||
enum PostproShader
|
||||
{
|
||||
FX_GRAYSCALE = 0,
|
||||
@ -45,8 +45,8 @@ public partial class shaders_postprocessing
|
||||
FX_BLUR,
|
||||
//FX_FXAA
|
||||
}
|
||||
|
||||
static string[] postproShaderText =
|
||||
|
||||
static string[] postproShaderText =
|
||||
{
|
||||
"GRAYSCALE",
|
||||
"POSTERIZATION",
|
||||
@ -62,32 +62,32 @@ public partial class shaders_postprocessing
|
||||
"BLUR",
|
||||
//"FXAA"
|
||||
};
|
||||
|
||||
|
||||
public static int Main()
|
||||
{
|
||||
// Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
int screenWidth = 800;
|
||||
int screenHeight = 450;
|
||||
|
||||
|
||||
SetConfigFlags(FLAG_MSAA_4X_HINT); // Enable Multi Sampling Anti Aliasing 4x (if available)
|
||||
|
||||
|
||||
InitWindow(screenWidth, screenHeight, "raylib [shaders] example - postprocessing shader");
|
||||
|
||||
|
||||
// Define the camera to look into our 3d world
|
||||
Camera3D camera = new Camera3D(new Vector3( 2.0f, 3.0f, 2.0f ), new Vector3( 0.0f, 1.0f, 0.0f ), new Vector3( 0.0f, 1.0f, 0.0f ), 45.0f, 0 );
|
||||
|
||||
|
||||
Model model = LoadModel("resources/models/church.obj"); // Load OBJ model
|
||||
Texture2D texture = LoadTexture("resources/models/church_diffuse.png"); // Load model texture (diffuse map)
|
||||
model.material.maps[(int)MAP_ALBEDO].texture = texture; // Set model diffuse texture
|
||||
|
||||
|
||||
Vector3 position = new Vector3( 0.0f, 0.0f, 0.0f ); // Set model position
|
||||
|
||||
|
||||
// Load all postpro shaders
|
||||
// NOTE 1: All postpro shader use the base vertex shader (DEFAULT_VERTEX_SHADER)
|
||||
// NOTE 2: We load the correct shader depending on GLSL version
|
||||
Shader[] shaders = new Shader[MAX_POSTPRO_SHADERS];
|
||||
|
||||
|
||||
// NOTE: Defining null (NULL) for vertex shader forces usage of internal default vertex shader
|
||||
shaders[(int)PostproShader.FX_GRAYSCALE] = LoadShader(null, FormatText("resources/shaders/glsl%i/grayscale.fs", GLSL_VERSION));
|
||||
shaders[(int)PostproShader.FX_POSTERIZATION] = LoadShader(null, FormatText("resources/shaders/glsl%i/posterization.fs", GLSL_VERSION));
|
||||
@ -101,85 +101,85 @@ public partial class shaders_postprocessing
|
||||
shaders[(int)PostproShader.FX_SOBEL] = LoadShader(null, FormatText("resources/shaders/glsl%i/sobel.fs", GLSL_VERSION));
|
||||
shaders[(int)PostproShader.FX_BLOOM] = LoadShader(null, FormatText("resources/shaders/glsl%i/bloom.fs", GLSL_VERSION));
|
||||
shaders[(int)PostproShader.FX_BLUR] = LoadShader(null, FormatText("resources/shaders/glsl%i/blur.fs", GLSL_VERSION));
|
||||
|
||||
|
||||
int currentShader = (int)PostproShader.FX_GRAYSCALE;
|
||||
|
||||
|
||||
// Create a RenderTexture2D to be used for render to texture
|
||||
RenderTexture2D target = LoadRenderTexture(screenWidth, screenHeight);
|
||||
|
||||
|
||||
// Setup orbital camera
|
||||
SetCameraMode(camera, (int)CAMERA_ORBITAL); // Set an orbital camera mode
|
||||
|
||||
|
||||
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
|
||||
//----------------------------------------------------------------------------------
|
||||
UpdateCamera(ref camera); // Update camera
|
||||
|
||||
|
||||
if (IsKeyPressed(KEY_RIGHT)) currentShader++;
|
||||
else if (IsKeyPressed(KEY_LEFT)) currentShader--;
|
||||
|
||||
|
||||
if (currentShader >= MAX_POSTPRO_SHADERS) currentShader = 0;
|
||||
else if (currentShader < 0) currentShader = MAX_POSTPRO_SHADERS - 1;
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
BeginDrawing();
|
||||
|
||||
|
||||
ClearBackground(RAYWHITE);
|
||||
|
||||
|
||||
BeginTextureMode(target); // Enable drawing to texture
|
||||
|
||||
|
||||
BeginMode3D(camera);
|
||||
|
||||
|
||||
DrawModel(model, position, 0.1f, WHITE); // Draw 3d model with texture
|
||||
|
||||
|
||||
DrawGrid(10, 1.0f); // Draw a grid
|
||||
|
||||
|
||||
EndMode3D();
|
||||
|
||||
|
||||
EndTextureMode(); // End drawing to texture (now we have a texture available for next passes)
|
||||
|
||||
|
||||
// Render previously generated texture using selected postpro shader
|
||||
BeginShaderMode(shaders[currentShader]);
|
||||
|
||||
|
||||
// NOTE: Render texture must be y-flipped due to default OpenGL coordinates (left-bottom)
|
||||
DrawTextureRec(target.texture, new Rectangle( 0, 0, target.texture.width, -target.texture.height ), new Vector2( 0, 0 ), WHITE);
|
||||
|
||||
|
||||
EndShaderMode();
|
||||
|
||||
|
||||
DrawRectangle(0, 9, 580, 30, Fade(LIGHTGRAY, 0.7f));
|
||||
|
||||
|
||||
DrawText("(c) Church 3D model by Alberto Cano", screenWidth - 200, screenHeight - 20, 10, GRAY);
|
||||
|
||||
|
||||
DrawText("CURRENT POSTPRO SHADER:", 10, 15, 20, BLACK);
|
||||
DrawText(postproShaderText[currentShader], 330, 15, 20, RED);
|
||||
DrawText("< >", 540, 10, 30, DARKBLUE);
|
||||
|
||||
|
||||
DrawFPS(700, 15);
|
||||
|
||||
|
||||
EndDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
|
||||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Unload all postpro shaders
|
||||
for (int i = 0; i < MAX_POSTPRO_SHADERS; i++) UnloadShader(shaders[i]);
|
||||
|
||||
|
||||
UnloadTexture(texture); // Unload texture
|
||||
UnloadModel(model); // Unload model
|
||||
UnloadRenderTexture(target); // Unload render texture
|
||||
|
||||
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -20,26 +20,26 @@ public partial class shaders_shapes_textures
|
||||
* Copyright (c) 2015 Ramon Santamaria (@raysan5)
|
||||
*
|
||||
********************************************************************************************/
|
||||
|
||||
|
||||
|
||||
|
||||
public static int Main()
|
||||
{
|
||||
// Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
int screenWidth = 800;
|
||||
int screenHeight = 450;
|
||||
|
||||
|
||||
InitWindow(screenWidth, screenHeight, "raylib [shaders] example - shapes and texture shaders");
|
||||
|
||||
|
||||
Texture2D fudesumi = LoadTexture("resources/fudesumi.png");
|
||||
|
||||
// NOTE: Using GLSL 330 shader version, on OpenGL ES 2.0 use GLSL 100 shader version
|
||||
Shader shader = LoadShader("resources/shaders/glsl330/base.vs",
|
||||
|
||||
// NOTE: Using GLSL 330 shader version, on OpenGL ES 2.0 use GLSL 100 shader version
|
||||
Shader shader = LoadShader("resources/shaders/glsl330/base.vs",
|
||||
"resources/shaders/glsl330/grayscale.fs");
|
||||
|
||||
|
||||
SetTargetFPS(60);
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Main game loop
|
||||
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||
{
|
||||
@ -47,68 +47,68 @@ public partial class shaders_shapes_textures
|
||||
//----------------------------------------------------------------------------------
|
||||
// TODO: Update your variables here
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
BeginDrawing();
|
||||
|
||||
|
||||
ClearBackground(RAYWHITE);
|
||||
|
||||
|
||||
// Start drawing with default shader
|
||||
|
||||
|
||||
DrawText("USING DEFAULT SHADER", 20, 40, 10, RED);
|
||||
|
||||
|
||||
DrawCircle(80, 120, 35, DARKBLUE);
|
||||
DrawCircleGradient(80, 220, 60, GREEN, SKYBLUE);
|
||||
DrawCircleLines(80, 340, 80, DARKBLUE);
|
||||
|
||||
|
||||
|
||||
|
||||
// Activate our custom shader to be applied on next shapes/textures drawings
|
||||
BeginShaderMode(shader);
|
||||
|
||||
|
||||
DrawText("USING CUSTOM SHADER", 190, 40, 10, RED);
|
||||
|
||||
|
||||
DrawRectangle(250 - 60, 90, 120, 60, RED);
|
||||
DrawRectangleGradientH(250 - 90, 170, 180, 130, MAROON, GOLD);
|
||||
DrawRectangleLines(250 - 40, 320, 80, 60, ORANGE);
|
||||
|
||||
|
||||
// Activate our default shader for next drawings
|
||||
EndShaderMode();
|
||||
|
||||
|
||||
DrawText("USING DEFAULT SHADER", 370, 40, 10, RED);
|
||||
|
||||
|
||||
DrawTriangle(new Vector2(430, 80),
|
||||
new Vector2(430 - 60, 150),
|
||||
new Vector2(430 + 60, 150), VIOLET);
|
||||
|
||||
|
||||
DrawTriangleLines(new Vector2(430, 160),
|
||||
new Vector2(430 - 20, 230),
|
||||
new Vector2(430 + 20, 230), DARKBLUE);
|
||||
|
||||
|
||||
DrawPoly(new Vector2(430, 320), 6, 80, 0, BROWN);
|
||||
|
||||
|
||||
// Activate our custom shader to be applied on next shapes/textures drawings
|
||||
BeginShaderMode(shader);
|
||||
|
||||
|
||||
DrawTexture(fudesumi, 500, -30, WHITE); // Using custom shader
|
||||
|
||||
|
||||
// Activate our default shader for next drawings
|
||||
EndShaderMode();
|
||||
|
||||
|
||||
DrawText("(c) Fudesumi sprite by Eiden Marsal", 380, screenHeight - 20, 10, GRAY);
|
||||
|
||||
|
||||
EndDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
|
||||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
UnloadShader(shader); // Unload shader
|
||||
UnloadTexture(fudesumi); // Unload texture
|
||||
|
||||
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -13,20 +13,20 @@ public partial class shapes_basic_shapes
|
||||
* Copyright (c) 2014 Ramon Santamaria (@raysan5)
|
||||
*
|
||||
********************************************************************************************/
|
||||
|
||||
|
||||
|
||||
|
||||
public static int Main()
|
||||
{
|
||||
// Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
int screenWidth = 800;
|
||||
int screenHeight = 450;
|
||||
|
||||
|
||||
InitWindow(screenWidth, screenHeight, "raylib [shapes] example - basic shapes drawing");
|
||||
|
||||
|
||||
SetTargetFPS(60);
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Main game loop
|
||||
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||
{
|
||||
@ -34,44 +34,44 @@ public partial class shapes_basic_shapes
|
||||
//----------------------------------------------------------------------------------
|
||||
// TODO: Update your variables here
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
BeginDrawing();
|
||||
|
||||
|
||||
ClearBackground(RAYWHITE);
|
||||
|
||||
|
||||
DrawText("some basic shapes available on raylib", 20, 20, 20, DARKGRAY);
|
||||
|
||||
|
||||
DrawLine(18, 42, screenWidth - 18, 42, BLACK);
|
||||
|
||||
|
||||
DrawCircle(screenWidth/4, 120, 35, DARKBLUE);
|
||||
DrawCircleGradient(screenWidth/4, 220, 60, GREEN, SKYBLUE);
|
||||
DrawCircleLines(screenWidth/4, 340, 80, DARKBLUE);
|
||||
|
||||
|
||||
DrawRectangle(screenWidth/4*2 - 60, 100, 120, 60, RED);
|
||||
DrawRectangleGradientH(screenWidth/4*2 - 90, 170, 180, 130, MAROON, GOLD);
|
||||
DrawRectangleLines(screenWidth/4*2 - 40, 320, 80, 60, ORANGE);
|
||||
|
||||
|
||||
DrawTriangle(new Vector2(screenWidth/4*3, 80),
|
||||
new Vector2(screenWidth/4*3 - 60, 150),
|
||||
new Vector2(screenWidth/4*3 + 60, 150), VIOLET);
|
||||
|
||||
|
||||
DrawTriangleLines(new Vector2(screenWidth/4*3, 160),
|
||||
new Vector2(screenWidth/4*3 - 20, 230),
|
||||
new Vector2(screenWidth/4*3 + 20, 230), DARKBLUE);
|
||||
|
||||
|
||||
DrawPoly(new Vector2(screenWidth/4*3, 320), 6, 80, 0, BROWN);
|
||||
|
||||
|
||||
EndDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
|
||||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -13,20 +13,20 @@ public partial class shapes_colors_palette
|
||||
* Copyright (c) 2014 Ramon Santamaria (@raysan5)
|
||||
*
|
||||
********************************************************************************************/
|
||||
|
||||
|
||||
|
||||
|
||||
public static int Main()
|
||||
{
|
||||
// Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
int screenWidth = 800;
|
||||
int screenHeight = 450;
|
||||
|
||||
|
||||
InitWindow(screenWidth, screenHeight, "raylib [shapes] example - raylib color palette");
|
||||
|
||||
|
||||
SetTargetFPS(60);
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Main game loop
|
||||
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||
{
|
||||
@ -34,15 +34,15 @@ public partial class shapes_colors_palette
|
||||
//----------------------------------------------------------------------------------
|
||||
// TODO: Update your variables here
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
BeginDrawing();
|
||||
|
||||
|
||||
ClearBackground(RAYWHITE);
|
||||
|
||||
|
||||
DrawText("raylib color palette", 28, 42, 20, BLACK);
|
||||
|
||||
|
||||
DrawRectangle(26, 80, 100, 100, DARKGRAY);
|
||||
DrawRectangle(26, 188, 100, 100, GRAY);
|
||||
DrawRectangle(26, 296, 100, 100, LIGHTGRAY);
|
||||
@ -64,8 +64,8 @@ public partial class shapes_colors_palette
|
||||
DrawRectangle(674, 80, 100, 100, DARKBROWN);
|
||||
DrawRectangle(674, 188, 100, 100, BROWN);
|
||||
DrawRectangle(674, 296, 100, 100, BEIGE);
|
||||
|
||||
|
||||
|
||||
|
||||
DrawText("DARKGRAY", 65, 166, 10, BLACK);
|
||||
DrawText("GRAY", 93, 274, 10, BLACK);
|
||||
DrawText("LIGHTGRAY", 61, 382, 10, BLACK);
|
||||
@ -87,16 +87,16 @@ public partial class shapes_colors_palette
|
||||
DrawText("DARKBROWN", 705, 166, 10, BLACK);
|
||||
DrawText("BROWN", 733, 274, 10, BLACK);
|
||||
DrawText("BEIGE", 737, 382, 10, BLACK);
|
||||
|
||||
|
||||
EndDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
|
||||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -13,24 +13,24 @@ public partial class shapes_lines_bezier
|
||||
* Copyright (c) 2017 Ramon Santamaria (@raysan5)
|
||||
*
|
||||
********************************************************************************************/
|
||||
|
||||
|
||||
|
||||
|
||||
public static int Main()
|
||||
{
|
||||
// Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
int screenWidth = 800;
|
||||
int screenHeight = 450;
|
||||
|
||||
|
||||
SetConfigFlags(FLAG_MSAA_4X_HINT);
|
||||
InitWindow(screenWidth, screenHeight, "raylib [shapes] example - cubic-bezier lines");
|
||||
|
||||
|
||||
Vector2 start = new Vector2( 0, 0 );
|
||||
Vector2 end = new Vector2( screenWidth, screenHeight );
|
||||
|
||||
|
||||
SetTargetFPS(60);
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Main game loop
|
||||
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||
{
|
||||
@ -39,27 +39,27 @@ public partial class shapes_lines_bezier
|
||||
if (IsMouseButtonDown(MOUSE_LEFT_BUTTON)) start = GetMousePosition();
|
||||
else if (IsMouseButtonDown(MOUSE_RIGHT_BUTTON)) end = GetMousePosition();
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
BeginDrawing();
|
||||
|
||||
|
||||
ClearBackground(RAYWHITE);
|
||||
|
||||
|
||||
DrawText("USE MOUSE LEFT-RIGHT CLICK to DEFINE LINE START and END POINTS", 15, 20, 20, GRAY);
|
||||
|
||||
|
||||
DrawLineBezier(start, end, 2.0f, RED);
|
||||
|
||||
|
||||
EndDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
|
||||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
//--------------------------------------------------------------------------------------
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -13,20 +13,20 @@ public partial class shapes_logo_raylib
|
||||
* Copyright (c) 2014 Ramon Santamaria (@raysan5)
|
||||
*
|
||||
********************************************************************************************/
|
||||
|
||||
|
||||
|
||||
|
||||
public static int Main()
|
||||
{
|
||||
// Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
int screenWidth = 800;
|
||||
int screenHeight = 450;
|
||||
|
||||
|
||||
InitWindow(screenWidth, screenHeight, "raylib [shapes] example - raylib logo using shapes");
|
||||
|
||||
|
||||
SetTargetFPS(60);
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Main game loop
|
||||
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||
{
|
||||
@ -34,28 +34,28 @@ public partial class shapes_logo_raylib
|
||||
//----------------------------------------------------------------------------------
|
||||
// TODO: Update your variables here
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
BeginDrawing();
|
||||
|
||||
|
||||
ClearBackground(RAYWHITE);
|
||||
|
||||
|
||||
DrawRectangle(screenWidth/2 - 128, screenHeight/2 - 128, 256, 256, BLACK);
|
||||
DrawRectangle(screenWidth/2 - 112, screenHeight/2 - 112, 224, 224, RAYWHITE);
|
||||
DrawText("raylib", screenWidth/2 - 44, screenHeight/2 + 48, 50, BLACK);
|
||||
|
||||
|
||||
DrawText("this is NOT a texture!", 350, 370, 10, GRAY);
|
||||
|
||||
|
||||
EndDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
|
||||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -14,35 +14,35 @@ public partial class shapes_logo_raylib_anim
|
||||
* Copyright (c) 2014 Ramon Santamaria (@raysan5)
|
||||
*
|
||||
********************************************************************************************/
|
||||
|
||||
|
||||
|
||||
|
||||
public static int Main()
|
||||
{
|
||||
// Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
int screenWidth = 800;
|
||||
int screenHeight = 450;
|
||||
|
||||
|
||||
InitWindow(screenWidth, screenHeight, "raylib [shapes] example - raylib logo animation");
|
||||
|
||||
|
||||
int logoPositionX = screenWidth/2 - 128;
|
||||
int logoPositionY = screenHeight/2 - 128;
|
||||
|
||||
|
||||
int framesCounter = 0;
|
||||
int lettersCount = 0;
|
||||
|
||||
|
||||
int topSideRecWidth = 16;
|
||||
int leftSideRecHeight = 16;
|
||||
|
||||
|
||||
int bottomSideRecWidth = 16;
|
||||
int rightSideRecHeight = 16;
|
||||
|
||||
|
||||
int state = 0; // Tracking animation states (State Machine)
|
||||
float alpha = 1.0f; // Useful for fading
|
||||
|
||||
|
||||
SetTargetFPS(60);
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Main game loop
|
||||
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||
{
|
||||
@ -51,7 +51,7 @@ public partial class shapes_logo_raylib_anim
|
||||
if (state == 0) // State 0: Small box blinking
|
||||
{
|
||||
framesCounter++;
|
||||
|
||||
|
||||
if (framesCounter == 120)
|
||||
{
|
||||
state = 1;
|
||||
@ -62,14 +62,14 @@ public partial class shapes_logo_raylib_anim
|
||||
{
|
||||
topSideRecWidth += 4;
|
||||
leftSideRecHeight += 4;
|
||||
|
||||
|
||||
if (topSideRecWidth == 256) state = 2;
|
||||
}
|
||||
else if (state == 2) // State 2: Bottom and right bars growing
|
||||
{
|
||||
bottomSideRecWidth += 4;
|
||||
rightSideRecHeight += 4;
|
||||
|
||||
|
||||
if (bottomSideRecWidth == 256) state = 3;
|
||||
}
|
||||
else if (state == 3) // State 3: Letters appearing (one by one)
|
||||
@ -81,11 +81,11 @@ public partial class shapes_logo_raylib_anim
|
||||
lettersCount++;
|
||||
framesCounter = 0;
|
||||
}
|
||||
|
||||
|
||||
if (lettersCount >= 10) // When all letters have appeared, just fade out everything
|
||||
{
|
||||
alpha -= 0.02f;
|
||||
|
||||
|
||||
if (alpha <= 0.0f)
|
||||
{
|
||||
alpha = 0.0f;
|
||||
@ -99,25 +99,25 @@ public partial class shapes_logo_raylib_anim
|
||||
{
|
||||
framesCounter = 0;
|
||||
lettersCount = 0;
|
||||
|
||||
|
||||
topSideRecWidth = 16;
|
||||
leftSideRecHeight = 16;
|
||||
|
||||
|
||||
bottomSideRecWidth = 16;
|
||||
rightSideRecHeight = 16;
|
||||
|
||||
|
||||
alpha = 1.0f;
|
||||
state = 0; // Return to State 0
|
||||
}
|
||||
}
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
BeginDrawing();
|
||||
|
||||
|
||||
ClearBackground(RAYWHITE);
|
||||
|
||||
|
||||
if (state == 0)
|
||||
{
|
||||
if ((framesCounter/15)%2 != 0) DrawRectangle(logoPositionX, logoPositionY, 16, 16, BLACK);
|
||||
@ -131,7 +131,7 @@ public partial class shapes_logo_raylib_anim
|
||||
{
|
||||
DrawRectangle(logoPositionX, logoPositionY, topSideRecWidth, 16, BLACK);
|
||||
DrawRectangle(logoPositionX, logoPositionY, 16, leftSideRecHeight, BLACK);
|
||||
|
||||
|
||||
DrawRectangle(logoPositionX + 240, logoPositionY, 16, rightSideRecHeight, BLACK);
|
||||
DrawRectangle(logoPositionX, logoPositionY + 240, bottomSideRecWidth, 16, BLACK);
|
||||
}
|
||||
@ -139,10 +139,10 @@ public partial class shapes_logo_raylib_anim
|
||||
{
|
||||
DrawRectangle(logoPositionX, logoPositionY, topSideRecWidth, 16, Fade(BLACK, alpha));
|
||||
DrawRectangle(logoPositionX, logoPositionY + 16, 16, leftSideRecHeight - 32, Fade(BLACK, alpha));
|
||||
|
||||
|
||||
DrawRectangle(logoPositionX + 240, logoPositionY + 16, 16, rightSideRecHeight - 32, Fade(BLACK, alpha));
|
||||
DrawRectangle(logoPositionX, logoPositionY + 240, bottomSideRecWidth, 16, Fade(BLACK, alpha));
|
||||
|
||||
|
||||
DrawRectangle(screenWidth/2 - 112, screenHeight/2 - 112, 224, 224, Fade(RAYWHITE, alpha));
|
||||
|
||||
// DrawText(SubText("raylib", 0, lettersCount), screenWidth/2 - 44, screenHeight/2 + 48, 50, Fade(BLACK, alpha));
|
||||
@ -153,16 +153,16 @@ public partial class shapes_logo_raylib_anim
|
||||
{
|
||||
DrawText("[R] REPLAY", 340, 200, 20, GRAY);
|
||||
}
|
||||
|
||||
|
||||
EndDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
|
||||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -13,32 +13,32 @@ public partial class text_bmfont_ttf
|
||||
* Copyright (c) 2016 Ramon Santamaria (@raysan5)
|
||||
*
|
||||
********************************************************************************************/
|
||||
|
||||
|
||||
|
||||
|
||||
public static int Main()
|
||||
{
|
||||
// Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
int screenWidth = 800;
|
||||
int screenHeight = 450;
|
||||
|
||||
|
||||
InitWindow(screenWidth, screenHeight, "raylib [text] example - bmfont and ttf sprite fonts loading");
|
||||
|
||||
|
||||
string msgBm = "THIS IS AN AngelCode SPRITE FONT";
|
||||
string msgTtf = "THIS SPRITE FONT has been GENERATED from a TTF";
|
||||
|
||||
|
||||
// NOTE: Textures/Fonts MUST be loaded after Window initialization (OpenGL context is required)
|
||||
Font fontBm = LoadFont("resources/bmfont.fnt"); // BMFont (AngelCode)
|
||||
Font fontTtf = LoadFont("resources/pixantiqua.ttf"); // TTF font
|
||||
|
||||
|
||||
Vector2 fontPosition;
|
||||
|
||||
|
||||
fontPosition.x = screenWidth/2 - MeasureTextEx(fontBm, msgBm, fontBm.baseSize, 0).x/2;
|
||||
fontPosition.y = screenHeight/2 - fontBm.baseSize/2 - 80;
|
||||
|
||||
|
||||
SetTargetFPS(60);
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Main game loop
|
||||
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||
{
|
||||
@ -46,28 +46,28 @@ public partial class text_bmfont_ttf
|
||||
//----------------------------------------------------------------------------------
|
||||
// TODO: Update variables here...
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
BeginDrawing();
|
||||
|
||||
|
||||
ClearBackground(RAYWHITE);
|
||||
|
||||
|
||||
DrawTextEx(fontBm, msgBm, fontPosition, fontBm.baseSize, 0, MAROON);
|
||||
DrawTextEx(fontTtf, msgTtf, new Vector2( 75.0f, 240.0f ), fontTtf.baseSize*0.8f, 2, LIME);
|
||||
|
||||
|
||||
EndDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
|
||||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
UnloadFont(fontBm); // AngelCode Font unloading
|
||||
UnloadFont(fontTtf); // TTF Font unloading
|
||||
|
||||
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -49,7 +49,7 @@ public partial class text_bmfont_unordered
|
||||
ClearBackground(RAYWHITE);
|
||||
|
||||
DrawText("Font name: PixAntiqua", 40, 50, 20, GRAY);
|
||||
//TODO: Uncomment this code when FormatText is fixed.
|
||||
//TODO: Uncomment this code when FormatText is fixed.
|
||||
// DrawText(FormatText("Font base size: %i", font.baseSize), 40, 80, 20, GRAY);
|
||||
// DrawText(FormatText("Font chars number: %i", font.charsCount), 40, 110, 20, GRAY);
|
||||
|
||||
|
@ -14,21 +14,21 @@ public partial class text_font_sdf
|
||||
* Copyright (c) 2015 Ramon Santamaria (@raysan5)
|
||||
*
|
||||
********************************************************************************************/
|
||||
|
||||
|
||||
|
||||
|
||||
public static int Main()
|
||||
{
|
||||
// Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
int screenWidth = 800;
|
||||
int screenHeight = 450;
|
||||
|
||||
|
||||
InitWindow(screenWidth, screenHeight, "raylib [text] example - SDF fonts");
|
||||
|
||||
|
||||
// NOTE: Textures/Fonts MUST be loaded after Window initialization (OpenGL context is required)
|
||||
|
||||
|
||||
string msg = "Signed Distance Fields";
|
||||
|
||||
|
||||
// Default font generation from TTF font
|
||||
Font fontDefault = new Font();
|
||||
fontDefault.baseSize = 16;
|
||||
@ -40,7 +40,7 @@ public partial class text_font_sdf
|
||||
//Image atlas = GenImageFontAtlas(fontDefault.chars, 95, 16, 4, 0);
|
||||
//fontDefault.texture = LoadTextureFromImage(atlas);
|
||||
//UnloadImage(atlas);
|
||||
|
||||
|
||||
// SDF font generation from TTF font
|
||||
// NOTE: SDF chars data is generated with LoadFontData(), it's just a bool option
|
||||
Font fontSDF = new Font();
|
||||
@ -54,82 +54,82 @@ public partial class text_font_sdf
|
||||
//atlas = GenImageFontAtlas(fontSDF.chars, 95, 16, 0, 1);
|
||||
//fontSDF.texture = LoadTextureFromImage(atlas);
|
||||
//UnloadImage(atlas);
|
||||
|
||||
|
||||
// Load SDF required shader (we use default vertex shader)
|
||||
Shader shader = LoadShader(null, "resources/shaders/sdf.fs");
|
||||
SetTextureFilter(fontSDF.texture, (int)FILTER_BILINEAR); // Required for SDF font
|
||||
|
||||
|
||||
Vector2 fontPosition = new Vector2( 40, screenHeight/2 - 50 );
|
||||
Vector2 textSize = new Vector2( 0.0f );
|
||||
float fontSize = 16.0f;
|
||||
int currentFont = 0; // 0 - fontDefault, 1 - fontSDF
|
||||
|
||||
|
||||
SetTargetFPS(60);
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Main game loop
|
||||
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||
{
|
||||
// Update
|
||||
//----------------------------------------------------------------------------------
|
||||
fontSize += GetMouseWheelMove()*8.0f;
|
||||
|
||||
|
||||
if (fontSize < 6) fontSize = 6;
|
||||
|
||||
|
||||
if (IsKeyDown(KEY_SPACE)) currentFont = 1;
|
||||
else currentFont = 0;
|
||||
|
||||
|
||||
if (currentFont == 0) textSize = MeasureTextEx(fontDefault, msg, fontSize, 0);
|
||||
else textSize = MeasureTextEx(fontSDF, msg, fontSize, 0);
|
||||
|
||||
|
||||
fontPosition.x = GetScreenWidth()/2 - textSize.x/2;
|
||||
fontPosition.y = GetScreenHeight()/2 - textSize.y/2 + 80;
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
BeginDrawing();
|
||||
|
||||
|
||||
ClearBackground(RAYWHITE);
|
||||
|
||||
|
||||
if (currentFont == 1)
|
||||
{
|
||||
// NOTE: SDF fonts require a custom SDf shader to compute fragment color
|
||||
BeginShaderMode(shader); // Activate SDF font shader
|
||||
DrawTextEx(fontSDF, msg, fontPosition, fontSize, 0, BLACK);
|
||||
EndShaderMode(); // Activate our default shader for next drawings
|
||||
|
||||
|
||||
DrawTexture(fontSDF.texture, 10, 10, BLACK);
|
||||
}
|
||||
else
|
||||
else
|
||||
{
|
||||
DrawTextEx(fontDefault, msg, fontPosition, fontSize, 0, BLACK);
|
||||
DrawTexture(fontDefault.texture, 10, 10, BLACK);
|
||||
}
|
||||
|
||||
|
||||
if (currentFont == 1) DrawText("SDF!", 320, 20, 80, RED);
|
||||
else DrawText("default font", 315, 40, 30, GRAY);
|
||||
|
||||
|
||||
DrawText("FONT SIZE: 16.0", GetScreenWidth() - 240, 20, 20, DARKGRAY);
|
||||
DrawText(FormatText("RENDER SIZE: %02.02f", fontSize), GetScreenWidth() - 240, 50, 20, DARKGRAY);
|
||||
DrawText("Use MOUSE WHEEL to SCALE TEXT!", GetScreenWidth() - 240, 90, 10, DARKGRAY);
|
||||
|
||||
|
||||
DrawText("PRESS SPACE to USE SDF FONT VERSION!", 340, GetScreenHeight() - 30, 20, MAROON);
|
||||
|
||||
|
||||
EndDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
|
||||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
UnloadFont(fontDefault); // Default font unloading
|
||||
UnloadFont(fontSDF); // SDF font unloading
|
||||
|
||||
|
||||
UnloadShader(shader); // Unload SDF shader
|
||||
|
||||
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -13,24 +13,24 @@ public partial class text_format_text
|
||||
* Copyright (c) 2014 Ramon Santamaria (@raysan5)
|
||||
*
|
||||
********************************************************************************************/
|
||||
|
||||
|
||||
|
||||
|
||||
public static int Main()
|
||||
{
|
||||
// Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
int screenWidth = 800;
|
||||
int screenHeight = 450;
|
||||
|
||||
|
||||
InitWindow(screenWidth, screenHeight, "raylib [text] example - text formatting");
|
||||
|
||||
|
||||
int score = 100020;
|
||||
int hiscore = 200450;
|
||||
int lives = 5;
|
||||
|
||||
|
||||
SetTargetFPS(60);
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Main game loop
|
||||
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||
{
|
||||
@ -38,30 +38,30 @@ public partial class text_format_text
|
||||
//----------------------------------------------------------------------------------
|
||||
// TODO: Update your variables here
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
BeginDrawing();
|
||||
|
||||
|
||||
ClearBackground(RAYWHITE);
|
||||
|
||||
|
||||
DrawText(FormatText("Score: %08i", score), 200, 80, 20, RED);
|
||||
|
||||
|
||||
DrawText(FormatText("HiScore: %08i", hiscore), 200, 120, 20, GREEN);
|
||||
|
||||
|
||||
DrawText(FormatText("Lives: %02i", lives), 200, 160, 40, BLUE);
|
||||
|
||||
|
||||
DrawText(FormatText("Elapsed Time: %02.02f ms", GetFrameTime()*1000), 200, 220, 20, BLACK);
|
||||
|
||||
|
||||
EndDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
|
||||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -14,30 +14,30 @@ public partial class text_input_box
|
||||
* Copyright (c) 2017 Ramon Santamaria (@raysan5)
|
||||
*
|
||||
********************************************************************************************/
|
||||
|
||||
|
||||
|
||||
|
||||
public const int MAX_INPUT_CHARS = 9;
|
||||
|
||||
|
||||
public static int Main()
|
||||
{
|
||||
// Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
int screenWidth = 800;
|
||||
int screenHeight = 450;
|
||||
|
||||
|
||||
InitWindow(screenWidth, screenHeight, "raylib [text] example - input box");
|
||||
|
||||
StringBuilder name = new StringBuilder(' ', MAX_INPUT_CHARS + 1); // NOTE: One extra space required for line ending char '\0'
|
||||
int letterCount = 0;
|
||||
|
||||
|
||||
Rectangle textBox = new Rectangle( screenWidth/2 - 100, 180, 225, 50 );
|
||||
bool mouseOnText = false;
|
||||
|
||||
|
||||
int framesCounter = 0;
|
||||
|
||||
|
||||
SetTargetFPS(60);
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Main game loop
|
||||
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||
{
|
||||
@ -45,47 +45,47 @@ public partial class text_input_box
|
||||
//----------------------------------------------------------------------------------
|
||||
if (CheckCollisionPointRec(GetMousePosition(), textBox)) mouseOnText = true;
|
||||
else mouseOnText = false;
|
||||
|
||||
|
||||
if (mouseOnText)
|
||||
{
|
||||
int key = GetKeyPressed();
|
||||
|
||||
|
||||
// NOTE: Only allow keys in range [32..125]
|
||||
if ((key >= 32) && (key <= 125) && (letterCount < MAX_INPUT_CHARS))
|
||||
{
|
||||
name[letterCount] = (char)key;
|
||||
letterCount++;
|
||||
}
|
||||
|
||||
|
||||
if (IsKeyPressed(KEY_BACKSPACE))
|
||||
{
|
||||
letterCount--;
|
||||
name[letterCount] = '\0';
|
||||
|
||||
|
||||
if (letterCount < 0) letterCount = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (mouseOnText) framesCounter++;
|
||||
else framesCounter = 0;
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
BeginDrawing();
|
||||
|
||||
|
||||
ClearBackground(RAYWHITE);
|
||||
|
||||
|
||||
DrawText("PLACE MOUSE OVER INPUT BOX!", 240, 140, 20, GRAY);
|
||||
|
||||
|
||||
DrawRectangleRec(textBox, LIGHTGRAY);
|
||||
if (mouseOnText) DrawRectangleLines((int)textBox.x, (int)textBox.y, (int)textBox.width, (int)textBox.height, RED);
|
||||
else DrawRectangleLines((int)textBox.x, (int)textBox.y, (int)textBox.width, (int)textBox.height, DARKGRAY);
|
||||
|
||||
|
||||
DrawText(name.ToString(), (int)textBox.x + 5, (int)textBox.y + 8, 40, MAROON);
|
||||
|
||||
|
||||
DrawText(FormatText("INPUT CHARS: %i/%i", letterCount, MAX_INPUT_CHARS), 315, 250, 20, DARKGRAY);
|
||||
|
||||
|
||||
if (mouseOnText)
|
||||
{
|
||||
if (letterCount < MAX_INPUT_CHARS)
|
||||
@ -95,28 +95,28 @@ public partial class text_input_box
|
||||
}
|
||||
else DrawText("Press BACKSPACE to delete chars...", 230, 300, 20, GRAY);
|
||||
}
|
||||
|
||||
|
||||
EndDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
|
||||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
//--------------------------------------------------------------------------------------
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
// Check if any key is pressed
|
||||
// NOTE: We limit keys check to keys between 32 (KEY_SPACE) and 126
|
||||
bool IsAnyKeyPressed()
|
||||
{
|
||||
bool keyPressed = false;
|
||||
int key = GetKeyPressed();
|
||||
|
||||
|
||||
if ((key >= 32) && (key <= 126)) keyPressed = true;
|
||||
|
||||
|
||||
return keyPressed;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -16,22 +16,22 @@ public partial class text_raylib_fonts
|
||||
* Copyright (c) 2017 Ramon Santamaria (@raysan5)
|
||||
*
|
||||
********************************************************************************************/
|
||||
|
||||
|
||||
|
||||
|
||||
public const int MAX_FONTS = 8;
|
||||
|
||||
|
||||
public static int Main()
|
||||
{
|
||||
// Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
int screenWidth = 800;
|
||||
int screenHeight = 450;
|
||||
|
||||
|
||||
InitWindow(screenWidth, screenHeight, "raylib [text] example - raylib fonts");
|
||||
|
||||
|
||||
// NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required)
|
||||
Font[] fonts = new Font[MAX_FONTS];
|
||||
|
||||
|
||||
fonts[0] = LoadFont("resources/fonts/alagard.png");
|
||||
fonts[1] = LoadFont("resources/fonts/pixelplay.png");
|
||||
fonts[2] = LoadFont("resources/fonts/mecha.png");
|
||||
@ -40,34 +40,34 @@ public partial class text_raylib_fonts
|
||||
fonts[5] = LoadFont("resources/fonts/pixantiqua.png");
|
||||
fonts[6] = LoadFont("resources/fonts/alpha_beta.png");
|
||||
fonts[7] = LoadFont("resources/fonts/jupiter_crash.png");
|
||||
|
||||
string[] messages = new string[MAX_FONTS] { "ALAGARD FONT designed by Hewett Tsoi",
|
||||
|
||||
string[] messages = new string[MAX_FONTS] { "ALAGARD FONT designed by Hewett Tsoi",
|
||||
"PIXELPLAY FONT designed by Aleksander Shevchuk",
|
||||
"MECHA FONT designed by Captain Falcon",
|
||||
"SETBACK FONT designed by Brian Kent (AEnigma)",
|
||||
"ROMULUS FONT designed by Hewett Tsoi",
|
||||
"MECHA FONT designed by Captain Falcon",
|
||||
"SETBACK FONT designed by Brian Kent (AEnigma)",
|
||||
"ROMULUS FONT designed by Hewett Tsoi",
|
||||
"PIXANTIQUA FONT designed by Gerhard Grossmann",
|
||||
"ALPHA_BETA FONT designed by Brian Kent (AEnigma)",
|
||||
"JUPITER_CRASH FONT designed by Brian Kent (AEnigma)" };
|
||||
|
||||
|
||||
int[] spacings = new int[MAX_FONTS]{ 2, 4, 8, 4, 3, 4, 4, 1 };
|
||||
|
||||
|
||||
Vector2[] positions = new Vector2[MAX_FONTS];
|
||||
|
||||
|
||||
for (int i = 0; i < MAX_FONTS; i++)
|
||||
{
|
||||
positions[i].x = screenWidth/2 - MeasureTextEx(fonts[i], messages[i], fonts[i].baseSize*2, spacings[i]).x/2;
|
||||
positions[i].y = 60 + fonts[i].baseSize + 45*i;
|
||||
}
|
||||
|
||||
|
||||
// Small Y position corrections
|
||||
positions[3].y += 8;
|
||||
positions[4].y += 2;
|
||||
positions[7].y -= 8;
|
||||
|
||||
|
||||
Color[] colors = new Color[MAX_FONTS] { MAROON, ORANGE, DARKGREEN, DARKBLUE, DARKPURPLE, LIME, GOLD, RED };
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Main game loop
|
||||
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||
{
|
||||
@ -75,34 +75,34 @@ public partial class text_raylib_fonts
|
||||
//----------------------------------------------------------------------------------
|
||||
// TODO: Update your variables here
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
BeginDrawing();
|
||||
|
||||
|
||||
ClearBackground(RAYWHITE);
|
||||
|
||||
|
||||
DrawText("free fonts included with raylib", 250, 20, 20, DARKGRAY);
|
||||
DrawLine(220, 50, 590, 50, DARKGRAY);
|
||||
|
||||
|
||||
for (int i = 0; i < MAX_FONTS; i++)
|
||||
{
|
||||
DrawTextEx(fonts[i], messages[i], positions[i], fonts[i].baseSize*2, spacings[i], colors[i]);
|
||||
}
|
||||
|
||||
|
||||
EndDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
|
||||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Fonts unloading
|
||||
for (int i = 0; i < MAX_FONTS; i++) UnloadFont(fonts[i]);
|
||||
|
||||
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -13,39 +13,39 @@ public partial class text_sprite_fonts
|
||||
* Copyright (c) 2014 Ramon Santamaria (@raysan5)
|
||||
*
|
||||
********************************************************************************************/
|
||||
|
||||
|
||||
|
||||
|
||||
public static int Main()
|
||||
{
|
||||
// Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
int screenWidth = 800;
|
||||
int screenHeight = 450;
|
||||
|
||||
|
||||
InitWindow(screenWidth, screenHeight, "raylib [text] example - sprite fonts usage");
|
||||
|
||||
|
||||
string msg1 = "THIS IS A custom SPRITE FONT...";
|
||||
string msg2 = "...and this is ANOTHER CUSTOM font...";
|
||||
string msg3 = "...and a THIRD one! GREAT! :D";
|
||||
|
||||
|
||||
// NOTE: Textures/Fonts MUST be loaded after Window initialization (OpenGL context is required)
|
||||
Font font1 = LoadFont("resources/custom_mecha.png"); // Font loading
|
||||
Font font2 = LoadFont("resources/custom_alagard.png"); // Font loading
|
||||
Font font3 = LoadFont("resources/custom_jupiter_crash.png"); // Font loading
|
||||
|
||||
|
||||
Vector2 fontPosition1, fontPosition2, fontPosition3;
|
||||
|
||||
|
||||
fontPosition1.x = screenWidth/2 - MeasureTextEx(font1, msg1, font1.baseSize, -3).x/2;
|
||||
fontPosition1.y = screenHeight/2 - font1.baseSize/2 - 80;
|
||||
|
||||
|
||||
fontPosition2.x = screenWidth/2 - MeasureTextEx(font2, msg2, font2.baseSize, -2).x/2;
|
||||
fontPosition2.y = screenHeight/2 - font2.baseSize/2 - 10;
|
||||
|
||||
|
||||
fontPosition3.x = screenWidth/2 - MeasureTextEx(font3, msg3, font3.baseSize, 2).x/2;
|
||||
fontPosition3.y = screenHeight/2 - font3.baseSize/2 + 50;
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Main game loop
|
||||
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||
{
|
||||
@ -53,30 +53,30 @@ public partial class text_sprite_fonts
|
||||
//----------------------------------------------------------------------------------
|
||||
// TODO: Update variables here...
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
BeginDrawing();
|
||||
|
||||
|
||||
ClearBackground(RAYWHITE);
|
||||
|
||||
|
||||
DrawTextEx(font1, msg1, fontPosition1, font1.baseSize, -3, WHITE);
|
||||
DrawTextEx(font2, msg2, fontPosition2, font2.baseSize, -2, WHITE);
|
||||
DrawTextEx(font3, msg3, fontPosition3, font3.baseSize, 2, WHITE);
|
||||
|
||||
|
||||
EndDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
|
||||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
UnloadFont(font1); // Font unloading
|
||||
UnloadFont(font2); // Font unloading
|
||||
UnloadFont(font3); // Font unloading
|
||||
|
||||
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -14,49 +14,49 @@ public partial class text_ttf_loading
|
||||
* Copyright (c) 2015 Ramon Santamaria (@raysan5)
|
||||
*
|
||||
********************************************************************************************/
|
||||
|
||||
|
||||
|
||||
|
||||
public static int Main()
|
||||
{
|
||||
// Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
int screenWidth = 800;
|
||||
int screenHeight = 450;
|
||||
|
||||
|
||||
InitWindow(screenWidth, screenHeight, "raylib [text] example - ttf loading");
|
||||
|
||||
|
||||
string msg = "TTF Font";
|
||||
|
||||
|
||||
// NOTE: Textures/Fonts MUST be loaded after Window initialization (OpenGL context is required)
|
||||
|
||||
|
||||
// TTF Font loading with custom generation parameters
|
||||
Font font = LoadFontEx("resources/KAISG.ttf", 96, 0, null);
|
||||
|
||||
|
||||
// Generate mipmap levels to use trilinear filtering
|
||||
// NOTE: On 2D drawing it won't be noticeable, it looks like FILTER_BILINEAR
|
||||
GenTextureMipmaps(ref font.texture);
|
||||
|
||||
|
||||
float fontSize = font.baseSize;
|
||||
Vector2 fontPosition = new Vector2( 40, screenHeight/2 - 80 );
|
||||
Vector2 textSize;
|
||||
|
||||
|
||||
SetTextureFilter(font.texture, (int)FILTER_POINT);
|
||||
int currentFontFilter = 0; // FILTER_POINT
|
||||
|
||||
|
||||
// NOTE: Drag and drop support only available for desktop platforms: Windows, Linux, OSX
|
||||
int count = 0;
|
||||
string[] droppedFiles;
|
||||
|
||||
|
||||
SetTargetFPS(60);
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Main game loop
|
||||
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||
{
|
||||
// Update
|
||||
//----------------------------------------------------------------------------------
|
||||
fontSize += GetMouseWheelMove()*4.0f;
|
||||
|
||||
|
||||
// Choose font texture filter method
|
||||
if (IsKeyPressed(KEY_ONE))
|
||||
{
|
||||
@ -74,17 +74,17 @@ public partial class text_ttf_loading
|
||||
SetTextureFilter(font.texture, (int)FILTER_TRILINEAR);
|
||||
currentFontFilter = 2;
|
||||
}
|
||||
|
||||
|
||||
textSize = MeasureTextEx(font, msg, fontSize, 0);
|
||||
|
||||
|
||||
if (IsKeyDown(KEY_LEFT)) fontPosition.x -= 10;
|
||||
else if (IsKeyDown(KEY_RIGHT)) fontPosition.x += 10;
|
||||
|
||||
|
||||
// Load a dropped TTF file dynamically (at current fontSize)
|
||||
if (IsFileDropped())
|
||||
{
|
||||
droppedFiles = GetDroppedFiles(ref count);
|
||||
|
||||
|
||||
if (count == 1) // Only support one ttf file dropped
|
||||
{
|
||||
UnloadFont(font);
|
||||
@ -93,44 +93,44 @@ public partial class text_ttf_loading
|
||||
}
|
||||
}
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
BeginDrawing();
|
||||
|
||||
|
||||
ClearBackground(RAYWHITE);
|
||||
|
||||
|
||||
DrawText("Use mouse wheel to change font size", 20, 20, 10, GRAY);
|
||||
DrawText("Use KEY_RIGHT and KEY_LEFT to move text", 20, 40, 10, GRAY);
|
||||
DrawText("Use 1, 2, 3 to change texture filter", 20, 60, 10, GRAY);
|
||||
DrawText("Drop a new TTF font for dynamic loading", 20, 80, 10, DARKGRAY);
|
||||
|
||||
|
||||
DrawTextEx(font, msg, fontPosition, fontSize, 0, BLACK);
|
||||
|
||||
|
||||
// TODO: It seems texSize measurement is not accurate due to chars offsets...
|
||||
//DrawRectangleLines(fontPosition.x, fontPosition.y, textSize.x, textSize.y, RED);
|
||||
|
||||
|
||||
DrawRectangle(0, screenHeight - 80, screenWidth, 80, LIGHTGRAY);
|
||||
DrawText(FormatText("Font size: %02.02f", fontSize), 20, screenHeight - 50, 10, DARKGRAY);
|
||||
DrawText(FormatText("Text size: [%02.02f, %02.02f]", textSize.x, textSize.y), 20, screenHeight - 30, 10, DARKGRAY);
|
||||
DrawText("CURRENT TEXTURE FILTER:", 250, 400, 20, GRAY);
|
||||
|
||||
|
||||
if (currentFontFilter == 0) DrawText("POINT", 570, 400, 20, BLACK);
|
||||
else if (currentFontFilter == 1) DrawText("BILINEAR", 570, 400, 20, BLACK);
|
||||
else if (currentFontFilter == 2) DrawText("TRILINEAR", 570, 400, 20, BLACK);
|
||||
|
||||
|
||||
EndDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
|
||||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
ClearDroppedFiles(); // Clear internal buffers
|
||||
UnloadFont(font); // Font unloading
|
||||
|
||||
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -13,24 +13,24 @@ public partial class text_writing_anim
|
||||
* Copyright (c) 2016 Ramon Santamaria (@raysan5)
|
||||
*
|
||||
********************************************************************************************/
|
||||
|
||||
|
||||
|
||||
|
||||
public static int Main()
|
||||
{
|
||||
// Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
int screenWidth = 800;
|
||||
int screenHeight = 450;
|
||||
|
||||
|
||||
InitWindow(screenWidth, screenHeight, "raylib [text] example - text writing anim");
|
||||
|
||||
|
||||
string message = "This sample illustrates a text writing\nanimation effect! Check it out! ;)";
|
||||
|
||||
|
||||
int framesCounter = 0;
|
||||
|
||||
|
||||
SetTargetFPS(60);
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Main game loop
|
||||
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||
{
|
||||
@ -38,30 +38,30 @@ public partial class text_writing_anim
|
||||
//----------------------------------------------------------------------------------
|
||||
if (IsKeyDown(KEY_SPACE)) framesCounter += 8;
|
||||
else framesCounter++;
|
||||
|
||||
|
||||
if (IsKeyPressed(KEY_ENTER)) framesCounter = 0;
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
BeginDrawing();
|
||||
|
||||
|
||||
ClearBackground(RAYWHITE);
|
||||
|
||||
|
||||
DrawText(SubText(message, 0, framesCounter/10), 210, 160, 20, MAROON);
|
||||
|
||||
|
||||
DrawText("PRESS [ENTER] to RESTART!", 240, 260, 20, LIGHTGRAY);
|
||||
DrawText("PRESS [SPACE] to SPEED UP!", 239, 300, 20, LIGHTGRAY);
|
||||
|
||||
|
||||
EndDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
|
||||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
//--------------------------------------------------------------------------------------
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -15,28 +15,28 @@ public partial class Examples
|
||||
* Copyright (c) 2016 Ramon Santamaria (@raysan5)
|
||||
*
|
||||
********************************************************************************************/
|
||||
|
||||
|
||||
|
||||
|
||||
public static int textures_image_9patch()
|
||||
{
|
||||
// Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
int screenWidth = 800;
|
||||
int screenHeight = 450;
|
||||
|
||||
|
||||
InitWindow(screenWidth, screenHeight, "raylib [textures] example - 9-patch drawing");
|
||||
|
||||
|
||||
// NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required)
|
||||
Texture2D nPatchTexture = LoadTexture("resources/ninepatch_button.png");
|
||||
Vector2 mousePosition;
|
||||
Vector2 origin = {0.0f, 0.0f};
|
||||
|
||||
|
||||
// The location and size of the n-patches.
|
||||
Rectangle dstRec1 = {480.0f, 160.0f, 32.0f, 32.0f};
|
||||
Rectangle dstRec2 = {160.0f, 160.0f, 32.0f, 32.0f};
|
||||
Rectangle dstRecH = {160.0f, 93.0f, 32.0f, 32.0f}; // this rec's height is ignored
|
||||
Rectangle dstRecV = {92.0f, 160.0f, 32.0f, 32.0f}; // this rec's width is ignored
|
||||
|
||||
|
||||
// A 9-patch (NPT_9PATCH) changes its sizes in both axis
|
||||
NPatchInfo ninePatchInfo1 = {(Rectangle){0.0f, 0.0f, 64.0f, 64.0f}, 12, 40, 12, 12, NPT_9PATCH };
|
||||
NPatchInfo ninePatchInfo2 = {(Rectangle){0.0f, 128.0f, 64.0f, 64.0f}, 16, 16, 16, 16, NPT_9PATCH };
|
||||
@ -44,10 +44,10 @@ public partial class Examples
|
||||
NPatchInfo h3PatchInfo = {(Rectangle){0.0f, 64.0f, 64.0f, 64.0f}, 8, 8, 8, 8, NPT_3PATCH_HORIZONTAL };
|
||||
// A vertical 3-patch (NPT_3PATCH_VERTICAL) changes its sizes along the y axis only
|
||||
NPatchInfo v3PatchInfo = {(Rectangle){0.0f, 192.0f, 64.0f, 64.0f}, 6, 6, 6, 6, NPT_3PATCH_VERTICAL };
|
||||
|
||||
|
||||
SetTargetFPS(60);
|
||||
//---------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Main game loop
|
||||
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||
{
|
||||
@ -61,7 +61,7 @@ public partial class Examples
|
||||
dstRec2.height = mousePosition.y - dstRec2.y;
|
||||
dstRecH.width = mousePosition.x - dstRecH.x;
|
||||
dstRecV.height = mousePosition.y - dstRecV.y;
|
||||
|
||||
|
||||
// set a minimum width and/or height
|
||||
if (dstRec1.width < 1.0f) dstRec1.width = 1.0f;
|
||||
if (dstRec1.width > 300.0f) dstRec1.width = 300.0f;
|
||||
@ -72,43 +72,43 @@ public partial class Examples
|
||||
if (dstRecH.width < 1.0f) dstRecH.width = 1.0f;
|
||||
if (dstRecV.height < 1.0f) dstRecV.height = 1.0f;
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
BeginDrawing();
|
||||
|
||||
|
||||
ClearBackground(RAYWHITE);
|
||||
|
||||
|
||||
// Draw the n-patches
|
||||
DrawTextureNPatch(nPatchTexture, ninePatchInfo2, dstRec2, origin, 0.0f, WHITE);
|
||||
DrawTextureNPatch(nPatchTexture, ninePatchInfo1, dstRec1, origin, 0.0f, WHITE);
|
||||
DrawTextureNPatch(nPatchTexture, h3PatchInfo, dstRecH, origin, 0.0f, WHITE);
|
||||
DrawTextureNPatch(nPatchTexture, v3PatchInfo, dstRecV, origin, 0.0f, WHITE);
|
||||
|
||||
|
||||
// Draw the source texture
|
||||
DrawRectangleLines( 5, 88, 74, 266, BLUE);
|
||||
DrawTexture(nPatchTexture, 10, 93, WHITE);
|
||||
DrawText("TEXTURE", 15, 360, 10, DARKGRAY);
|
||||
|
||||
|
||||
DrawRectangle( 10, 10, 250, 73, Fade(SKYBLUE, 0.5));
|
||||
DrawRectangleLines( 10, 10, 250, 73, BLUE);
|
||||
|
||||
|
||||
DrawText("9-Patch and 3-Patch example", 20, 20, 10, BLACK);
|
||||
DrawText(" Move the mouse to stretch or", 40, 40, 10, DARKGRAY);
|
||||
DrawText(" shrink the n-patches.", 40, 60, 10, DARKGRAY);
|
||||
|
||||
|
||||
EndDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
|
||||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
UnloadTexture(nPatchTexture); // Texture unloading
|
||||
|
||||
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -15,46 +15,46 @@ public partial class textures_image_drawing
|
||||
* Copyright (c) 2016 Ramon Santamaria (@raysan5)
|
||||
*
|
||||
********************************************************************************************/
|
||||
|
||||
|
||||
|
||||
|
||||
public static int Main()
|
||||
{
|
||||
// Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
int screenWidth = 800;
|
||||
int screenHeight = 450;
|
||||
|
||||
|
||||
InitWindow(screenWidth, screenHeight, "raylib [textures] example - image drawing");
|
||||
|
||||
|
||||
// NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required)
|
||||
|
||||
|
||||
Image cat = LoadImage("resources/cat.png"); // Load image in CPU memory (RAM)
|
||||
ImageCrop(ref cat, new Rectangle( 100, 10, 280, 380 )); // Crop an image piece
|
||||
ImageFlipHorizontal(ref cat); // Flip cropped image horizontally
|
||||
ImageResize(ref cat, 150, 200); // Resize flipped-cropped image
|
||||
|
||||
|
||||
Image parrots = LoadImage("resources/parrots.png"); // Load image in CPU memory (RAM)
|
||||
|
||||
|
||||
// Draw one image over the other with a scaling of 1.5f
|
||||
ImageDraw(ref parrots, cat, new Rectangle( 0, 0, cat.width, cat.height ), new Rectangle( 30, 40, cat.width*1.5f, cat.height*1.5f ));
|
||||
ImageCrop(ref parrots, new Rectangle( 0, 50, parrots.width, parrots.height - 100 )); // Crop resulting image
|
||||
|
||||
|
||||
UnloadImage(cat); // Unload image from RAM
|
||||
|
||||
|
||||
// Load custom font for frawing on image
|
||||
Font font = LoadFont("resources/custom_jupiter_crash.png");
|
||||
|
||||
|
||||
// Draw over image using custom font
|
||||
ImageDrawTextEx(ref parrots, new Vector2( 300, 230 ), font, "PARROTS ref CAT", font.baseSize, -2, WHITE);
|
||||
|
||||
|
||||
UnloadFont(font); // Unload custom spritefont (already drawn used on image)
|
||||
|
||||
|
||||
Texture2D texture = LoadTextureFromImage(parrots); // Image converted to texture, uploaded to GPU memory (VRAM)
|
||||
UnloadImage(parrots); // Once image has been converted to texture and uploaded to VRAM, it can be unloaded from RAM
|
||||
|
||||
|
||||
SetTargetFPS(60);
|
||||
//---------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Main game loop
|
||||
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||
{
|
||||
@ -62,30 +62,30 @@ public partial class textures_image_drawing
|
||||
//----------------------------------------------------------------------------------
|
||||
// TODO: Update your variables here
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
BeginDrawing();
|
||||
|
||||
|
||||
ClearBackground(RAYWHITE);
|
||||
|
||||
|
||||
DrawTexture(texture, screenWidth/2 - texture.width/2, screenHeight/2 - texture.height/2 - 40, WHITE);
|
||||
DrawRectangleLines(screenWidth/2 - texture.width/2, screenHeight/2 - texture.height/2 - 40, texture.width, texture.height, DARKGRAY);
|
||||
|
||||
|
||||
DrawText("We are drawing only one texture from various images composed!", 240, 350, 10, DARKGRAY);
|
||||
DrawText("Source images have been cropped, scaled, flipped and copied one over the other.", 190, 370, 10, DARKGRAY);
|
||||
|
||||
|
||||
EndDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
|
||||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
UnloadTexture(texture); // Texture unloading
|
||||
|
||||
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -13,19 +13,19 @@ public partial class textures_image_generation
|
||||
* Copyright (c) 2O17 Wilhem Barbier (@nounoursheureux)
|
||||
*
|
||||
********************************************************************************************/
|
||||
|
||||
|
||||
|
||||
|
||||
public const int NUM_TEXTURES = 7;
|
||||
|
||||
|
||||
public static int Main()
|
||||
{
|
||||
// Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
int screenWidth = 800;
|
||||
int screenHeight = 450;
|
||||
|
||||
|
||||
InitWindow(screenWidth, screenHeight, "raylib [textures] example - procedural images generation");
|
||||
|
||||
|
||||
Image verticalGradient = GenImageGradientV(screenWidth, screenHeight, RED, BLUE);
|
||||
Image horizontalGradient = GenImageGradientH(screenWidth, screenHeight, RED, BLUE);
|
||||
Image radialGradient = GenImageGradientRadial(screenWidth, screenHeight, 0.0f, WHITE, BLACK);
|
||||
@ -33,7 +33,7 @@ public partial class textures_image_generation
|
||||
Image whiteNoise = GenImageWhiteNoise(screenWidth, screenHeight, 0.5f);
|
||||
Image perlinNoise = GenImagePerlinNoise(screenWidth, screenHeight, 50, 50, 4.0f);
|
||||
Image cellular = GenImageCellular(screenWidth, screenHeight, 32);
|
||||
|
||||
|
||||
Texture2D[] textures = new Texture2D[NUM_TEXTURES];
|
||||
textures[0] = LoadTextureFromImage(verticalGradient);
|
||||
textures[1] = LoadTextureFromImage(horizontalGradient);
|
||||
@ -42,7 +42,7 @@ public partial class textures_image_generation
|
||||
textures[4] = LoadTextureFromImage(whiteNoise);
|
||||
textures[5] = LoadTextureFromImage(perlinNoise);
|
||||
textures[6] = LoadTextureFromImage(cellular);
|
||||
|
||||
|
||||
// Unload image data (CPU RAM)
|
||||
UnloadImage(verticalGradient);
|
||||
UnloadImage(horizontalGradient);
|
||||
@ -51,12 +51,12 @@ public partial class textures_image_generation
|
||||
UnloadImage(whiteNoise);
|
||||
UnloadImage(perlinNoise);
|
||||
UnloadImage(cellular);
|
||||
|
||||
|
||||
int currentTexture = 0;
|
||||
|
||||
|
||||
SetTargetFPS(60);
|
||||
//---------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Main game loop
|
||||
while (!WindowShouldClose())
|
||||
{
|
||||
@ -67,19 +67,19 @@ public partial class textures_image_generation
|
||||
currentTexture = (currentTexture + 1)%NUM_TEXTURES; // Cycle between the textures
|
||||
}
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
BeginDrawing();
|
||||
|
||||
|
||||
ClearBackground(RAYWHITE);
|
||||
|
||||
|
||||
DrawTexture(textures[currentTexture], 0, 0, WHITE);
|
||||
|
||||
|
||||
DrawRectangle(30, 400, 325, 30, Fade(SKYBLUE, 0.5f));
|
||||
DrawRectangleLines(30, 400, 325, 30, Fade(WHITE, 0.5f));
|
||||
DrawText("MOUSE LEFT BUTTON to CYCLE PROCEDURAL TEXTURES", 40, 410, 10, WHITE);
|
||||
|
||||
|
||||
switch(currentTexture)
|
||||
{
|
||||
case 0: DrawText("VERTICAL GRADIENT", 560, 10, 20, RAYWHITE); break;
|
||||
@ -91,21 +91,21 @@ public partial class textures_image_generation
|
||||
case 6: DrawText("CELLULAR", 670, 10, 20, RAYWHITE); break;
|
||||
default: break;
|
||||
}
|
||||
|
||||
|
||||
EndDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
|
||||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Unload textures data (GPU VRAM)
|
||||
for (int i = 0; i < NUM_TEXTURES; i++) UnloadTexture(textures[i]);
|
||||
|
||||
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -15,25 +15,25 @@ public partial class textures_image_loading
|
||||
* Copyright (c) 2015 Ramon Santamaria (@raysan5)
|
||||
*
|
||||
********************************************************************************************/
|
||||
|
||||
|
||||
|
||||
|
||||
public static int Main()
|
||||
{
|
||||
// Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
int screenWidth = 800;
|
||||
int screenHeight = 450;
|
||||
|
||||
|
||||
InitWindow(screenWidth, screenHeight, "raylib [textures] example - image loading");
|
||||
|
||||
|
||||
// NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required)
|
||||
|
||||
|
||||
Image image = LoadImage("resources/raylib_logo.png"); // Loaded in CPU memory (RAM)
|
||||
Texture2D texture = LoadTextureFromImage(image); // Image converted to texture, GPU memory (VRAM)
|
||||
|
||||
|
||||
UnloadImage(image); // Once image has been converted to texture and uploaded to VRAM, it can be unloaded from RAM
|
||||
//---------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Main game loop
|
||||
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||
{
|
||||
@ -41,28 +41,28 @@ public partial class textures_image_loading
|
||||
//----------------------------------------------------------------------------------
|
||||
// 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 loaded from an image!", 300, 370, 10, GRAY);
|
||||
|
||||
|
||||
EndDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
|
||||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
UnloadTexture(texture); // Texture unloading
|
||||
|
||||
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -16,23 +16,23 @@ public partial class textures_image_processing
|
||||
* Copyright (c) 2016 Ramon Santamaria (@raysan5)
|
||||
*
|
||||
********************************************************************************************/
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public const int NUM_PROCESSES = 8;
|
||||
|
||||
|
||||
enum ImageProcess
|
||||
{
|
||||
NONE = 0,
|
||||
COLOR_GRAYSCALE,
|
||||
COLOR_TINT,
|
||||
COLOR_INVERT,
|
||||
COLOR_CONTRAST,
|
||||
COLOR_BRIGHTNESS,
|
||||
FLIP_VERTICAL,
|
||||
FLIP_HORIZONTAL
|
||||
{
|
||||
NONE = 0,
|
||||
COLOR_GRAYSCALE,
|
||||
COLOR_TINT,
|
||||
COLOR_INVERT,
|
||||
COLOR_CONTRAST,
|
||||
COLOR_BRIGHTNESS,
|
||||
FLIP_VERTICAL,
|
||||
FLIP_HORIZONTAL
|
||||
}
|
||||
|
||||
|
||||
static string[] processText = {
|
||||
"NO PROCESSING",
|
||||
"COLOR GRAYSCALE",
|
||||
@ -43,32 +43,32 @@ public partial class textures_image_processing
|
||||
"FLIP VERTICAL",
|
||||
"FLIP HORIZONTAL"
|
||||
};
|
||||
|
||||
|
||||
public static int Main()
|
||||
{
|
||||
// Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
int screenWidth = 800;
|
||||
int screenHeight = 450;
|
||||
|
||||
|
||||
InitWindow(screenWidth, screenHeight, "raylib [textures] example - image processing");
|
||||
|
||||
|
||||
// NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required)
|
||||
|
||||
|
||||
Image image = LoadImage("resources/parrots.png"); // Loaded in CPU memory (RAM)
|
||||
ImageFormat(ref image, (int)UNCOMPRESSED_R8G8B8A8); // Format image to RGBA 32bit (required for texture update) <-- ISSUE
|
||||
Texture2D texture = LoadTextureFromImage(image); // Image converted to texture, GPU memory (VRAM)
|
||||
|
||||
|
||||
int currentProcess = (int)ImageProcess.NONE;
|
||||
bool textureReload = false;
|
||||
|
||||
|
||||
Rectangle[] selectRecs = new Rectangle[NUM_PROCESSES];
|
||||
|
||||
|
||||
for (int i = 0; i < NUM_PROCESSES; i++) selectRecs[i] = new Rectangle( 40, 50 + 32*i, 150, 30 );
|
||||
|
||||
|
||||
SetTargetFPS(60);
|
||||
//---------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Main game loop
|
||||
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||
{
|
||||
@ -86,14 +86,14 @@ public partial class textures_image_processing
|
||||
if (currentProcess < 0) currentProcess = 7;
|
||||
textureReload = true;
|
||||
}
|
||||
|
||||
|
||||
if (textureReload)
|
||||
{
|
||||
UnloadImage(image); // Unload current image data
|
||||
image = LoadImage("resources/parrots.png"); // Re-load image data
|
||||
|
||||
// NOTE: Image processing is a costly CPU process to be done every frame,
|
||||
// If image processing is required in a frame-basis, it should be done
|
||||
|
||||
// NOTE: Image processing is a costly CPU process to be done every frame,
|
||||
// If image processing is required in a frame-basis, it should be done
|
||||
// with a texture and by shaders
|
||||
switch (currentProcess)
|
||||
{
|
||||
@ -106,23 +106,23 @@ public partial class textures_image_processing
|
||||
case (int)ImageProcess.FLIP_HORIZONTAL: ImageFlipHorizontal(ref image); break;
|
||||
default: break;
|
||||
}
|
||||
|
||||
|
||||
Color[] pixels = GetImageData(image); // Get pixel data from image (RGBA 32bit)
|
||||
UpdateTexture(texture, pixels); // Update texture with new image data
|
||||
// free(pixels); // Unload pixels data from RAM
|
||||
|
||||
|
||||
textureReload = false;
|
||||
}
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
BeginDrawing();
|
||||
|
||||
|
||||
ClearBackground(RAYWHITE);
|
||||
|
||||
|
||||
DrawText("IMAGE PROCESSING:", 40, 30, 10, DARKGRAY);
|
||||
|
||||
|
||||
// Draw rectangles
|
||||
for (int i = 0; i < NUM_PROCESSES; i++)
|
||||
{
|
||||
@ -130,22 +130,22 @@ public partial class textures_image_processing
|
||||
DrawRectangleLines((int)selectRecs[i].x, (int)selectRecs[i].y, (int)selectRecs[i].width, (int)selectRecs[i].height, (i == currentProcess) ? BLUE : GRAY);
|
||||
DrawText(processText[i], (int)(selectRecs[i].x + selectRecs[i].width/2 - MeasureText(processText[i], 10)/2), (int)selectRecs[i].y + 11, 10, (i == currentProcess) ? DARKBLUE : DARKGRAY);
|
||||
}
|
||||
|
||||
|
||||
DrawTexture(texture, screenWidth - texture.width - 60, screenHeight/2 - texture.height/2, WHITE);
|
||||
DrawRectangleLines(screenWidth - texture.width - 60, screenHeight/2 - texture.height/2, texture.width, texture.height, BLACK);
|
||||
|
||||
|
||||
EndDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
|
||||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
UnloadTexture(texture); // Unload texture from VRAM
|
||||
UnloadImage(image); // Unload image from RAM
|
||||
|
||||
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -13,35 +13,35 @@ public partial class textures_image_text
|
||||
* Copyright (c) 2017 Ramon Santamaria (@raysan5)
|
||||
*
|
||||
********************************************************************************************/
|
||||
|
||||
|
||||
|
||||
|
||||
public static int Main()
|
||||
{
|
||||
// Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
int screenWidth = 800;
|
||||
int screenHeight = 450;
|
||||
|
||||
|
||||
InitWindow(screenWidth, screenHeight, "raylib [texture] example - image text drawing");
|
||||
|
||||
|
||||
// TTF Font loading with custom generation parameters
|
||||
Font font = LoadFontEx("resources/KAISG.ttf", 64, 95, null);
|
||||
|
||||
|
||||
Image parrots = LoadImage("resources/parrots.png"); // Load image in CPU memory (RAM)
|
||||
|
||||
|
||||
// Draw over image using custom font
|
||||
ImageDrawTextEx(ref parrots, new Vector2( 20, 20 ), font, "[Parrots font drawing]", font.baseSize, 0, WHITE);
|
||||
|
||||
|
||||
Texture2D texture = LoadTextureFromImage(parrots); // Image converted to texture, uploaded to GPU memory (VRAM)
|
||||
UnloadImage(parrots); // Once image has been converted to texture and uploaded to VRAM, it can be unloaded from RAM
|
||||
|
||||
|
||||
Vector2 position = new Vector2( screenWidth/2 - texture.width/2, screenHeight/2 - texture.height/2 - 20 );
|
||||
|
||||
|
||||
bool showFont = false;
|
||||
|
||||
|
||||
SetTargetFPS(60);
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Main game loop
|
||||
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||
{
|
||||
@ -50,39 +50,39 @@ public partial class textures_image_text
|
||||
if (IsKeyDown(KEY_SPACE)) showFont = true;
|
||||
else showFont = false;
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
BeginDrawing();
|
||||
|
||||
|
||||
ClearBackground(RAYWHITE);
|
||||
|
||||
|
||||
if (!showFont)
|
||||
{
|
||||
// Draw texture with text already drawn inside
|
||||
DrawTextureV(texture, position, WHITE);
|
||||
|
||||
|
||||
// Draw text directly using sprite font
|
||||
DrawTextEx(font, "[Parrots font drawing]", new Vector2( position.x + 20,
|
||||
DrawTextEx(font, "[Parrots font drawing]", new Vector2( position.x + 20,
|
||||
position.y + 20 + 280 ), font.baseSize, 0, WHITE);
|
||||
}
|
||||
else DrawTexture(font.texture, screenWidth/2 - font.texture.width/2, 50, BLACK);
|
||||
|
||||
|
||||
DrawText("PRESS SPACE to SEE USED SPRITEFONT ", 290, 420, 10, DARKGRAY);
|
||||
|
||||
|
||||
EndDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
|
||||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
UnloadTexture(texture); // Texture unloading
|
||||
|
||||
|
||||
UnloadFont(font); // Unload custom spritefont
|
||||
|
||||
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -13,21 +13,21 @@ public partial class textures_logo_raylib
|
||||
* Copyright (c) 2014 Ramon Santamaria (@raysan5)
|
||||
*
|
||||
********************************************************************************************/
|
||||
|
||||
|
||||
|
||||
|
||||
public static int Main()
|
||||
{
|
||||
// Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
int screenWidth = 800;
|
||||
int screenHeight = 450;
|
||||
|
||||
|
||||
InitWindow(screenWidth, screenHeight, "raylib [textures] example - texture loading and drawing");
|
||||
|
||||
|
||||
// NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required)
|
||||
Texture2D texture = LoadTexture("resources/raylib_logo.png"); // Texture loading
|
||||
//---------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Main game loop
|
||||
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||
{
|
||||
@ -35,28 +35,28 @@ public partial class textures_logo_raylib
|
||||
//----------------------------------------------------------------------------------
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -14,8 +14,8 @@ public partial class textures_particles_blending
|
||||
* Copyright (c) 2017 Ramon Santamaria (@raysan5)
|
||||
*
|
||||
********************************************************************************************/
|
||||
|
||||
|
||||
|
||||
|
||||
public const int MAX_PARTICLES = 200;
|
||||
|
||||
// Particle structure with basic data
|
||||
@ -28,19 +28,19 @@ public partial class textures_particles_blending
|
||||
public float rotation;
|
||||
public bool active; // NOTE: Use it to activate/deactive particle
|
||||
}
|
||||
|
||||
|
||||
public static int Main()
|
||||
{
|
||||
// Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
int screenWidth = 800;
|
||||
int screenHeight = 450;
|
||||
|
||||
|
||||
InitWindow(screenWidth, screenHeight, "raylib [textures] example - particles blending");
|
||||
|
||||
|
||||
// Particles pool, reuse them!
|
||||
Particle[] mouseTail = new Particle[MAX_PARTICLES];
|
||||
|
||||
Particle[] mouseTail = new Particle[MAX_PARTICLES];
|
||||
|
||||
// Initialize particles
|
||||
for (int i = 0; i < MAX_PARTICLES; i++)
|
||||
{
|
||||
@ -51,22 +51,22 @@ public partial class textures_particles_blending
|
||||
mouseTail[i].rotation = GetRandomValue(0, 360);
|
||||
mouseTail[i].active = false;
|
||||
}
|
||||
|
||||
|
||||
float gravity = 3.0f;
|
||||
|
||||
|
||||
Texture2D smoke = LoadTexture("resources/smoke.png");
|
||||
|
||||
|
||||
int blending = (int)BLEND_ALPHA;
|
||||
|
||||
|
||||
SetTargetFPS(60);
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Main game loop
|
||||
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||
{
|
||||
// Update
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Activate one particle every frame and Update active particles
|
||||
// NOTE: Particles initial position should be mouse position when activated
|
||||
// NOTE: Particles fall down with gravity and rotation... and disappear after 2 seconds (alpha = 0)
|
||||
@ -81,62 +81,62 @@ public partial class textures_particles_blending
|
||||
i = MAX_PARTICLES;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for (int i = 0; i < MAX_PARTICLES; i++)
|
||||
{
|
||||
if (mouseTail[i].active)
|
||||
{
|
||||
mouseTail[i].position.y += gravity;
|
||||
mouseTail[i].alpha -= 0.01f;
|
||||
|
||||
|
||||
if (mouseTail[i].alpha <= 0.0f) mouseTail[i].active = false;
|
||||
|
||||
|
||||
mouseTail[i].rotation += 5.0f;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (IsKeyPressed(KEY_SPACE))
|
||||
{
|
||||
if (blending == (int)BLEND_ALPHA) blending = (int)BLEND_ADDITIVE;
|
||||
else blending = (int)BLEND_ALPHA;
|
||||
}
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
BeginDrawing();
|
||||
|
||||
|
||||
ClearBackground(DARKGRAY);
|
||||
|
||||
|
||||
BeginBlendMode(blending);
|
||||
|
||||
|
||||
// Draw active particles
|
||||
for (int i = 0; i < MAX_PARTICLES; i++)
|
||||
{
|
||||
if (mouseTail[i].active) DrawTexturePro(smoke, new Rectangle( 0, 0, smoke.width, smoke.height ),
|
||||
if (mouseTail[i].active) DrawTexturePro(smoke, new Rectangle( 0, 0, smoke.width, smoke.height ),
|
||||
new Rectangle( mouseTail[i].position.x, mouseTail[i].position.y, smoke.width*mouseTail[i].size, smoke.height*mouseTail[i].size ),
|
||||
new Vector2( smoke.width*mouseTail[i].size/2, smoke.height*mouseTail[i].size/2 ), mouseTail[i].rotation,
|
||||
Fade(mouseTail[i].color, mouseTail[i].alpha));
|
||||
}
|
||||
|
||||
|
||||
EndBlendMode();
|
||||
|
||||
|
||||
DrawText("PRESS SPACE to CHANGE BLENDING MODE", 180, 20, 20, BLACK);
|
||||
|
||||
|
||||
if (blending == (int)BLEND_ALPHA) DrawText("ALPHA BLENDING", 290, screenHeight - 40, 20, BLACK);
|
||||
else DrawText("ADDITIVE BLENDING", 280, screenHeight - 40, 20, RAYWHITE);
|
||||
|
||||
|
||||
EndDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
|
||||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
UnloadTexture(smoke);
|
||||
|
||||
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -16,33 +16,33 @@ public partial class textures_raw_data
|
||||
* Copyright (c) 2015 Ramon Santamaria (@raysan5)
|
||||
*
|
||||
********************************************************************************************/
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public static int Main()
|
||||
{
|
||||
// Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
int screenWidth = 800;
|
||||
int screenHeight = 450;
|
||||
|
||||
|
||||
InitWindow(screenWidth, screenHeight, "raylib [textures] example - texture from raw data");
|
||||
|
||||
|
||||
// NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required)
|
||||
|
||||
|
||||
// Load RAW image data (512x512, 32bit RGBA, no file header)
|
||||
Image fudesumiRaw = LoadImageRaw("resources/fudesumi.raw", 384, 512, (int)UNCOMPRESSED_R8G8B8A8, 0);
|
||||
Texture2D fudesumi = LoadTextureFromImage(fudesumiRaw); // Upload CPU (RAM) image to GPU (VRAM)
|
||||
UnloadImage(fudesumiRaw); // Unload CPU (RAM) image data
|
||||
|
||||
|
||||
// Generate a isChecked texture by code (1024x1024 pixels)
|
||||
int width = 1024;
|
||||
int height = 1024;
|
||||
|
||||
|
||||
// Dynamic memory allocation to store pixels data (Color type)
|
||||
// Color *pixels = (Color *)malloc(width*height*sizeof(Color));
|
||||
Color[] pixels = new Color[width*height];
|
||||
|
||||
|
||||
for (int y = 0; y < height; y++)
|
||||
{
|
||||
for (int x = 0; x < width; x++)
|
||||
@ -51,16 +51,16 @@ public partial class textures_raw_data
|
||||
else pixels[y*height + x] = GOLD;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Load pixels data into an image structure and create texture
|
||||
Image isCheckedIm = LoadImageEx(pixels, width, height);
|
||||
Texture2D isChecked = LoadTextureFromImage(isCheckedIm);
|
||||
UnloadImage(isCheckedIm); // Unload CPU (RAM) image data
|
||||
|
||||
|
||||
// Dynamic memory must be freed after using it
|
||||
// free(pixels); // Unload CPU (RAM) pixels data
|
||||
//---------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Main game loop
|
||||
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||
{
|
||||
@ -68,34 +68,34 @@ public partial class textures_raw_data
|
||||
//----------------------------------------------------------------------------------
|
||||
// TODO: Update your variables here
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
BeginDrawing();
|
||||
|
||||
|
||||
ClearBackground(RAYWHITE);
|
||||
|
||||
|
||||
DrawTexture(isChecked, screenWidth/2 - isChecked.width/2, screenHeight/2 - isChecked.height/2, Fade(WHITE, 0.5f));
|
||||
DrawTexture(fudesumi, 430, -30, WHITE);
|
||||
|
||||
|
||||
DrawText("CHECKED TEXTURE ", 84, 100, 30, BROWN);
|
||||
DrawText("GENERATED by CODE", 72, 164, 30, BROWN);
|
||||
DrawText("and RAW IMAGE LOADING", 46, 226, 30, BROWN);
|
||||
|
||||
|
||||
DrawText("(c) Fudesumi sprite by Eiden Marsal", 310, screenHeight - 20, 10, BROWN);
|
||||
|
||||
|
||||
EndDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
|
||||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
UnloadTexture(fudesumi); // Texture unloading
|
||||
UnloadTexture(isChecked); // Texture unloading
|
||||
|
||||
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -13,92 +13,92 @@ public partial class textures_rectangle
|
||||
* Copyright (c) 2014 Ramon Santamaria (@raysan5)
|
||||
*
|
||||
********************************************************************************************/
|
||||
|
||||
|
||||
|
||||
|
||||
public const int MAX_FRAME_SPEED = 15;
|
||||
public const int MIN_FRAME_SPEED = 1;
|
||||
|
||||
|
||||
public static int Main()
|
||||
{
|
||||
// Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
int screenWidth = 800;
|
||||
int screenHeight = 450;
|
||||
|
||||
|
||||
InitWindow(screenWidth, screenHeight, "raylib [texture] example - texture rectangle");
|
||||
|
||||
|
||||
// NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required)
|
||||
Texture2D scarfy = LoadTexture("resources/scarfy.png"); // Texture loading
|
||||
|
||||
|
||||
Vector2 position = new Vector2( 350.0f, 280.0f );
|
||||
Rectangle frameRec = new Rectangle( 0.0f, 0.0f, (float)scarfy.width/6, (float)scarfy.height );
|
||||
int currentFrame = 0;
|
||||
|
||||
|
||||
int framesCounter = 0;
|
||||
int framesSpeed = 8; // Number of spritesheet frames shown by second
|
||||
|
||||
|
||||
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
|
||||
//----------------------------------------------------------------------------------
|
||||
framesCounter++;
|
||||
|
||||
|
||||
if (framesCounter >= (60/framesSpeed))
|
||||
{
|
||||
framesCounter = 0;
|
||||
currentFrame++;
|
||||
|
||||
|
||||
if (currentFrame > 5) currentFrame = 0;
|
||||
|
||||
|
||||
frameRec.x = (float)currentFrame*(float)scarfy.width/6;
|
||||
}
|
||||
|
||||
|
||||
if (IsKeyPressed(KEY_RIGHT)) framesSpeed++;
|
||||
else if (IsKeyPressed(KEY_LEFT)) framesSpeed--;
|
||||
|
||||
|
||||
if (framesSpeed > MAX_FRAME_SPEED) framesSpeed = MAX_FRAME_SPEED;
|
||||
else if (framesSpeed < MIN_FRAME_SPEED) framesSpeed = MIN_FRAME_SPEED;
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
BeginDrawing();
|
||||
|
||||
|
||||
ClearBackground(RAYWHITE);
|
||||
|
||||
|
||||
DrawTexture(scarfy, 15, 40, WHITE);
|
||||
DrawRectangleLines(15, 40, scarfy.width, scarfy.height, LIME);
|
||||
DrawRectangleLines(15 + (int)frameRec.x, 40 + (int)frameRec.y, (int)frameRec.width, (int)frameRec.height, RED);
|
||||
|
||||
|
||||
DrawText("FRAME SPEED: ", 165, 210, 10, DARKGRAY);
|
||||
DrawText(FormatText("%02i FPS", framesSpeed), 575, 210, 10, DARKGRAY);
|
||||
DrawText("PRESS RIGHT/LEFT KEYS to CHANGE SPEED!", 290, 240, 10, DARKGRAY);
|
||||
|
||||
|
||||
for (int i = 0; i < MAX_FRAME_SPEED; i++)
|
||||
{
|
||||
if (i < framesSpeed) DrawRectangle(250 + 21*i, 205, 20, 20, RED);
|
||||
DrawRectangleLines(250 + 21*i, 205, 20, 20, MAROON);
|
||||
}
|
||||
|
||||
|
||||
DrawTextureRec(scarfy, frameRec, position, WHITE); // Draw part of the texture
|
||||
|
||||
|
||||
DrawText("(c) Scarfy sprite by Eiden Marsal", screenWidth - 200, screenHeight - 20, 10, GRAY);
|
||||
|
||||
|
||||
EndDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
|
||||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
UnloadTexture(scarfy); // Texture unloading
|
||||
|
||||
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -13,37 +13,37 @@ public partial class textures_srcrec_dstrec
|
||||
* Copyright (c) 2015 Ramon Santamaria (@raysan5)
|
||||
*
|
||||
********************************************************************************************/
|
||||
|
||||
|
||||
|
||||
|
||||
public static int Main()
|
||||
{
|
||||
// Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
int screenWidth = 800;
|
||||
int screenHeight = 450;
|
||||
|
||||
|
||||
InitWindow(screenWidth, screenHeight, "raylib [textures] examples - texture source and destination rectangles");
|
||||
|
||||
|
||||
// NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required)
|
||||
Texture2D scarfy = LoadTexture("resources/scarfy.png"); // Texture loading
|
||||
|
||||
|
||||
int frameWidth = scarfy.width/6;
|
||||
int frameHeight = scarfy.height;
|
||||
|
||||
|
||||
// NOTE: Source rectangle (part of the texture to use for drawing)
|
||||
Rectangle sourceRec = new Rectangle( 0, 0, frameWidth, frameHeight );
|
||||
|
||||
|
||||
// NOTE: Destination rectangle (screen rectangle where drawing part of texture)
|
||||
Rectangle destRec = new Rectangle( screenWidth/2, screenHeight/2, frameWidth*2, frameHeight*2 );
|
||||
|
||||
|
||||
// NOTE: Origin of the texture (rotation/scale point), it's relative to destination rectangle size
|
||||
Vector2 origin = new Vector2( frameWidth, frameHeight );
|
||||
|
||||
|
||||
int rotation = 0;
|
||||
|
||||
|
||||
SetTargetFPS(60);
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Main game loop
|
||||
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||
{
|
||||
@ -51,36 +51,36 @@ public partial class textures_srcrec_dstrec
|
||||
//----------------------------------------------------------------------------------
|
||||
rotation++;
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
BeginDrawing();
|
||||
|
||||
|
||||
ClearBackground(RAYWHITE);
|
||||
|
||||
|
||||
// NOTE: Using DrawTexturePro() we can easily rotate and scale the part of the texture we draw
|
||||
// sourceRec defines the part of the texture we use for drawing
|
||||
// destRec defines the rectangle where our texture part will fit (scaling it to fit)
|
||||
// origin defines the point of the texture used as reference for rotation and scaling
|
||||
// rotation defines the texture rotation (using origin as rotation point)
|
||||
DrawTexturePro(scarfy, sourceRec, destRec, origin, rotation, WHITE);
|
||||
|
||||
|
||||
DrawLine((int)destRec.x, 0, (int)destRec.x, screenHeight, GRAY);
|
||||
DrawLine(0, (int)destRec.y, screenWidth, (int)destRec.y, GRAY);
|
||||
|
||||
|
||||
DrawText("(c) Scarfy sprite by Eiden Marsal", screenWidth - 200, screenHeight - 20, 10, GRAY);
|
||||
|
||||
|
||||
EndDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
|
||||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
UnloadTexture(scarfy); // Texture unloading
|
||||
|
||||
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -5,7 +5,7 @@ public partial class textures_to_image
|
||||
{
|
||||
/*******************************************************************************************
|
||||
*
|
||||
* raylib [textures] example - Retrieve image data from texture: GetTextureData()
|
||||
* raylib [textures] example - Retrieve image data from texture: GetTextureData()
|
||||
*
|
||||
* NOTE: Images are loaded in CPU memory (RAM); textures are loaded in GPU memory (VRAM)
|
||||
*
|
||||
@ -15,30 +15,30 @@ public partial class textures_to_image
|
||||
* Copyright (c) 2015 Ramon Santamaria (@raysan5)
|
||||
*
|
||||
********************************************************************************************/
|
||||
|
||||
|
||||
|
||||
|
||||
public static int Main()
|
||||
{
|
||||
// Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
int screenWidth = 800;
|
||||
int screenHeight = 450;
|
||||
|
||||
|
||||
InitWindow(screenWidth, screenHeight, "raylib [textures] example - texture to image");
|
||||
|
||||
|
||||
// NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required)
|
||||
|
||||
|
||||
Image image = LoadImage("resources/raylib_logo.png"); // Load image data into CPU memory (RAM)
|
||||
Texture2D texture = LoadTextureFromImage(image); // Image converted to texture, GPU memory (RAM -> VRAM)
|
||||
UnloadImage(image); // Unload image data from CPU memory (RAM)
|
||||
|
||||
|
||||
image = GetTextureData(texture); // Retrieve image data from GPU memory (VRAM -> RAM)
|
||||
UnloadTexture(texture); // Unload texture from GPU memory (VRAM)
|
||||
|
||||
|
||||
texture = LoadTextureFromImage(image); // Recreate texture from retrieved image data (RAM -> VRAM)
|
||||
UnloadImage(image); // Unload retrieved image data from CPU memory (RAM)
|
||||
//---------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Main game loop
|
||||
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||
{
|
||||
@ -46,28 +46,28 @@ public partial class textures_to_image
|
||||
//----------------------------------------------------------------------------------
|
||||
// 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 loaded from an image!", 300, 370, 10, GRAY);
|
||||
|
||||
|
||||
EndDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
|
||||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
UnloadTexture(texture); // Texture unloading
|
||||
|
||||
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user