2
0
mirror of https://github.com/raylib-cs/raylib-cs synced 2025-04-17 15:04:44 -04:00

Fixed trailing whitespace

- Removed trailing whitespace from bindings and examples.
This commit is contained in:
ChrisDill 2018-10-24 12:41:55 +01:00
parent 01ec64945c
commit 527bf58521
75 changed files with 1671 additions and 1697 deletions

View File

@ -1,9 +1,4 @@
/********************************************************************************************** // Easings - https://github.com/raysan5/raylib/blob/master/src/easings.h
*
* Raylib easings bindings
* Original - https://github.com/raysan5/raylib/blob/master/src/easings.h
*
**********************************************************************************************/
using System; using System;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
@ -13,94 +8,94 @@ namespace Raylib
public static partial class Raylib public static partial class Raylib
{ {
#region Raylib-cs Functions #region Raylib-cs Functions
// Linear Easing functions // Linear Easing functions
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern float EaseLinearNone(float t, float b, float c, float d); public static extern float EaseLinearNone(float t, float b, float c, float d);
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern float EaseLinearIn(float t, float b, float c, float d); public static extern float EaseLinearIn(float t, float b, float c, float d);
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern float EaseLinearOut(float t, float b, float c, float d); public static extern float EaseLinearOut(float t, float b, float c, float d);
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern float EaseLinearInOut(float t, float b, float c, float d); public static extern float EaseLinearInOut(float t, float b, float c, float d);
// Sine Easing functions // Sine Easing functions
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern float EaseSineIn(float t, float b, float c, float d); public static extern float EaseSineIn(float t, float b, float c, float d);
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern float EaseSineOut(float t, float b, float c, float d); public static extern float EaseSineOut(float t, float b, float c, float d);
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern float EaseSineInOut(float t, float b, float c, float d); public static extern float EaseSineInOut(float t, float b, float c, float d);
// Circular Easing functions // Circular Easing functions
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern float EaseCircIn(float t, float b, float c, float d); public static extern float EaseCircIn(float t, float b, float c, float d);
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern float EaseCircOut(float t, float b, float c, float d); public static extern float EaseCircOut(float t, float b, float c, float d);
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern float EaseCircInOut(float t, float b, float c, float d); public static extern float EaseCircInOut(float t, float b, float c, float d);
// Cubic Easing functions // Cubic Easing functions
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern float EaseCubicIn(float t, float b, float c, float d); public static extern float EaseCubicIn(float t, float b, float c, float d);
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern float EaseCubicOut(float t, float b, float c, float d); public static extern float EaseCubicOut(float t, float b, float c, float d);
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern float EaseCubicInOut(float t, float b, float c, float d); public static extern float EaseCubicInOut(float t, float b, float c, float d);
// Quadratic Easing functions // Quadratic Easing functions
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern float EaseQuadIn(float t, float b, float c, float d); public static extern float EaseQuadIn(float t, float b, float c, float d);
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern float EaseQuadOut(float t, float b, float c, float d); public static extern float EaseQuadOut(float t, float b, float c, float d);
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern float EaseQuadInOut(float t, float b, float c, float d); public static extern float EaseQuadInOut(float t, float b, float c, float d);
// Exponential Easing functions // Exponential Easing functions
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern float EaseExpoIn(float t, float b, float c, float d); public static extern float EaseExpoIn(float t, float b, float c, float d);
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern float EaseExpoOut(float t, float b, float c, float d); public static extern float EaseExpoOut(float t, float b, float c, float d);
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern float EaseExpoInOut(float t, float b, float c, float d); public static extern float EaseExpoInOut(float t, float b, float c, float d);
// Back Easing functions // Back Easing functions
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern float EaseBackIn(float t, float b, float c, float d); public static extern float EaseBackIn(float t, float b, float c, float d);
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern float EaseBackOut(float t, float b, float c, float d); public static extern float EaseBackOut(float t, float b, float c, float d);
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern float EaseBackInOut(float t, float b, float c, float d); public static extern float EaseBackInOut(float t, float b, float c, float d);
// Bounce Easing functions // Bounce Easing functions
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern float EaseBounceOut(float t, float b, float c, float d); public static extern float EaseBounceOut(float t, float b, float c, float d);
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern float EaseBounceIn(float t, float b, float c, float d); public static extern float EaseBounceIn(float t, float b, float c, float d);
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern float EaseBounceInOut(float t, float b, float c, float d); public static extern float EaseBounceInOut(float t, float b, float c, float d);
// Elastic Easing functions // Elastic Easing functions
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern float EaseElasticIn(float t, float b, float c, float d); public static extern float EaseElasticIn(float t, float b, float c, float d);
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern float EaseElasticOut(float t, float b, float c, float d); 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); public static extern float EaseElasticInOut(float t, float b, float c, float d);
#endregion #endregion
} }
} }

View File

@ -1,9 +1,4 @@
/********************************************************************************************** // Physac - https://github.com/raysan5/raylib/blob/master/src/physac.h
*
* Physac
* Original -https://github.com/raysan5/raylib/blob/master/src/physac.h
*
**********************************************************************************************/
using System; using System;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
@ -37,11 +32,13 @@ namespace Raylib
{ {
public uint vertexCount; // Current used vertex and normals count public uint vertexCount; // Current used vertex and normals count
[MarshalAs(UnmanagedType.ByValArray, ArraySubType = UnmanagedType.Struct, SizeConst = Raylib.PHYSAC_MAX_VERTICES)] //[MarshalAs(UnmanagedType.ByValArray, ArraySubType = UnmanagedType.Struct, SizeConst = Raylib.PHYSAC_MAX_VERTICES)]
public Vector2[] positions; // Polygon vertex positions vectors //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 //[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)] [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
@ -79,17 +76,18 @@ namespace Raylib
} }
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
public struct PhysicsManifoldData public unsafe struct PhysicsManifoldData
{ {
public uint id; // Reference unique identifier public uint id; // Reference unique identifier
public PhysicsBodyData bodyA; // Manifold first physics body reference public PhysicsBodyData bodyA; // Manifold first physics body reference
public PhysicsBodyData bodyB; // Manifold second physics body reference public PhysicsBodyData bodyB; // Manifold second physics body reference
public float penetration; // Depth of penetration from collision public float penetration; // Depth of penetration from collision
public Vector2 normal; // Normal direction vector from 'a' to 'b' public Vector2 normal; // Normal direction vector from 'a' to 'b'
[MarshalAs(UnmanagedType.ByValArray, ArraySubType = UnmanagedType.Struct, SizeConst = 2)] //[MarshalAs(UnmanagedType.ByValArray, ArraySubType = UnmanagedType.Struct, SizeConst = 2)]
public Vector2[] contacts; // Points of contact during collision // public fixed Vector2[] contacts; // Points of contact during collision
public unsafe Vector2* contacts;
public uint contactsCount; // Current collision number of contacts public uint contactsCount; // Current collision number of contacts
public float restitution; // Mixed restitution during collision public float restitution; // Mixed restitution during collision
public float dynamicFriction; // Mixed dynamic friction during collision public float dynamicFriction; // Mixed dynamic friction during collision
@ -120,19 +118,23 @@ namespace Raylib
#endregion #endregion
#region Raylib-cs Functions #region Raylib-cs Functions
// Initializes physics values, pointers and creates physics loop thread // Initializes physics values, pointers and creates physics loop thread
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)] [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 // Returns true if physics thread is currently enabled
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern bool IsPhysicsEnabled(); public static extern bool IsPhysicsEnabled();
// Sets physics global gravity force // Sets physics global gravity force
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)] [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 // Creates a new circle physics body with generic parameters
[DllImport(nativeLibName, EntryPoint = "CreatePhysicsBodyCircle")] [DllImport(nativeLibName, EntryPoint = "CreatePhysicsBodyCircle")]
@ -167,23 +169,23 @@ namespace Raylib
// Adds a force to a physics body // Adds a force to a physics body
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)] [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 // Adds an angular force to a physics body
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)] [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 // Shatters a polygon shape physics body to little physics bodies with explosion force
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)] [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 // Returns the current amount of created physics bodies
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)] [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 // Returns a physics body of the bodies pool at a specific index
[DllImport(nativeLibName, EntryPoint = "GetPhysicsBody")] [DllImport(nativeLibName, EntryPoint = "GetPhysicsBody")]
public static extern IntPtr GetPhysicsBodyImport(int index); public static extern IntPtr GetPhysicsBodyImport(int index);
public static PhysicsBodyData GetPhysicsBody(int index) public static PhysicsBodyData GetPhysicsBody(int index)
{ {
var body = GetPhysicsBodyImport(index); var body = GetPhysicsBodyImport(index);
@ -193,33 +195,32 @@ namespace Raylib
// Returns the physics body shape type (PHYSICS_CIRCLE or PHYSICS_POLYGON) // Returns the physics body shape type (PHYSICS_CIRCLE or PHYSICS_POLYGON)
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)] [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 // Returns the amount of vertices of a physics body shape
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)] [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) // Returns transformed position of a body shape (body position + vertex transformed position)
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)] [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 // Sets physics body shape transform based on radians parameter
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)] [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 // Unitializes and destroy a physics body
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)] [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 // Destroys created physics bodies and manifolds and resets global values
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern void ResetPhysics(); public static extern void ResetPhysics();
// Unitializes physics pointers and closes physics loop thread // Unitializes physics pointers and closes physics loop thread
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern void ClosePhysics(); public static extern void ClosePhysics();
#endregion #endregion
} }
} }

View File

@ -1,9 +1,4 @@
/********************************************************************************************** // Raygui - https://github.com/raysan5/raygui/blob/master/src/raygui.h
*
* Raygui
* Original - https://github.com/raysan5/raygui/blob/master/src/raygui.h
*
**********************************************************************************************/
using System; using System;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;

View File

@ -1,9 +1,5 @@
/********************************************************************************************** // Raylib - https://github.com/raysan5/raylib/blob/master/src/raylib.h
*
* 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
*
**********************************************************************************************/
using System; using System;
using System.IO; using System.IO;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
@ -186,7 +182,7 @@ namespace Raylib
NPT_9PATCH = 0, // 3x3 NPT_9PATCH = 0, // 3x3
NPT_3PATCH_VERTICAL, // 1x3 NPT_3PATCH_VERTICAL, // 1x3
NPT_3PATCH_HORIZONTAL // 3x1 NPT_3PATCH_HORIZONTAL // 3x1
} }
// enum extension for constants // enum extension for constants
// Keyboard Function Keys // Keyboard Function Keys
@ -933,7 +929,7 @@ namespace Raylib
#endregion #endregion
#region Raylib-cs Functions #region Raylib-cs Functions
//------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------
// Window and Graphics Device Functions (Module: core) // Window and Graphics Device Functions (Module: core)
@ -1354,7 +1350,7 @@ namespace Raylib
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern int GetTouchPointsCount(); public static extern int GetTouchPointsCount();
// Get gesture hold time in milliseconds // Get gesture hold time in milliseconds
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern float GetGestureHoldDuration(); public static extern float GetGestureHoldDuration();
@ -2396,7 +2392,7 @@ namespace Raylib
// Set pitch for audio stream (1.0 is base level) // Set pitch for audio stream (1.0 is base level)
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern void SetAudioStreamPitch(AudioStream stream, float pitch); public static extern void SetAudioStreamPitch(AudioStream stream, float pitch);
#endregion #endregion
} }
} }

View File

@ -1,9 +1,4 @@
/********************************************************************************************** // Raymath - https://github.com/raysan5/raylib/blob/master/src/raymath.h
*
* Raymath v1.2 bindings - Math functions to work with Vector3, Matrix and Quaternions
* Original - https://github.com/raysan5/raylib/blob/master/src/raymath.h
*
**********************************************************************************************/
using System; using System;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;

View File

@ -1,9 +1,4 @@
/********************************************************************************************** // Rlgl - https://github.com/raysan5/raylib/blob/master/src/rlgl.h
*
* Rlgl
* Original - https://github.com/raysan5/raylib/blob/master/src/rlgl.h
*
**********************************************************************************************/
using System; using System;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
@ -28,6 +23,5 @@ namespace Raylib
#region Raylib-cs Functions #region Raylib-cs Functions
#endregion #endregion
} }
} }

View File

@ -15,8 +15,7 @@ public partial class audio_module_playing
* Copyright (c) 2016 Ramon Santamaria (@raysan5) * Copyright (c) 2016 Ramon Santamaria (@raysan5)
* *
********************************************************************************************/ ********************************************************************************************/
public const int MAX_CIRCLES = 64; public const int MAX_CIRCLES = 64;
struct CircleWave struct CircleWave
@ -27,26 +26,26 @@ public partial class audio_module_playing
public float speed; public float speed;
public Color color; public Color color;
} }
public static int Main() public static int Main()
{ {
// Initialization // Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
int screenWidth = 800; int screenWidth = 800;
int screenHeight = 450; int screenHeight = 450;
SetConfigFlags(FLAG_MSAA_4X_HINT); // NOTE: Try to enable MSAA 4X SetConfigFlags(FLAG_MSAA_4X_HINT); // NOTE: Try to enable MSAA 4X
InitWindow(screenWidth, screenHeight, "raylib [audio] example - module playing (streaming)"); InitWindow(screenWidth, screenHeight, "raylib [audio] example - module playing (streaming)");
InitAudioDevice(); // Initialize audio device InitAudioDevice(); // Initialize audio device
Color[] colors = new Color[14] { ORANGE, RED, GOLD, LIME, BLUE, VIOLET, BROWN, LIGHTGRAY, PINK, Color[] colors = new Color[14] { ORANGE, RED, GOLD, LIME, BLUE, VIOLET, BROWN, LIGHTGRAY, PINK,
YELLOW, GREEN, SKYBLUE, PURPLE, BEIGE }; YELLOW, GREEN, SKYBLUE, PURPLE, BEIGE };
// Creates ome circles for visual effect // Creates ome circles for visual effect
CircleWave[] circles = new CircleWave[MAX_CIRCLES]; CircleWave[] circles = new CircleWave[MAX_CIRCLES];
for (int i = MAX_CIRCLES - 1; i >= 0; i--) for (int i = MAX_CIRCLES - 1; i >= 0; i--)
{ {
circles[i].alpha = 0.0f; 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].speed = (float)GetRandomValue(1, 100)/20000.0f;
circles[i].color = colors[GetRandomValue(0, 13)]; circles[i].color = colors[GetRandomValue(0, 13)];
} }
var xm = LoadMusicStream("resources/mini1111.xm"); var xm = LoadMusicStream("resources/mini1111.xm");
PlayMusicStream(xm); PlayMusicStream(xm);
float timePlayed = 0.0f; float timePlayed = 0.0f;
bool pause = false; bool pause = false;
SetTargetFPS(60); // Set our game to run at 60 frames-per-second SetTargetFPS(60); // Set our game to run at 60 frames-per-second
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
// Main game loop // Main game loop
while (!WindowShouldClose()) // Detect window close button or ESC key while (!WindowShouldClose()) // Detect window close button or ESC key
{ {
// Update // Update
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
UpdateMusicStream(xm); // Update music buffer with new stream data UpdateMusicStream(xm); // Update music buffer with new stream data
// Restart music playing (stop and play) // Restart music playing (stop and play)
if (IsKeyPressed(KEY_SPACE)) if (IsKeyPressed(KEY_SPACE))
{ {
StopMusicStream(xm); StopMusicStream(xm);
PlayMusicStream(xm); PlayMusicStream(xm);
} }
// Pause/Resume music playing // Pause/Resume music playing
if (IsKeyPressed(KEY_P)) if (IsKeyPressed(KEY_P))
{ {
pause = !pause; pause = !pause;
if (pause) PauseMusicStream(xm); if (pause) PauseMusicStream(xm);
else ResumeMusicStream(xm); else ResumeMusicStream(xm);
} }
// Get timePlayed scaled to bar dimensions // Get timePlayed scaled to bar dimensions
timePlayed = GetMusicTimePlayed(xm)/GetMusicTimeLength(xm)*(screenWidth - 40); timePlayed = GetMusicTimePlayed(xm)/GetMusicTimeLength(xm)*(screenWidth - 40);
// Color circles animation // Color circles animation
for (int i = MAX_CIRCLES - 1; (i >= 0) && !pause; i--) for (int i = MAX_CIRCLES - 1; (i >= 0) && !pause; i--)
{ {
circles[i].alpha += circles[i].speed; circles[i].alpha += circles[i].speed;
circles[i].radius += circles[i].speed*10.0f; circles[i].radius += circles[i].speed*10.0f;
if (circles[i].alpha > 1.0f) circles[i].speed *= -1; if (circles[i].alpha > 1.0f) circles[i].speed *= -1;
if (circles[i].alpha <= 0.0f) if (circles[i].alpha <= 0.0f)
{ {
circles[i].alpha = 0.0f; circles[i].alpha = 0.0f;
@ -112,36 +111,36 @@ public partial class audio_module_playing
} }
} }
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// Draw // Draw
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
BeginDrawing(); BeginDrawing();
ClearBackground(RAYWHITE); ClearBackground(RAYWHITE);
for (int i = MAX_CIRCLES - 1; i >= 0; i--) for (int i = MAX_CIRCLES - 1; i >= 0; i--)
{ {
DrawCircleV(circles[i].position, circles[i].radius, Fade(circles[i].color, circles[i].alpha)); DrawCircleV(circles[i].position, circles[i].radius, Fade(circles[i].color, circles[i].alpha));
} }
// Draw time bar // Draw time bar
DrawRectangle(20, screenHeight - 20 - 12, screenWidth - 40, 12, LIGHTGRAY); DrawRectangle(20, screenHeight - 20 - 12, screenWidth - 40, 12, LIGHTGRAY);
DrawRectangle(20, screenHeight - 20 - 12, (int)timePlayed, 12, MAROON); DrawRectangle(20, screenHeight - 20 - 12, (int)timePlayed, 12, MAROON);
DrawRectangleLines(20, screenHeight - 20 - 12, screenWidth - 40, 12, GRAY); DrawRectangleLines(20, screenHeight - 20 - 12, screenWidth - 40, 12, GRAY);
EndDrawing(); EndDrawing();
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
} }
// De-Initialization // De-Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
UnloadMusicStream(xm); // Unload music stream buffers from RAM UnloadMusicStream(xm); // Unload music stream buffers from RAM
CloseAudioDevice(); // Close audio device (music streaming is automatically stopped) CloseAudioDevice(); // Close audio device (music streaming is automatically stopped)
CloseWindow(); // Close window and OpenGL context CloseWindow(); // Close window and OpenGL context
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
return 0; return 0;
} }
} }

View File

@ -15,84 +15,84 @@ public partial class audio_music_stream
* Copyright (c) 2015 Ramon Santamaria (@raysan5) * Copyright (c) 2015 Ramon Santamaria (@raysan5)
* *
********************************************************************************************/ ********************************************************************************************/
public static int Main() public static int Main()
{ {
// Initialization // Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
int screenWidth = 800; int screenWidth = 800;
int screenHeight = 450; int screenHeight = 450;
InitWindow(screenWidth, screenHeight, "raylib [audio] example - music playing (streaming)"); InitWindow(screenWidth, screenHeight, "raylib [audio] example - music playing (streaming)");
InitAudioDevice(); // Initialize audio device InitAudioDevice(); // Initialize audio device
var music = LoadMusicStream("resources/guitar_noodling.ogg"); var music = LoadMusicStream("resources/guitar_noodling.ogg");
PlayMusicStream(music); PlayMusicStream(music);
float timePlayed = 0.0f; float timePlayed = 0.0f;
bool pause = false; bool pause = false;
SetTargetFPS(60); // Set our game to run at 60 frames-per-second SetTargetFPS(60); // Set our game to run at 60 frames-per-second
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
// Main game loop // Main game loop
while (!WindowShouldClose()) // Detect window close button or ESC key while (!WindowShouldClose()) // Detect window close button or ESC key
{ {
// Update // Update
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
UpdateMusicStream(music); // Update music buffer with new stream data UpdateMusicStream(music); // Update music buffer with new stream data
// Restart music playing (stop and play) // Restart music playing (stop and play)
if (IsKeyPressed(KEY_SPACE)) if (IsKeyPressed(KEY_SPACE))
{ {
StopMusicStream(music); StopMusicStream(music);
PlayMusicStream(music); PlayMusicStream(music);
} }
// Pause/Resume music playing // Pause/Resume music playing
if (IsKeyPressed(KEY_P)) if (IsKeyPressed(KEY_P))
{ {
pause = !pause; pause = !pause;
if (pause) PauseMusicStream(music); if (pause) PauseMusicStream(music);
else ResumeMusicStream(music); else ResumeMusicStream(music);
} }
// Get timePlayed scaled to bar dimensions (400 pixels) // Get timePlayed scaled to bar dimensions (400 pixels)
timePlayed = GetMusicTimePlayed(music)/GetMusicTimeLength(music)*400; timePlayed = GetMusicTimePlayed(music)/GetMusicTimeLength(music)*400;
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// Draw // Draw
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
BeginDrawing(); BeginDrawing();
ClearBackground(RAYWHITE); ClearBackground(RAYWHITE);
DrawText("MUSIC SHOULD BE PLAYING!", 255, 150, 20, LIGHTGRAY); DrawText("MUSIC SHOULD BE PLAYING!", 255, 150, 20, LIGHTGRAY);
DrawRectangle(200, 200, 400, 12, LIGHTGRAY); DrawRectangle(200, 200, 400, 12, LIGHTGRAY);
DrawRectangle(200, 200, (int)timePlayed, 12, MAROON); DrawRectangle(200, 200, (int)timePlayed, 12, MAROON);
DrawRectangleLines(200, 200, 400, 12, GRAY); DrawRectangleLines(200, 200, 400, 12, GRAY);
DrawText("PRESS SPACE TO RESTART MUSIC", 215, 250, 20, LIGHTGRAY); DrawText("PRESS SPACE TO RESTART MUSIC", 215, 250, 20, LIGHTGRAY);
DrawText("PRESS P TO PAUSE/RESUME MUSIC", 208, 280, 20, LIGHTGRAY); DrawText("PRESS P TO PAUSE/RESUME MUSIC", 208, 280, 20, LIGHTGRAY);
EndDrawing(); EndDrawing();
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
} }
// De-Initialization // De-Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
UnloadMusicStream(music); // Unload music stream buffers from RAM UnloadMusicStream(music); // Unload music stream buffers from RAM
CloseAudioDevice(); // Close audio device (music streaming is automatically stopped) CloseAudioDevice(); // Close audio device (music streaming is automatically stopped)
CloseWindow(); // Close window and OpenGL context CloseWindow(); // Close window and OpenGL context
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
return 0; return 0;
} }
} }

View File

@ -16,104 +16,104 @@ public partial class audio_raw_stream
* Copyright (c) 2015 Ramon Santamaria (@raysan5) * Copyright (c) 2015 Ramon Santamaria (@raysan5)
* *
********************************************************************************************/ ********************************************************************************************/
public const int MAX_SAMPLES = 22050; public const int MAX_SAMPLES = 22050;
public const int MAX_SAMPLES_PER_UPDATE = 4096; public const int MAX_SAMPLES_PER_UPDATE = 4096;
public static int Main() public static int Main()
{ {
// Initialization // Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
int screenWidth = 800; int screenWidth = 800;
int screenHeight = 450; int screenHeight = 450;
InitWindow(screenWidth, screenHeight, "raylib [audio] example - raw audio streaming"); InitWindow(screenWidth, screenHeight, "raylib [audio] example - raw audio streaming");
InitAudioDevice(); // Initialize audio device InitAudioDevice(); // Initialize audio device
// Init raw audio stream (sample rate: 22050, sample size: 16bit-short, channels: 1-mono) // Init raw audio stream (sample rate: 22050, sample size: 16bit-short, channels: 1-mono)
AudioStream stream = InitAudioStream(22050, 16, 1); AudioStream stream = InitAudioStream(22050, 16, 1);
// Generate samples data from sine wave // Generate samples data from sine wave
short[] data = new short[MAX_SAMPLES]; short[] data = new short[MAX_SAMPLES];
//short *data = (short *)malloc(sizeof(short)*MAX_SAMPLES); //short *data = (short *)malloc(sizeof(short)*MAX_SAMPLES);
// TODO: Review data generation, it seems data is discontinued for loop, // TODO: Review data generation, it seems data is discontinued for loop,
// for that reason, there is a clip everytime audio stream is looped... // for that reason, there is a clip everytime audio stream is looped...
for (int i = 0; i < MAX_SAMPLES; i++) for (int i = 0; i < MAX_SAMPLES; i++)
{ {
data[i] = (short)(Math.Sin(((2*Math.PI*(float)i)/2)*DEG2RAD)*32000); data[i] = (short)(Math.Sin(((2*Math.PI*(float)i)/2)*DEG2RAD)*32000);
} }
PlayAudioStream(stream); // Start processing stream buffer (no data loaded currently) PlayAudioStream(stream); // Start processing stream buffer (no data loaded currently)
int totalSamples = MAX_SAMPLES; int totalSamples = MAX_SAMPLES;
int samplesLeft = totalSamples; int samplesLeft = totalSamples;
Vector2 position = new Vector2( 0, 0 ); Vector2 position = new Vector2( 0, 0 );
SetTargetFPS(30); // Set our game to run at 30 frames-per-second SetTargetFPS(30); // Set our game to run at 30 frames-per-second
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
// Main game loop // Main game loop
while (!WindowShouldClose()) // Detect window close button or ESC key while (!WindowShouldClose()) // Detect window close button or ESC key
{ {
// Update // Update
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// Refill audio stream if required // Refill audio stream if required
// NOTE: Every update we check if stream data has been already consumed and we update // 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), // 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... // but notice that at some point we update < MAX_SAMPLES_PER_UPDATE data...
if (IsAudioBufferProcessed(stream)) if (IsAudioBufferProcessed(stream))
{ {
int numSamples = 0; int numSamples = 0;
if (samplesLeft >= MAX_SAMPLES_PER_UPDATE) numSamples = MAX_SAMPLES_PER_UPDATE; if (samplesLeft >= MAX_SAMPLES_PER_UPDATE) numSamples = MAX_SAMPLES_PER_UPDATE;
else numSamples = samplesLeft; else numSamples = samplesLeft;
// UpdateAudioStream(stream, data + (totalSamples - samplesLeft), numSamples); // UpdateAudioStream(stream, data + (totalSamples - samplesLeft), numSamples);
samplesLeft -= numSamples; samplesLeft -= numSamples;
// Reset samples feeding (loop audio) // Reset samples feeding (loop audio)
if (samplesLeft <= 0) samplesLeft = totalSamples; if (samplesLeft <= 0) samplesLeft = totalSamples;
} }
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// Draw // Draw
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
BeginDrawing(); BeginDrawing();
ClearBackground(RAYWHITE); ClearBackground(RAYWHITE);
DrawText("SINE WAVE SHOULD BE PLAYING!", 240, 140, 20, LIGHTGRAY); DrawText("SINE WAVE SHOULD BE PLAYING!", 240, 140, 20, LIGHTGRAY);
// NOTE: Draw a part of the sine wave (only screen width, proportional values) // NOTE: Draw a part of the sine wave (only screen width, proportional values)
for (int i = 0; i < GetScreenWidth(); i++) for (int i = 0; i < GetScreenWidth(); i++)
{ {
position.x = i; position.x = i;
position.y = 250 + 50*data[i]/32000; position.y = 250 + 50*data[i]/32000;
DrawPixelV(position, RED); DrawPixelV(position, RED);
} }
EndDrawing(); EndDrawing();
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
} }
// De-Initialization // De-Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
// free(data); // Unload sine wave data // free(data); // Unload sine wave data
CloseAudioStream(stream); // Close raw audio stream and delete buffers from RAM CloseAudioStream(stream); // Close raw audio stream and delete buffers from RAM
CloseAudioDevice(); // Close audio device (music streaming is automatically stopped) CloseAudioDevice(); // Close audio device (music streaming is automatically stopped)
CloseWindow(); // Close window and OpenGL context CloseWindow(); // Close window and OpenGL context
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
return 0; return 0;
} }
} }

View File

@ -15,25 +15,25 @@ public partial class audio_sound_loading
* Copyright (c) 2014 Ramon Santamaria (@raysan5) * Copyright (c) 2014 Ramon Santamaria (@raysan5)
* *
********************************************************************************************/ ********************************************************************************************/
public static int Main() public static int Main()
{ {
// Initialization // Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
int screenWidth = 800; int screenWidth = 800;
int screenHeight = 450; int screenHeight = 450;
InitWindow(screenWidth, screenHeight, "raylib [audio] example - sound loading and playing"); InitWindow(screenWidth, screenHeight, "raylib [audio] example - sound loading and playing");
InitAudioDevice(); // Initialize audio device InitAudioDevice(); // Initialize audio device
Sound fxWav = LoadSound("resources/sound.wav"); // Load WAV audio file Sound fxWav = LoadSound("resources/sound.wav"); // Load WAV audio file
Sound fxOgg = LoadSound("resources/tanatana.ogg"); // Load OGG audio file Sound fxOgg = LoadSound("resources/tanatana.ogg"); // Load OGG audio file
SetTargetFPS(60); SetTargetFPS(60);
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
// Main game loop // Main game loop
while (!WindowShouldClose()) // Detect window close button or ESC key 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_SPACE)) PlaySound(fxWav); // Play WAV sound
if (IsKeyPressed(KEY_ENTER)) PlaySound(fxOgg); // Play OGG sound if (IsKeyPressed(KEY_ENTER)) PlaySound(fxOgg); // Play OGG sound
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// Draw // Draw
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
BeginDrawing(); BeginDrawing();
ClearBackground(RAYWHITE); ClearBackground(RAYWHITE);
DrawText("Press SPACE to PLAY the WAV sound!", 200, 180, 20, LIGHTGRAY); DrawText("Press SPACE to PLAY the WAV sound!", 200, 180, 20, LIGHTGRAY);
DrawText("Press ENTER to PLAY the OGG sound!", 200, 220, 20, LIGHTGRAY); DrawText("Press ENTER to PLAY the OGG sound!", 200, 220, 20, LIGHTGRAY);
EndDrawing(); EndDrawing();
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
} }
// De-Initialization // De-Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
UnloadSound(fxWav); // Unload sound data UnloadSound(fxWav); // Unload sound data
UnloadSound(fxOgg); // Unload sound data UnloadSound(fxOgg); // Unload sound data
CloseAudioDevice(); // Close audio device CloseAudioDevice(); // Close audio device
CloseWindow(); // Close window and OpenGL context CloseWindow(); // Close window and OpenGL context
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
return 0; return 0;
} }
} }

View File

@ -134,7 +134,7 @@ public partial class core_2d_camera
} }
// De-Initialization // De-Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
CloseWindow(); // Close window and OpenGL context CloseWindow(); // Close window and OpenGL context
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------

View File

@ -15,19 +15,19 @@ public partial class core_3d_camera_first_person
* Copyright (c) 2015 Ramon Santamaria (@raysan5) * Copyright (c) 2015 Ramon Santamaria (@raysan5)
* *
********************************************************************************************/ ********************************************************************************************/
public const int MAX_COLUMNS = 20; public const int MAX_COLUMNS = 20;
public static int Main() public static int Main()
{ {
// Initialization // Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
int screenWidth = 800; int screenWidth = 800;
int screenHeight = 450; int screenHeight = 450;
InitWindow(screenWidth, screenHeight, "raylib [core] example - 3d camera first person"); InitWindow(screenWidth, screenHeight, "raylib [core] example - 3d camera first person");
// Define the camera to look into our 3d world (position, target, up vector) // Define the camera to look into our 3d world (position, target, up vector)
Camera3D camera = new Camera3D(); Camera3D camera = new Camera3D();
camera.position = new Vector3( 4.0f, 2.0f, 4.0f ); 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.up = new Vector3( 0.0f, 1.0f, 0.0f );
camera.fovy = 60.0f; camera.fovy = 60.0f;
camera.type = (int)CAMERA_PERSPECTIVE; camera.type = (int)CAMERA_PERSPECTIVE;
// Generates some random columns // Generates some random columns
float[] heights = new float[MAX_COLUMNS]; float[] heights = new float[MAX_COLUMNS];
Vector3[] positions = new Vector3[MAX_COLUMNS]; Vector3[] positions = new Vector3[MAX_COLUMNS];
Color[] colors = new Color[MAX_COLUMNS]; Color[] colors = new Color[MAX_COLUMNS];
for (int i = 0; i < MAX_COLUMNS; i++) for (int i = 0; i < MAX_COLUMNS; i++)
{ {
heights[i] = (float)GetRandomValue(1, 12); heights[i] = (float)GetRandomValue(1, 12);
positions[i] = new Vector3( GetRandomValue(-15, 15), heights[i]/2, GetRandomValue(-15, 15) ); 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 ); colors[i] = new Color( GetRandomValue(20, 255), GetRandomValue(10, 55), 30, 255 );
} }
SetCameraMode(camera, (int)CAMERA_FIRST_PERSON); // Set a first person camera mode SetCameraMode(camera, (int)CAMERA_FIRST_PERSON); // Set a first person camera mode
SetTargetFPS(60); // Set our game to run at 60 frames-per-second SetTargetFPS(60); // Set our game to run at 60 frames-per-second
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
// Main game loop // Main game loop
while (!WindowShouldClose()) // Detect window close button or ESC key 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 UpdateCamera(ref camera); // Update camera
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// Draw // Draw
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
BeginDrawing(); BeginDrawing();
ClearBackground(RAYWHITE); ClearBackground(RAYWHITE);
BeginMode3D(camera); BeginMode3D(camera);
DrawPlane(new Vector3( 0.0f, 0.0f, 0.0f ), new Vector2( 32.0f, 32.0f ), LIGHTGRAY); // Draw ground 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, 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( 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 DrawCube(new Vector3( 0.0f, 2.5f, 16.0f ), 32.0f, 5.0f, 1.0f, GOLD); // Draw a yellow wall
// Draw some cubes around // Draw some cubes around
for (int i = 0; i < MAX_COLUMNS; i++) for (int i = 0; i < MAX_COLUMNS; i++)
{ {
DrawCube(positions[i], 2.0f, heights[i], 2.0f, colors[i]); DrawCube(positions[i], 2.0f, heights[i], 2.0f, colors[i]);
DrawCubeWires(positions[i], 2.0f, heights[i], 2.0f, MAROON); DrawCubeWires(positions[i], 2.0f, heights[i], 2.0f, MAROON);
} }
EndMode3D(); EndMode3D();
DrawRectangle( 10, 10, 220, 70, Fade(SKYBLUE, 0.5f)); DrawRectangle( 10, 10, 220, 70, Fade(SKYBLUE, 0.5f));
DrawRectangleLines( 10, 10, 220, 70, BLUE); DrawRectangleLines( 10, 10, 220, 70, BLUE);
DrawText("First person camera default controls:", 20, 20, 10, BLACK); DrawText("First person camera default controls:", 20, 20, 10, BLACK);
DrawText("- Move with keys: W, A, S, D", 40, 40, 10, DARKGRAY); DrawText("- Move with keys: W, A, S, D", 40, 40, 10, DARKGRAY);
DrawText("- Mouse move to look around", 40, 60, 10, DARKGRAY); DrawText("- Mouse move to look around", 40, 60, 10, DARKGRAY);
EndDrawing(); EndDrawing();
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
} }
// De-Initialization // De-Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
CloseWindow(); // Close window and OpenGL context CloseWindow(); // Close window and OpenGL context
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
return 0; return 0;
} }
} }

View File

@ -15,17 +15,17 @@ public partial class core_3d_camera_free
* Copyright (c) 2015 Ramon Santamaria (@raysan5) * Copyright (c) 2015 Ramon Santamaria (@raysan5)
* *
********************************************************************************************/ ********************************************************************************************/
public static int Main() public static int Main()
{ {
// Initialization // Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
int screenWidth = 800; int screenWidth = 800;
int screenHeight = 450; int screenHeight = 450;
InitWindow(screenWidth, screenHeight, "raylib [core] example - 3d camera free"); InitWindow(screenWidth, screenHeight, "raylib [core] example - 3d camera free");
// Define the camera to look into our 3d world // Define the camera to look into our 3d world
Camera3D camera; Camera3D camera;
camera.position = new Vector3( 10.0f, 10.0f, 10.0f ); // Camera3D position 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.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.fovy = 45.0f; // Camera3D field-of-view Y
camera.type = (int)CAMERA_PERSPECTIVE; // Camera3D mode type camera.type = (int)CAMERA_PERSPECTIVE; // Camera3D mode type
Vector3 cubePosition = new Vector3( 0.0f, 0.0f, 0.0f ); Vector3 cubePosition = new Vector3( 0.0f, 0.0f, 0.0f );
SetCameraMode(camera, (int)CAMERA_FREE); // Set a free camera mode SetCameraMode(camera, (int)CAMERA_FREE); // Set a free camera mode
SetTargetFPS(60); // Set our game to run at 60 frames-per-second SetTargetFPS(60); // Set our game to run at 60 frames-per-second
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
// Main game loop // Main game loop
while (!WindowShouldClose()) // Detect window close button or ESC key while (!WindowShouldClose()) // Detect window close button or ESC key
{ {
// Update // Update
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
UpdateCamera(ref camera); // Update camera UpdateCamera(ref camera); // Update camera
if (IsKeyDown('Z')) camera.target = new Vector3( 0.0f, 0.0f, 0.0f ); if (IsKeyDown('Z')) camera.target = new Vector3( 0.0f, 0.0f, 0.0f );
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// Draw // Draw
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
BeginDrawing(); BeginDrawing();
ClearBackground(RAYWHITE); ClearBackground(RAYWHITE);
BeginMode3D(camera); BeginMode3D(camera);
DrawCube(cubePosition, 2.0f, 2.0f, 2.0f, RED); DrawCube(cubePosition, 2.0f, 2.0f, 2.0f, RED);
DrawCubeWires(cubePosition, 2.0f, 2.0f, 2.0f, MAROON); DrawCubeWires(cubePosition, 2.0f, 2.0f, 2.0f, MAROON);
DrawGrid(10, 1.0f); DrawGrid(10, 1.0f);
EndMode3D(); EndMode3D();
DrawRectangle( 10, 10, 320, 133, Fade(SKYBLUE, 0.5f)); DrawRectangle( 10, 10, 320, 133, Fade(SKYBLUE, 0.5f));
DrawRectangleLines( 10, 10, 320, 133, BLUE); DrawRectangleLines( 10, 10, 320, 133, BLUE);
DrawText("Free camera default controls:", 20, 20, 10, BLACK); DrawText("Free camera default controls:", 20, 20, 10, BLACK);
DrawText("- Mouse Wheel to Zoom in-out", 40, 40, 10, DARKGRAY); DrawText("- Mouse Wheel to Zoom in-out", 40, 40, 10, DARKGRAY);
DrawText("- Mouse Wheel Pressed to Pan", 40, 60, 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 + Mouse Wheel Pressed to Rotate", 40, 80, 10, DARKGRAY);
DrawText("- Alt + Ctrl + Mouse Wheel Pressed for Smooth Zoom", 40, 100, 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); DrawText("- Z to zoom to (0, 0, 0)", 40, 120, 10, DARKGRAY);
EndDrawing(); EndDrawing();
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
} }
// De-Initialization // De-Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
CloseWindow(); // Close window and OpenGL context CloseWindow(); // Close window and OpenGL context
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
return 0; return 0;
} }
} }

View File

@ -14,17 +14,17 @@ public partial class core_3d_mode
* Copyright (c) 2014 Ramon Santamaria (@raysan5) * Copyright (c) 2014 Ramon Santamaria (@raysan5)
* *
********************************************************************************************/ ********************************************************************************************/
public static int Main() public static int Main()
{ {
// Initialization // Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
int screenWidth = 800; int screenWidth = 800;
int screenHeight = 450; int screenHeight = 450;
InitWindow(screenWidth, screenHeight, "raylib [core] example - 3d mode"); InitWindow(screenWidth, screenHeight, "raylib [core] example - 3d mode");
// Define the camera to look into our 3d world // Define the camera to look into our 3d world
Camera3D camera; Camera3D camera;
camera.position = new Vector3( 0.0f, 10.0f, 10.0f ); // Camera3D position 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.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.fovy = 45.0f; // Camera3D field-of-view Y
camera.type = CAMERA_PERSPECTIVE; // Camera3D mode type camera.type = CAMERA_PERSPECTIVE; // Camera3D mode type
Vector3 cubePosition = new Vector3( 0.0f, 0.0f, 0.0f ); Vector3 cubePosition = new Vector3( 0.0f, 0.0f, 0.0f );
SetTargetFPS(60); // Set our game to run at 60 frames-per-second SetTargetFPS(60); // Set our game to run at 60 frames-per-second
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
// Main game loop // Main game loop
while (!WindowShouldClose()) // Detect window close button or ESC key while (!WindowShouldClose()) // Detect window close button or ESC key
{ {
@ -45,35 +45,35 @@ public partial class core_3d_mode
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// TODO: Update your variables here // TODO: Update your variables here
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// Draw // Draw
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
BeginDrawing(); BeginDrawing();
ClearBackground(RAYWHITE); ClearBackground(RAYWHITE);
BeginMode3D(camera); BeginMode3D(camera);
DrawCube(cubePosition, 2.0f, 2.0f, 2.0f, RED); DrawCube(cubePosition, 2.0f, 2.0f, 2.0f, RED);
DrawCubeWires(cubePosition, 2.0f, 2.0f, 2.0f, MAROON); DrawCubeWires(cubePosition, 2.0f, 2.0f, 2.0f, MAROON);
DrawGrid(10, 1.0f); DrawGrid(10, 1.0f);
EndMode3D(); EndMode3D();
DrawText("Welcome to the third dimension!", 10, 40, 20, DARKGRAY); DrawText("Welcome to the third dimension!", 10, 40, 20, DARKGRAY);
DrawFPS(10, 10); DrawFPS(10, 10);
EndDrawing(); EndDrawing();
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
} }
// De-Initialization // De-Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
CloseWindow(); // Close window and OpenGL context CloseWindow(); // Close window and OpenGL context
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
return 0; return 0;
} }
} }

View File

@ -15,17 +15,17 @@ public partial class core_3d_picking
* Copyright (c) 2015 Ramon Santamaria (@raysan5) * Copyright (c) 2015 Ramon Santamaria (@raysan5)
* *
********************************************************************************************/ ********************************************************************************************/
public static int Main() public static int Main()
{ {
// Initialization // Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
int screenWidth = 800; int screenWidth = 800;
int screenHeight = 450; int screenHeight = 450;
InitWindow(screenWidth, screenHeight, "raylib [core] example - 3d picking"); InitWindow(screenWidth, screenHeight, "raylib [core] example - 3d picking");
// Define the camera to look into our 3d world // Define the camera to look into our 3d world
Camera3D camera; Camera3D camera;
camera.position = new Vector3( 10.0f, 10.0f, 10.0f ); // Camera3D position 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.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.fovy = 45.0f; // Camera3D field-of-view Y
camera.type = (int)CAMERA_PERSPECTIVE; // Camera3D mode type camera.type = (int)CAMERA_PERSPECTIVE; // Camera3D mode type
Vector3 cubePosition = new Vector3( 0.0f, 1.0f, 0.0f ); Vector3 cubePosition = new Vector3( 0.0f, 1.0f, 0.0f );
Vector3 cubeSize = new Vector3( 2.0f, 2.0f, 2.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 Ray ray = new Ray(new Vector3(0.0f, 0.0f, 0.0f), Vector3.Zero); // Picking line ray
bool collision = false; bool collision = false;
SetCameraMode(camera, (int)CAMERA_FREE); // Set a free camera mode SetCameraMode(camera, (int)CAMERA_FREE); // Set a free camera mode
SetTargetFPS(60); // Set our game to run at 60 frames-per-second SetTargetFPS(60); // Set our game to run at 60 frames-per-second
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
// Main game loop // Main game loop
while (!WindowShouldClose()) // Detect window close button or ESC key while (!WindowShouldClose()) // Detect window close button or ESC key
{ {
// Update // Update
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
UpdateCamera(ref camera); // Update camera UpdateCamera(ref camera); // Update camera
if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON))
{ {
ray = GetMouseRay(GetMousePosition(), camera); ray = GetMouseRay(GetMousePosition(), camera);
// Check collision between ray and box // Check collision between ray and box
collision = CheckCollisionRayBox(ray, collision = CheckCollisionRayBox(ray,
new BoundingBox(new Vector3( cubePosition.x - cubeSize.x/2, cubePosition.y - cubeSize.y/2, cubePosition.z - cubeSize.z/2 ), 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 ))); new Vector3( cubePosition.x + cubeSize.x/2, cubePosition.y + cubeSize.y/2, cubePosition.z + cubeSize.z/2 )));
} }
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// Draw // Draw
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
BeginDrawing(); BeginDrawing();
ClearBackground(RAYWHITE); ClearBackground(RAYWHITE);
BeginMode3D(camera); BeginMode3D(camera);
if (collision) if (collision)
{ {
DrawCube(cubePosition, cubeSize.x, cubeSize.y, cubeSize.z, RED); DrawCube(cubePosition, cubeSize.x, cubeSize.y, cubeSize.z, RED);
DrawCubeWires(cubePosition, cubeSize.x, cubeSize.y, cubeSize.z, MAROON); DrawCubeWires(cubePosition, cubeSize.x, cubeSize.y, cubeSize.z, MAROON);
DrawCubeWires(cubePosition, cubeSize.x + 0.2f, cubeSize.y + 0.2f, cubeSize.z + 0.2f, GREEN); DrawCubeWires(cubePosition, cubeSize.x + 0.2f, cubeSize.y + 0.2f, cubeSize.z + 0.2f, GREEN);
} }
else else
@ -84,27 +84,27 @@ public partial class core_3d_picking
DrawCube(cubePosition, cubeSize.x, cubeSize.y, cubeSize.z, GRAY); DrawCube(cubePosition, cubeSize.x, cubeSize.y, cubeSize.z, GRAY);
DrawCubeWires(cubePosition, cubeSize.x, cubeSize.y, cubeSize.z, DARKGRAY); DrawCubeWires(cubePosition, cubeSize.x, cubeSize.y, cubeSize.z, DARKGRAY);
} }
DrawRay(ray, MAROON); DrawRay(ray, MAROON);
DrawGrid(10, 1.0f); DrawGrid(10, 1.0f);
EndMode3D(); EndMode3D();
DrawText("Try selecting the box with mouse!", 240, 10, 20, DARKGRAY); 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); if(collision) DrawText("BOX SELECTED", (screenWidth - MeasureText("BOX SELECTED", 30)) / 2, (int)(screenHeight * 0.1f), 30, GREEN);
DrawFPS(10, 10); DrawFPS(10, 10);
EndDrawing(); EndDrawing();
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
} }
// De-Initialization // De-Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
CloseWindow(); // Close window and OpenGL context CloseWindow(); // Close window and OpenGL context
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
return 0; return 0;
} }
} }

View File

@ -23,20 +23,20 @@ public partial class core_basic_window
* Copyright (c) 2013-2016 Ramon Santamaria (@raysan5) * Copyright (c) 2013-2016 Ramon Santamaria (@raysan5)
* *
********************************************************************************************/ ********************************************************************************************/
public static int Main() public static int Main()
{ {
// Initialization // Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
int screenWidth = 800; int screenWidth = 800;
int screenHeight = 450; int screenHeight = 450;
InitWindow(screenWidth, screenHeight, "raylib [core] example - basic window"); InitWindow(screenWidth, screenHeight, "raylib [core] example - basic window");
SetTargetFPS(60); SetTargetFPS(60);
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
// Main game loop // Main game loop
while (!WindowShouldClose()) // Detect window close button or ESC key while (!WindowShouldClose()) // Detect window close button or ESC key
{ {
@ -44,24 +44,24 @@ public partial class core_basic_window
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// TODO: Update your variables here // TODO: Update your variables here
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// Draw // Draw
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
BeginDrawing(); BeginDrawing();
ClearBackground(RAYWHITE); ClearBackground(RAYWHITE);
DrawText("Congrats! You created your first window!", 190, 200, 20, MAROON); DrawText("Congrats! You created your first window!", 190, 200, 20, MAROON);
EndDrawing(); EndDrawing();
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
} }
// De-Initialization // De-Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
CloseWindow(); // Close window and OpenGL context CloseWindow(); // Close window and OpenGL context
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
return 0; return 0;
} }
} }

View File

@ -17,23 +17,23 @@ public partial class Examples
* Copyright (c) 2015 Ramon Santamaria (@raysan5) * Copyright (c) 2015 Ramon Santamaria (@raysan5)
* *
********************************************************************************************/ ********************************************************************************************/
//#define PLATFORM_WEB //#define PLATFORM_WEB
#include <emscripten/emscripten.h> #include <emscripten/emscripten.h>
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// Global Variables Definition // Global Variables Definition
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
int screenWidth = 800; int screenWidth = 800;
int screenHeight = 450; int screenHeight = 450;
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// Module Functions Declaration // Module Functions Declaration
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
void UpdateDrawFrame(void); // Update and Draw one frame void UpdateDrawFrame(void); // Update and Draw one frame
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// Main Enry Point // Main Enry Point
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
@ -42,26 +42,26 @@ public partial class Examples
// Initialization // Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
InitWindow(screenWidth, screenHeight, "raylib [core] example - basic window"); InitWindow(screenWidth, screenHeight, "raylib [core] example - basic window");
emscripten_set_main_loop(UpdateDrawFrame, 0, 1); emscripten_set_main_loop(UpdateDrawFrame, 0, 1);
#else #else
SetTargetFPS(60); // Set our game to run at 60 frames-per-second SetTargetFPS(60); // Set our game to run at 60 frames-per-second
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
// Main game loop // Main game loop
while (!WindowShouldClose()) // Detect window close button or ESC key while (!WindowShouldClose()) // Detect window close button or ESC key
{ {
UpdateDrawFrame(); UpdateDrawFrame();
} }
// De-Initialization // De-Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
CloseWindow(); // Close window and OpenGL context CloseWindow(); // Close window and OpenGL context
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
return 0; return 0;
} }
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// Module Functions Definition // Module Functions Definition
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
@ -71,16 +71,16 @@ public partial class Examples
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// TODO: Update your variables here // TODO: Update your variables here
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// Draw // Draw
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
BeginDrawing(); BeginDrawing();
ClearBackground(RAYWHITE); ClearBackground(RAYWHITE);
DrawText("Congrats! You created your first window!", 190, 200, 20, LIGHTGRAY); DrawText("Congrats! You created your first window!", 190, 200, 20, LIGHTGRAY);
EndDrawing(); EndDrawing();
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
} }
} }

View File

@ -13,23 +13,23 @@ public partial class core_color_select
* Copyright (c) 2014 Ramon Santamaria (@raysan5) * Copyright (c) 2014 Ramon Santamaria (@raysan5)
* *
********************************************************************************************/ ********************************************************************************************/
public static int Main() public static int Main()
{ {
// Initialization // Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
int screenWidth = 800; int screenWidth = 800;
int screenHeight = 450; int screenHeight = 450;
InitWindow(screenWidth, screenHeight, "raylib [core] example - color selection (collision detection)"); InitWindow(screenWidth, screenHeight, "raylib [core] example - color selection (collision detection)");
Color[] colors = new Color[21] { DARKGRAY, MAROON, ORANGE, DARKGREEN, DARKBLUE, DARKPURPLE, DARKBROWN, Color[] colors = new Color[21] { DARKGRAY, MAROON, ORANGE, DARKGREEN, DARKBLUE, DARKPURPLE, DARKBROWN,
GRAY, RED, GOLD, LIME, BLUE, VIOLET, BROWN, LIGHTGRAY, PINK, YELLOW, GRAY, RED, GOLD, LIME, BLUE, VIOLET, BROWN, LIGHTGRAY, PINK, YELLOW,
GREEN, SKYBLUE, PURPLE, BEIGE }; GREEN, SKYBLUE, PURPLE, BEIGE };
Rectangle[] colorsRecs = new Rectangle[21]; // Rectangles array Rectangle[] colorsRecs = new Rectangle[21]; // Rectangles array
// Fills colorsRecs data (for every rectangle) // Fills colorsRecs data (for every rectangle)
for (int i = 0; i < 21; i++) for (int i = 0; i < 21; i++)
{ {
@ -38,43 +38,43 @@ public partial class core_color_select
colorsRecs[i].width = 100; colorsRecs[i].width = 100;
colorsRecs[i].height = 100; colorsRecs[i].height = 100;
} }
bool[] selected = new bool[21]; // Selected rectangles indicator bool[] selected = new bool[21]; // Selected rectangles indicator
Vector2 mousePoint; Vector2 mousePoint;
SetTargetFPS(60); // Set our game to run at 60 frames-per-second SetTargetFPS(60); // Set our game to run at 60 frames-per-second
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
// Main game loop // Main game loop
while (!WindowShouldClose()) // Detect window close button or ESC key while (!WindowShouldClose()) // Detect window close button or ESC key
{ {
// Update // Update
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
mousePoint = GetMousePosition(); mousePoint = GetMousePosition();
for (int i = 0; i < 21; i++) // Iterate along all the rectangles for (int i = 0; i < 21; i++) // Iterate along all the rectangles
{ {
if (CheckCollisionPointRec(mousePoint, colorsRecs[i])) if (CheckCollisionPointRec(mousePoint, colorsRecs[i]))
{ {
colors[i].a = 120; colors[i].a = 120;
if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) selected[i] = !selected[i]; if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) selected[i] = !selected[i];
} }
else colors[i].a = 255; else colors[i].a = 255;
} }
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// Draw // Draw
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
BeginDrawing(); BeginDrawing();
ClearBackground(RAYWHITE); ClearBackground(RAYWHITE);
for (int i = 0; i < 21; i++) // Draw all rectangles for (int i = 0; i < 21; i++) // Draw all rectangles
{ {
DrawRectangleRec(colorsRecs[i], colors[i]); DrawRectangleRec(colorsRecs[i], colors[i]);
// Draw four rectangles around selected rectangle // Draw four rectangles around selected rectangle
if (selected[i]) 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 DrawRectangle((int)colorsRecs[i].x, (int)colorsRecs[i].y + 90, 100, 10, RAYWHITE); // Square bottom rectangle
} }
} }
EndDrawing(); EndDrawing();
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
} }
// De-Initialization // De-Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
CloseWindow(); // Close window and OpenGL context CloseWindow(); // Close window and OpenGL context
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
return 0; return 0;
} }
} }

View File

@ -13,19 +13,19 @@ public partial class Examples
* Copyright (c) 2018 Ramon Santamaria (@raysan5) and Pablo Marcos Oltra (@pamarcos) * Copyright (c) 2018 Ramon Santamaria (@raysan5) and Pablo Marcos Oltra (@pamarcos)
* *
********************************************************************************************/ ********************************************************************************************/
// Custom logging funtion // Custom logging funtion
void LogCustom(int msgType, const char *text, va_list args) void LogCustom(int msgType, const char *text, va_list args)
{ {
char timeStr[64]; char timeStr[64];
time_t now = time(NULL); time_t now = time(NULL);
struct tm *tm_info = localtime(&now); struct tm *tm_info = localtime(&now);
strftime(timeStr, sizeof(timeStr), "%Y-%m-%d %H:%M:%S", tm_info); strftime(timeStr, sizeof(timeStr), "%Y-%m-%d %H:%M:%S", tm_info);
printf("[%s] ", timeStr); printf("[%s] ", timeStr);
switch (msgType) switch (msgType)
{ {
case LOG_INFO: printf("[INFO] : "); break; case LOG_INFO: printf("[INFO] : "); break;
@ -34,27 +34,27 @@ public partial class Examples
case LOG_DEBUG: printf("[DEBUG]: "); break; case LOG_DEBUG: printf("[DEBUG]: "); break;
default: break; default: break;
} }
vprintf(text, args); vprintf(text, args);
printf("\n"); printf("\n");
} }
public static int core_custom_logging() public static int core_custom_logging()
{ {
// Initialization // Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
int screenWidth = 800; int screenWidth = 800;
int screenHeight = 450; int screenHeight = 450;
// First thing we do is setting our custom logger to ensure everything raylib logs // First thing we do is setting our custom logger to ensure everything raylib logs
// will use our own logger instead of its internal one // will use our own logger instead of its internal one
SetTraceLogCallback(LogCustom); SetTraceLogCallback(LogCustom);
InitWindow(screenWidth, screenHeight, "raylib [core] example - custom logging"); InitWindow(screenWidth, screenHeight, "raylib [core] example - custom logging");
SetTargetFPS(60); SetTargetFPS(60);
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
// Main game loop // Main game loop
while (!WindowShouldClose()) // Detect window close button or ESC key while (!WindowShouldClose()) // Detect window close button or ESC key
{ {
@ -62,25 +62,25 @@ public partial class Examples
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// TODO: Update your variables here // TODO: Update your variables here
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// Draw // Draw
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
BeginDrawing(); BeginDrawing();
ClearBackground(RAYWHITE); ClearBackground(RAYWHITE);
DrawText("Check out the console output to see the custom logger in action!", 60, 200, 20, LIGHTGRAY); DrawText("Check out the console output to see the custom logger in action!", 60, 200, 20, LIGHTGRAY);
EndDrawing(); EndDrawing();
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
} }
// De-Initialization // De-Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
CloseWindow(); // Close window and OpenGL context CloseWindow(); // Close window and OpenGL context
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
return 0; return 0;
} }
} }

View File

@ -15,23 +15,23 @@ public partial class core_drop_files
* Copyright (c) 2015 Ramon Santamaria (@raysan5) * Copyright (c) 2015 Ramon Santamaria (@raysan5)
* *
********************************************************************************************/ ********************************************************************************************/
public static int Main() public static int Main()
{ {
// Initialization // Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
int screenWidth = 800; int screenWidth = 800;
int screenHeight = 450; int screenHeight = 450;
InitWindow(screenWidth, screenHeight, "raylib [core] example - drop files"); InitWindow(screenWidth, screenHeight, "raylib [core] example - drop files");
int count = 0; int count = 0;
string[] droppedFiles = { }; string[] droppedFiles = { };
SetTargetFPS(60); SetTargetFPS(60);
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
// Main game loop // Main game loop
while (!WindowShouldClose()) // Detect window close button or ESC key while (!WindowShouldClose()) // Detect window close button or ESC key
{ {
@ -42,40 +42,40 @@ public partial class core_drop_files
droppedFiles = GetDroppedFiles(ref count); droppedFiles = GetDroppedFiles(ref count);
} }
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// Draw // Draw
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
BeginDrawing(); BeginDrawing();
ClearBackground(RAYWHITE); ClearBackground(RAYWHITE);
if (count == 0) DrawText("Drop your files to this window!", 100, 40, 20, DARKGRAY); if (count == 0) DrawText("Drop your files to this window!", 100, 40, 20, DARKGRAY);
else else
{ {
DrawText("Dropped files:", 100, 40, 20, DARKGRAY); DrawText("Dropped files:", 100, 40, 20, DARKGRAY);
for (int i = 0; i < count; i++) for (int i = 0; i < count; i++)
{ {
if (i%2 == 0) DrawRectangle(0, 85 + 40*i, screenWidth, 40, Fade(LIGHTGRAY, 0.5f)); 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)); else DrawRectangle(0, 85 + 40*i, screenWidth, 40, Fade(LIGHTGRAY, 0.3f));
DrawText(droppedFiles[i], 120, 100 + 40*i, 10, GRAY); DrawText(droppedFiles[i], 120, 100 + 40*i, 10, GRAY);
} }
DrawText("Drop new files...", 100, 110 + 40*count, 20, DARKGRAY); DrawText("Drop new files...", 100, 110 + 40*count, 20, DARKGRAY);
} }
EndDrawing(); EndDrawing();
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
} }
// De-Initialization // De-Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
ClearDroppedFiles(); // Clear internal buffers ClearDroppedFiles(); // Clear internal buffers
CloseWindow(); // Close window and OpenGL context CloseWindow(); // Close window and OpenGL context
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
return 0; return 0;
} }
} }

View File

@ -14,33 +14,33 @@ public partial class core_gestures_detection
* Copyright (c) 2016 Ramon Santamaria (@raysan5) * Copyright (c) 2016 Ramon Santamaria (@raysan5)
* *
********************************************************************************************/ ********************************************************************************************/
public const int MAX_GESTURE_STRINGS = 20; public const int MAX_GESTURE_STRINGS = 20;
public static int Main() public static int Main()
{ {
// Initialization // Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
int screenWidth = 800; int screenWidth = 800;
int screenHeight = 450; int screenHeight = 450;
InitWindow(screenWidth, screenHeight, "raylib [core] example - gestures detection"); InitWindow(screenWidth, screenHeight, "raylib [core] example - gestures detection");
Vector2 touchPosition = new Vector2( 0, 0 ); Vector2 touchPosition = new Vector2( 0, 0 );
Rectangle touchArea = new Rectangle( 220, 10, screenWidth - 230, screenHeight - 20 ); Rectangle touchArea = new Rectangle( 220, 10, screenWidth - 230, screenHeight - 20 );
int gesturesCount = 0; int gesturesCount = 0;
string[] gestureStrings = new string[MAX_GESTURE_STRINGS]; string[] gestureStrings = new string[MAX_GESTURE_STRINGS];
int currentGesture = (int)GESTURE_NONE; int currentGesture = (int)GESTURE_NONE;
int lastGesture = (int)GESTURE_NONE; int lastGesture = (int)GESTURE_NONE;
//SetGesturesEnabled(0b0000000000001001); // Enable only some gestures to be detected //SetGesturesEnabled(0b0000000000001001); // Enable only some gestures to be detected
SetTargetFPS(60); SetTargetFPS(60);
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
// Main game loop // Main game loop
while (!WindowShouldClose()) // Detect window close button or ESC key while (!WindowShouldClose()) // Detect window close button or ESC key
{ {
@ -49,7 +49,7 @@ public partial class core_gestures_detection
lastGesture = currentGesture; lastGesture = currentGesture;
currentGesture = GetGestureDetected(); currentGesture = GetGestureDetected();
touchPosition = GetTouchPosition(0); touchPosition = GetTouchPosition(0);
if (CheckCollisionPointRec(touchPosition, touchArea) && (currentGesture != (int)GESTURE_NONE)) if (CheckCollisionPointRec(touchPosition, touchArea) && (currentGesture != (int)GESTURE_NONE))
{ {
if (currentGesture != lastGesture) if (currentGesture != lastGesture)
@ -69,53 +69,53 @@ public partial class core_gestures_detection
case (int)GESTURE_PINCH_OUT: gestureStrings[gesturesCount] = "GESTURE PINCH OUT"; break; case (int)GESTURE_PINCH_OUT: gestureStrings[gesturesCount] = "GESTURE PINCH OUT"; break;
default: break; default: break;
} }
gesturesCount++; gesturesCount++;
// Reset gestures strings // Reset gestures strings
if (gesturesCount >= MAX_GESTURE_STRINGS) if (gesturesCount >= MAX_GESTURE_STRINGS)
{ {
for (int i = 0; i < MAX_GESTURE_STRINGS; i++) gestureStrings[i] = " "; for (int i = 0; i < MAX_GESTURE_STRINGS; i++) gestureStrings[i] = " ";
gesturesCount = 0; gesturesCount = 0;
} }
} }
} }
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// Draw // Draw
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
BeginDrawing(); BeginDrawing();
ClearBackground(RAYWHITE); ClearBackground(RAYWHITE);
DrawRectangleRec(touchArea, GRAY); DrawRectangleRec(touchArea, GRAY);
DrawRectangle(225, 15, screenWidth - 240, screenHeight - 30, RAYWHITE); DrawRectangle(225, 15, screenWidth - 240, screenHeight - 30, RAYWHITE);
DrawText("GESTURES TEST AREA", screenWidth - 270, screenHeight - 40, 20, Fade(GRAY, 0.5f)); DrawText("GESTURES TEST AREA", screenWidth - 270, screenHeight - 40, 20, Fade(GRAY, 0.5f));
for (int i = 0; i < gesturesCount; i++) for (int i = 0; i < gesturesCount; i++)
{ {
if (i%2 == 0) DrawRectangle(10, 30 + 20*i, 200, 20, Fade(LIGHTGRAY, 0.5f)); 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)); 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); if (i < gesturesCount - 1) DrawText(gestureStrings[i], 35, 36 + 20*i, 10, DARKGRAY);
else DrawText(gestureStrings[i], 35, 36 + 20*i, 10, MAROON); else DrawText(gestureStrings[i], 35, 36 + 20*i, 10, MAROON);
} }
DrawRectangleLines(10, 29, 200, screenHeight - 50, GRAY); DrawRectangleLines(10, 29, 200, screenHeight - 50, GRAY);
DrawText("DETECTED GESTURES", 50, 15, 10, GRAY); DrawText("DETECTED GESTURES", 50, 15, 10, GRAY);
if (currentGesture != (int)GESTURE_NONE) DrawCircleV(touchPosition, 30, MAROON); if (currentGesture != (int)GESTURE_NONE) DrawCircleV(touchPosition, 30, MAROON);
EndDrawing(); EndDrawing();
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
} }
// De-Initialization // De-Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
CloseWindow(); // Close window and OpenGL context CloseWindow(); // Close window and OpenGL context
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
return 0; return 0;
} }
} }

View File

@ -9,9 +9,9 @@ public partial class core_input_gamepad
* raylib [core] example - Gamepad input * raylib [core] example - Gamepad input
* *
* NOTE: This example requires a Gamepad connected to the system * 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) * - Xbox 360 Controller (Xbox 360, Xbox One)
* - PLAYSTATION(R)3 Controller * - PLAYSTATION(R)3 Controller
* Check raylib.h for buttons configuration * Check raylib.h for buttons configuration
* *
* This example has been created using raylib 1.6 (www.raylib.com) * 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 screenWidth = 800;
int screenHeight = 450; 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"); InitWindow(screenWidth, screenHeight, "raylib [core] example - gamepad input");

View File

@ -13,22 +13,22 @@ public partial class core_input_keys
* Copyright (c) 2014 Ramon Santamaria (@raysan5) * Copyright (c) 2014 Ramon Santamaria (@raysan5)
* *
********************************************************************************************/ ********************************************************************************************/
public static int Main() public static int Main()
{ {
// Initialization // Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
int screenWidth = 800; int screenWidth = 800;
int screenHeight = 450; int screenHeight = 450;
InitWindow(screenWidth, screenHeight, "raylib [core] example - keyboard input"); InitWindow(screenWidth, screenHeight, "raylib [core] example - keyboard input");
Vector2 ballPosition = new Vector2( (float)screenWidth/2, (float)screenHeight/2 ); Vector2 ballPosition = new Vector2( (float)screenWidth/2, (float)screenHeight/2 );
SetTargetFPS(60); // Set target frames-per-second SetTargetFPS(60); // Set target frames-per-second
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
// Main game loop // Main game loop
while (!WindowShouldClose()) // Detect window close button or ESC key 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_UP)) ballPosition.y -= 2.0f;
if (IsKeyDown(KEY_DOWN)) ballPosition.y += 2.0f; if (IsKeyDown(KEY_DOWN)) ballPosition.y += 2.0f;
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// Draw // Draw
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
BeginDrawing(); BeginDrawing();
ClearBackground(RAYWHITE); ClearBackground(RAYWHITE);
DrawText("move the ball with arrow keys", 10, 10, 20, DARKGRAY); DrawText("move the ball with arrow keys", 10, 10, 20, DARKGRAY);
DrawCircleV(ballPosition, 50, MAROON); DrawCircleV(ballPosition, 50, MAROON);
EndDrawing(); EndDrawing();
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
} }
// De-Initialization // De-Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
CloseWindow(); // Close window and OpenGL context CloseWindow(); // Close window and OpenGL context
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
return 0; return 0;
} }
} }

View File

@ -13,54 +13,54 @@ public partial class core_input_mouse
* Copyright (c) 2014 Ramon Santamaria (@raysan5) * Copyright (c) 2014 Ramon Santamaria (@raysan5)
* *
********************************************************************************************/ ********************************************************************************************/
public static int Main() public static int Main()
{ {
// Initialization // Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
int screenWidth = 800; int screenWidth = 800;
int screenHeight = 450; int screenHeight = 450;
InitWindow(screenWidth, screenHeight, "raylib [core] example - mouse input"); InitWindow(screenWidth, screenHeight, "raylib [core] example - mouse input");
Vector2 ballPosition = new Vector2( -100.0f, -100.0f ); Vector2 ballPosition = new Vector2( -100.0f, -100.0f );
Color ballColor = DARKBLUE; Color ballColor = DARKBLUE;
SetTargetFPS(60); SetTargetFPS(60);
//--------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------
// Main game loop // Main game loop
while (!WindowShouldClose()) // Detect window close button or ESC key while (!WindowShouldClose()) // Detect window close button or ESC key
{ {
// Update // Update
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
ballPosition = GetMousePosition(); ballPosition = GetMousePosition();
if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) ballColor = MAROON; if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) ballColor = MAROON;
else if (IsMouseButtonPressed(MOUSE_MIDDLE_BUTTON)) ballColor = LIME; else if (IsMouseButtonPressed(MOUSE_MIDDLE_BUTTON)) ballColor = LIME;
else if (IsMouseButtonPressed(MOUSE_RIGHT_BUTTON)) ballColor = DARKBLUE; else if (IsMouseButtonPressed(MOUSE_RIGHT_BUTTON)) ballColor = DARKBLUE;
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// Draw // Draw
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
BeginDrawing(); BeginDrawing();
ClearBackground(RAYWHITE); ClearBackground(RAYWHITE);
DrawCircleV(ballPosition, 40, ballColor); DrawCircleV(ballPosition, 40, ballColor);
DrawText("move ball with mouse and click mouse button to change color", 10, 10, 20, DARKGRAY); DrawText("move ball with mouse and click mouse button to change color", 10, 10, 20, DARKGRAY);
EndDrawing(); EndDrawing();
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
} }
// De-Initialization // De-Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
CloseWindow(); // Close window and OpenGL context CloseWindow(); // Close window and OpenGL context
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
return 0; return 0;
} }
} }

View File

@ -13,7 +13,7 @@ public partial class core_mouse_wheel
* Copyright (c) 2014 Ramon Santamaria (@raysan5) * Copyright (c) 2014 Ramon Santamaria (@raysan5)
* *
********************************************************************************************/ ********************************************************************************************/
public static int Main() public static int Main()
{ {
@ -21,15 +21,15 @@ public partial class core_mouse_wheel
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
int screenWidth = 800; int screenWidth = 800;
int screenHeight = 450; int screenHeight = 450;
InitWindow(screenWidth, screenHeight, "raylib [core] example - mouse wheel"); InitWindow(screenWidth, screenHeight, "raylib [core] example - mouse wheel");
int boxPositionY = screenHeight/2 - 40; int boxPositionY = screenHeight/2 - 40;
int scrollSpeed = 4; // Scrolling speed in pixels int scrollSpeed = 4; // Scrolling speed in pixels
SetTargetFPS(60); SetTargetFPS(60);
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
// Main game loop // Main game loop
while (!WindowShouldClose()) // Detect window close button or ESC key while (!WindowShouldClose()) // Detect window close button or ESC key
{ {
@ -37,15 +37,15 @@ public partial class core_mouse_wheel
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
boxPositionY -= (GetMouseWheelMove()*scrollSpeed); boxPositionY -= (GetMouseWheelMove()*scrollSpeed);
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// Draw // Draw
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
BeginDrawing(); BeginDrawing();
ClearBackground(RAYWHITE); ClearBackground(RAYWHITE);
DrawRectangle(screenWidth/2 - 40, boxPositionY, 80, 80, MAROON); DrawRectangle(screenWidth/2 - 40, boxPositionY, 80, 80, MAROON);
DrawText("Use mouse wheel to move the cube up and down!", 10, 10, 20, GRAY); 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(FormatText("Box position Y: %03i", boxPositionY), 10, 40, 20, LIGHTGRAY);
DrawText($"Box position Y: {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(); EndDrawing();
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
} }
// De-Initialization // De-Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
CloseWindow(); // Close window and OpenGL context CloseWindow(); // Close window and OpenGL context
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
return 0; return 0;
} }
} }

View File

@ -13,31 +13,31 @@ public partial class core_random_values
* Copyright (c) 2014 Ramon Santamaria (@raysan5) * Copyright (c) 2014 Ramon Santamaria (@raysan5)
* *
********************************************************************************************/ ********************************************************************************************/
public static int Main() public static int Main()
{ {
// Initialization // Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
int screenWidth = 800; int screenWidth = 800;
int screenHeight = 450; int screenHeight = 450;
InitWindow(screenWidth, screenHeight, "raylib [core] example - generate random values"); InitWindow(screenWidth, screenHeight, "raylib [core] example - generate random values");
int framesCounter = 0; // Variable used to count frames int framesCounter = 0; // Variable used to count frames
int randValue = GetRandomValue(-8, 5); // Get a random integer number between -8 and 5 (both included) 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 SetTargetFPS(60); // Set our game to run at 60 frames-per-second
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
// Main game loop // Main game loop
while (!WindowShouldClose()) // Detect window close button or ESC key while (!WindowShouldClose()) // Detect window close button or ESC key
{ {
// Update // Update
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
framesCounter++; framesCounter++;
// Every two seconds (120 frames) a new random value is generated // Every two seconds (120 frames) a new random value is generated
if (((framesCounter/120)%2) == 1) if (((framesCounter/120)%2) == 1)
{ {
@ -45,27 +45,27 @@ public partial class core_random_values
framesCounter = 0; framesCounter = 0;
} }
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// Draw // Draw
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
BeginDrawing(); BeginDrawing();
ClearBackground(RAYWHITE); ClearBackground(RAYWHITE);
DrawText("Every 2 seconds a new random value is generated:", 130, 100, 20, MAROON); DrawText("Every 2 seconds a new random value is generated:", 130, 100, 20, MAROON);
//DrawText(FormatText("%i", randValue), 360, 180, 80, LIGHTGRAY); //DrawText(FormatText("%i", randValue), 360, 180, 80, LIGHTGRAY);
DrawText($"{randValue}", 360, 180, 80, LIGHTGRAY); DrawText($"{randValue}", 360, 180, 80, LIGHTGRAY);
EndDrawing(); EndDrawing();
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
} }
// De-Initialization // De-Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
CloseWindow(); // Close window and OpenGL context CloseWindow(); // Close window and OpenGL context
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
return 0; return 0;
} }
} }

View File

@ -13,7 +13,7 @@ public partial class core_storage_values
* Copyright (c) 2015 Ramon Santamaria (@raysan5) * Copyright (c) 2015 Ramon Santamaria (@raysan5)
* *
********************************************************************************************/ ********************************************************************************************/
// NOTE: Storage positions must start with 0, directly related to file memory layout // NOTE: Storage positions must start with 0, directly related to file memory layout
enum StorageData { STORAGE_SCORE = 0, STORAGE_HISCORE }; enum StorageData { STORAGE_SCORE = 0, STORAGE_HISCORE };
@ -23,17 +23,17 @@ public partial class core_storage_values
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
int screenWidth = 800; int screenWidth = 800;
int screenHeight = 450; int screenHeight = 450;
InitWindow(screenWidth, screenHeight, "raylib [core] example - storage save/load values"); InitWindow(screenWidth, screenHeight, "raylib [core] example - storage save/load values");
int score = 0; int score = 0;
int hiscore = 0; int hiscore = 0;
int framesCounter = 0; int framesCounter = 0;
SetTargetFPS(60); SetTargetFPS(60);
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
// Main game loop // Main game loop
while (!WindowShouldClose()) // Detect window close button or ESC key while (!WindowShouldClose()) // Detect window close button or ESC key
{ {
@ -44,7 +44,7 @@ public partial class core_storage_values
score = GetRandomValue(1000, 2000); score = GetRandomValue(1000, 2000);
hiscore = GetRandomValue(2000, 4000); hiscore = GetRandomValue(2000, 4000);
} }
if (IsKeyPressed(KEY_ENTER)) if (IsKeyPressed(KEY_ENTER))
{ {
StorageSaveValue((int)StorageData.STORAGE_SCORE, score); StorageSaveValue((int)StorageData.STORAGE_SCORE, score);
@ -56,14 +56,14 @@ public partial class core_storage_values
score = StorageLoadValue((int)StorageData.STORAGE_SCORE); score = StorageLoadValue((int)StorageData.STORAGE_SCORE);
hiscore = StorageLoadValue((int)StorageData.STORAGE_HISCORE); hiscore = StorageLoadValue((int)StorageData.STORAGE_HISCORE);
} }
framesCounter++; framesCounter++;
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// Draw // Draw
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
BeginDrawing(); BeginDrawing();
ClearBackground(RAYWHITE); ClearBackground(RAYWHITE);
// DrawText(FormatText("SCORE: %i", score), 280, 130, 40, MAROON); // 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 R to generate random numbers", 220, 40, 20, LIGHTGRAY);
DrawText("Press ENTER to SAVE values", 250, 310, 20, LIGHTGRAY); DrawText("Press ENTER to SAVE values", 250, 310, 20, LIGHTGRAY);
DrawText("Press SPACE to LOAD values", 252, 350, 20, LIGHTGRAY); DrawText("Press SPACE to LOAD values", 252, 350, 20, LIGHTGRAY);
EndDrawing(); EndDrawing();
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
} }
// De-Initialization // De-Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
CloseWindow(); // Close window and OpenGL context CloseWindow(); // Close window and OpenGL context
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
return 0; return 0;
} }
} }

View File

@ -16,23 +16,23 @@ public partial class core_vr_simulator
* Copyright (c) 2017 Ramon Santamaria (@raysan5) * Copyright (c) 2017 Ramon Santamaria (@raysan5)
* *
********************************************************************************************/ ********************************************************************************************/
public static int Main() public static int Main()
{ {
// Initialization // Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
int screenWidth = 1080; int screenWidth = 1080;
int screenHeight = 600; int screenHeight = 600;
// NOTE: screenWidth/screenHeight should match VR device aspect ratio // NOTE: screenWidth/screenHeight should match VR device aspect ratio
InitWindow(screenWidth, screenHeight, "raylib [core] example - vr simulator"); InitWindow(screenWidth, screenHeight, "raylib [core] example - vr simulator");
// Init VR simulator (Oculus Rift CV1 parameters) // Init VR simulator (Oculus Rift CV1 parameters)
// fails? // fails?
InitVrSimulator(GetVrDeviceInfo((int)HMD_OCULUS_RIFT_CV1)); InitVrSimulator(GetVrDeviceInfo((int)HMD_OCULUS_RIFT_CV1));
// Define the camera to look into our 3d world // Define the camera to look into our 3d world
Camera3D camera; Camera3D camera;
camera.position = new Vector3( 5.0f, 2.0f, 5.0f ); // Camera3D position 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.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.fovy = 60.0f; // Camera3D field-of-view Y
camera.type = (int)CAMERA_PERSPECTIVE; // Camera3D type camera.type = (int)CAMERA_PERSPECTIVE; // Camera3D type
Vector3 cubePosition = new Vector3( 0.0f, 0.0f, 0.0f ); Vector3 cubePosition = new Vector3( 0.0f, 0.0f, 0.0f );
SetCameraMode(camera, (int)CAMERA_FIRST_PERSON); // Set first person camera mode SetCameraMode(camera, (int)CAMERA_FIRST_PERSON); // Set first person camera mode
SetTargetFPS(90); // Set our game to run at 90 frames-per-second SetTargetFPS(90); // Set our game to run at 90 frames-per-second
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
// Main game loop // Main game loop
while (!WindowShouldClose()) // Detect window close button or ESC key while (!WindowShouldClose()) // Detect window close button or ESC key
{ {
// Update // Update
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
UpdateCamera(ref camera); // Update camera (simulator mode) UpdateCamera(ref camera); // Update camera (simulator mode)
if (IsKeyPressed(KEY_SPACE)) ToggleVrMode(); // Toggle VR mode if (IsKeyPressed(KEY_SPACE)) ToggleVrMode(); // Toggle VR mode
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// Draw // Draw
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
BeginDrawing(); BeginDrawing();
ClearBackground(RAYWHITE); ClearBackground(RAYWHITE);
BeginVrDrawing(); BeginVrDrawing();
BeginMode3D(camera); BeginMode3D(camera);
DrawCube(cubePosition, 2.0f, 2.0f, 2.0f, RED); DrawCube(cubePosition, 2.0f, 2.0f, 2.0f, RED);
DrawCubeWires(cubePosition, 2.0f, 2.0f, 2.0f, MAROON); DrawCubeWires(cubePosition, 2.0f, 2.0f, 2.0f, MAROON);
DrawGrid(40, 1.0f); DrawGrid(40, 1.0f);
EndMode3D(); EndMode3D();
EndVrDrawing(); EndVrDrawing();
DrawFPS(10, 10); DrawFPS(10, 10);
EndDrawing(); EndDrawing();
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
} }
// De-Initialization // De-Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
CloseVrSimulator(); // Close VR simulator CloseVrSimulator(); // Close VR simulator
CloseWindow(); // Close window and OpenGL context CloseWindow(); // Close window and OpenGL context
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
return 0; return 0;
} }
} }

View File

@ -15,17 +15,17 @@ public partial class core_world_screen
* Copyright (c) 2015 Ramon Santamaria (@raysan5) * Copyright (c) 2015 Ramon Santamaria (@raysan5)
* *
********************************************************************************************/ ********************************************************************************************/
public static int Main() public static int Main()
{ {
// Initialization // Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
int screenWidth = 800; int screenWidth = 800;
int screenHeight = 450; int screenHeight = 450;
InitWindow(screenWidth, screenHeight, "raylib [core] example - 3d camera free"); InitWindow(screenWidth, screenHeight, "raylib [core] example - 3d camera free");
// Define the camera to look into our 3d world // Define the camera to look into our 3d world
Camera3D camera = new Camera3D(); Camera3D camera = new Camera3D();
camera.position = new Vector3( 10.0f, 10.0f, 10.0f ); 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.up = new Vector3( 0.0f, 1.0f, 0.0f );
camera.fovy = 45.0f; camera.fovy = 45.0f;
camera.type = (int)CAMERA_PERSPECTIVE; camera.type = (int)CAMERA_PERSPECTIVE;
Vector3 cubePosition = new Vector3( 0.0f, 0.0f, 0.0f ); Vector3 cubePosition = new Vector3( 0.0f, 0.0f, 0.0f );
Vector2 cubeScreenPosition; Vector2 cubeScreenPosition;
SetCameraMode(camera, (int)CAMERA_FREE); // Set a free camera mode SetCameraMode(camera, (int)CAMERA_FREE); // Set a free camera mode
SetTargetFPS(60); // Set our game to run at 60 frames-per-second SetTargetFPS(60); // Set our game to run at 60 frames-per-second
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
// Main game loop // Main game loop
while (!WindowShouldClose()) // Detect window close button or ESC key while (!WindowShouldClose()) // Detect window close button or ESC key
{ {
// Update // Update
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
UpdateCamera(ref camera); // Update camera UpdateCamera(ref camera); // Update camera
// Calculate cube screen space position (with a little offset to be in top) // 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); cubeScreenPosition = GetWorldToScreen(new Vector3(cubePosition.x, cubePosition.y + 2.5f, cubePosition.z), camera);
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// Draw // Draw
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
BeginDrawing(); BeginDrawing();
ClearBackground(RAYWHITE); ClearBackground(RAYWHITE);
BeginMode3D(camera); BeginMode3D(camera);
DrawCube(cubePosition, 2.0f, 2.0f, 2.0f, RED); DrawCube(cubePosition, 2.0f, 2.0f, 2.0f, RED);
DrawCubeWires(cubePosition, 2.0f, 2.0f, 2.0f, MAROON); DrawCubeWires(cubePosition, 2.0f, 2.0f, 2.0f, MAROON);
DrawGrid(10, 1.0f); DrawGrid(10, 1.0f);
EndMode3D(); EndMode3D();
DrawText("Enemy: 100 / 100", (int)cubeScreenPosition.x - MeasureText("Enemy: 100 / 100", 20) / 2, (int)cubeScreenPosition.y, 20, BLACK); 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); 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(); EndDrawing();
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
} }
// De-Initialization // De-Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
CloseWindow(); // Close window and OpenGL context CloseWindow(); // Close window and OpenGL context
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
return 0; return 0;
} }
} }

View File

@ -15,17 +15,17 @@ public partial class models_billboard
* Copyright (c) 2015 Ramon Santamaria (@raysan5) * Copyright (c) 2015 Ramon Santamaria (@raysan5)
* *
********************************************************************************************/ ********************************************************************************************/
public static int Main() public static int Main()
{ {
// Initialization // Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
int screenWidth = 800; int screenWidth = 800;
int screenHeight = 450; int screenHeight = 450;
InitWindow(screenWidth, screenHeight, "raylib [models] example - drawing billboards"); InitWindow(screenWidth, screenHeight, "raylib [models] example - drawing billboards");
// Define the camera to look into our 3d world // Define the camera to look into our 3d world
Camera3D camera = new Camera3D(); Camera3D camera = new Camera3D();
camera.position = new Vector3( 5.0f, 4.0f, 5.0f ); 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.up = new Vector3( 0.0f, 1.0f, 0.0f );
camera.fovy = 45.0f; camera.fovy = 45.0f;
camera.type = CAMERA_PERSPECTIVE; camera.type = CAMERA_PERSPECTIVE;
Texture2D bill = LoadTexture("resources/billboard.png"); // Our texture billboard Texture2D bill = LoadTexture("resources/billboard.png"); // Our texture billboard
Vector3 billPosition = new Vector3( 0.0f, 2.0f, 0.0f ); // Position where draw 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 SetCameraMode(camera, (int)CAMERA_ORBITAL); // Set an orbital camera mode
SetTargetFPS(60); // Set our game to run at 60 frames-per-second SetTargetFPS(60); // Set our game to run at 60 frames-per-second
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
// Main game loop // Main game loop
while (!WindowShouldClose()) // Detect window close button or ESC key while (!WindowShouldClose()) // Detect window close button or ESC key
{ {
@ -49,34 +49,34 @@ public partial class models_billboard
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
UpdateCamera(ref camera); // Update camera UpdateCamera(ref camera); // Update camera
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// Draw // Draw
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
BeginDrawing(); BeginDrawing();
ClearBackground(RAYWHITE); ClearBackground(RAYWHITE);
BeginMode3D(camera); BeginMode3D(camera);
DrawBillboard(camera, bill, billPosition, 2.0f, WHITE); DrawBillboard(camera, bill, billPosition, 2.0f, WHITE);
DrawGrid(10, 1.0f); // Draw a grid DrawGrid(10, 1.0f); // Draw a grid
EndMode3D(); EndMode3D();
DrawFPS(10, 10); DrawFPS(10, 10);
EndDrawing(); EndDrawing();
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
} }
// De-Initialization // De-Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
UnloadTexture(bill); // Unload texture UnloadTexture(bill); // Unload texture
CloseWindow(); // Close window and OpenGL context CloseWindow(); // Close window and OpenGL context
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
return 0; return 0;
} }
} }

View File

@ -13,114 +13,114 @@ public partial class models_box_collisions
* Copyright (c) 2015 Ramon Santamaria (@raysan5) * Copyright (c) 2015 Ramon Santamaria (@raysan5)
* *
********************************************************************************************/ ********************************************************************************************/
public static int Main() public static int Main()
{ {
// Initialization // Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
int screenWidth = 800; int screenWidth = 800;
int screenHeight = 450; int screenHeight = 450;
InitWindow(screenWidth, screenHeight, "raylib [models] example - box collisions"); InitWindow(screenWidth, screenHeight, "raylib [models] example - box collisions");
// Define the camera to look into our 3d world // 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 ); 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 playerPosition = new Vector3( 0.0f, 1.0f, 2.0f );
Vector3 playerSize = new Vector3( 1.0f, 2.0f, 1.0f ); Vector3 playerSize = new Vector3( 1.0f, 2.0f, 1.0f );
Color playerColor = GREEN; Color playerColor = GREEN;
Vector3 enemyBoxPos = new Vector3( -4.0f, 1.0f, 0.0f ); Vector3 enemyBoxPos = new Vector3( -4.0f, 1.0f, 0.0f );
Vector3 enemyBoxSize = new Vector3( 2.0f, 2.0f, 2.0f ); Vector3 enemyBoxSize = new Vector3( 2.0f, 2.0f, 2.0f );
Vector3 enemySpherePos = new Vector3( 4.0f, 0.0f, 0.0f ); Vector3 enemySpherePos = new Vector3( 4.0f, 0.0f, 0.0f );
float enemySphereSize = 1.5f; float enemySphereSize = 1.5f;
bool collision = false; bool collision = false;
SetTargetFPS(60); // Set our game to run at 60 frames-per-second SetTargetFPS(60); // Set our game to run at 60 frames-per-second
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
// Main game loop // Main game loop
while (!WindowShouldClose()) // Detect window close button or ESC key while (!WindowShouldClose()) // Detect window close button or ESC key
{ {
// Update // Update
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// Move player // Move player
if (IsKeyDown(KEY_RIGHT)) playerPosition.x += 0.2f; if (IsKeyDown(KEY_RIGHT)) playerPosition.x += 0.2f;
else if (IsKeyDown(KEY_LEFT)) 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_DOWN)) playerPosition.z += 0.2f;
else if (IsKeyDown(KEY_UP)) playerPosition.z -= 0.2f; else if (IsKeyDown(KEY_UP)) playerPosition.z -= 0.2f;
collision = false; collision = false;
// Check collisions player vs enemy-box // Check collisions player vs enemy-box
if (CheckCollisionBoxes( if (CheckCollisionBoxes(
new BoundingBox(new Vector3( playerPosition.x - playerSize.x/2, new BoundingBox(new Vector3( playerPosition.x - playerSize.x/2,
playerPosition.y - playerSize.y/2, playerPosition.y - playerSize.y/2,
playerPosition.z - playerSize.z/2 ), playerPosition.z - playerSize.z/2 ),
new Vector3( playerPosition.x + playerSize.x/2, new Vector3( playerPosition.x + playerSize.x/2,
playerPosition.y + playerSize.y/2, playerPosition.y + playerSize.y/2,
playerPosition.z + playerSize.z/2 )), playerPosition.z + playerSize.z/2 )),
new BoundingBox(new Vector3( enemyBoxPos.x - enemyBoxSize.x/2, new BoundingBox(new Vector3( enemyBoxPos.x - enemyBoxSize.x/2,
enemyBoxPos.y - enemyBoxSize.y/2, enemyBoxPos.y - enemyBoxSize.y/2,
enemyBoxPos.z - enemyBoxSize.z/2 ), enemyBoxPos.z - enemyBoxSize.z/2 ),
new Vector3( enemyBoxPos.x + enemyBoxSize.x/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; enemyBoxPos.z + enemyBoxSize.z/2 )))) collision = true;
// Check collisions player vs enemy-sphere // Check collisions player vs enemy-sphere
if (CheckCollisionBoxSphere( if (CheckCollisionBoxSphere(
new BoundingBox(new Vector3( playerPosition.x - playerSize.x/2, new BoundingBox(new Vector3( playerPosition.x - playerSize.x/2,
playerPosition.y - playerSize.y/2, playerPosition.y - playerSize.y/2,
playerPosition.z - playerSize.z/2 ), playerPosition.z - playerSize.z/2 ),
new Vector3( playerPosition.x + playerSize.x/2, new Vector3( playerPosition.x + playerSize.x/2,
playerPosition.y + playerSize.y/2, playerPosition.y + playerSize.y/2,
playerPosition.z + playerSize.z/2 )), playerPosition.z + playerSize.z/2 )),
enemySpherePos, enemySphereSize)) collision = true; enemySpherePos, enemySphereSize)) collision = true;
if (collision) playerColor = RED; if (collision) playerColor = RED;
else playerColor = GREEN; else playerColor = GREEN;
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// Draw // Draw
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
BeginDrawing(); BeginDrawing();
ClearBackground(RAYWHITE); ClearBackground(RAYWHITE);
BeginMode3D(camera); BeginMode3D(camera);
// Draw enemy-box // Draw enemy-box
DrawCube(enemyBoxPos, enemyBoxSize.x, enemyBoxSize.y, enemyBoxSize.z, GRAY); DrawCube(enemyBoxPos, enemyBoxSize.x, enemyBoxSize.y, enemyBoxSize.z, GRAY);
DrawCubeWires(enemyBoxPos, enemyBoxSize.x, enemyBoxSize.y, enemyBoxSize.z, DARKGRAY); DrawCubeWires(enemyBoxPos, enemyBoxSize.x, enemyBoxSize.y, enemyBoxSize.z, DARKGRAY);
// Draw enemy-sphere // Draw enemy-sphere
DrawSphere(enemySpherePos, enemySphereSize, GRAY); DrawSphere(enemySpherePos, enemySphereSize, GRAY);
DrawSphereWires(enemySpherePos, enemySphereSize, 16, 16, DARKGRAY); DrawSphereWires(enemySpherePos, enemySphereSize, 16, 16, DARKGRAY);
// Draw player // Draw player
DrawCubeV(playerPosition, playerSize, playerColor); DrawCubeV(playerPosition, playerSize, playerColor);
DrawGrid(10, 1.0f); // Draw a grid DrawGrid(10, 1.0f); // Draw a grid
EndMode3D(); EndMode3D();
DrawText("Move player with cursors to collide", 220, 40, 20, GRAY); DrawText("Move player with cursors to collide", 220, 40, 20, GRAY);
DrawFPS(10, 10); DrawFPS(10, 10);
EndDrawing(); EndDrawing();
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
} }
// De-Initialization // De-Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
CloseWindow(); // Close window and OpenGL context CloseWindow(); // Close window and OpenGL context
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
return 0; return 0;
} }
} }

View File

@ -15,39 +15,39 @@ public partial class models_cubicmap
* Copyright (c) 2015 Ramon Santamaria (@raysan5) * Copyright (c) 2015 Ramon Santamaria (@raysan5)
* *
********************************************************************************************/ ********************************************************************************************/
public static int Main() public static int Main()
{ {
// Initialization // Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
int screenWidth = 800; int screenWidth = 800;
int screenHeight = 450; int screenHeight = 450;
InitWindow(screenWidth, screenHeight, "raylib [models] example - cubesmap loading and drawing"); InitWindow(screenWidth, screenHeight, "raylib [models] example - cubesmap loading and drawing");
// Define the camera to look into our 3d world // 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 ); 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) Image image = LoadImage("resources/cubicmap.png"); // Load cubicmap image (RAM)
Texture2D cubicmap = LoadTextureFromImage(image); // Convert image to texture to display (VRAM) Texture2D cubicmap = LoadTextureFromImage(image); // Convert image to texture to display (VRAM)
Mesh mesh = GenMeshCubicmap(image, new Vector3( 1.0f, 1.0f, 1.0f )); Mesh mesh = GenMeshCubicmap(image, new Vector3( 1.0f, 1.0f, 1.0f ));
Model model = LoadModelFromMesh(mesh); Model model = LoadModelFromMesh(mesh);
// NOTE: By default each cube is mapped to one part of texture atlas // NOTE: By default each cube is mapped to one part of texture atlas
Texture2D texture = LoadTexture("resources/cubicmap_atlas.png"); // Load map texture Texture2D texture = LoadTexture("resources/cubicmap_atlas.png"); // Load map texture
model.material.maps[(int)MAP_ALBEDO].texture = texture; // Set map diffuse 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 Vector3 mapPosition = new Vector3( -16.0f, 0.0f, -8.0f ); // Set model position
UnloadImage(image); // Unload cubesmap image from RAM, already uploaded to VRAM UnloadImage(image); // Unload cubesmap image from RAM, already uploaded to VRAM
SetCameraMode(camera, (int)CAMERA_ORBITAL); // Set an orbital camera mode SetCameraMode(camera, (int)CAMERA_ORBITAL); // Set an orbital camera mode
SetTargetFPS(60); // Set our game to run at 60 frames-per-second SetTargetFPS(60); // Set our game to run at 60 frames-per-second
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
// Main game loop // Main game loop
while (!WindowShouldClose()) // Detect window close button or ESC key while (!WindowShouldClose()) // Detect window close button or ESC key
{ {
@ -55,40 +55,40 @@ public partial class models_cubicmap
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
UpdateCamera(ref camera); // Update camera UpdateCamera(ref camera); // Update camera
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// Draw // Draw
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
BeginDrawing(); BeginDrawing();
ClearBackground(RAYWHITE); ClearBackground(RAYWHITE);
BeginMode3D(camera); BeginMode3D(camera);
DrawModel(model, mapPosition, 1.0f, WHITE); DrawModel(model, mapPosition, 1.0f, WHITE);
EndMode3D(); EndMode3D();
DrawTextureEx(cubicmap, new Vector2( screenWidth - cubicmap.width*4 - 20, 20 ), 0.0f, 4.0f, WHITE); 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); DrawRectangleLines(screenWidth - cubicmap.width*4 - 20, 20, cubicmap.width*4, cubicmap.height*4, GREEN);
DrawText("cubicmap image used to", 658, 90, 10, GRAY); DrawText("cubicmap image used to", 658, 90, 10, GRAY);
DrawText("generate map 3d model", 658, 104, 10, GRAY); DrawText("generate map 3d model", 658, 104, 10, GRAY);
DrawFPS(10, 10); DrawFPS(10, 10);
EndDrawing(); EndDrawing();
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
} }
// De-Initialization // De-Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
UnloadTexture(cubicmap); // Unload cubicmap texture UnloadTexture(cubicmap); // Unload cubicmap texture
UnloadTexture(texture); // Unload map texture UnloadTexture(texture); // Unload map texture
UnloadModel(model); // Unload map model UnloadModel(model); // Unload map model
CloseWindow(); // Close window and OpenGL context CloseWindow(); // Close window and OpenGL context
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
return 0; return 0;
} }
} }

View File

@ -14,17 +14,17 @@ public partial class models_geometric_shapes
* Copyright (c) 2014 Ramon Santamaria (@raysan5) * Copyright (c) 2014 Ramon Santamaria (@raysan5)
* *
********************************************************************************************/ ********************************************************************************************/
public static int Main() public static int Main()
{ {
// Initialization // Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
int screenWidth = 800; int screenWidth = 800;
int screenHeight = 450; int screenHeight = 450;
InitWindow(screenWidth, screenHeight, "raylib [models] example - geometric shapes"); InitWindow(screenWidth, screenHeight, "raylib [models] example - geometric shapes");
// Define the camera to look into our 3d world // Define the camera to look into our 3d world
Camera3D camera = new Camera3D(); Camera3D camera = new Camera3D();
camera.position = new Vector3( 0.0f, 10.0f, 10.0f ); 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.up = new Vector3( 0.0f, 1.0f, 0.0f );
camera.fovy = 45.0f; camera.fovy = 45.0f;
camera.type = CAMERA_PERSPECTIVE; camera.type = CAMERA_PERSPECTIVE;
SetTargetFPS(60); // Set our game to run at 60 frames-per-second SetTargetFPS(60); // Set our game to run at 60 frames-per-second
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
// Main game loop // Main game loop
while (!WindowShouldClose()) // Detect window close button or ESC key while (!WindowShouldClose()) // Detect window close button or ESC key
{ {
@ -43,44 +43,44 @@ public partial class models_geometric_shapes
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// TODO: Update your variables here // TODO: Update your variables here
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// Draw // Draw
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
BeginDrawing(); BeginDrawing();
ClearBackground(RAYWHITE); ClearBackground(RAYWHITE);
BeginMode3D(camera); BeginMode3D(camera);
DrawCube(new Vector3(-4.0f, 0.0f, 2.0f), 2.0f, 5.0f, 2.0f, RED); 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), 2.0f, 5.0f, 2.0f, GOLD);
DrawCubeWires(new Vector3(-4.0f, 0.0f, -2.0f), 3.0f, 6.0f, 2.0f, MAROON); 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); 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); 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); 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.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); 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); 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); DrawCylinderWires(new Vector3(1.0f, 0.0f, -4.0f), 0.0f, 1.5f, 3.0f, 8, PINK);
DrawGrid(10, 1.0f); // Draw a grid DrawGrid(10, 1.0f); // Draw a grid
EndMode3D(); EndMode3D();
DrawFPS(10, 10); DrawFPS(10, 10);
EndDrawing(); EndDrawing();
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
} }
// De-Initialization // De-Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
CloseWindow(); // Close window and OpenGL context CloseWindow(); // Close window and OpenGL context
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
return 0; return 0;
} }
} }

View File

@ -15,36 +15,36 @@ public partial class models_heightmap
* Copyright (c) 2015 Ramon Santamaria (@raysan5) * Copyright (c) 2015 Ramon Santamaria (@raysan5)
* *
********************************************************************************************/ ********************************************************************************************/
public static int Main() public static int Main()
{ {
// Initialization // Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
int screenWidth = 800; int screenWidth = 800;
int screenHeight = 450; int screenHeight = 450;
InitWindow(screenWidth, screenHeight, "raylib [models] example - heightmap loading and drawing"); InitWindow(screenWidth, screenHeight, "raylib [models] example - heightmap loading and drawing");
// Define our custom camera to look into our 3d world // 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 ); 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) Image image = LoadImage("resources/heightmap.png"); // Load heightmap image (RAM)
Texture2D texture = LoadTextureFromImage(image); // Convert image to texture (VRAM) Texture2D texture = LoadTextureFromImage(image); // Convert image to texture (VRAM)
Mesh mesh = GenMeshHeightmap(image, new Vector3( 16, 8, 16 )); // Generate heightmap mesh (RAM and 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 model = LoadModelFromMesh(mesh); // Load model from generated mesh
model.material.maps[(int)MAP_ALBEDO].texture = texture; // Set map diffuse texture 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 Vector3 mapPosition = new Vector3( -8.0f, 0.0f, -8.0f ); // Define model position
UnloadImage(image); // Unload heightmap image from RAM, already uploaded to VRAM UnloadImage(image); // Unload heightmap image from RAM, already uploaded to VRAM
SetCameraMode(camera, (int)CAMERA_ORBITAL); // Set an orbital camera mode SetCameraMode(camera, (int)CAMERA_ORBITAL); // Set an orbital camera mode
SetTargetFPS(60); // Set our game to run at 60 frames-per-second SetTargetFPS(60); // Set our game to run at 60 frames-per-second
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
// Main game loop // Main game loop
while (!WindowShouldClose()) // Detect window close button or ESC key while (!WindowShouldClose()) // Detect window close button or ESC key
{ {
@ -52,38 +52,38 @@ public partial class models_heightmap
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
UpdateCamera(ref camera); // Update camera UpdateCamera(ref camera); // Update camera
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// Draw // Draw
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
BeginDrawing(); BeginDrawing();
ClearBackground(RAYWHITE); ClearBackground(RAYWHITE);
BeginMode3D(camera); BeginMode3D(camera);
DrawModel(model, mapPosition, 1.0f, RED); DrawModel(model, mapPosition, 1.0f, RED);
DrawGrid(20, 1.0f); DrawGrid(20, 1.0f);
EndMode3D(); EndMode3D();
DrawTexture(texture, screenWidth - texture.width - 20, 20, WHITE); DrawTexture(texture, screenWidth - texture.width - 20, 20, WHITE);
DrawRectangleLines(screenWidth - texture.width - 20, 20, texture.width, texture.height, GREEN); DrawRectangleLines(screenWidth - texture.width - 20, 20, texture.width, texture.height, GREEN);
DrawFPS(10, 10); DrawFPS(10, 10);
EndDrawing(); EndDrawing();
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
} }
// De-Initialization // De-Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
UnloadTexture(texture); // Unload texture UnloadTexture(texture); // Unload texture
UnloadModel(model); // Unload model UnloadModel(model); // Unload model
CloseWindow(); // Close window and OpenGL context CloseWindow(); // Close window and OpenGL context
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
return 0; return 0;
} }
} }

View File

@ -15,26 +15,26 @@ public partial class models_mesh_generation
* Copyright (c) 2017 Ramon Santamaria (Ray San) * Copyright (c) 2017 Ramon Santamaria (Ray San)
* *
********************************************************************************************/ ********************************************************************************************/
public const int NUM_MODELS = 7; public const int NUM_MODELS = 7;
public static int Main() public static int Main()
{ {
// Initialization // Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
int screenWidth = 800; int screenWidth = 800;
int screenHeight = 450; int screenHeight = 450;
InitWindow(screenWidth, screenHeight, "raylib [models] example - mesh generation"); InitWindow(screenWidth, screenHeight, "raylib [models] example - mesh generation");
// We generate a isChecked image for texturing // We generate a isChecked image for texturing
Image isChecked = GenImageChecked(2, 2, 1, 1, RED, GREEN); Image isChecked = GenImageChecked(2, 2, 1, 1, RED, GREEN);
Texture2D texture = LoadTextureFromImage(isChecked); Texture2D texture = LoadTextureFromImage(isChecked);
UnloadImage(isChecked); UnloadImage(isChecked);
Model[] models = new Model[NUM_MODELS]; Model[] models = new Model[NUM_MODELS];
models[0] = LoadModelFromMesh(GenMeshPlane(2, 2, 5, 5)); models[0] = LoadModelFromMesh(GenMeshPlane(2, 2, 5, 5));
models[1] = LoadModelFromMesh(GenMeshCube(2.0f, 1.0f, 2.0f)); models[1] = LoadModelFromMesh(GenMeshCube(2.0f, 1.0f, 2.0f));
models[2] = LoadModelFromMesh(GenMeshSphere(2, 32, 32)); 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[4] = LoadModelFromMesh(GenMeshCylinder(1, 2, 16));
models[5] = LoadModelFromMesh(GenMeshTorus(0.25f, 4.0f, 16, 32)); models[5] = LoadModelFromMesh(GenMeshTorus(0.25f, 4.0f, 16, 32));
models[6] = LoadModelFromMesh(GenMeshKnot(1.0f, 2.0f, 16, 128)); models[6] = LoadModelFromMesh(GenMeshKnot(1.0f, 2.0f, 16, 128));
// Set isChecked texture as default diffuse component for all models material // 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; 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 // 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 ); 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 // Model drawing position
Vector3 position = new Vector3( 0.0f, 0.0f, 0.0f ); Vector3 position = new Vector3( 0.0f, 0.0f, 0.0f );
int currentModel = 0; int currentModel = 0;
SetCameraMode(camera, (int)CAMERA_ORBITAL); // Set a orbital camera mode SetCameraMode(camera, (int)CAMERA_ORBITAL); // Set a orbital camera mode
SetTargetFPS(60); // Set our game to run at 60 frames-per-second SetTargetFPS(60); // Set our game to run at 60 frames-per-second
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
// Main game loop // Main game loop
while (!WindowShouldClose()) // Detect window close button or ESC key while (!WindowShouldClose()) // Detect window close button or ESC key
{ {
// Update // Update
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
UpdateCamera(ref camera); // Update internal camera and our camera UpdateCamera(ref camera); // Update internal camera and our camera
if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON))
{ {
currentModel = (currentModel + 1)%NUM_MODELS; // Cycle between the textures currentModel = (currentModel + 1)%NUM_MODELS; // Cycle between the textures
} }
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// Draw // Draw
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
BeginDrawing(); BeginDrawing();
ClearBackground(RAYWHITE); ClearBackground(RAYWHITE);
BeginMode3D(camera); BeginMode3D(camera);
DrawModel(models[currentModel], position, 1.0f, WHITE); DrawModel(models[currentModel], position, 1.0f, WHITE);
DrawGrid(10, 1.0f); DrawGrid(10, 1.0f);
EndMode3D(); EndMode3D();
DrawRectangle(30, 400, 310, 30, Fade(SKYBLUE, 0.5f)); DrawRectangle(30, 400, 310, 30, Fade(SKYBLUE, 0.5f));
DrawRectangleLines(30, 400, 310, 30, Fade(DARKBLUE, 0.5f)); DrawRectangleLines(30, 400, 310, 30, Fade(DARKBLUE, 0.5f));
DrawText("MOUSE LEFT BUTTON to CYCLE PROCEDURAL MODELS", 40, 410, 10, BLUE); DrawText("MOUSE LEFT BUTTON to CYCLE PROCEDURAL MODELS", 40, 410, 10, BLUE);
switch(currentModel) switch(currentModel)
{ {
case 0: DrawText("PLANE", 680, 10, 20, DARKBLUE); break; 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; case 6: DrawText("KNOT", 680, 10, 20, DARKBLUE); break;
default: break; default: break;
} }
EndDrawing(); EndDrawing();
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
} }
// De-Initialization // De-Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
// Unload models data (GPU VRAM) // Unload models data (GPU VRAM)
for (int i = 0; i < NUM_MODELS; i++) UnloadModel(models[i]); for (int i = 0; i < NUM_MODELS; i++) UnloadModel(models[i]);
CloseWindow(); // Close window and OpenGL context CloseWindow(); // Close window and OpenGL context
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
return 0; return 0;
} }
} }

View File

@ -17,19 +17,19 @@ public partial class models_mesh_picking
* Example contributed by Joel Davis (@joeld42) * Example contributed by Joel Davis (@joeld42)
* *
********************************************************************************************/ ********************************************************************************************/
public const float FLT_MAX = 3.40282347E+38F; public const float FLT_MAX = 3.40282347E+38F;
public static int Main() public static int Main()
{ {
// Initialization // Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
int screenWidth = 800; int screenWidth = 800;
int screenHeight = 450; int screenHeight = 450;
InitWindow(screenWidth, screenHeight, "raylib [models] example - mesh picking"); InitWindow(screenWidth, screenHeight, "raylib [models] example - mesh picking");
// Define the camera to look into our 3d world // Define the camera to look into our 3d world
Camera3D camera; Camera3D camera;
camera.position = new Vector3( 20.0f, 20.0f, 20.0f ); // Camera3D position 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.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.fovy = 45.0f; // Camera3D field-of-view Y
camera.type = CAMERA_PERSPECTIVE; // Camera3D mode type camera.type = CAMERA_PERSPECTIVE; // Camera3D mode type
Ray ray; // Picking ray Ray ray; // Picking ray
Model tower = LoadModel("resources/models/turret.obj"); // Load OBJ model Model tower = LoadModel("resources/models/turret.obj"); // Load OBJ model
Texture2D texture = LoadTexture("resources/models/turret_diffuse.png"); // Load model texture Texture2D texture = LoadTexture("resources/models/turret_diffuse.png"); // Load model texture
tower.material.maps[(int)MAP_ALBEDO].texture = texture; // Set model diffuse 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 Vector3 towerPos = new Vector3( 0.0f, 0.0f, 0.0f ); // Set model position
BoundingBox towerBBox = MeshBoundingBox(tower.mesh); // Get mesh bounding box BoundingBox towerBBox = MeshBoundingBox(tower.mesh); // Get mesh bounding box
bool hitMeshBBox = false; bool hitMeshBBox = false;
bool hitTriangle = false; bool hitTriangle = false;
// Test triangle // 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 tb = new Vector3( -4.0f, 2.5f, 1.0f );
Vector3 tc = new Vector3( -8.0f, 6.5f, 0.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 SetCameraMode(camera, (int)CAMERA_FREE); // Set a free camera mode
SetTargetFPS(60); // Set our game to run at 60 frames-per-second SetTargetFPS(60); // Set our game to run at 60 frames-per-second
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
// Main game loop // Main game loop
@ -66,143 +66,143 @@ public partial class models_mesh_picking
// Update // Update
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
UpdateCamera(ref camera); // Update camera UpdateCamera(ref camera); // Update camera
// Display information about closest hit // Display information about closest hit
RayHitInfo nearestHit = new RayHitInfo(); RayHitInfo nearestHit = new RayHitInfo();
string hitObjectName = "None"; string hitObjectName = "None";
nearestHit.distance = FLT_MAX; nearestHit.distance = FLT_MAX;
nearestHit.hit = false; nearestHit.hit = false;
Color cursorColor = WHITE; Color cursorColor = WHITE;
// Get ray and test against ground, triangle, and mesh // Get ray and test against ground, triangle, and mesh
ray = GetMouseRay(GetMousePosition(), camera); ray = GetMouseRay(GetMousePosition(), camera);
// Check ray collision aginst ground plane // Check ray collision aginst ground plane
RayHitInfo groundHitInfo = GetCollisionRayGround(ray, 0.0f); RayHitInfo groundHitInfo = GetCollisionRayGround(ray, 0.0f);
if ((groundHitInfo.hit) && (groundHitInfo.distance < nearestHit.distance)) if ((groundHitInfo.hit) && (groundHitInfo.distance < nearestHit.distance))
{ {
nearestHit = groundHitInfo; nearestHit = groundHitInfo;
cursorColor = GREEN; cursorColor = GREEN;
hitObjectName = "Ground"; hitObjectName = "Ground";
} }
// Check ray collision against test triangle // Check ray collision against test triangle
RayHitInfo triHitInfo = GetCollisionRayTriangle(ray, ta, tb, tc); RayHitInfo triHitInfo = GetCollisionRayTriangle(ray, ta, tb, tc);
if ((triHitInfo.hit) && (triHitInfo.distance < nearestHit.distance)) if ((triHitInfo.hit) && (triHitInfo.distance < nearestHit.distance))
{ {
nearestHit = triHitInfo; nearestHit = triHitInfo;
cursorColor = PURPLE; cursorColor = PURPLE;
hitObjectName = "Triangle"; hitObjectName = "Triangle";
bary = Vector3Barycenter(nearestHit.position, ta, tb, tc); bary = Vector3Barycenter(nearestHit.position, ta, tb, tc);
hitTriangle = true; hitTriangle = true;
} }
else hitTriangle = false; else hitTriangle = false;
RayHitInfo meshHitInfo; RayHitInfo meshHitInfo;
// Check ray collision against bounding box first, before trying the full ray-mesh test // Check ray collision against bounding box first, before trying the full ray-mesh test
if (CheckCollisionRayBox(ray, towerBBox)) if (CheckCollisionRayBox(ray, towerBBox))
{ {
hitMeshBBox = true; hitMeshBBox = true;
// Check ray collision against model // Check ray collision against model
// NOTE: It considers model.transform matrix! // NOTE: It considers model.transform matrix!
meshHitInfo = GetCollisionRayModel(ray, ref tower); meshHitInfo = GetCollisionRayModel(ray, ref tower);
if ((meshHitInfo.hit) && (meshHitInfo.distance < nearestHit.distance)) if ((meshHitInfo.hit) && (meshHitInfo.distance < nearestHit.distance))
{ {
nearestHit = meshHitInfo; nearestHit = meshHitInfo;
cursorColor = ORANGE; cursorColor = ORANGE;
hitObjectName = "Mesh"; hitObjectName = "Mesh";
} }
} hitMeshBBox = false; } hitMeshBBox = false;
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// Draw // Draw
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
BeginDrawing(); BeginDrawing();
ClearBackground(RAYWHITE); ClearBackground(RAYWHITE);
BeginMode3D(camera); BeginMode3D(camera);
// Draw the tower // Draw the tower
// WARNING: If scale is different than 1.0f, // WARNING: If scale is different than 1.0f,
// not considered by GetCollisionRayModel() // not considered by GetCollisionRayModel()
DrawModel(tower, towerPos, 1.0f, WHITE); DrawModel(tower, towerPos, 1.0f, WHITE);
// Draw the test triangle // Draw the test triangle
DrawLine3D(ta, tb, PURPLE); DrawLine3D(ta, tb, PURPLE);
DrawLine3D(tb, tc, PURPLE); DrawLine3D(tb, tc, PURPLE);
DrawLine3D(tc, ta, PURPLE); DrawLine3D(tc, ta, PURPLE);
// Draw the mesh bbox if we hit it // Draw the mesh bbox if we hit it
if (hitMeshBBox) DrawBoundingBox(towerBBox, LIME); if (hitMeshBBox) DrawBoundingBox(towerBBox, LIME);
// If we hit something, draw the cursor at the hit point // 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); DrawCube(nearestHit.position, 0.3f, 0.3f, 0.3f, cursorColor);
DrawCubeWires(nearestHit.position, 0.3f, 0.3f, 0.3f, RED); DrawCubeWires(nearestHit.position, 0.3f, 0.3f, 0.3f, RED);
Vector3 normalEnd; Vector3 normalEnd;
normalEnd.x = nearestHit.position.x + nearestHit.normal.x; normalEnd.x = nearestHit.position.x + nearestHit.normal.x;
normalEnd.y = nearestHit.position.y + nearestHit.normal.y; normalEnd.y = nearestHit.position.y + nearestHit.normal.y;
normalEnd.z = nearestHit.position.z + nearestHit.normal.z; normalEnd.z = nearestHit.position.z + nearestHit.normal.z;
DrawLine3D(nearestHit.position, normalEnd, RED); DrawLine3D(nearestHit.position, normalEnd, RED);
} }
DrawRay(ray, MAROON); DrawRay(ray, MAROON);
DrawGrid(10, 10.0f); DrawGrid(10, 10.0f);
EndMode3D(); EndMode3D();
// Draw some debug GUI text // Draw some debug GUI text
DrawText(FormatText("Hit Object: %s", hitObjectName), 10, 50, 10, BLACK); DrawText(FormatText("Hit Object: %s", hitObjectName), 10, 50, 10, BLACK);
if (nearestHit.hit) if (nearestHit.hit)
{ {
int ypos = 70; int ypos = 70;
DrawText(FormatText("Distance: %3.2f", nearestHit.distance), 10, ypos, 10, BLACK); DrawText(FormatText("Distance: %3.2f", nearestHit.distance), 10, ypos, 10, BLACK);
DrawText(FormatText("Hit Pos: %3.2f %3.2f %3.2f", DrawText(FormatText("Hit Pos: %3.2f %3.2f %3.2f",
nearestHit.position.x, nearestHit.position.x,
nearestHit.position.y, nearestHit.position.y,
nearestHit.position.z), 10, ypos + 15, 10, BLACK); nearestHit.position.z), 10, ypos + 15, 10, BLACK);
DrawText(FormatText("Hit Norm: %3.2f %3.2f %3.2f", DrawText(FormatText("Hit Norm: %3.2f %3.2f %3.2f",
nearestHit.normal.x, nearestHit.normal.x,
nearestHit.normal.y, nearestHit.normal.y,
nearestHit.normal.z), 10, ypos + 30, 10, BLACK); 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); 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("Use Mouse to Move Camera", 10, 430, 10, GRAY);
DrawText("(c) Turret 3D model by Alberto Cano", screenWidth - 200, screenHeight - 20, 10, GRAY); DrawText("(c) Turret 3D model by Alberto Cano", screenWidth - 200, screenHeight - 20, 10, GRAY);
DrawFPS(10, 10); DrawFPS(10, 10);
EndDrawing(); EndDrawing();
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
} }
// De-Initialization // De-Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
UnloadModel(tower); // Unload model UnloadModel(tower); // Unload model
UnloadTexture(texture); // Unload texture UnloadTexture(texture); // Unload texture
CloseWindow(); // Close window and OpenGL context CloseWindow(); // Close window and OpenGL context
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
return 0; return 0;
} }
} }

View File

@ -15,17 +15,17 @@ public partial class models_obj_loading
* Copyright (c) 2014 Ramon Santamaria (@raysan5) * Copyright (c) 2014 Ramon Santamaria (@raysan5)
* *
********************************************************************************************/ ********************************************************************************************/
public static int Main() public static int Main()
{ {
// Initialization // Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
int screenWidth = 800; int screenWidth = 800;
int screenHeight = 450; int screenHeight = 450;
InitWindow(screenWidth, screenHeight, "raylib [models] example - obj model loading"); InitWindow(screenWidth, screenHeight, "raylib [models] example - obj model loading");
// Define the camera to look into our 3d world // Define the camera to look into our 3d world
Camera3D camera = new Camera3D(); Camera3D camera = new Camera3D();
camera.position = new Vector3( 8.0f, 8.0f, 8.0f ); // Camera3D position 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.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.fovy = 45.0f; // Camera3D field-of-view Y
camera.type = CAMERA_PERSPECTIVE; // Camera3D mode type camera.type = CAMERA_PERSPECTIVE; // Camera3D mode type
Model model = LoadModel("resources/models/castle.obj"); // Load OBJ model Model model = LoadModel("resources/models/castle.obj"); // Load OBJ model
Texture2D texture = LoadTexture("resources/models/castle_diffuse.png"); // Load model texture Texture2D texture = LoadTexture("resources/models/castle_diffuse.png"); // Load model texture
model.material.maps[(int)MAP_ALBEDO].texture = texture; // Set map diffuse 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 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 SetTargetFPS(60); // Set our game to run at 60 frames-per-second
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
// Main game loop // Main game loop
while (!WindowShouldClose()) // Detect window close button or ESC key while (!WindowShouldClose()) // Detect window close button or ESC key
{ {
@ -49,39 +49,39 @@ public partial class models_obj_loading
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
//... //...
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// Draw // Draw
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
BeginDrawing(); BeginDrawing();
ClearBackground(RAYWHITE); ClearBackground(RAYWHITE);
BeginMode3D(camera); BeginMode3D(camera);
DrawModel(model, position, 0.2f, WHITE); // Draw 3d model with texture DrawModel(model, position, 0.2f, WHITE); // Draw 3d model with texture
DrawGrid(10, 1.0f); // Draw a grid DrawGrid(10, 1.0f); // Draw a grid
DrawGizmo(position); // Draw gizmo DrawGizmo(position); // Draw gizmo
EndMode3D(); EndMode3D();
DrawText("(c) Castle 3D model by Alberto Cano", screenWidth - 200, screenHeight - 20, 10, GRAY); DrawText("(c) Castle 3D model by Alberto Cano", screenWidth - 200, screenHeight - 20, 10, GRAY);
DrawFPS(10, 10); DrawFPS(10, 10);
EndDrawing(); EndDrawing();
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
} }
// De-Initialization // De-Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
UnloadTexture(texture); // Unload texture UnloadTexture(texture); // Unload texture
UnloadModel(model); // Unload model UnloadModel(model); // Unload model
CloseWindow(); // Close window and OpenGL context CloseWindow(); // Close window and OpenGL context
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
return 0; return 0;
} }
} }

View File

@ -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 * 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) * Copyright (c) 2018 Max Danielsson ref Ramon Santamaria (@raysan5)
* *
********************************************************************************************/ ********************************************************************************************/
public const float FOVY_PERSPECTIVE = 45.0f; public const float FOVY_PERSPECTIVE = 45.0f;
public const float WIDTH_ORTHOGRAPHIC = 10.0f; public const float WIDTH_ORTHOGRAPHIC = 10.0f;
public static int Main() public static int Main()
{ {
// Initialization // Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
int screenWidth = 800; int screenWidth = 800;
int screenHeight = 450; int screenHeight = 450;
InitWindow(screenWidth, screenHeight, "raylib [models] example - geometric shapes"); InitWindow(screenWidth, screenHeight, "raylib [models] example - geometric shapes");
// Define the camera to look into our 3d world // 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 ); 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 SetTargetFPS(60); // Set our game to run at 60 frames-per-second
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
// Main game loop // Main game loop
while (!WindowShouldClose()) // Detect window close button or ESC key while (!WindowShouldClose()) // Detect window close button or ESC key
{ {
// Update // Update
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
if (IsKeyPressed(KEY_SPACE)) if (IsKeyPressed(KEY_SPACE))
{ {
if (camera.type == CAMERA_PERSPECTIVE) if (camera.type == CAMERA_PERSPECTIVE)
{ {
camera.fovy = WIDTH_ORTHOGRAPHIC; camera.fovy = WIDTH_ORTHOGRAPHIC;
camera.type = CAMERA_ORTHOGRAPHIC; camera.type = CAMERA_ORTHOGRAPHIC;
} }
else else
{ {
camera.fovy = FOVY_PERSPECTIVE; camera.fovy = FOVY_PERSPECTIVE;
camera.type = CAMERA_PERSPECTIVE; camera.type = CAMERA_PERSPECTIVE;
} }
} }
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// Draw // Draw
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
BeginDrawing(); BeginDrawing();
ClearBackground(RAYWHITE); ClearBackground(RAYWHITE);
BeginMode3D(camera); BeginMode3D(camera);
DrawCube(new Vector3(-4.0f, 0.0f, 2.0f), 2.0f, 5.0f, 2.0f, RED); 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), 2.0f, 5.0f, 2.0f, GOLD);
DrawCubeWires(new Vector3(-4.0f, 0.0f, -2.0f), 3.0f, 6.0f, 2.0f, MAROON); 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); 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); 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); 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.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); 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); 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); DrawCylinderWires(new Vector3(1.0f, 0.0f, -4.0f), 0.0f, 1.5f, 3.0f, 8, PINK);
DrawGrid(10, 1.0f); // Draw a grid DrawGrid(10, 1.0f); // Draw a grid
EndMode3D(); EndMode3D();
DrawText("Press Spacebar to switch camera type", 10, GetScreenHeight() - 30, 20, DARKGRAY); DrawText("Press Spacebar to switch camera type", 10, GetScreenHeight() - 30, 20, DARKGRAY);
if (camera.type == CAMERA_ORTHOGRAPHIC) DrawText("ORTHOGRAPHIC", 10, 40, 20, BLACK); if (camera.type == CAMERA_ORTHOGRAPHIC) DrawText("ORTHOGRAPHIC", 10, 40, 20, BLACK);
else if (camera.type == CAMERA_PERSPECTIVE) DrawText("PERSPECTIVE", 10, 40, 20, BLACK); else if (camera.type == CAMERA_PERSPECTIVE) DrawText("PERSPECTIVE", 10, 40, 20, BLACK);
DrawFPS(10, 10); DrawFPS(10, 10);
EndDrawing(); EndDrawing();
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
} }
// De-Initialization // De-Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
CloseWindow(); // Close window and OpenGL context CloseWindow(); // Close window and OpenGL context
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
return 0; return 0;
} }
} }

View File

@ -15,48 +15,48 @@ public partial class models_skybox
* Copyright (c) 2017 Ramon Santamaria (@raysan5) * Copyright (c) 2017 Ramon Santamaria (@raysan5)
* *
********************************************************************************************/ ********************************************************************************************/
public static int Main() public static int Main()
{ {
// Initialization // Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
int screenWidth = 800; int screenWidth = 800;
int screenHeight = 450; int screenHeight = 450;
InitWindow(screenWidth, screenHeight, "raylib [models] example - skybox loading and drawing"); InitWindow(screenWidth, screenHeight, "raylib [models] example - skybox loading and drawing");
// Define the camera to look into our 3d world // 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 ); 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); Mesh cube = GenMeshCube(1.0f, 1.0f, 1.0f);
Model skybox = LoadModelFromMesh(cube); Model skybox = LoadModelFromMesh(cube);
// Load skybox shader and set required locations // Load skybox shader and set required locations
// NOTE: Some locations are automatically set at shader loading // NOTE: Some locations are automatically set at shader loading
skybox.material.shader = LoadShader("resources/shaders/skybox.vs", "resources/shaders/skybox.fs"); 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); SetShaderValuei(skybox.material.shader, GetShaderLocation(skybox.material.shader, "environmentMap"), new int[]{ (int)MAP_CUBEMAP }, 1);
// Load cubemap shader and setup required shader locations // Load cubemap shader and setup required shader locations
Shader shdrCubemap = LoadShader("resources/shaders/cubemap.vs", "resources/shaders/cubemap.fs"); Shader shdrCubemap = LoadShader("resources/shaders/cubemap.vs", "resources/shaders/cubemap.fs");
SetShaderValuei(shdrCubemap, GetShaderLocation(shdrCubemap, "equirectangularMap"), new int[]{ 0 }, 1); SetShaderValuei(shdrCubemap, GetShaderLocation(shdrCubemap, "equirectangularMap"), new int[]{ 0 }, 1);
// Load HDR panorama (sphere) texture // Load HDR panorama (sphere) texture
Texture2D texHDR = LoadTexture("resources/dresden_square.hdr"); Texture2D texHDR = LoadTexture("resources/dresden_square.hdr");
// Generate cubemap (texture with 6 quads-cube-mapping) from panorama HDR texture // 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 // 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); skybox.material.maps[(int)MAP_CUBEMAP].texture = GenTextureCubemap(shdrCubemap, texHDR, 512);
UnloadTexture(texHDR); // Texture not required anymore, cubemap already generated UnloadTexture(texHDR); // Texture not required anymore, cubemap already generated
UnloadShader(shdrCubemap); // Unload cubemap generation shader, not required anymore UnloadShader(shdrCubemap); // Unload cubemap generation shader, not required anymore
SetCameraMode(camera, (int)CAMERA_FIRST_PERSON); // Set a first person camera mode SetCameraMode(camera, (int)CAMERA_FIRST_PERSON); // Set a first person camera mode
SetTargetFPS(60); // Set our game to run at 60 frames-per-second SetTargetFPS(60); // Set our game to run at 60 frames-per-second
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
// Main game loop // Main game loop
while (!WindowShouldClose()) // Detect window close button or ESC key while (!WindowShouldClose()) // Detect window close button or ESC key
{ {
@ -64,34 +64,34 @@ public partial class models_skybox
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
UpdateCamera(ref camera); // Update camera UpdateCamera(ref camera); // Update camera
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// Draw // Draw
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
BeginDrawing(); BeginDrawing();
ClearBackground(RAYWHITE); ClearBackground(RAYWHITE);
BeginMode3D(camera); BeginMode3D(camera);
DrawModel(skybox, new Vector3(0, 0, 0), 1.0f, WHITE); DrawModel(skybox, new Vector3(0, 0, 0), 1.0f, WHITE);
DrawGrid(10, 1.0f); DrawGrid(10, 1.0f);
EndMode3D(); EndMode3D();
DrawFPS(10, 10); DrawFPS(10, 10);
EndDrawing(); EndDrawing();
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
} }
// De-Initialization // De-Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
UnloadModel(skybox); // Unload skybox model (and textures) UnloadModel(skybox); // Unload skybox model (and textures)
CloseWindow(); // Close window and OpenGL context CloseWindow(); // Close window and OpenGL context
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
return 0; return 0;
} }
} }

View File

@ -19,11 +19,11 @@ public partial class models_yaw_pitch_roll
* Copyright (c) 2017 Ramon Santamaria (@raysan5) * Copyright (c) 2017 Ramon Santamaria (@raysan5)
* *
********************************************************************************************/ ********************************************************************************************/
// Draw angle gauge controls // Draw angle gauge controls
//void DrawAngleGauge(Texture2D angleGauge, int x, int y, float angle, char title[], Color color); //void DrawAngleGauge(Texture2D angleGauge, int x, int y, float angle, char title[], Color color);
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// Main entry point // Main entry point
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
@ -33,42 +33,42 @@ public partial class models_yaw_pitch_roll
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
const int screenWidth = 800; const int screenWidth = 800;
const int screenHeight = 450; const int screenHeight = 450;
InitWindow(screenWidth, screenHeight, "raylib [models] example - plane rotations (yaw, pitch, roll)"); InitWindow(screenWidth, screenHeight, "raylib [models] example - plane rotations (yaw, pitch, roll)");
Texture2D texAngleGauge = LoadTexture("resources/angle_gauge.png"); Texture2D texAngleGauge = LoadTexture("resources/angle_gauge.png");
Texture2D texBackground = LoadTexture("resources/background.png"); Texture2D texBackground = LoadTexture("resources/background.png");
Texture2D texPitch = LoadTexture("resources/pitch.png"); Texture2D texPitch = LoadTexture("resources/pitch.png");
Texture2D texPlane = LoadTexture("resources/plane.png"); Texture2D texPlane = LoadTexture("resources/plane.png");
RenderTexture2D framebuffer = LoadRenderTexture(192, 192); RenderTexture2D framebuffer = LoadRenderTexture(192, 192);
// Model loading // Model loading
Model model = LoadModel("resources/plane.obj"); // Load OBJ model 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 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); GenTextureMipmaps(ref model.material.maps[(int)MAP_ALBEDO].texture);
Camera3D camera = new Camera3D(); Camera3D camera = new Camera3D();
camera.position = new Vector3( 0.0f, 60.0f, -120.0f );// Camera3D position perspective 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.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.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.fovy = 30.0f; // Camera3D field-of-view Y
camera.type = CAMERA_PERSPECTIVE; // Camera3D type camera.type = CAMERA_PERSPECTIVE; // Camera3D type
float pitch = 0.0f; float pitch = 0.0f;
float roll = 0.0f; float roll = 0.0f;
float yaw = 0.0f; float yaw = 0.0f;
SetTargetFPS(60); SetTargetFPS(60);
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
while (!WindowShouldClose()) // Detect window close button or ESC key while (!WindowShouldClose()) // Detect window close button or ESC key
{ {
// Update // Update
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// Plane roll (x-axis) controls // Plane roll (x-axis) controls
if (IsKeyDown(KEY_LEFT)) roll += 1.0f; if (IsKeyDown(KEY_LEFT)) roll += 1.0f;
else if (IsKeyDown(KEY_RIGHT)) 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; if (roll > 0.0f) roll -= 0.5f;
else if (roll < 0.0f) roll += 0.5f; else if (roll < 0.0f) roll += 0.5f;
} }
// Plane yaw (y-axis) controls // Plane yaw (y-axis) controls
if (IsKeyDown(KEY_S)) yaw += 1.0f; if (IsKeyDown(KEY_S)) yaw += 1.0f;
else if (IsKeyDown(KEY_A)) 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; if (yaw > 0.0f) yaw -= 0.5f;
else if (yaw < 0.0f) yaw += 0.5f; else if (yaw < 0.0f) yaw += 0.5f;
} }
// Plane pitch (z-axis) controls // Plane pitch (z-axis) controls
if (IsKeyDown(KEY_DOWN)) pitch += 0.6f; if (IsKeyDown(KEY_DOWN)) pitch += 0.6f;
else if (IsKeyDown(KEY_UP)) 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; if (pitch > 0.3f) pitch -= 0.3f;
else 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 // Wraps the phase of an angle to fit between -180 and +180 degrees
int pitchOffset = (int)pitch; int pitchOffset = (int)pitch;
while (pitchOffset > 180) pitchOffset -= 360; while (pitchOffset > 180) pitchOffset -= 360;
while (pitchOffset < -180) pitchOffset += 360; while (pitchOffset < -180) pitchOffset += 360;
pitchOffset *= 10; pitchOffset *= 10;
Matrix transform = MatrixIdentity(); Matrix transform = MatrixIdentity();
transform = MatrixMultiply(transform, MatrixRotateZ(DEG2RAD*roll)); transform = MatrixMultiply(transform, MatrixRotateZ(DEG2RAD*roll));
transform = MatrixMultiply(transform, MatrixRotateX(DEG2RAD*pitch)); transform = MatrixMultiply(transform, MatrixRotateX(DEG2RAD*pitch));
transform = MatrixMultiply(transform, MatrixRotateY(DEG2RAD*yaw)); transform = MatrixMultiply(transform, MatrixRotateY(DEG2RAD*yaw));
model.transform = transform; model.transform = transform;
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// Draw // Draw
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
BeginDrawing(); BeginDrawing();
ClearBackground(RAYWHITE); ClearBackground(RAYWHITE);
// Draw framebuffer texture (Ahrs Display) // Draw framebuffer texture (Ahrs Display)
int centerX = framebuffer.texture.width/2; int centerX = framebuffer.texture.width/2;
int centerY = framebuffer.texture.height/2; int centerY = framebuffer.texture.height/2;
float scaleFactor = 0.5f; float scaleFactor = 0.5f;
BeginTextureMode(framebuffer); BeginTextureMode(framebuffer);
BeginBlendMode((int)BLEND_ALPHA); BeginBlendMode((int)BLEND_ALPHA);
DrawTexturePro(texBackground, new Rectangle( 0, 0, texBackground.width, texBackground.height ), DrawTexturePro(texBackground, new Rectangle( 0, 0, texBackground.width, texBackground.height ),
new Rectangle( centerX, centerY, texBackground.width*scaleFactor, texBackground.height*scaleFactor), new Rectangle( centerX, centerY, texBackground.width*scaleFactor, texBackground.height*scaleFactor),
new Vector2( texBackground.width/2*scaleFactor, texBackground.height/2*scaleFactor + pitchOffset*scaleFactor ), roll, WHITE); new Vector2( texBackground.width/2*scaleFactor, texBackground.height/2*scaleFactor + pitchOffset*scaleFactor ), roll, WHITE);
DrawTexturePro(texPitch, new Rectangle( 0, 0, texPitch.width, texPitch.height ), DrawTexturePro(texPitch, new Rectangle( 0, 0, texPitch.width, texPitch.height ),
new Rectangle( centerX, centerY, texPitch.width*scaleFactor, texPitch.height*scaleFactor ), new Rectangle( centerX, centerY, texPitch.width*scaleFactor, texPitch.height*scaleFactor ),
new Vector2( texPitch.width/2*scaleFactor, texPitch.height/2*scaleFactor + pitchOffset*scaleFactor ), roll, WHITE); new Vector2( texPitch.width/2*scaleFactor, texPitch.height/2*scaleFactor + pitchOffset*scaleFactor ), roll, WHITE);
DrawTexturePro(texPlane, new Rectangle( 0, 0, texPlane.width, texPlane.height ), DrawTexturePro(texPlane, new Rectangle( 0, 0, texPlane.width, texPlane.height ),
new Rectangle( centerX, centerY, texPlane.width*scaleFactor, texPlane.height*scaleFactor ), new Rectangle( centerX, centerY, texPlane.width*scaleFactor, texPlane.height*scaleFactor ),
new Vector2( texPlane.width/2*scaleFactor, texPlane.height/2*scaleFactor ), 0, WHITE); new Vector2( texPlane.width/2*scaleFactor, texPlane.height/2*scaleFactor ), 0, WHITE);
EndBlendMode(); EndBlendMode();
EndTextureMode(); EndTextureMode();
// Draw 3D model (recomended to draw 3D always before 2D) // Draw 3D model (recomended to draw 3D always before 2D)
BeginMode3D(camera); BeginMode3D(camera);
DrawModel(model, new Vector3( 0, 6.0f, 0 ), 1.0f, WHITE); // Draw 3d model with texture DrawModel(model, new Vector3( 0, 6.0f, 0 ), 1.0f, WHITE); // Draw 3d model with texture
DrawGrid(10, 10.0f); DrawGrid(10, 10.0f);
EndMode3D(); EndMode3D();
// Draw 2D GUI stuff // Draw 2D GUI stuff
DrawAngleGauge(texAngleGauge, 80, 70, roll, "roll", RED); DrawAngleGauge(texAngleGauge, 80, 70, roll, "roll", RED);
DrawAngleGauge(texAngleGauge, 190, 70, pitch, "pitch", GREEN); DrawAngleGauge(texAngleGauge, 190, 70, pitch, "pitch", GREEN);
DrawAngleGauge(texAngleGauge, 300, 70, yaw, "yaw", SKYBLUE); DrawAngleGauge(texAngleGauge, 300, 70, yaw, "yaw", SKYBLUE);
DrawRectangle(30, 360, 260, 70, Fade(SKYBLUE, 0.5f)); DrawRectangle(30, 360, 260, 70, Fade(SKYBLUE, 0.5f));
DrawRectangleLines(30, 360, 260, 70, Fade(DARKBLUE, 0.5f)); DrawRectangleLines(30, 360, 260, 70, Fade(DARKBLUE, 0.5f));
DrawText("Pitch controlled with: KEY_UP / KEY_DOWN", 40, 370, 10, DARKGRAY); 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("Roll controlled with: KEY_LEFT / KEY_RIGHT", 40, 390, 10, DARKGRAY);
DrawText("Yaw controlled with: KEY_A / KEY_S", 40, 410, 10, DARKGRAY); DrawText("Yaw controlled with: KEY_A / KEY_S", 40, 410, 10, DARKGRAY);
// Draw framebuffer texture // Draw framebuffer texture
DrawTextureRec(framebuffer.texture, new Rectangle( 0, 0, framebuffer.texture.width, -framebuffer.texture.height ), 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)); 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); DrawRectangleLines(screenWidth - framebuffer.texture.width - 20, 20, framebuffer.texture.width, framebuffer.texture.height, DARKGRAY);
EndDrawing(); EndDrawing();
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
} }
// De-Initialization // De-Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
// Unload all loaded data // Unload all loaded data
UnloadModel(model); UnloadModel(model);
UnloadRenderTexture(framebuffer); UnloadRenderTexture(framebuffer);
UnloadTexture(texAngleGauge); UnloadTexture(texAngleGauge);
UnloadTexture(texBackground); UnloadTexture(texBackground);
UnloadTexture(texPitch); UnloadTexture(texPitch);
UnloadTexture(texPlane); UnloadTexture(texPlane);
CloseWindow(); // Close window and OpenGL context CloseWindow(); // Close window and OpenGL context
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
return 0; return 0;
} }
// Draw angle gauge controls // Draw angle gauge controls
static void DrawAngleGauge(Texture2D angleGauge, int x, int y, float angle, string title, Color color) 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 ); Rectangle dstRec = new Rectangle( x, y, angleGauge.width, angleGauge.height );
Vector2 origin = new Vector2( angleGauge.width/2, angleGauge.height/2); Vector2 origin = new Vector2( angleGauge.width/2, angleGauge.height/2);
int textSize = 20; int textSize = 20;
DrawTexturePro(angleGauge, srcRec, dstRec, origin, angle, color); 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(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); DrawText(title, x - MeasureText(title, textSize) / 2, y + 60, textSize, DARKGRAY);
} }
} }

View File

@ -13,8 +13,8 @@ public partial class bunnymark
* Copyright (c) 2014 Ramon Santamaria (@raysan5) * Copyright (c) 2014 Ramon Santamaria (@raysan5)
* *
********************************************************************************************/ ********************************************************************************************/
public const int MAX_BUNNIES = 100000; public const int MAX_BUNNIES = 100000;
struct Bunny struct Bunny
@ -23,25 +23,25 @@ public partial class bunnymark
public Vector2 speed; public Vector2 speed;
public Color color; public Color color;
} }
public static int Main() public static int Main()
{ {
// Initialization // Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
int screenWidth = 1280; int screenWidth = 1280;
int screenHeight = 960; int screenHeight = 960;
InitWindow(screenWidth, screenHeight, "raylib example - Bunnymark"); InitWindow(screenWidth, screenHeight, "raylib example - Bunnymark");
Texture2D texBunny = LoadTexture("resources/wabbit_alpha.png"); Texture2D texBunny = LoadTexture("resources/wabbit_alpha.png");
Bunny[] bunnies = new Bunny[MAX_BUNNIES]; // Bunnies array Bunny[] bunnies = new Bunny[MAX_BUNNIES]; // Bunnies array
int bunniesCount = 0; // Bunnies counter int bunniesCount = 0; // Bunnies counter
SetTargetFPS(60); SetTargetFPS(60);
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
// Main game loop // Main game loop
while (!WindowShouldClose()) // Detect window close button or ESC key while (!WindowShouldClose()) // Detect window close button or ESC key
{ {
@ -58,24 +58,24 @@ public partial class bunnymark
bunniesCount++; bunniesCount++;
} }
} }
// Update bunnies // Update bunnies
for (int i = 0; i < bunniesCount; i++) for (int i = 0; i < bunniesCount; i++)
{ {
bunnies[i].position.x += bunnies[i].speed.x; bunnies[i].position.x += bunnies[i].speed.x;
bunnies[i].position.y += bunnies[i].speed.y; 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.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; if ((bunnies[i].position.y > GetScreenHeight()) || (bunnies[i].position.y < 0)) bunnies[i].speed.y *= -1;
} }
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// Draw // Draw
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
BeginDrawing(); BeginDrawing();
ClearBackground(RAYWHITE); ClearBackground(RAYWHITE);
for (int i = 0; i < bunniesCount; i++) for (int i = 0; i < bunniesCount; i++)
{ {
// NOTE: When internal QUADS batch limit is reached, a draw call is launched and // 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 // 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); DrawTexture(texBunny, (int)bunnies[i].position.x, (int)bunnies[i].position.y, RAYWHITE);
} }
DrawRectangle(0, 0, screenWidth, 40, LIGHTGRAY); DrawRectangle(0, 0, screenWidth, 40, LIGHTGRAY);
DrawText("raylib bunnymark", 10, 10, 20, DARKGRAY); DrawText("raylib bunnymark", 10, 10, 20, DARKGRAY);
// DrawText(FormatText("bunnies: %i", bunniesCount), 400, 10, 20, RED); // DrawText(FormatText("bunnies: %i", bunniesCount), 400, 10, 20, RED);
DrawText($"bunnies: {bunniesCount}", 400, 10, 20, RED); DrawText($"bunnies: {bunniesCount}", 400, 10, 20, RED);
DrawFPS(260, 10); DrawFPS(260, 10);
EndDrawing(); EndDrawing();
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
} }
// De-Initialization // De-Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
CloseWindow(); // Close window and OpenGL context CloseWindow(); // Close window and OpenGL context
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
return 0; return 0;
} }
} }

View File

@ -12,44 +12,44 @@ public partial class physics_demo
* *
* Use the following line to compile: * 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 * -lglfw3 -lopengl32 -lgdi32 -lopenal32 -lwinmm -std=c99 -Wl,--subsystem,windows -Wl,-allow-multiple-definition
* *
* Copyright (c) 2016-2018 Victor Fisac * Copyright (c) 2016-2018 Victor Fisac
* *
********************************************************************************************/ ********************************************************************************************/
public static int Main() public static int Main()
{ {
// Initialization // Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
int screenWidth = 800; int screenWidth = 800;
int screenHeight = 450; int screenHeight = 450;
SetConfigFlags(FLAG_MSAA_4X_HINT); SetConfigFlags(FLAG_MSAA_4X_HINT);
InitWindow(screenWidth, screenHeight, "Physac [raylib] - Physics demo"); InitWindow(screenWidth, screenHeight, "Physac [raylib] - Physics demo");
// Physac logo drawing position // Physac logo drawing position
int logoX = screenWidth - MeasureText("Physac", 30) - 10; int logoX = screenWidth - MeasureText("Physac", 30) - 10;
int logoY = 15; int logoY = 15;
bool needsReset = false; bool needsReset = false;
// Initialize physics and default physics bodies // Initialize physics and default physics bodies
InitPhysics(); InitPhysics();
// Create floor rectangle physics body // Create floor rectangle physics body
var floor = CreatePhysicsBodyRectangle(new Vector2( screenWidth/2, screenHeight ), 500, 100, 10); 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) floor.enabled = false; // Disable body state to convert it to static (no dynamics, but collisions)
// Create obstacle circle physics body // Create obstacle circle physics body
var circle = CreatePhysicsBodyCircle(new Vector2( screenWidth/2, screenHeight/2 ), 45, 10); 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) circle.enabled = false; // Disable body state to convert it to static (no dynamics, but collisions)
SetTargetFPS(60); SetTargetFPS(60);
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
// Main game loop // Main game loop
while (!WindowShouldClose()) // Detect window close button or ESC key 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 = CreatePhysicsBodyRectangle(new Vector2( screenWidth/2, screenHeight ), 500, 100, 10);
floor.enabled = false; floor.enabled = false;
circle = CreatePhysicsBodyCircle(new Vector2( screenWidth/2, screenHeight/2 ), 45, 10); circle = CreatePhysicsBodyCircle(new Vector2( screenWidth/2, screenHeight/2 ), 45, 10);
circle.enabled = false; circle.enabled = false;
} }
// Reset physics input // Reset physics input
if (IsKeyPressed('R')) if (IsKeyPressed('R'))
{ {
ResetPhysics(); ResetPhysics();
needsReset = true; needsReset = true;
} }
// Physics body creation inputs // Physics body creation inputs
if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) CreatePhysicsBodyPolygon(GetMousePosition(), GetRandomValue(20, 80), GetRandomValue(3, 8), 10); 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); else if (IsMouseButtonPressed(MOUSE_RIGHT_BUTTON)) CreatePhysicsBodyCircle(GetMousePosition(), GetRandomValue(10, 45), 10);
// Destroy falling physics bodies // Destroy falling physics bodies
int bodiesCount = GetPhysicsBodiesCount(); int bodiesCount = GetPhysicsBodiesCount();
for (int i = bodiesCount - 1; i >= 0; i--) 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); if (body.id != 0 && (body.position.y > screenHeight*2)) DestroyPhysicsBody(body);
} }
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// Draw // Draw
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
BeginDrawing(); BeginDrawing();
ClearBackground(BLACK); ClearBackground(BLACK);
DrawFPS(screenWidth - 90, screenHeight - 30); DrawFPS(screenWidth - 90, screenHeight - 30);
// Draw created physics bodies // Draw created physics bodies
bodiesCount = GetPhysicsBodiesCount(); bodiesCount = GetPhysicsBodiesCount();
for (int i = 0; i < bodiesCount; i++) for (int i = 0; i < bodiesCount; i++)
{ {
var body = GetPhysicsBody(i); var body = GetPhysicsBody(i);
if (body.id != 0) // can't check struct for null if (body.id != 0) // can't check struct for null
{ {
int vertexCount = GetPhysicsShapeVerticesCount(i); int vertexCount = GetPhysicsShapeVerticesCount(i);
@ -107,33 +107,33 @@ public partial class physics_demo
// Get physics bodies shape vertices to draw lines // Get physics bodies shape vertices to draw lines
// Note: GetPhysicsShapeVertex() already calculates rotation transformations // Note: GetPhysicsShapeVertex() already calculates rotation transformations
Vector2 vertexA = GetPhysicsShapeVertex(body, j); Vector2 vertexA = GetPhysicsShapeVertex(body, j);
int jj = (((j + 1) < vertexCount) ? (j + 1) : 0); // Get next vertex or first to close the shape int jj = (((j + 1) < vertexCount) ? (j + 1) : 0); // Get next vertex or first to close the shape
Vector2 vertexB = GetPhysicsShapeVertex(body, jj); Vector2 vertexB = GetPhysicsShapeVertex(body, jj);
DrawLineV(vertexA, vertexB, GREEN); // Draw a line between two vertex positions DrawLineV(vertexA, vertexB, GREEN); // Draw a line between two vertex positions
} }
} }
} }
DrawText("Left mouse button to create a polygon", 10, 10, 10, WHITE); 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("Right mouse button to create a circle", 10, 25, 10, WHITE);
DrawText("Press 'R' to reset example", 10, 40, 10, WHITE); DrawText("Press 'R' to reset example", 10, 40, 10, WHITE);
DrawText("Physac", logoX, logoY, 30, WHITE); DrawText("Physac", logoX, logoY, 30, WHITE);
DrawText("Powered by", logoX + 50, logoY - 7, 10, WHITE); DrawText("Powered by", logoX + 50, logoY - 7, 10, WHITE);
EndDrawing(); EndDrawing();
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
} }
// De-Initialization // De-Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
ClosePhysics(); // Unitialize physics ClosePhysics(); // Unitialize physics
CloseWindow(); // Close window and OpenGL context CloseWindow(); // Close window and OpenGL context
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
return 0; return 0;
} }
} }

View File

@ -12,62 +12,62 @@ public partial class physics_friction
* *
* Use the following line to compile: * 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 * -lglfw3 -lopengl32 -lgdi32 -lopenal32 -lwinmm -std=c99 -Wl,--subsystem,windows -Wl,-allow-multiple-definition
* *
* Copyright (c) 2016-2018 Victor Fisac * Copyright (c) 2016-2018 Victor Fisac
* *
********************************************************************************************/ ********************************************************************************************/
public static int Main() public static int Main()
{ {
// Initialization // Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
int screenWidth = 800; int screenWidth = 800;
int screenHeight = 450; int screenHeight = 450;
SetConfigFlags(FLAG_MSAA_4X_HINT); SetConfigFlags(FLAG_MSAA_4X_HINT);
InitWindow(screenWidth, screenHeight, "Physac [raylib] - Physics friction"); InitWindow(screenWidth, screenHeight, "Physac [raylib] - Physics friction");
// Physac logo drawing position // Physac logo drawing position
int logoX = screenWidth - MeasureText("Physac", 30) - 10; int logoX = screenWidth - MeasureText("Physac", 30) - 10;
int logoY = 15; int logoY = 15;
// Initialize physics and default physics bodies // Initialize physics and default physics bodies
InitPhysics(); InitPhysics();
// Create floor rectangle physics body // Create floor rectangle physics body
PhysicsBodyData floor = CreatePhysicsBodyRectangle(new Vector2( screenWidth/2, screenHeight ), screenWidth, 100, 10); 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.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); 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) wall.enabled = false; // Disable body state to convert it to static (no dynamics, but collisions)
// Create left ramp physics body // Create left ramp physics body
PhysicsBodyData rectLeft = CreatePhysicsBodyRectangle(new Vector2( 25, screenHeight - 5 ), 250, 250, 10); 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) rectLeft.enabled = false; // Disable body state to convert it to static (no dynamics, but collisions)
SetPhysicsBodyRotation(rectLeft, 30*DEG2RAD); SetPhysicsBodyRotation(rectLeft, 30*DEG2RAD);
// Create right ramp physics body // Create right ramp physics body
PhysicsBodyData rectRight = CreatePhysicsBodyRectangle(new Vector2( screenWidth - 25, screenHeight - 5 ), 250, 250, 10); 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) rectRight.enabled = false; // Disable body state to convert it to static (no dynamics, but collisions)
SetPhysicsBodyRotation(rectRight, 330*DEG2RAD); SetPhysicsBodyRotation(rectRight, 330*DEG2RAD);
// Create dynamic physics bodies // Create dynamic physics bodies
PhysicsBodyData bodyA = CreatePhysicsBodyRectangle(new Vector2( 35, screenHeight*0.6f ), 40, 40, 10); PhysicsBodyData bodyA = CreatePhysicsBodyRectangle(new Vector2( 35, screenHeight*0.6f ), 40, 40, 10);
bodyA.staticFriction = 0.1f; bodyA.staticFriction = 0.1f;
bodyA.dynamicFriction = 0.1f; bodyA.dynamicFriction = 0.1f;
SetPhysicsBodyRotation(bodyA, 30*DEG2RAD); SetPhysicsBodyRotation(bodyA, 30*DEG2RAD);
PhysicsBodyData bodyB = CreatePhysicsBodyRectangle(new Vector2( screenWidth - 35, screenHeight*0.6f ), 40, 40, 10); PhysicsBodyData bodyB = CreatePhysicsBodyRectangle(new Vector2( screenWidth - 35, screenHeight*0.6f ), 40, 40, 10);
bodyB.staticFriction = 1; bodyB.staticFriction = 1;
bodyB.dynamicFriction = 1; bodyB.dynamicFriction = 1;
SetPhysicsBodyRotation(bodyB, 330*DEG2RAD); SetPhysicsBodyRotation(bodyB, 330*DEG2RAD);
SetTargetFPS(60); SetTargetFPS(60);
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
// Main game loop // Main game loop
while (!WindowShouldClose()) // Detect window close button or ESC key 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.velocity = new Vector2( 0, 0 );
bodyA.angularVelocity = 0; bodyA.angularVelocity = 0;
SetPhysicsBodyRotation(bodyA, 30*DEG2RAD); SetPhysicsBodyRotation(bodyA, 30*DEG2RAD);
bodyB.position = new Vector2( screenWidth - 35, screenHeight*0.6f ); bodyB.position = new Vector2( screenWidth - 35, screenHeight*0.6f );
bodyB.velocity = new Vector2( 0, 0 ); bodyB.velocity = new Vector2( 0, 0 );
bodyB.angularVelocity = 0; bodyB.angularVelocity = 0;
SetPhysicsBodyRotation(bodyB, 330*DEG2RAD); SetPhysicsBodyRotation(bodyB, 330*DEG2RAD);
} }
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// Draw // Draw
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
BeginDrawing(); BeginDrawing();
ClearBackground(BLACK); ClearBackground(BLACK);
DrawFPS(screenWidth - 90, screenHeight - 30); DrawFPS(screenWidth - 90, screenHeight - 30);
// Draw created physics bodies // Draw created physics bodies
int bodiesCount = GetPhysicsBodiesCount(); int bodiesCount = GetPhysicsBodiesCount();
for (int i = 0; i < bodiesCount; i++) for (int i = 0; i < bodiesCount; i++)
{ {
PhysicsBodyData body = GetPhysicsBody(i); PhysicsBodyData body = GetPhysicsBody(i);
if (body.id != 0) // check for null? if (body.id != 0) // check for null?
{ {
int vertexCount = GetPhysicsShapeVerticesCount(i); int vertexCount = GetPhysicsShapeVerticesCount(i);
@ -110,39 +110,39 @@ public partial class physics_friction
// Get physics bodies shape vertices to draw lines // Get physics bodies shape vertices to draw lines
// Note: GetPhysicsShapeVertex() already calculates rotation transformations // Note: GetPhysicsShapeVertex() already calculates rotation transformations
Vector2 vertexA = GetPhysicsShapeVertex(body, j); Vector2 vertexA = GetPhysicsShapeVertex(body, j);
int jj = (((j + 1) < vertexCount) ? (j + 1) : 0); // Get next vertex or first to close the shape int jj = (((j + 1) < vertexCount) ? (j + 1) : 0); // Get next vertex or first to close the shape
Vector2 vertexB = GetPhysicsShapeVertex(body, jj); Vector2 vertexB = GetPhysicsShapeVertex(body, jj);
DrawLineV(vertexA, vertexB, GREEN); // Draw a line between two vertex positions DrawLineV(vertexA, vertexB, GREEN); // Draw a line between two vertex positions
} }
} }
} }
DrawRectangle(0, screenHeight - 49, screenWidth, 49, BLACK); DrawRectangle(0, screenHeight - 49, screenWidth, 49, BLACK);
DrawText("Friction amount", (screenWidth - MeasureText("Friction amount", 30))/2, 75, 30, WHITE); 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("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("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("Press 'R' to reset example", 10, 10, 10, WHITE);
DrawText("Physac", logoX, logoY, 30, WHITE); DrawText("Physac", logoX, logoY, 30, WHITE);
DrawText("Powered by", logoX + 50, logoY - 7, 10, WHITE); DrawText("Powered by", logoX + 50, logoY - 7, 10, WHITE);
EndDrawing(); EndDrawing();
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
} }
// De-Initialization // De-Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
ClosePhysics(); // Unitialize physics ClosePhysics(); // Unitialize physics
CloseWindow(); // Close window and OpenGL context CloseWindow(); // Close window and OpenGL context
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
return 0; return 0;
} }
} }

View File

@ -12,37 +12,37 @@ public partial class physics_restitution
* *
* Use the following line to compile: * 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 * -lglfw3 -lopengl32 -lgdi32 -lopenal32 -lwinmm -std=c99 -Wl,--subsystem,windows -Wl,-allow-multiple-definition
* *
* Copyright (c) 2016-2018 Victor Fisac * Copyright (c) 2016-2018 Victor Fisac
* *
********************************************************************************************/ ********************************************************************************************/
public static int Main() public static int Main()
{ {
// Initialization // Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
int screenWidth = 800; int screenWidth = 800;
int screenHeight = 450; int screenHeight = 450;
SetConfigFlags(FLAG_MSAA_4X_HINT); SetConfigFlags(FLAG_MSAA_4X_HINT);
InitWindow(screenWidth, screenHeight, "Physac [raylib] - Physics restitution"); InitWindow(screenWidth, screenHeight, "Physac [raylib] - Physics restitution");
// Physac logo drawing position // Physac logo drawing position
int logoX = screenWidth - MeasureText("Physac", 30) - 10; int logoX = screenWidth - MeasureText("Physac", 30) - 10;
int logoY = 15; int logoY = 15;
// Initialize physics and default physics bodies // Initialize physics and default physics bodies
InitPhysics(); InitPhysics();
// Create floor rectangle physics body // Create floor rectangle physics body
PhysicsBodyData floor = CreatePhysicsBodyRectangle(new Vector2( screenWidth/2, screenHeight ), screenWidth, 100, 10); 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.enabled = false; // Disable body state to convert it to static (no dynamics, but collisions)
floor.restitution = 1; floor.restitution = 1;
// Create circles physics body // Create circles physics body
PhysicsBodyData circleA = CreatePhysicsBodyCircle(new Vector2( screenWidth*0.25f, screenHeight/2 ), 30, 10); PhysicsBodyData circleA = CreatePhysicsBodyCircle(new Vector2( screenWidth*0.25f, screenHeight/2 ), 30, 10);
circleA.restitution = 0; circleA.restitution = 0;
@ -50,10 +50,10 @@ public partial class physics_restitution
circleB.restitution = 0.5f; circleB.restitution = 0.5f;
PhysicsBodyData circleC = CreatePhysicsBodyCircle(new Vector2( screenWidth*0.75f, screenHeight/2 ), 30, 10); PhysicsBodyData circleC = CreatePhysicsBodyCircle(new Vector2( screenWidth*0.75f, screenHeight/2 ), 30, 10);
circleC.restitution = 1; circleC.restitution = 1;
SetTargetFPS(60); SetTargetFPS(60);
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
// Main game loop // Main game loop
while (!WindowShouldClose()) // Detect window close button or ESC key while (!WindowShouldClose()) // Detect window close button or ESC key
{ {
@ -72,58 +72,58 @@ public partial class physics_restitution
circleC.velocity = new Vector2( 0, 0 ); circleC.velocity = new Vector2( 0, 0 );
} }
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// Draw // Draw
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
BeginDrawing(); BeginDrawing();
ClearBackground(BLACK); ClearBackground(BLACK);
DrawFPS(screenWidth - 90, screenHeight - 30); DrawFPS(screenWidth - 90, screenHeight - 30);
// Draw created physics bodies // Draw created physics bodies
int bodiesCount = GetPhysicsBodiesCount(); int bodiesCount = GetPhysicsBodiesCount();
for (int i = 0; i < bodiesCount; i++) for (int i = 0; i < bodiesCount; i++)
{ {
PhysicsBodyData body = GetPhysicsBody(i); PhysicsBodyData body = GetPhysicsBody(i);
int vertexCount = GetPhysicsShapeVerticesCount(i); int vertexCount = GetPhysicsShapeVerticesCount(i);
for (int j = 0; j < vertexCount; j++) for (int j = 0; j < vertexCount; j++)
{ {
// Get physics bodies shape vertices to draw lines // Get physics bodies shape vertices to draw lines
// Note: GetPhysicsShapeVertex() already calculates rotation transformations // Note: GetPhysicsShapeVertex() already calculates rotation transformations
Vector2 vertexA = GetPhysicsShapeVertex(body, j); Vector2 vertexA = GetPhysicsShapeVertex(body, j);
int jj = (((j + 1) < vertexCount) ? (j + 1) : 0); // Get next vertex or first to close the shape int jj = (((j + 1) < vertexCount) ? (j + 1) : 0); // Get next vertex or first to close the shape
Vector2 vertexB = GetPhysicsShapeVertex(body, jj); Vector2 vertexB = GetPhysicsShapeVertex(body, jj);
DrawLineV(vertexA, vertexB, GREEN); // Draw a line between two vertex positions DrawLineV(vertexA, vertexB, GREEN); // Draw a line between two vertex positions
} }
} }
DrawText("Restitution amount", (screenWidth - MeasureText("Restitution amount", 30))/2, 75, 30, WHITE); 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", (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("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("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("Press 'R' to reset example", 10, 10, 10, WHITE);
DrawText("Physac", logoX, logoY, 30, WHITE); DrawText("Physac", logoX, logoY, 30, WHITE);
DrawText("Powered by", logoX + 50, logoY - 7, 10, WHITE); DrawText("Powered by", logoX + 50, logoY - 7, 10, WHITE);
EndDrawing(); EndDrawing();
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
} }
// De-Initialization // De-Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
ClosePhysics(); // Unitialize physics ClosePhysics(); // Unitialize physics
CloseWindow(); // Close window and OpenGL context CloseWindow(); // Close window and OpenGL context
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
return 0; return 0;
} }
} }

View File

@ -12,40 +12,40 @@ public partial class physics_shatter
* *
* Use the following line to compile: * 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 * -lglfw3 -lopengl32 -lgdi32 -lopenal32 -lwinmm -std=c99 -Wl,--subsystem,windows -Wl,-allow-multiple-definition
* *
* Copyright (c) 2016-2018 Victor Fisac * Copyright (c) 2016-2018 Victor Fisac
* *
********************************************************************************************/ ********************************************************************************************/
public static int Main() public static int Main()
{ {
// Initialization // Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
int screenWidth = 800; int screenWidth = 800;
int screenHeight = 450; int screenHeight = 450;
SetConfigFlags(FLAG_MSAA_4X_HINT); SetConfigFlags(FLAG_MSAA_4X_HINT);
InitWindow(screenWidth, screenHeight, "Physac [raylib] - Body shatter"); InitWindow(screenWidth, screenHeight, "Physac [raylib] - Body shatter");
// Physac logo drawing position // Physac logo drawing position
int logoX = screenWidth - MeasureText("Physac", 30) - 10; int logoX = screenWidth - MeasureText("Physac", 30) - 10;
int logoY = 15; int logoY = 15;
bool needsReset = false; bool needsReset = false;
// Initialize physics and default physics bodies // Initialize physics and default physics bodies
InitPhysics(); InitPhysics();
SetPhysicsGravity(0, 0); SetPhysicsGravity(0, 0);
// Create random polygon physics body to shatter // Create random polygon physics body to shatter
CreatePhysicsBodyPolygon(new Vector2( screenWidth/2, screenHeight/2 ), GetRandomValue(80, 200), GetRandomValue(3, 8), 10); CreatePhysicsBodyPolygon(new Vector2( screenWidth/2, screenHeight/2 ), GetRandomValue(80, 200), GetRandomValue(3, 8), 10);
SetTargetFPS(60); SetTargetFPS(60);
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
// Main game loop // Main game loop
while (!WindowShouldClose()) // Detect window close button or ESC key 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 // Create random polygon physics body to shatter
CreatePhysicsBodyPolygon(new Vector2( screenWidth/2, screenHeight/2 ), GetRandomValue(80, 200), GetRandomValue(3, 8), 10); CreatePhysicsBodyPolygon(new Vector2( screenWidth/2, screenHeight/2 ), GetRandomValue(80, 200), GetRandomValue(3, 8), 10);
} }
if (IsKeyPressed('R')) // Reset physics input if (IsKeyPressed('R')) // Reset physics input
{ {
ResetPhysics(); ResetPhysics();
needsReset = true; needsReset = true;
} }
if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) // Physics shatter input if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) // Physics shatter input
{ {
// Note: some values need to be stored in variables due to asynchronous changes during main thread // 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 // Draw
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
BeginDrawing(); BeginDrawing();
ClearBackground(BLACK); ClearBackground(BLACK);
// Draw created physics bodies // Draw created physics bodies
int bodiesCount = GetPhysicsBodiesCount(); int bodiesCount = GetPhysicsBodiesCount();
for (int i = 0; i < bodiesCount; i++) for (int i = 0; i < bodiesCount; i++)
{ {
PhysicsBodyData currentBody = GetPhysicsBody(i); PhysicsBodyData currentBody = GetPhysicsBody(i);
int vertexCount = GetPhysicsShapeVerticesCount(i); int vertexCount = GetPhysicsShapeVerticesCount(i);
for (int j = 0; j < vertexCount; j++) for (int j = 0; j < vertexCount; j++)
{ {
// Get physics bodies shape vertices to draw lines // Get physics bodies shape vertices to draw lines
// Note: GetPhysicsShapeVertex() already calculates rotation transformations // Note: GetPhysicsShapeVertex() already calculates rotation transformations
Vector2 vertexA = GetPhysicsShapeVertex(currentBody, j); Vector2 vertexA = GetPhysicsShapeVertex(currentBody, j);
int jj = (((j + 1) < vertexCount) ? (j + 1) : 0); // Get next vertex or first to close the shape int jj = (((j + 1) < vertexCount) ? (j + 1) : 0); // Get next vertex or first to close the shape
Vector2 vertexB = GetPhysicsShapeVertex(currentBody, jj); Vector2 vertexB = GetPhysicsShapeVertex(currentBody, jj);
DrawLineV(vertexA, vertexB, GREEN); // Draw a line between two vertex positions 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("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("Physac", logoX, logoY, 30, WHITE);
DrawText("Powered by", logoX + 50, logoY - 7, 10, WHITE); DrawText("Powered by", logoX + 50, logoY - 7, 10, WHITE);
EndDrawing(); EndDrawing();
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
} }
// De-Initialization // De-Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
ClosePhysics(); // Unitialize physics ClosePhysics(); // Unitialize physics
CloseWindow(); // Close window and OpenGL context CloseWindow(); // Close window and OpenGL context
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
return 0; return 0;
} }
} }

View File

@ -23,19 +23,19 @@ public partial class shaders_custom_uniform
* Copyright (c) 2015 Ramon Santamaria (@raysan5) * Copyright (c) 2015 Ramon Santamaria (@raysan5)
* *
********************************************************************************************/ ********************************************************************************************/
public static int Main() public static int Main()
{ {
// Initialization // Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
int screenWidth = 800; int screenWidth = 800;
int screenHeight = 450; int screenHeight = 450;
SetConfigFlags(FLAG_MSAA_4X_HINT); // Enable Multi Sampling Anti Aliasing 4x (if available) SetConfigFlags(FLAG_MSAA_4X_HINT); // Enable Multi Sampling Anti Aliasing 4x (if available)
InitWindow(screenWidth, screenHeight, "raylib [shaders] example - custom uniform variable"); InitWindow(screenWidth, screenHeight, "raylib [shaders] example - custom uniform variable");
// Define the camera to look into our 3d world // Define the camera to look into our 3d world
Camera3D camera = new Camera3D(); Camera3D camera = new Camera3D();
camera.position = new Vector3( 8.0f, 8.0f, 8.0f ); 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.up = new Vector3( 0.0f, 1.0f, 0.0f );
camera.fovy = 45.0f; camera.fovy = 45.0f;
camera.type = CAMERA_PERSPECTIVE; camera.type = CAMERA_PERSPECTIVE;
Model model = LoadModel("resources/models/barracks.obj"); // Load OBJ model Model model = LoadModel("resources/models/barracks.obj"); // Load OBJ model
Texture2D texture = LoadTexture("resources/models/barracks_diffuse.png"); // Load model texture (diffuse map) 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 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 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 "resources/shaders/glsl330/swirl.fs"); // Load postpro shader
// Get variable (uniform) location on the shader to connect with the program // 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 // NOTE: If uniform variable could not be found in the shader, function returns -1
int swirlCenterLoc = GetShaderLocation(shader, "center"); int swirlCenterLoc = GetShaderLocation(shader, "center");
float[] swirlCenter = new float[2] { (float)screenWidth/2, (float)screenHeight/2 }; float[] swirlCenter = new float[2] { (float)screenWidth/2, (float)screenHeight/2 };
// Create a RenderTexture2D to be used for render to texture // Create a RenderTexture2D to be used for render to texture
RenderTexture2D target = LoadRenderTexture(screenWidth, screenHeight); RenderTexture2D target = LoadRenderTexture(screenWidth, screenHeight);
// Setup orbital camera // Setup orbital camera
SetCameraMode(camera, (int)CAMERA_ORBITAL); // Set an orbital camera mode SetCameraMode(camera, (int)CAMERA_ORBITAL); // Set an orbital camera mode
SetTargetFPS(60); // Set our game to run at 60 frames-per-second SetTargetFPS(60); // Set our game to run at 60 frames-per-second
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
// Main game loop // Main game loop
while (!WindowShouldClose()) // Detect window close button or ESC key while (!WindowShouldClose()) // Detect window close button or ESC key
{ {
// Update // Update
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
Vector2 mousePosition = GetMousePosition(); Vector2 mousePosition = GetMousePosition();
swirlCenter[0] = mousePosition.x; swirlCenter[0] = mousePosition.x;
swirlCenter[1] = screenHeight - mousePosition.y; swirlCenter[1] = screenHeight - mousePosition.y;
// Send new value to the shader to be used on drawing // Send new value to the shader to be used on drawing
SetShaderValue(shader, swirlCenterLoc, swirlCenter, 2); SetShaderValue(shader, swirlCenterLoc, swirlCenter, 2);
UpdateCamera(ref camera); // Update camera UpdateCamera(ref camera); // Update camera
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// Draw // Draw
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
BeginDrawing(); BeginDrawing();
ClearBackground(RAYWHITE); ClearBackground(RAYWHITE);
BeginTextureMode(target); // Enable drawing to texture BeginTextureMode(target); // Enable drawing to texture
BeginMode3D(camera); BeginMode3D(camera);
DrawModel(model, position, 0.5f, WHITE); // Draw 3d model with texture DrawModel(model, position, 0.5f, WHITE); // Draw 3d model with texture
DrawGrid(10, 1.0f); // Draw a grid DrawGrid(10, 1.0f); // Draw a grid
EndMode3D(); EndMode3D();
DrawText("TEXT DRAWN IN RENDER TEXTURE", 200, 10, 30, RED); DrawText("TEXT DRAWN IN RENDER TEXTURE", 200, 10, 30, RED);
EndTextureMode(); // End drawing to texture (now we have a texture available for next passes) EndTextureMode(); // End drawing to texture (now we have a texture available for next passes)
BeginShaderMode(shader); BeginShaderMode(shader);
// NOTE: Render texture must be y-flipped due to default OpenGL coordinates (left-bottom) // 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); DrawTextureRec(target.texture, new Rectangle( 0, 0, target.texture.width, -target.texture.height ), new Vector2( 0, 0 ), WHITE);
EndShaderMode(); EndShaderMode();
DrawText("(c) Barracks 3D model by Alberto Cano", screenWidth - 220, screenHeight - 20, 10, GRAY); DrawText("(c) Barracks 3D model by Alberto Cano", screenWidth - 220, screenHeight - 20, 10, GRAY);
DrawFPS(10, 10); DrawFPS(10, 10);
EndDrawing(); EndDrawing();
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
} }
// De-Initialization // De-Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
UnloadShader(shader); // Unload shader UnloadShader(shader); // Unload shader
UnloadTexture(texture); // Unload texture UnloadTexture(texture); // Unload texture
UnloadModel(model); // Unload model UnloadModel(model); // Unload model
UnloadRenderTexture(target); // Unload render texture UnloadRenderTexture(target); // Unload render texture
CloseWindow(); // Close window and OpenGL context CloseWindow(); // Close window and OpenGL context
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
return 0; return 0;
} }
} }

View File

@ -23,19 +23,19 @@ public partial class shaders_model_shader
* Copyright (c) 2014 Ramon Santamaria (@raysan5) * Copyright (c) 2014 Ramon Santamaria (@raysan5)
* *
********************************************************************************************/ ********************************************************************************************/
public static int Main() public static int Main()
{ {
// Initialization // Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
int screenWidth = 800; int screenWidth = 800;
int screenHeight = 450; int screenHeight = 450;
SetConfigFlags(FLAG_MSAA_4X_HINT); // Enable Multi Sampling Anti Aliasing 4x (if available) SetConfigFlags(FLAG_MSAA_4X_HINT); // Enable Multi Sampling Anti Aliasing 4x (if available)
InitWindow(screenWidth, screenHeight, "raylib [shaders] example - model shader"); InitWindow(screenWidth, screenHeight, "raylib [shaders] example - model shader");
// Define the camera to look into our 3d world // Define the camera to look into our 3d world
Camera3D camera = new Camera3D(); Camera3D camera = new Camera3D();
camera.position = new Vector3( 4.0f, 4.0f, 4.0f ); 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.up = new Vector3( 0.0f, 1.0f, 0.0f );
camera.fovy = 45.0f; camera.fovy = 45.0f;
camera.type = CAMERA_PERSPECTIVE; camera.type = CAMERA_PERSPECTIVE;
Model model = LoadModel("resources/models/watermill.obj"); // Load OBJ model Model model = LoadModel("resources/models/watermill.obj"); // Load OBJ model
Texture2D texture = LoadTexture("resources/models/watermill_diffuse.png"); // Load model texture 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 "resources/shaders/glsl330/grayscale.fs"); // Load model shader
model.material.shader = shader; // Set shader effect to 3d model model.material.shader = shader; // Set shader effect to 3d model
model.material.maps[(int)MAP_ALBEDO].texture = texture; // Bind texture to 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 Vector3 position = new Vector3( 0.0f, 0.0f, 0.0f ); // Set model position
SetCameraMode(camera, (int)CAMERA_FREE); // Set an orbital camera mode SetCameraMode(camera, (int)CAMERA_FREE); // Set an orbital camera mode
SetTargetFPS(60); // Set our game to run at 60 frames-per-second SetTargetFPS(60); // Set our game to run at 60 frames-per-second
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
// Main game loop // Main game loop
while (!WindowShouldClose()) // Detect window close button or ESC key while (!WindowShouldClose()) // Detect window close button or ESC key
{ {
@ -66,41 +66,41 @@ public partial class shaders_model_shader
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
UpdateCamera(ref camera); // Update camera UpdateCamera(ref camera); // Update camera
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// Draw // Draw
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
BeginDrawing(); BeginDrawing();
ClearBackground(RAYWHITE); ClearBackground(RAYWHITE);
BeginMode3D(camera); BeginMode3D(camera);
DrawModel(model, position, 0.2f, WHITE); // Draw 3d model with texture DrawModel(model, position, 0.2f, WHITE); // Draw 3d model with texture
DrawGrid(10, 1.0f); // Draw a grid DrawGrid(10, 1.0f); // Draw a grid
EndMode3D(); EndMode3D();
DrawText("(c) Watermill 3D model by Alberto Cano", screenWidth - 210, screenHeight - 20, 10, GRAY); 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 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); DrawText(FormatText("Camera3D target: (%.2f, %.2f, %.2f)", camera.target.x, camera.target.y, camera.target.z), 600, 40, 10, GRAY);
DrawFPS(10, 10); DrawFPS(10, 10);
EndDrawing(); EndDrawing();
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
} }
// De-Initialization // De-Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
UnloadShader(shader); // Unload shader UnloadShader(shader); // Unload shader
UnloadTexture(texture); // Unload texture UnloadTexture(texture); // Unload texture
UnloadModel(model); // Unload model UnloadModel(model); // Unload model
CloseWindow(); // Close window and OpenGL context CloseWindow(); // Close window and OpenGL context
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
return 0; return 0;
} }
} }

View File

@ -22,13 +22,13 @@ public partial class shaders_postprocessing
* Copyright (c) 2015 Ramon Santamaria (@raysan5) * Copyright (c) 2015 Ramon Santamaria (@raysan5)
* *
********************************************************************************************/ ********************************************************************************************/
public const int GLSL_VERSION = 330; public const int GLSL_VERSION = 330;
// public const int GLSL_VERSION = 100; // public const int GLSL_VERSION = 100;
public const int MAX_POSTPRO_SHADERS = 12; public const int MAX_POSTPRO_SHADERS = 12;
enum PostproShader enum PostproShader
{ {
FX_GRAYSCALE = 0, FX_GRAYSCALE = 0,
@ -45,8 +45,8 @@ public partial class shaders_postprocessing
FX_BLUR, FX_BLUR,
//FX_FXAA //FX_FXAA
} }
static string[] postproShaderText = static string[] postproShaderText =
{ {
"GRAYSCALE", "GRAYSCALE",
"POSTERIZATION", "POSTERIZATION",
@ -62,32 +62,32 @@ public partial class shaders_postprocessing
"BLUR", "BLUR",
//"FXAA" //"FXAA"
}; };
public static int Main() public static int Main()
{ {
// Initialization // Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
int screenWidth = 800; int screenWidth = 800;
int screenHeight = 450; int screenHeight = 450;
SetConfigFlags(FLAG_MSAA_4X_HINT); // Enable Multi Sampling Anti Aliasing 4x (if available) SetConfigFlags(FLAG_MSAA_4X_HINT); // Enable Multi Sampling Anti Aliasing 4x (if available)
InitWindow(screenWidth, screenHeight, "raylib [shaders] example - postprocessing shader"); InitWindow(screenWidth, screenHeight, "raylib [shaders] example - postprocessing shader");
// Define the camera to look into our 3d world // 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 ); 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 Model model = LoadModel("resources/models/church.obj"); // Load OBJ model
Texture2D texture = LoadTexture("resources/models/church_diffuse.png"); // Load model texture (diffuse map) 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 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 Vector3 position = new Vector3( 0.0f, 0.0f, 0.0f ); // Set model position
// Load all postpro shaders // Load all postpro shaders
// NOTE 1: All postpro shader use the base vertex shader (DEFAULT_VERTEX_SHADER) // NOTE 1: All postpro shader use the base vertex shader (DEFAULT_VERTEX_SHADER)
// NOTE 2: We load the correct shader depending on GLSL version // NOTE 2: We load the correct shader depending on GLSL version
Shader[] shaders = new Shader[MAX_POSTPRO_SHADERS]; Shader[] shaders = new Shader[MAX_POSTPRO_SHADERS];
// NOTE: Defining null (NULL) for vertex shader forces usage of internal default vertex shader // 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_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)); 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_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_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)); shaders[(int)PostproShader.FX_BLUR] = LoadShader(null, FormatText("resources/shaders/glsl%i/blur.fs", GLSL_VERSION));
int currentShader = (int)PostproShader.FX_GRAYSCALE; int currentShader = (int)PostproShader.FX_GRAYSCALE;
// Create a RenderTexture2D to be used for render to texture // Create a RenderTexture2D to be used for render to texture
RenderTexture2D target = LoadRenderTexture(screenWidth, screenHeight); RenderTexture2D target = LoadRenderTexture(screenWidth, screenHeight);
// Setup orbital camera // Setup orbital camera
SetCameraMode(camera, (int)CAMERA_ORBITAL); // Set an orbital camera mode SetCameraMode(camera, (int)CAMERA_ORBITAL); // Set an orbital camera mode
SetTargetFPS(60); // Set our game to run at 60 frames-per-second SetTargetFPS(60); // Set our game to run at 60 frames-per-second
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
// Main game loop // Main game loop
while (!WindowShouldClose()) // Detect window close button or ESC key while (!WindowShouldClose()) // Detect window close button or ESC key
{ {
// Update // Update
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
UpdateCamera(ref camera); // Update camera UpdateCamera(ref camera); // Update camera
if (IsKeyPressed(KEY_RIGHT)) currentShader++; if (IsKeyPressed(KEY_RIGHT)) currentShader++;
else if (IsKeyPressed(KEY_LEFT)) currentShader--; else if (IsKeyPressed(KEY_LEFT)) currentShader--;
if (currentShader >= MAX_POSTPRO_SHADERS) currentShader = 0; if (currentShader >= MAX_POSTPRO_SHADERS) currentShader = 0;
else if (currentShader < 0) currentShader = MAX_POSTPRO_SHADERS - 1; else if (currentShader < 0) currentShader = MAX_POSTPRO_SHADERS - 1;
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// Draw // Draw
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
BeginDrawing(); BeginDrawing();
ClearBackground(RAYWHITE); ClearBackground(RAYWHITE);
BeginTextureMode(target); // Enable drawing to texture BeginTextureMode(target); // Enable drawing to texture
BeginMode3D(camera); BeginMode3D(camera);
DrawModel(model, position, 0.1f, WHITE); // Draw 3d model with texture DrawModel(model, position, 0.1f, WHITE); // Draw 3d model with texture
DrawGrid(10, 1.0f); // Draw a grid DrawGrid(10, 1.0f); // Draw a grid
EndMode3D(); EndMode3D();
EndTextureMode(); // End drawing to texture (now we have a texture available for next passes) EndTextureMode(); // End drawing to texture (now we have a texture available for next passes)
// Render previously generated texture using selected postpro shader // Render previously generated texture using selected postpro shader
BeginShaderMode(shaders[currentShader]); BeginShaderMode(shaders[currentShader]);
// NOTE: Render texture must be y-flipped due to default OpenGL coordinates (left-bottom) // 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); DrawTextureRec(target.texture, new Rectangle( 0, 0, target.texture.width, -target.texture.height ), new Vector2( 0, 0 ), WHITE);
EndShaderMode(); EndShaderMode();
DrawRectangle(0, 9, 580, 30, Fade(LIGHTGRAY, 0.7f)); DrawRectangle(0, 9, 580, 30, Fade(LIGHTGRAY, 0.7f));
DrawText("(c) Church 3D model by Alberto Cano", screenWidth - 200, screenHeight - 20, 10, GRAY); DrawText("(c) Church 3D model by Alberto Cano", screenWidth - 200, screenHeight - 20, 10, GRAY);
DrawText("CURRENT POSTPRO SHADER:", 10, 15, 20, BLACK); DrawText("CURRENT POSTPRO SHADER:", 10, 15, 20, BLACK);
DrawText(postproShaderText[currentShader], 330, 15, 20, RED); DrawText(postproShaderText[currentShader], 330, 15, 20, RED);
DrawText("< >", 540, 10, 30, DARKBLUE); DrawText("< >", 540, 10, 30, DARKBLUE);
DrawFPS(700, 15); DrawFPS(700, 15);
EndDrawing(); EndDrawing();
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
} }
// De-Initialization // De-Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
// Unload all postpro shaders // Unload all postpro shaders
for (int i = 0; i < MAX_POSTPRO_SHADERS; i++) UnloadShader(shaders[i]); for (int i = 0; i < MAX_POSTPRO_SHADERS; i++) UnloadShader(shaders[i]);
UnloadTexture(texture); // Unload texture UnloadTexture(texture); // Unload texture
UnloadModel(model); // Unload model UnloadModel(model); // Unload model
UnloadRenderTexture(target); // Unload render texture UnloadRenderTexture(target); // Unload render texture
CloseWindow(); // Close window and OpenGL context CloseWindow(); // Close window and OpenGL context
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
return 0; return 0;
} }
} }

View File

@ -20,26 +20,26 @@ public partial class shaders_shapes_textures
* Copyright (c) 2015 Ramon Santamaria (@raysan5) * Copyright (c) 2015 Ramon Santamaria (@raysan5)
* *
********************************************************************************************/ ********************************************************************************************/
public static int Main() public static int Main()
{ {
// Initialization // Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
int screenWidth = 800; int screenWidth = 800;
int screenHeight = 450; int screenHeight = 450;
InitWindow(screenWidth, screenHeight, "raylib [shaders] example - shapes and texture shaders"); InitWindow(screenWidth, screenHeight, "raylib [shaders] example - shapes and texture shaders");
Texture2D fudesumi = LoadTexture("resources/fudesumi.png"); Texture2D fudesumi = LoadTexture("resources/fudesumi.png");
// NOTE: Using GLSL 330 shader version, on OpenGL ES 2.0 use GLSL 100 shader version // NOTE: Using GLSL 330 shader version, on OpenGL ES 2.0 use GLSL 100 shader version
Shader shader = LoadShader("resources/shaders/glsl330/base.vs", Shader shader = LoadShader("resources/shaders/glsl330/base.vs",
"resources/shaders/glsl330/grayscale.fs"); "resources/shaders/glsl330/grayscale.fs");
SetTargetFPS(60); SetTargetFPS(60);
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
// Main game loop // Main game loop
while (!WindowShouldClose()) // Detect window close button or ESC key while (!WindowShouldClose()) // Detect window close button or ESC key
{ {
@ -47,68 +47,68 @@ public partial class shaders_shapes_textures
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// TODO: Update your variables here // TODO: Update your variables here
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// Draw // Draw
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
BeginDrawing(); BeginDrawing();
ClearBackground(RAYWHITE); ClearBackground(RAYWHITE);
// Start drawing with default shader // Start drawing with default shader
DrawText("USING DEFAULT SHADER", 20, 40, 10, RED); DrawText("USING DEFAULT SHADER", 20, 40, 10, RED);
DrawCircle(80, 120, 35, DARKBLUE); DrawCircle(80, 120, 35, DARKBLUE);
DrawCircleGradient(80, 220, 60, GREEN, SKYBLUE); DrawCircleGradient(80, 220, 60, GREEN, SKYBLUE);
DrawCircleLines(80, 340, 80, DARKBLUE); DrawCircleLines(80, 340, 80, DARKBLUE);
// Activate our custom shader to be applied on next shapes/textures drawings // Activate our custom shader to be applied on next shapes/textures drawings
BeginShaderMode(shader); BeginShaderMode(shader);
DrawText("USING CUSTOM SHADER", 190, 40, 10, RED); DrawText("USING CUSTOM SHADER", 190, 40, 10, RED);
DrawRectangle(250 - 60, 90, 120, 60, RED); DrawRectangle(250 - 60, 90, 120, 60, RED);
DrawRectangleGradientH(250 - 90, 170, 180, 130, MAROON, GOLD); DrawRectangleGradientH(250 - 90, 170, 180, 130, MAROON, GOLD);
DrawRectangleLines(250 - 40, 320, 80, 60, ORANGE); DrawRectangleLines(250 - 40, 320, 80, 60, ORANGE);
// Activate our default shader for next drawings // Activate our default shader for next drawings
EndShaderMode(); EndShaderMode();
DrawText("USING DEFAULT SHADER", 370, 40, 10, RED); DrawText("USING DEFAULT SHADER", 370, 40, 10, RED);
DrawTriangle(new Vector2(430, 80), DrawTriangle(new Vector2(430, 80),
new Vector2(430 - 60, 150), new Vector2(430 - 60, 150),
new Vector2(430 + 60, 150), VIOLET); new Vector2(430 + 60, 150), VIOLET);
DrawTriangleLines(new Vector2(430, 160), DrawTriangleLines(new Vector2(430, 160),
new Vector2(430 - 20, 230), new Vector2(430 - 20, 230),
new Vector2(430 + 20, 230), DARKBLUE); new Vector2(430 + 20, 230), DARKBLUE);
DrawPoly(new Vector2(430, 320), 6, 80, 0, BROWN); DrawPoly(new Vector2(430, 320), 6, 80, 0, BROWN);
// Activate our custom shader to be applied on next shapes/textures drawings // Activate our custom shader to be applied on next shapes/textures drawings
BeginShaderMode(shader); BeginShaderMode(shader);
DrawTexture(fudesumi, 500, -30, WHITE); // Using custom shader DrawTexture(fudesumi, 500, -30, WHITE); // Using custom shader
// Activate our default shader for next drawings // Activate our default shader for next drawings
EndShaderMode(); EndShaderMode();
DrawText("(c) Fudesumi sprite by Eiden Marsal", 380, screenHeight - 20, 10, GRAY); DrawText("(c) Fudesumi sprite by Eiden Marsal", 380, screenHeight - 20, 10, GRAY);
EndDrawing(); EndDrawing();
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
} }
// De-Initialization // De-Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
UnloadShader(shader); // Unload shader UnloadShader(shader); // Unload shader
UnloadTexture(fudesumi); // Unload texture UnloadTexture(fudesumi); // Unload texture
CloseWindow(); // Close window and OpenGL context CloseWindow(); // Close window and OpenGL context
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
return 0; return 0;
} }
} }

View File

@ -13,20 +13,20 @@ public partial class shapes_basic_shapes
* Copyright (c) 2014 Ramon Santamaria (@raysan5) * Copyright (c) 2014 Ramon Santamaria (@raysan5)
* *
********************************************************************************************/ ********************************************************************************************/
public static int Main() public static int Main()
{ {
// Initialization // Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
int screenWidth = 800; int screenWidth = 800;
int screenHeight = 450; int screenHeight = 450;
InitWindow(screenWidth, screenHeight, "raylib [shapes] example - basic shapes drawing"); InitWindow(screenWidth, screenHeight, "raylib [shapes] example - basic shapes drawing");
SetTargetFPS(60); SetTargetFPS(60);
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
// Main game loop // Main game loop
while (!WindowShouldClose()) // Detect window close button or ESC key while (!WindowShouldClose()) // Detect window close button or ESC key
{ {
@ -34,44 +34,44 @@ public partial class shapes_basic_shapes
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// TODO: Update your variables here // TODO: Update your variables here
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// Draw // Draw
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
BeginDrawing(); BeginDrawing();
ClearBackground(RAYWHITE); ClearBackground(RAYWHITE);
DrawText("some basic shapes available on raylib", 20, 20, 20, DARKGRAY); DrawText("some basic shapes available on raylib", 20, 20, 20, DARKGRAY);
DrawLine(18, 42, screenWidth - 18, 42, BLACK); DrawLine(18, 42, screenWidth - 18, 42, BLACK);
DrawCircle(screenWidth/4, 120, 35, DARKBLUE); DrawCircle(screenWidth/4, 120, 35, DARKBLUE);
DrawCircleGradient(screenWidth/4, 220, 60, GREEN, SKYBLUE); DrawCircleGradient(screenWidth/4, 220, 60, GREEN, SKYBLUE);
DrawCircleLines(screenWidth/4, 340, 80, DARKBLUE); DrawCircleLines(screenWidth/4, 340, 80, DARKBLUE);
DrawRectangle(screenWidth/4*2 - 60, 100, 120, 60, RED); DrawRectangle(screenWidth/4*2 - 60, 100, 120, 60, RED);
DrawRectangleGradientH(screenWidth/4*2 - 90, 170, 180, 130, MAROON, GOLD); DrawRectangleGradientH(screenWidth/4*2 - 90, 170, 180, 130, MAROON, GOLD);
DrawRectangleLines(screenWidth/4*2 - 40, 320, 80, 60, ORANGE); DrawRectangleLines(screenWidth/4*2 - 40, 320, 80, 60, ORANGE);
DrawTriangle(new Vector2(screenWidth/4*3, 80), DrawTriangle(new Vector2(screenWidth/4*3, 80),
new Vector2(screenWidth/4*3 - 60, 150), new Vector2(screenWidth/4*3 - 60, 150),
new Vector2(screenWidth/4*3 + 60, 150), VIOLET); new Vector2(screenWidth/4*3 + 60, 150), VIOLET);
DrawTriangleLines(new Vector2(screenWidth/4*3, 160), DrawTriangleLines(new Vector2(screenWidth/4*3, 160),
new Vector2(screenWidth/4*3 - 20, 230), new Vector2(screenWidth/4*3 - 20, 230),
new Vector2(screenWidth/4*3 + 20, 230), DARKBLUE); new Vector2(screenWidth/4*3 + 20, 230), DARKBLUE);
DrawPoly(new Vector2(screenWidth/4*3, 320), 6, 80, 0, BROWN); DrawPoly(new Vector2(screenWidth/4*3, 320), 6, 80, 0, BROWN);
EndDrawing(); EndDrawing();
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
} }
// De-Initialization // De-Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
CloseWindow(); // Close window and OpenGL context CloseWindow(); // Close window and OpenGL context
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
return 0; return 0;
} }
} }

View File

@ -13,20 +13,20 @@ public partial class shapes_colors_palette
* Copyright (c) 2014 Ramon Santamaria (@raysan5) * Copyright (c) 2014 Ramon Santamaria (@raysan5)
* *
********************************************************************************************/ ********************************************************************************************/
public static int Main() public static int Main()
{ {
// Initialization // Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
int screenWidth = 800; int screenWidth = 800;
int screenHeight = 450; int screenHeight = 450;
InitWindow(screenWidth, screenHeight, "raylib [shapes] example - raylib color palette"); InitWindow(screenWidth, screenHeight, "raylib [shapes] example - raylib color palette");
SetTargetFPS(60); SetTargetFPS(60);
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
// Main game loop // Main game loop
while (!WindowShouldClose()) // Detect window close button or ESC key while (!WindowShouldClose()) // Detect window close button or ESC key
{ {
@ -34,15 +34,15 @@ public partial class shapes_colors_palette
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// TODO: Update your variables here // TODO: Update your variables here
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// Draw // Draw
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
BeginDrawing(); BeginDrawing();
ClearBackground(RAYWHITE); ClearBackground(RAYWHITE);
DrawText("raylib color palette", 28, 42, 20, BLACK); DrawText("raylib color palette", 28, 42, 20, BLACK);
DrawRectangle(26, 80, 100, 100, DARKGRAY); DrawRectangle(26, 80, 100, 100, DARKGRAY);
DrawRectangle(26, 188, 100, 100, GRAY); DrawRectangle(26, 188, 100, 100, GRAY);
DrawRectangle(26, 296, 100, 100, LIGHTGRAY); DrawRectangle(26, 296, 100, 100, LIGHTGRAY);
@ -64,8 +64,8 @@ public partial class shapes_colors_palette
DrawRectangle(674, 80, 100, 100, DARKBROWN); DrawRectangle(674, 80, 100, 100, DARKBROWN);
DrawRectangle(674, 188, 100, 100, BROWN); DrawRectangle(674, 188, 100, 100, BROWN);
DrawRectangle(674, 296, 100, 100, BEIGE); DrawRectangle(674, 296, 100, 100, BEIGE);
DrawText("DARKGRAY", 65, 166, 10, BLACK); DrawText("DARKGRAY", 65, 166, 10, BLACK);
DrawText("GRAY", 93, 274, 10, BLACK); DrawText("GRAY", 93, 274, 10, BLACK);
DrawText("LIGHTGRAY", 61, 382, 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("DARKBROWN", 705, 166, 10, BLACK);
DrawText("BROWN", 733, 274, 10, BLACK); DrawText("BROWN", 733, 274, 10, BLACK);
DrawText("BEIGE", 737, 382, 10, BLACK); DrawText("BEIGE", 737, 382, 10, BLACK);
EndDrawing(); EndDrawing();
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
} }
// De-Initialization // De-Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
CloseWindow(); // Close window and OpenGL context CloseWindow(); // Close window and OpenGL context
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
return 0; return 0;
} }
} }

View File

@ -13,24 +13,24 @@ public partial class shapes_lines_bezier
* Copyright (c) 2017 Ramon Santamaria (@raysan5) * Copyright (c) 2017 Ramon Santamaria (@raysan5)
* *
********************************************************************************************/ ********************************************************************************************/
public static int Main() public static int Main()
{ {
// Initialization // Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
int screenWidth = 800; int screenWidth = 800;
int screenHeight = 450; int screenHeight = 450;
SetConfigFlags(FLAG_MSAA_4X_HINT); SetConfigFlags(FLAG_MSAA_4X_HINT);
InitWindow(screenWidth, screenHeight, "raylib [shapes] example - cubic-bezier lines"); InitWindow(screenWidth, screenHeight, "raylib [shapes] example - cubic-bezier lines");
Vector2 start = new Vector2( 0, 0 ); Vector2 start = new Vector2( 0, 0 );
Vector2 end = new Vector2( screenWidth, screenHeight ); Vector2 end = new Vector2( screenWidth, screenHeight );
SetTargetFPS(60); SetTargetFPS(60);
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
// Main game loop // Main game loop
while (!WindowShouldClose()) // Detect window close button or ESC key 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(); if (IsMouseButtonDown(MOUSE_LEFT_BUTTON)) start = GetMousePosition();
else if (IsMouseButtonDown(MOUSE_RIGHT_BUTTON)) end = GetMousePosition(); else if (IsMouseButtonDown(MOUSE_RIGHT_BUTTON)) end = GetMousePosition();
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// Draw // Draw
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
BeginDrawing(); BeginDrawing();
ClearBackground(RAYWHITE); ClearBackground(RAYWHITE);
DrawText("USE MOUSE LEFT-RIGHT CLICK to DEFINE LINE START and END POINTS", 15, 20, 20, GRAY); DrawText("USE MOUSE LEFT-RIGHT CLICK to DEFINE LINE START and END POINTS", 15, 20, 20, GRAY);
DrawLineBezier(start, end, 2.0f, RED); DrawLineBezier(start, end, 2.0f, RED);
EndDrawing(); EndDrawing();
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
} }
// De-Initialization // De-Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
CloseWindow(); // Close window and OpenGL context CloseWindow(); // Close window and OpenGL context
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
return 0; return 0;
} }
} }

View File

@ -13,20 +13,20 @@ public partial class shapes_logo_raylib
* Copyright (c) 2014 Ramon Santamaria (@raysan5) * Copyright (c) 2014 Ramon Santamaria (@raysan5)
* *
********************************************************************************************/ ********************************************************************************************/
public static int Main() public static int Main()
{ {
// Initialization // Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
int screenWidth = 800; int screenWidth = 800;
int screenHeight = 450; int screenHeight = 450;
InitWindow(screenWidth, screenHeight, "raylib [shapes] example - raylib logo using shapes"); InitWindow(screenWidth, screenHeight, "raylib [shapes] example - raylib logo using shapes");
SetTargetFPS(60); SetTargetFPS(60);
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
// Main game loop // Main game loop
while (!WindowShouldClose()) // Detect window close button or ESC key while (!WindowShouldClose()) // Detect window close button or ESC key
{ {
@ -34,28 +34,28 @@ public partial class shapes_logo_raylib
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// TODO: Update your variables here // TODO: Update your variables here
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// Draw // Draw
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
BeginDrawing(); BeginDrawing();
ClearBackground(RAYWHITE); ClearBackground(RAYWHITE);
DrawRectangle(screenWidth/2 - 128, screenHeight/2 - 128, 256, 256, BLACK); DrawRectangle(screenWidth/2 - 128, screenHeight/2 - 128, 256, 256, BLACK);
DrawRectangle(screenWidth/2 - 112, screenHeight/2 - 112, 224, 224, RAYWHITE); DrawRectangle(screenWidth/2 - 112, screenHeight/2 - 112, 224, 224, RAYWHITE);
DrawText("raylib", screenWidth/2 - 44, screenHeight/2 + 48, 50, BLACK); DrawText("raylib", screenWidth/2 - 44, screenHeight/2 + 48, 50, BLACK);
DrawText("this is NOT a texture!", 350, 370, 10, GRAY); DrawText("this is NOT a texture!", 350, 370, 10, GRAY);
EndDrawing(); EndDrawing();
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
} }
// De-Initialization // De-Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
CloseWindow(); // Close window and OpenGL context CloseWindow(); // Close window and OpenGL context
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
return 0; return 0;
} }
} }

View File

@ -14,35 +14,35 @@ public partial class shapes_logo_raylib_anim
* Copyright (c) 2014 Ramon Santamaria (@raysan5) * Copyright (c) 2014 Ramon Santamaria (@raysan5)
* *
********************************************************************************************/ ********************************************************************************************/
public static int Main() public static int Main()
{ {
// Initialization // Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
int screenWidth = 800; int screenWidth = 800;
int screenHeight = 450; int screenHeight = 450;
InitWindow(screenWidth, screenHeight, "raylib [shapes] example - raylib logo animation"); InitWindow(screenWidth, screenHeight, "raylib [shapes] example - raylib logo animation");
int logoPositionX = screenWidth/2 - 128; int logoPositionX = screenWidth/2 - 128;
int logoPositionY = screenHeight/2 - 128; int logoPositionY = screenHeight/2 - 128;
int framesCounter = 0; int framesCounter = 0;
int lettersCount = 0; int lettersCount = 0;
int topSideRecWidth = 16; int topSideRecWidth = 16;
int leftSideRecHeight = 16; int leftSideRecHeight = 16;
int bottomSideRecWidth = 16; int bottomSideRecWidth = 16;
int rightSideRecHeight = 16; int rightSideRecHeight = 16;
int state = 0; // Tracking animation states (State Machine) int state = 0; // Tracking animation states (State Machine)
float alpha = 1.0f; // Useful for fading float alpha = 1.0f; // Useful for fading
SetTargetFPS(60); SetTargetFPS(60);
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
// Main game loop // Main game loop
while (!WindowShouldClose()) // Detect window close button or ESC key 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 if (state == 0) // State 0: Small box blinking
{ {
framesCounter++; framesCounter++;
if (framesCounter == 120) if (framesCounter == 120)
{ {
state = 1; state = 1;
@ -62,14 +62,14 @@ public partial class shapes_logo_raylib_anim
{ {
topSideRecWidth += 4; topSideRecWidth += 4;
leftSideRecHeight += 4; leftSideRecHeight += 4;
if (topSideRecWidth == 256) state = 2; if (topSideRecWidth == 256) state = 2;
} }
else if (state == 2) // State 2: Bottom and right bars growing else if (state == 2) // State 2: Bottom and right bars growing
{ {
bottomSideRecWidth += 4; bottomSideRecWidth += 4;
rightSideRecHeight += 4; rightSideRecHeight += 4;
if (bottomSideRecWidth == 256) state = 3; if (bottomSideRecWidth == 256) state = 3;
} }
else if (state == 3) // State 3: Letters appearing (one by one) else if (state == 3) // State 3: Letters appearing (one by one)
@ -81,11 +81,11 @@ public partial class shapes_logo_raylib_anim
lettersCount++; lettersCount++;
framesCounter = 0; framesCounter = 0;
} }
if (lettersCount >= 10) // When all letters have appeared, just fade out everything if (lettersCount >= 10) // When all letters have appeared, just fade out everything
{ {
alpha -= 0.02f; alpha -= 0.02f;
if (alpha <= 0.0f) if (alpha <= 0.0f)
{ {
alpha = 0.0f; alpha = 0.0f;
@ -99,25 +99,25 @@ public partial class shapes_logo_raylib_anim
{ {
framesCounter = 0; framesCounter = 0;
lettersCount = 0; lettersCount = 0;
topSideRecWidth = 16; topSideRecWidth = 16;
leftSideRecHeight = 16; leftSideRecHeight = 16;
bottomSideRecWidth = 16; bottomSideRecWidth = 16;
rightSideRecHeight = 16; rightSideRecHeight = 16;
alpha = 1.0f; alpha = 1.0f;
state = 0; // Return to State 0 state = 0; // Return to State 0
} }
} }
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// Draw // Draw
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
BeginDrawing(); BeginDrawing();
ClearBackground(RAYWHITE); ClearBackground(RAYWHITE);
if (state == 0) if (state == 0)
{ {
if ((framesCounter/15)%2 != 0) DrawRectangle(logoPositionX, logoPositionY, 16, 16, BLACK); 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, topSideRecWidth, 16, BLACK);
DrawRectangle(logoPositionX, logoPositionY, 16, leftSideRecHeight, BLACK); DrawRectangle(logoPositionX, logoPositionY, 16, leftSideRecHeight, BLACK);
DrawRectangle(logoPositionX + 240, logoPositionY, 16, rightSideRecHeight, BLACK); DrawRectangle(logoPositionX + 240, logoPositionY, 16, rightSideRecHeight, BLACK);
DrawRectangle(logoPositionX, logoPositionY + 240, bottomSideRecWidth, 16, 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, topSideRecWidth, 16, Fade(BLACK, alpha));
DrawRectangle(logoPositionX, logoPositionY + 16, 16, leftSideRecHeight - 32, 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 + 240, logoPositionY + 16, 16, rightSideRecHeight - 32, Fade(BLACK, alpha));
DrawRectangle(logoPositionX, logoPositionY + 240, bottomSideRecWidth, 16, Fade(BLACK, alpha)); DrawRectangle(logoPositionX, logoPositionY + 240, bottomSideRecWidth, 16, Fade(BLACK, alpha));
DrawRectangle(screenWidth/2 - 112, screenHeight/2 - 112, 224, 224, Fade(RAYWHITE, 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)); // 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); DrawText("[R] REPLAY", 340, 200, 20, GRAY);
} }
EndDrawing(); EndDrawing();
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
} }
// De-Initialization // De-Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
CloseWindow(); // Close window and OpenGL context CloseWindow(); // Close window and OpenGL context
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
return 0; return 0;
} }
} }

View File

@ -13,32 +13,32 @@ public partial class text_bmfont_ttf
* Copyright (c) 2016 Ramon Santamaria (@raysan5) * Copyright (c) 2016 Ramon Santamaria (@raysan5)
* *
********************************************************************************************/ ********************************************************************************************/
public static int Main() public static int Main()
{ {
// Initialization // Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
int screenWidth = 800; int screenWidth = 800;
int screenHeight = 450; int screenHeight = 450;
InitWindow(screenWidth, screenHeight, "raylib [text] example - bmfont and ttf sprite fonts loading"); InitWindow(screenWidth, screenHeight, "raylib [text] example - bmfont and ttf sprite fonts loading");
string msgBm = "THIS IS AN AngelCode SPRITE FONT"; string msgBm = "THIS IS AN AngelCode SPRITE FONT";
string msgTtf = "THIS SPRITE FONT has been GENERATED from a TTF"; string msgTtf = "THIS SPRITE FONT has been GENERATED from a TTF";
// NOTE: Textures/Fonts MUST be loaded after Window initialization (OpenGL context is required) // NOTE: Textures/Fonts MUST be loaded after Window initialization (OpenGL context is required)
Font fontBm = LoadFont("resources/bmfont.fnt"); // BMFont (AngelCode) Font fontBm = LoadFont("resources/bmfont.fnt"); // BMFont (AngelCode)
Font fontTtf = LoadFont("resources/pixantiqua.ttf"); // TTF font Font fontTtf = LoadFont("resources/pixantiqua.ttf"); // TTF font
Vector2 fontPosition; Vector2 fontPosition;
fontPosition.x = screenWidth/2 - MeasureTextEx(fontBm, msgBm, fontBm.baseSize, 0).x/2; fontPosition.x = screenWidth/2 - MeasureTextEx(fontBm, msgBm, fontBm.baseSize, 0).x/2;
fontPosition.y = screenHeight/2 - fontBm.baseSize/2 - 80; fontPosition.y = screenHeight/2 - fontBm.baseSize/2 - 80;
SetTargetFPS(60); SetTargetFPS(60);
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
// Main game loop // Main game loop
while (!WindowShouldClose()) // Detect window close button or ESC key while (!WindowShouldClose()) // Detect window close button or ESC key
{ {
@ -46,28 +46,28 @@ public partial class text_bmfont_ttf
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// TODO: Update variables here... // TODO: Update variables here...
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// Draw // Draw
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
BeginDrawing(); BeginDrawing();
ClearBackground(RAYWHITE); ClearBackground(RAYWHITE);
DrawTextEx(fontBm, msgBm, fontPosition, fontBm.baseSize, 0, MAROON); DrawTextEx(fontBm, msgBm, fontPosition, fontBm.baseSize, 0, MAROON);
DrawTextEx(fontTtf, msgTtf, new Vector2( 75.0f, 240.0f ), fontTtf.baseSize*0.8f, 2, LIME); DrawTextEx(fontTtf, msgTtf, new Vector2( 75.0f, 240.0f ), fontTtf.baseSize*0.8f, 2, LIME);
EndDrawing(); EndDrawing();
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
} }
// De-Initialization // De-Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
UnloadFont(fontBm); // AngelCode Font unloading UnloadFont(fontBm); // AngelCode Font unloading
UnloadFont(fontTtf); // TTF Font unloading UnloadFont(fontTtf); // TTF Font unloading
CloseWindow(); // Close window and OpenGL context CloseWindow(); // Close window and OpenGL context
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
return 0; return 0;
} }
} }

View File

@ -49,7 +49,7 @@ public partial class text_bmfont_unordered
ClearBackground(RAYWHITE); ClearBackground(RAYWHITE);
DrawText("Font name: PixAntiqua", 40, 50, 20, GRAY); 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 base size: %i", font.baseSize), 40, 80, 20, GRAY);
// DrawText(FormatText("Font chars number: %i", font.charsCount), 40, 110, 20, GRAY); // DrawText(FormatText("Font chars number: %i", font.charsCount), 40, 110, 20, GRAY);

View File

@ -14,21 +14,21 @@ public partial class text_font_sdf
* Copyright (c) 2015 Ramon Santamaria (@raysan5) * Copyright (c) 2015 Ramon Santamaria (@raysan5)
* *
********************************************************************************************/ ********************************************************************************************/
public static int Main() public static int Main()
{ {
// Initialization // Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
int screenWidth = 800; int screenWidth = 800;
int screenHeight = 450; int screenHeight = 450;
InitWindow(screenWidth, screenHeight, "raylib [text] example - SDF fonts"); InitWindow(screenWidth, screenHeight, "raylib [text] example - SDF fonts");
// NOTE: Textures/Fonts MUST be loaded after Window initialization (OpenGL context is required) // NOTE: Textures/Fonts MUST be loaded after Window initialization (OpenGL context is required)
string msg = "Signed Distance Fields"; string msg = "Signed Distance Fields";
// Default font generation from TTF font // Default font generation from TTF font
Font fontDefault = new Font(); Font fontDefault = new Font();
fontDefault.baseSize = 16; fontDefault.baseSize = 16;
@ -40,7 +40,7 @@ public partial class text_font_sdf
//Image atlas = GenImageFontAtlas(fontDefault.chars, 95, 16, 4, 0); //Image atlas = GenImageFontAtlas(fontDefault.chars, 95, 16, 4, 0);
//fontDefault.texture = LoadTextureFromImage(atlas); //fontDefault.texture = LoadTextureFromImage(atlas);
//UnloadImage(atlas); //UnloadImage(atlas);
// SDF font generation from TTF font // SDF font generation from TTF font
// NOTE: SDF chars data is generated with LoadFontData(), it's just a bool option // NOTE: SDF chars data is generated with LoadFontData(), it's just a bool option
Font fontSDF = new Font(); Font fontSDF = new Font();
@ -54,82 +54,82 @@ public partial class text_font_sdf
//atlas = GenImageFontAtlas(fontSDF.chars, 95, 16, 0, 1); //atlas = GenImageFontAtlas(fontSDF.chars, 95, 16, 0, 1);
//fontSDF.texture = LoadTextureFromImage(atlas); //fontSDF.texture = LoadTextureFromImage(atlas);
//UnloadImage(atlas); //UnloadImage(atlas);
// Load SDF required shader (we use default vertex shader) // Load SDF required shader (we use default vertex shader)
Shader shader = LoadShader(null, "resources/shaders/sdf.fs"); Shader shader = LoadShader(null, "resources/shaders/sdf.fs");
SetTextureFilter(fontSDF.texture, (int)FILTER_BILINEAR); // Required for SDF font SetTextureFilter(fontSDF.texture, (int)FILTER_BILINEAR); // Required for SDF font
Vector2 fontPosition = new Vector2( 40, screenHeight/2 - 50 ); Vector2 fontPosition = new Vector2( 40, screenHeight/2 - 50 );
Vector2 textSize = new Vector2( 0.0f ); Vector2 textSize = new Vector2( 0.0f );
float fontSize = 16.0f; float fontSize = 16.0f;
int currentFont = 0; // 0 - fontDefault, 1 - fontSDF int currentFont = 0; // 0 - fontDefault, 1 - fontSDF
SetTargetFPS(60); SetTargetFPS(60);
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
// Main game loop // Main game loop
while (!WindowShouldClose()) // Detect window close button or ESC key while (!WindowShouldClose()) // Detect window close button or ESC key
{ {
// Update // Update
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
fontSize += GetMouseWheelMove()*8.0f; fontSize += GetMouseWheelMove()*8.0f;
if (fontSize < 6) fontSize = 6; if (fontSize < 6) fontSize = 6;
if (IsKeyDown(KEY_SPACE)) currentFont = 1; if (IsKeyDown(KEY_SPACE)) currentFont = 1;
else currentFont = 0; else currentFont = 0;
if (currentFont == 0) textSize = MeasureTextEx(fontDefault, msg, fontSize, 0); if (currentFont == 0) textSize = MeasureTextEx(fontDefault, msg, fontSize, 0);
else textSize = MeasureTextEx(fontSDF, msg, fontSize, 0); else textSize = MeasureTextEx(fontSDF, msg, fontSize, 0);
fontPosition.x = GetScreenWidth()/2 - textSize.x/2; fontPosition.x = GetScreenWidth()/2 - textSize.x/2;
fontPosition.y = GetScreenHeight()/2 - textSize.y/2 + 80; fontPosition.y = GetScreenHeight()/2 - textSize.y/2 + 80;
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// Draw // Draw
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
BeginDrawing(); BeginDrawing();
ClearBackground(RAYWHITE); ClearBackground(RAYWHITE);
if (currentFont == 1) if (currentFont == 1)
{ {
// NOTE: SDF fonts require a custom SDf shader to compute fragment color // NOTE: SDF fonts require a custom SDf shader to compute fragment color
BeginShaderMode(shader); // Activate SDF font shader BeginShaderMode(shader); // Activate SDF font shader
DrawTextEx(fontSDF, msg, fontPosition, fontSize, 0, BLACK); DrawTextEx(fontSDF, msg, fontPosition, fontSize, 0, BLACK);
EndShaderMode(); // Activate our default shader for next drawings EndShaderMode(); // Activate our default shader for next drawings
DrawTexture(fontSDF.texture, 10, 10, BLACK); DrawTexture(fontSDF.texture, 10, 10, BLACK);
} }
else else
{ {
DrawTextEx(fontDefault, msg, fontPosition, fontSize, 0, BLACK); DrawTextEx(fontDefault, msg, fontPosition, fontSize, 0, BLACK);
DrawTexture(fontDefault.texture, 10, 10, BLACK); DrawTexture(fontDefault.texture, 10, 10, BLACK);
} }
if (currentFont == 1) DrawText("SDF!", 320, 20, 80, RED); if (currentFont == 1) DrawText("SDF!", 320, 20, 80, RED);
else DrawText("default font", 315, 40, 30, GRAY); else DrawText("default font", 315, 40, 30, GRAY);
DrawText("FONT SIZE: 16.0", GetScreenWidth() - 240, 20, 20, DARKGRAY); DrawText("FONT SIZE: 16.0", GetScreenWidth() - 240, 20, 20, DARKGRAY);
DrawText(FormatText("RENDER SIZE: %02.02f", fontSize), GetScreenWidth() - 240, 50, 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("Use MOUSE WHEEL to SCALE TEXT!", GetScreenWidth() - 240, 90, 10, DARKGRAY);
DrawText("PRESS SPACE to USE SDF FONT VERSION!", 340, GetScreenHeight() - 30, 20, MAROON); DrawText("PRESS SPACE to USE SDF FONT VERSION!", 340, GetScreenHeight() - 30, 20, MAROON);
EndDrawing(); EndDrawing();
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
} }
// De-Initialization // De-Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
UnloadFont(fontDefault); // Default font unloading UnloadFont(fontDefault); // Default font unloading
UnloadFont(fontSDF); // SDF font unloading UnloadFont(fontSDF); // SDF font unloading
UnloadShader(shader); // Unload SDF shader UnloadShader(shader); // Unload SDF shader
CloseWindow(); // Close window and OpenGL context CloseWindow(); // Close window and OpenGL context
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
return 0; return 0;
} }
} }

View File

@ -13,24 +13,24 @@ public partial class text_format_text
* Copyright (c) 2014 Ramon Santamaria (@raysan5) * Copyright (c) 2014 Ramon Santamaria (@raysan5)
* *
********************************************************************************************/ ********************************************************************************************/
public static int Main() public static int Main()
{ {
// Initialization // Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
int screenWidth = 800; int screenWidth = 800;
int screenHeight = 450; int screenHeight = 450;
InitWindow(screenWidth, screenHeight, "raylib [text] example - text formatting"); InitWindow(screenWidth, screenHeight, "raylib [text] example - text formatting");
int score = 100020; int score = 100020;
int hiscore = 200450; int hiscore = 200450;
int lives = 5; int lives = 5;
SetTargetFPS(60); SetTargetFPS(60);
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
// Main game loop // Main game loop
while (!WindowShouldClose()) // Detect window close button or ESC key while (!WindowShouldClose()) // Detect window close button or ESC key
{ {
@ -38,30 +38,30 @@ public partial class text_format_text
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// TODO: Update your variables here // TODO: Update your variables here
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// Draw // Draw
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
BeginDrawing(); BeginDrawing();
ClearBackground(RAYWHITE); ClearBackground(RAYWHITE);
DrawText(FormatText("Score: %08i", score), 200, 80, 20, RED); DrawText(FormatText("Score: %08i", score), 200, 80, 20, RED);
DrawText(FormatText("HiScore: %08i", hiscore), 200, 120, 20, GREEN); DrawText(FormatText("HiScore: %08i", hiscore), 200, 120, 20, GREEN);
DrawText(FormatText("Lives: %02i", lives), 200, 160, 40, BLUE); DrawText(FormatText("Lives: %02i", lives), 200, 160, 40, BLUE);
DrawText(FormatText("Elapsed Time: %02.02f ms", GetFrameTime()*1000), 200, 220, 20, BLACK); DrawText(FormatText("Elapsed Time: %02.02f ms", GetFrameTime()*1000), 200, 220, 20, BLACK);
EndDrawing(); EndDrawing();
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
} }
// De-Initialization // De-Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
CloseWindow(); // Close window and OpenGL context CloseWindow(); // Close window and OpenGL context
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
return 0; return 0;
} }
} }

View File

@ -14,30 +14,30 @@ public partial class text_input_box
* Copyright (c) 2017 Ramon Santamaria (@raysan5) * Copyright (c) 2017 Ramon Santamaria (@raysan5)
* *
********************************************************************************************/ ********************************************************************************************/
public const int MAX_INPUT_CHARS = 9; public const int MAX_INPUT_CHARS = 9;
public static int Main() public static int Main()
{ {
// Initialization // Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
int screenWidth = 800; int screenWidth = 800;
int screenHeight = 450; int screenHeight = 450;
InitWindow(screenWidth, screenHeight, "raylib [text] example - input box"); 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' StringBuilder name = new StringBuilder(' ', MAX_INPUT_CHARS + 1); // NOTE: One extra space required for line ending char '\0'
int letterCount = 0; int letterCount = 0;
Rectangle textBox = new Rectangle( screenWidth/2 - 100, 180, 225, 50 ); Rectangle textBox = new Rectangle( screenWidth/2 - 100, 180, 225, 50 );
bool mouseOnText = false; bool mouseOnText = false;
int framesCounter = 0; int framesCounter = 0;
SetTargetFPS(60); SetTargetFPS(60);
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
// Main game loop // Main game loop
while (!WindowShouldClose()) // Detect window close button or ESC key 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; if (CheckCollisionPointRec(GetMousePosition(), textBox)) mouseOnText = true;
else mouseOnText = false; else mouseOnText = false;
if (mouseOnText) if (mouseOnText)
{ {
int key = GetKeyPressed(); int key = GetKeyPressed();
// NOTE: Only allow keys in range [32..125] // NOTE: Only allow keys in range [32..125]
if ((key >= 32) && (key <= 125) && (letterCount < MAX_INPUT_CHARS)) if ((key >= 32) && (key <= 125) && (letterCount < MAX_INPUT_CHARS))
{ {
name[letterCount] = (char)key; name[letterCount] = (char)key;
letterCount++; letterCount++;
} }
if (IsKeyPressed(KEY_BACKSPACE)) if (IsKeyPressed(KEY_BACKSPACE))
{ {
letterCount--; letterCount--;
name[letterCount] = '\0'; name[letterCount] = '\0';
if (letterCount < 0) letterCount = 0; if (letterCount < 0) letterCount = 0;
} }
} }
if (mouseOnText) framesCounter++; if (mouseOnText) framesCounter++;
else framesCounter = 0; else framesCounter = 0;
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// Draw // Draw
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
BeginDrawing(); BeginDrawing();
ClearBackground(RAYWHITE); ClearBackground(RAYWHITE);
DrawText("PLACE MOUSE OVER INPUT BOX!", 240, 140, 20, GRAY); DrawText("PLACE MOUSE OVER INPUT BOX!", 240, 140, 20, GRAY);
DrawRectangleRec(textBox, LIGHTGRAY); DrawRectangleRec(textBox, LIGHTGRAY);
if (mouseOnText) DrawRectangleLines((int)textBox.x, (int)textBox.y, (int)textBox.width, (int)textBox.height, RED); 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); 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(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); DrawText(FormatText("INPUT CHARS: %i/%i", letterCount, MAX_INPUT_CHARS), 315, 250, 20, DARKGRAY);
if (mouseOnText) if (mouseOnText)
{ {
if (letterCount < MAX_INPUT_CHARS) 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); else DrawText("Press BACKSPACE to delete chars...", 230, 300, 20, GRAY);
} }
EndDrawing(); EndDrawing();
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
} }
// De-Initialization // De-Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
CloseWindow(); // Close window and OpenGL context CloseWindow(); // Close window and OpenGL context
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
return 0; return 0;
} }
// Check if any key is pressed // Check if any key is pressed
// NOTE: We limit keys check to keys between 32 (KEY_SPACE) and 126 // NOTE: We limit keys check to keys between 32 (KEY_SPACE) and 126
bool IsAnyKeyPressed() bool IsAnyKeyPressed()
{ {
bool keyPressed = false; bool keyPressed = false;
int key = GetKeyPressed(); int key = GetKeyPressed();
if ((key >= 32) && (key <= 126)) keyPressed = true; if ((key >= 32) && (key <= 126)) keyPressed = true;
return keyPressed; return keyPressed;
} }
} }

View File

@ -16,22 +16,22 @@ public partial class text_raylib_fonts
* Copyright (c) 2017 Ramon Santamaria (@raysan5) * Copyright (c) 2017 Ramon Santamaria (@raysan5)
* *
********************************************************************************************/ ********************************************************************************************/
public const int MAX_FONTS = 8; public const int MAX_FONTS = 8;
public static int Main() public static int Main()
{ {
// Initialization // Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
int screenWidth = 800; int screenWidth = 800;
int screenHeight = 450; int screenHeight = 450;
InitWindow(screenWidth, screenHeight, "raylib [text] example - raylib fonts"); InitWindow(screenWidth, screenHeight, "raylib [text] example - raylib fonts");
// NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required) // NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required)
Font[] fonts = new Font[MAX_FONTS]; Font[] fonts = new Font[MAX_FONTS];
fonts[0] = LoadFont("resources/fonts/alagard.png"); fonts[0] = LoadFont("resources/fonts/alagard.png");
fonts[1] = LoadFont("resources/fonts/pixelplay.png"); fonts[1] = LoadFont("resources/fonts/pixelplay.png");
fonts[2] = LoadFont("resources/fonts/mecha.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[5] = LoadFont("resources/fonts/pixantiqua.png");
fonts[6] = LoadFont("resources/fonts/alpha_beta.png"); fonts[6] = LoadFont("resources/fonts/alpha_beta.png");
fonts[7] = LoadFont("resources/fonts/jupiter_crash.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", "PIXELPLAY FONT designed by Aleksander Shevchuk",
"MECHA FONT designed by Captain Falcon", "MECHA FONT designed by Captain Falcon",
"SETBACK FONT designed by Brian Kent (AEnigma)", "SETBACK FONT designed by Brian Kent (AEnigma)",
"ROMULUS FONT designed by Hewett Tsoi", "ROMULUS FONT designed by Hewett Tsoi",
"PIXANTIQUA FONT designed by Gerhard Grossmann", "PIXANTIQUA FONT designed by Gerhard Grossmann",
"ALPHA_BETA FONT designed by Brian Kent (AEnigma)", "ALPHA_BETA FONT designed by Brian Kent (AEnigma)",
"JUPITER_CRASH 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 }; int[] spacings = new int[MAX_FONTS]{ 2, 4, 8, 4, 3, 4, 4, 1 };
Vector2[] positions = new Vector2[MAX_FONTS]; Vector2[] positions = new Vector2[MAX_FONTS];
for (int i = 0; i < MAX_FONTS; i++) 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].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; positions[i].y = 60 + fonts[i].baseSize + 45*i;
} }
// Small Y position corrections // Small Y position corrections
positions[3].y += 8; positions[3].y += 8;
positions[4].y += 2; positions[4].y += 2;
positions[7].y -= 8; positions[7].y -= 8;
Color[] colors = new Color[MAX_FONTS] { MAROON, ORANGE, DARKGREEN, DARKBLUE, DARKPURPLE, LIME, GOLD, RED }; Color[] colors = new Color[MAX_FONTS] { MAROON, ORANGE, DARKGREEN, DARKBLUE, DARKPURPLE, LIME, GOLD, RED };
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
// Main game loop // Main game loop
while (!WindowShouldClose()) // Detect window close button or ESC key while (!WindowShouldClose()) // Detect window close button or ESC key
{ {
@ -75,34 +75,34 @@ public partial class text_raylib_fonts
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// TODO: Update your variables here // TODO: Update your variables here
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// Draw // Draw
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
BeginDrawing(); BeginDrawing();
ClearBackground(RAYWHITE); ClearBackground(RAYWHITE);
DrawText("free fonts included with raylib", 250, 20, 20, DARKGRAY); DrawText("free fonts included with raylib", 250, 20, 20, DARKGRAY);
DrawLine(220, 50, 590, 50, DARKGRAY); DrawLine(220, 50, 590, 50, DARKGRAY);
for (int i = 0; i < MAX_FONTS; i++) for (int i = 0; i < MAX_FONTS; i++)
{ {
DrawTextEx(fonts[i], messages[i], positions[i], fonts[i].baseSize*2, spacings[i], colors[i]); DrawTextEx(fonts[i], messages[i], positions[i], fonts[i].baseSize*2, spacings[i], colors[i]);
} }
EndDrawing(); EndDrawing();
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
} }
// De-Initialization // De-Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
// Fonts unloading // Fonts unloading
for (int i = 0; i < MAX_FONTS; i++) UnloadFont(fonts[i]); for (int i = 0; i < MAX_FONTS; i++) UnloadFont(fonts[i]);
CloseWindow(); // Close window and OpenGL context CloseWindow(); // Close window and OpenGL context
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
return 0; return 0;
} }
} }

View File

@ -13,39 +13,39 @@ public partial class text_sprite_fonts
* Copyright (c) 2014 Ramon Santamaria (@raysan5) * Copyright (c) 2014 Ramon Santamaria (@raysan5)
* *
********************************************************************************************/ ********************************************************************************************/
public static int Main() public static int Main()
{ {
// Initialization // Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
int screenWidth = 800; int screenWidth = 800;
int screenHeight = 450; int screenHeight = 450;
InitWindow(screenWidth, screenHeight, "raylib [text] example - sprite fonts usage"); InitWindow(screenWidth, screenHeight, "raylib [text] example - sprite fonts usage");
string msg1 = "THIS IS A custom SPRITE FONT..."; string msg1 = "THIS IS A custom SPRITE FONT...";
string msg2 = "...and this is ANOTHER CUSTOM font..."; string msg2 = "...and this is ANOTHER CUSTOM font...";
string msg3 = "...and a THIRD one! GREAT! :D"; string msg3 = "...and a THIRD one! GREAT! :D";
// NOTE: Textures/Fonts MUST be loaded after Window initialization (OpenGL context is required) // NOTE: Textures/Fonts MUST be loaded after Window initialization (OpenGL context is required)
Font font1 = LoadFont("resources/custom_mecha.png"); // Font loading Font font1 = LoadFont("resources/custom_mecha.png"); // Font loading
Font font2 = LoadFont("resources/custom_alagard.png"); // Font loading Font font2 = LoadFont("resources/custom_alagard.png"); // Font loading
Font font3 = LoadFont("resources/custom_jupiter_crash.png"); // Font loading Font font3 = LoadFont("resources/custom_jupiter_crash.png"); // Font loading
Vector2 fontPosition1, fontPosition2, fontPosition3; Vector2 fontPosition1, fontPosition2, fontPosition3;
fontPosition1.x = screenWidth/2 - MeasureTextEx(font1, msg1, font1.baseSize, -3).x/2; fontPosition1.x = screenWidth/2 - MeasureTextEx(font1, msg1, font1.baseSize, -3).x/2;
fontPosition1.y = screenHeight/2 - font1.baseSize/2 - 80; fontPosition1.y = screenHeight/2 - font1.baseSize/2 - 80;
fontPosition2.x = screenWidth/2 - MeasureTextEx(font2, msg2, font2.baseSize, -2).x/2; fontPosition2.x = screenWidth/2 - MeasureTextEx(font2, msg2, font2.baseSize, -2).x/2;
fontPosition2.y = screenHeight/2 - font2.baseSize/2 - 10; fontPosition2.y = screenHeight/2 - font2.baseSize/2 - 10;
fontPosition3.x = screenWidth/2 - MeasureTextEx(font3, msg3, font3.baseSize, 2).x/2; fontPosition3.x = screenWidth/2 - MeasureTextEx(font3, msg3, font3.baseSize, 2).x/2;
fontPosition3.y = screenHeight/2 - font3.baseSize/2 + 50; fontPosition3.y = screenHeight/2 - font3.baseSize/2 + 50;
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
// Main game loop // Main game loop
while (!WindowShouldClose()) // Detect window close button or ESC key while (!WindowShouldClose()) // Detect window close button or ESC key
{ {
@ -53,30 +53,30 @@ public partial class text_sprite_fonts
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// TODO: Update variables here... // TODO: Update variables here...
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// Draw // Draw
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
BeginDrawing(); BeginDrawing();
ClearBackground(RAYWHITE); ClearBackground(RAYWHITE);
DrawTextEx(font1, msg1, fontPosition1, font1.baseSize, -3, WHITE); DrawTextEx(font1, msg1, fontPosition1, font1.baseSize, -3, WHITE);
DrawTextEx(font2, msg2, fontPosition2, font2.baseSize, -2, WHITE); DrawTextEx(font2, msg2, fontPosition2, font2.baseSize, -2, WHITE);
DrawTextEx(font3, msg3, fontPosition3, font3.baseSize, 2, WHITE); DrawTextEx(font3, msg3, fontPosition3, font3.baseSize, 2, WHITE);
EndDrawing(); EndDrawing();
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
} }
// De-Initialization // De-Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
UnloadFont(font1); // Font unloading UnloadFont(font1); // Font unloading
UnloadFont(font2); // Font unloading UnloadFont(font2); // Font unloading
UnloadFont(font3); // Font unloading UnloadFont(font3); // Font unloading
CloseWindow(); // Close window and OpenGL context CloseWindow(); // Close window and OpenGL context
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
return 0; return 0;
} }
} }

View File

@ -14,49 +14,49 @@ public partial class text_ttf_loading
* Copyright (c) 2015 Ramon Santamaria (@raysan5) * Copyright (c) 2015 Ramon Santamaria (@raysan5)
* *
********************************************************************************************/ ********************************************************************************************/
public static int Main() public static int Main()
{ {
// Initialization // Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
int screenWidth = 800; int screenWidth = 800;
int screenHeight = 450; int screenHeight = 450;
InitWindow(screenWidth, screenHeight, "raylib [text] example - ttf loading"); InitWindow(screenWidth, screenHeight, "raylib [text] example - ttf loading");
string msg = "TTF Font"; string msg = "TTF Font";
// NOTE: Textures/Fonts MUST be loaded after Window initialization (OpenGL context is required) // NOTE: Textures/Fonts MUST be loaded after Window initialization (OpenGL context is required)
// TTF Font loading with custom generation parameters // TTF Font loading with custom generation parameters
Font font = LoadFontEx("resources/KAISG.ttf", 96, 0, null); Font font = LoadFontEx("resources/KAISG.ttf", 96, 0, null);
// Generate mipmap levels to use trilinear filtering // Generate mipmap levels to use trilinear filtering
// NOTE: On 2D drawing it won't be noticeable, it looks like FILTER_BILINEAR // NOTE: On 2D drawing it won't be noticeable, it looks like FILTER_BILINEAR
GenTextureMipmaps(ref font.texture); GenTextureMipmaps(ref font.texture);
float fontSize = font.baseSize; float fontSize = font.baseSize;
Vector2 fontPosition = new Vector2( 40, screenHeight/2 - 80 ); Vector2 fontPosition = new Vector2( 40, screenHeight/2 - 80 );
Vector2 textSize; Vector2 textSize;
SetTextureFilter(font.texture, (int)FILTER_POINT); SetTextureFilter(font.texture, (int)FILTER_POINT);
int currentFontFilter = 0; // FILTER_POINT int currentFontFilter = 0; // FILTER_POINT
// NOTE: Drag and drop support only available for desktop platforms: Windows, Linux, OSX // NOTE: Drag and drop support only available for desktop platforms: Windows, Linux, OSX
int count = 0; int count = 0;
string[] droppedFiles; string[] droppedFiles;
SetTargetFPS(60); SetTargetFPS(60);
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
// Main game loop // Main game loop
while (!WindowShouldClose()) // Detect window close button or ESC key while (!WindowShouldClose()) // Detect window close button or ESC key
{ {
// Update // Update
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
fontSize += GetMouseWheelMove()*4.0f; fontSize += GetMouseWheelMove()*4.0f;
// Choose font texture filter method // Choose font texture filter method
if (IsKeyPressed(KEY_ONE)) if (IsKeyPressed(KEY_ONE))
{ {
@ -74,17 +74,17 @@ public partial class text_ttf_loading
SetTextureFilter(font.texture, (int)FILTER_TRILINEAR); SetTextureFilter(font.texture, (int)FILTER_TRILINEAR);
currentFontFilter = 2; currentFontFilter = 2;
} }
textSize = MeasureTextEx(font, msg, fontSize, 0); textSize = MeasureTextEx(font, msg, fontSize, 0);
if (IsKeyDown(KEY_LEFT)) fontPosition.x -= 10; if (IsKeyDown(KEY_LEFT)) fontPosition.x -= 10;
else if (IsKeyDown(KEY_RIGHT)) fontPosition.x += 10; else if (IsKeyDown(KEY_RIGHT)) fontPosition.x += 10;
// Load a dropped TTF file dynamically (at current fontSize) // Load a dropped TTF file dynamically (at current fontSize)
if (IsFileDropped()) if (IsFileDropped())
{ {
droppedFiles = GetDroppedFiles(ref count); droppedFiles = GetDroppedFiles(ref count);
if (count == 1) // Only support one ttf file dropped if (count == 1) // Only support one ttf file dropped
{ {
UnloadFont(font); UnloadFont(font);
@ -93,44 +93,44 @@ public partial class text_ttf_loading
} }
} }
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// Draw // Draw
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
BeginDrawing(); BeginDrawing();
ClearBackground(RAYWHITE); ClearBackground(RAYWHITE);
DrawText("Use mouse wheel to change font size", 20, 20, 10, GRAY); 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 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("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); DrawText("Drop a new TTF font for dynamic loading", 20, 80, 10, DARKGRAY);
DrawTextEx(font, msg, fontPosition, fontSize, 0, BLACK); DrawTextEx(font, msg, fontPosition, fontSize, 0, BLACK);
// TODO: It seems texSize measurement is not accurate due to chars offsets... // TODO: It seems texSize measurement is not accurate due to chars offsets...
//DrawRectangleLines(fontPosition.x, fontPosition.y, textSize.x, textSize.y, RED); //DrawRectangleLines(fontPosition.x, fontPosition.y, textSize.x, textSize.y, RED);
DrawRectangle(0, screenHeight - 80, screenWidth, 80, LIGHTGRAY); DrawRectangle(0, screenHeight - 80, screenWidth, 80, LIGHTGRAY);
DrawText(FormatText("Font size: %02.02f", fontSize), 20, screenHeight - 50, 10, DARKGRAY); 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(FormatText("Text size: [%02.02f, %02.02f]", textSize.x, textSize.y), 20, screenHeight - 30, 10, DARKGRAY);
DrawText("CURRENT TEXTURE FILTER:", 250, 400, 20, GRAY); DrawText("CURRENT TEXTURE FILTER:", 250, 400, 20, GRAY);
if (currentFontFilter == 0) DrawText("POINT", 570, 400, 20, BLACK); if (currentFontFilter == 0) DrawText("POINT", 570, 400, 20, BLACK);
else if (currentFontFilter == 1) DrawText("BILINEAR", 570, 400, 20, BLACK); else if (currentFontFilter == 1) DrawText("BILINEAR", 570, 400, 20, BLACK);
else if (currentFontFilter == 2) DrawText("TRILINEAR", 570, 400, 20, BLACK); else if (currentFontFilter == 2) DrawText("TRILINEAR", 570, 400, 20, BLACK);
EndDrawing(); EndDrawing();
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
} }
// De-Initialization // De-Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
ClearDroppedFiles(); // Clear internal buffers ClearDroppedFiles(); // Clear internal buffers
UnloadFont(font); // Font unloading UnloadFont(font); // Font unloading
CloseWindow(); // Close window and OpenGL context CloseWindow(); // Close window and OpenGL context
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
return 0; return 0;
} }
} }

View File

@ -13,24 +13,24 @@ public partial class text_writing_anim
* Copyright (c) 2016 Ramon Santamaria (@raysan5) * Copyright (c) 2016 Ramon Santamaria (@raysan5)
* *
********************************************************************************************/ ********************************************************************************************/
public static int Main() public static int Main()
{ {
// Initialization // Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
int screenWidth = 800; int screenWidth = 800;
int screenHeight = 450; int screenHeight = 450;
InitWindow(screenWidth, screenHeight, "raylib [text] example - text writing anim"); InitWindow(screenWidth, screenHeight, "raylib [text] example - text writing anim");
string message = "This sample illustrates a text writing\nanimation effect! Check it out! ;)"; string message = "This sample illustrates a text writing\nanimation effect! Check it out! ;)";
int framesCounter = 0; int framesCounter = 0;
SetTargetFPS(60); SetTargetFPS(60);
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
// Main game loop // Main game loop
while (!WindowShouldClose()) // Detect window close button or ESC key 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; if (IsKeyDown(KEY_SPACE)) framesCounter += 8;
else framesCounter++; else framesCounter++;
if (IsKeyPressed(KEY_ENTER)) framesCounter = 0; if (IsKeyPressed(KEY_ENTER)) framesCounter = 0;
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// Draw // Draw
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
BeginDrawing(); BeginDrawing();
ClearBackground(RAYWHITE); ClearBackground(RAYWHITE);
DrawText(SubText(message, 0, framesCounter/10), 210, 160, 20, MAROON); DrawText(SubText(message, 0, framesCounter/10), 210, 160, 20, MAROON);
DrawText("PRESS [ENTER] to RESTART!", 240, 260, 20, LIGHTGRAY); DrawText("PRESS [ENTER] to RESTART!", 240, 260, 20, LIGHTGRAY);
DrawText("PRESS [SPACE] to SPEED UP!", 239, 300, 20, LIGHTGRAY); DrawText("PRESS [SPACE] to SPEED UP!", 239, 300, 20, LIGHTGRAY);
EndDrawing(); EndDrawing();
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
} }
// De-Initialization // De-Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
CloseWindow(); // Close window and OpenGL context CloseWindow(); // Close window and OpenGL context
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
return 0; return 0;
} }
} }

View File

@ -15,28 +15,28 @@ public partial class Examples
* Copyright (c) 2016 Ramon Santamaria (@raysan5) * Copyright (c) 2016 Ramon Santamaria (@raysan5)
* *
********************************************************************************************/ ********************************************************************************************/
public static int textures_image_9patch() public static int textures_image_9patch()
{ {
// Initialization // Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
int screenWidth = 800; int screenWidth = 800;
int screenHeight = 450; int screenHeight = 450;
InitWindow(screenWidth, screenHeight, "raylib [textures] example - 9-patch drawing"); InitWindow(screenWidth, screenHeight, "raylib [textures] example - 9-patch drawing");
// NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required) // NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required)
Texture2D nPatchTexture = LoadTexture("resources/ninepatch_button.png"); Texture2D nPatchTexture = LoadTexture("resources/ninepatch_button.png");
Vector2 mousePosition; Vector2 mousePosition;
Vector2 origin = {0.0f, 0.0f}; Vector2 origin = {0.0f, 0.0f};
// The location and size of the n-patches. // The location and size of the n-patches.
Rectangle dstRec1 = {480.0f, 160.0f, 32.0f, 32.0f}; Rectangle dstRec1 = {480.0f, 160.0f, 32.0f, 32.0f};
Rectangle dstRec2 = {160.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 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 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 // 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 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 }; 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 }; 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 // 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 }; NPatchInfo v3PatchInfo = {(Rectangle){0.0f, 192.0f, 64.0f, 64.0f}, 6, 6, 6, 6, NPT_3PATCH_VERTICAL };
SetTargetFPS(60); SetTargetFPS(60);
//--------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------
// Main game loop // Main game loop
while (!WindowShouldClose()) // Detect window close button or ESC key while (!WindowShouldClose()) // Detect window close button or ESC key
{ {
@ -61,7 +61,7 @@ public partial class Examples
dstRec2.height = mousePosition.y - dstRec2.y; dstRec2.height = mousePosition.y - dstRec2.y;
dstRecH.width = mousePosition.x - dstRecH.x; dstRecH.width = mousePosition.x - dstRecH.x;
dstRecV.height = mousePosition.y - dstRecV.y; dstRecV.height = mousePosition.y - dstRecV.y;
// set a minimum width and/or height // set a minimum width and/or height
if (dstRec1.width < 1.0f) dstRec1.width = 1.0f; if (dstRec1.width < 1.0f) dstRec1.width = 1.0f;
if (dstRec1.width > 300.0f) dstRec1.width = 300.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 (dstRecH.width < 1.0f) dstRecH.width = 1.0f;
if (dstRecV.height < 1.0f) dstRecV.height = 1.0f; if (dstRecV.height < 1.0f) dstRecV.height = 1.0f;
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// Draw // Draw
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
BeginDrawing(); BeginDrawing();
ClearBackground(RAYWHITE); ClearBackground(RAYWHITE);
// Draw the n-patches // Draw the n-patches
DrawTextureNPatch(nPatchTexture, ninePatchInfo2, dstRec2, origin, 0.0f, WHITE); DrawTextureNPatch(nPatchTexture, ninePatchInfo2, dstRec2, origin, 0.0f, WHITE);
DrawTextureNPatch(nPatchTexture, ninePatchInfo1, dstRec1, origin, 0.0f, WHITE); DrawTextureNPatch(nPatchTexture, ninePatchInfo1, dstRec1, origin, 0.0f, WHITE);
DrawTextureNPatch(nPatchTexture, h3PatchInfo, dstRecH, origin, 0.0f, WHITE); DrawTextureNPatch(nPatchTexture, h3PatchInfo, dstRecH, origin, 0.0f, WHITE);
DrawTextureNPatch(nPatchTexture, v3PatchInfo, dstRecV, origin, 0.0f, WHITE); DrawTextureNPatch(nPatchTexture, v3PatchInfo, dstRecV, origin, 0.0f, WHITE);
// Draw the source texture // Draw the source texture
DrawRectangleLines( 5, 88, 74, 266, BLUE); DrawRectangleLines( 5, 88, 74, 266, BLUE);
DrawTexture(nPatchTexture, 10, 93, WHITE); DrawTexture(nPatchTexture, 10, 93, WHITE);
DrawText("TEXTURE", 15, 360, 10, DARKGRAY); DrawText("TEXTURE", 15, 360, 10, DARKGRAY);
DrawRectangle( 10, 10, 250, 73, Fade(SKYBLUE, 0.5)); DrawRectangle( 10, 10, 250, 73, Fade(SKYBLUE, 0.5));
DrawRectangleLines( 10, 10, 250, 73, BLUE); DrawRectangleLines( 10, 10, 250, 73, BLUE);
DrawText("9-Patch and 3-Patch example", 20, 20, 10, BLACK); DrawText("9-Patch and 3-Patch example", 20, 20, 10, BLACK);
DrawText(" Move the mouse to stretch or", 40, 40, 10, DARKGRAY); DrawText(" Move the mouse to stretch or", 40, 40, 10, DARKGRAY);
DrawText(" shrink the n-patches.", 40, 60, 10, DARKGRAY); DrawText(" shrink the n-patches.", 40, 60, 10, DARKGRAY);
EndDrawing(); EndDrawing();
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
} }
// De-Initialization // De-Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
UnloadTexture(nPatchTexture); // Texture unloading UnloadTexture(nPatchTexture); // Texture unloading
CloseWindow(); // Close window and OpenGL context CloseWindow(); // Close window and OpenGL context
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
return 0; return 0;
} }
} }

View File

@ -15,46 +15,46 @@ public partial class textures_image_drawing
* Copyright (c) 2016 Ramon Santamaria (@raysan5) * Copyright (c) 2016 Ramon Santamaria (@raysan5)
* *
********************************************************************************************/ ********************************************************************************************/
public static int Main() public static int Main()
{ {
// Initialization // Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
int screenWidth = 800; int screenWidth = 800;
int screenHeight = 450; int screenHeight = 450;
InitWindow(screenWidth, screenHeight, "raylib [textures] example - image drawing"); InitWindow(screenWidth, screenHeight, "raylib [textures] example - image drawing");
// NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required) // NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required)
Image cat = LoadImage("resources/cat.png"); // Load image in CPU memory (RAM) 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 ImageCrop(ref cat, new Rectangle( 100, 10, 280, 380 )); // Crop an image piece
ImageFlipHorizontal(ref cat); // Flip cropped image horizontally ImageFlipHorizontal(ref cat); // Flip cropped image horizontally
ImageResize(ref cat, 150, 200); // Resize flipped-cropped image ImageResize(ref cat, 150, 200); // Resize flipped-cropped image
Image parrots = LoadImage("resources/parrots.png"); // Load image in CPU memory (RAM) Image parrots = LoadImage("resources/parrots.png"); // Load image in CPU memory (RAM)
// Draw one image over the other with a scaling of 1.5f // 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 )); 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 ImageCrop(ref parrots, new Rectangle( 0, 50, parrots.width, parrots.height - 100 )); // Crop resulting image
UnloadImage(cat); // Unload image from RAM UnloadImage(cat); // Unload image from RAM
// Load custom font for frawing on image // Load custom font for frawing on image
Font font = LoadFont("resources/custom_jupiter_crash.png"); Font font = LoadFont("resources/custom_jupiter_crash.png");
// Draw over image using custom font // Draw over image using custom font
ImageDrawTextEx(ref parrots, new Vector2( 300, 230 ), font, "PARROTS ref CAT", font.baseSize, -2, WHITE); 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) UnloadFont(font); // Unload custom spritefont (already drawn used on image)
Texture2D texture = LoadTextureFromImage(parrots); // Image converted to texture, uploaded to GPU memory (VRAM) 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 UnloadImage(parrots); // Once image has been converted to texture and uploaded to VRAM, it can be unloaded from RAM
SetTargetFPS(60); SetTargetFPS(60);
//--------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------
// Main game loop // Main game loop
while (!WindowShouldClose()) // Detect window close button or ESC key while (!WindowShouldClose()) // Detect window close button or ESC key
{ {
@ -62,30 +62,30 @@ public partial class textures_image_drawing
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// TODO: Update your variables here // TODO: Update your variables here
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// Draw // Draw
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
BeginDrawing(); BeginDrawing();
ClearBackground(RAYWHITE); ClearBackground(RAYWHITE);
DrawTexture(texture, screenWidth/2 - texture.width/2, screenHeight/2 - texture.height/2 - 40, WHITE); 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); 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("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); DrawText("Source images have been cropped, scaled, flipped and copied one over the other.", 190, 370, 10, DARKGRAY);
EndDrawing(); EndDrawing();
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
} }
// De-Initialization // De-Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
UnloadTexture(texture); // Texture unloading UnloadTexture(texture); // Texture unloading
CloseWindow(); // Close window and OpenGL context CloseWindow(); // Close window and OpenGL context
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
return 0; return 0;
} }
} }

View File

@ -13,19 +13,19 @@ public partial class textures_image_generation
* Copyright (c) 2O17 Wilhem Barbier (@nounoursheureux) * Copyright (c) 2O17 Wilhem Barbier (@nounoursheureux)
* *
********************************************************************************************/ ********************************************************************************************/
public const int NUM_TEXTURES = 7; public const int NUM_TEXTURES = 7;
public static int Main() public static int Main()
{ {
// Initialization // Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
int screenWidth = 800; int screenWidth = 800;
int screenHeight = 450; int screenHeight = 450;
InitWindow(screenWidth, screenHeight, "raylib [textures] example - procedural images generation"); InitWindow(screenWidth, screenHeight, "raylib [textures] example - procedural images generation");
Image verticalGradient = GenImageGradientV(screenWidth, screenHeight, RED, BLUE); Image verticalGradient = GenImageGradientV(screenWidth, screenHeight, RED, BLUE);
Image horizontalGradient = GenImageGradientH(screenWidth, screenHeight, RED, BLUE); Image horizontalGradient = GenImageGradientH(screenWidth, screenHeight, RED, BLUE);
Image radialGradient = GenImageGradientRadial(screenWidth, screenHeight, 0.0f, WHITE, BLACK); 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 whiteNoise = GenImageWhiteNoise(screenWidth, screenHeight, 0.5f);
Image perlinNoise = GenImagePerlinNoise(screenWidth, screenHeight, 50, 50, 4.0f); Image perlinNoise = GenImagePerlinNoise(screenWidth, screenHeight, 50, 50, 4.0f);
Image cellular = GenImageCellular(screenWidth, screenHeight, 32); Image cellular = GenImageCellular(screenWidth, screenHeight, 32);
Texture2D[] textures = new Texture2D[NUM_TEXTURES]; Texture2D[] textures = new Texture2D[NUM_TEXTURES];
textures[0] = LoadTextureFromImage(verticalGradient); textures[0] = LoadTextureFromImage(verticalGradient);
textures[1] = LoadTextureFromImage(horizontalGradient); textures[1] = LoadTextureFromImage(horizontalGradient);
@ -42,7 +42,7 @@ public partial class textures_image_generation
textures[4] = LoadTextureFromImage(whiteNoise); textures[4] = LoadTextureFromImage(whiteNoise);
textures[5] = LoadTextureFromImage(perlinNoise); textures[5] = LoadTextureFromImage(perlinNoise);
textures[6] = LoadTextureFromImage(cellular); textures[6] = LoadTextureFromImage(cellular);
// Unload image data (CPU RAM) // Unload image data (CPU RAM)
UnloadImage(verticalGradient); UnloadImage(verticalGradient);
UnloadImage(horizontalGradient); UnloadImage(horizontalGradient);
@ -51,12 +51,12 @@ public partial class textures_image_generation
UnloadImage(whiteNoise); UnloadImage(whiteNoise);
UnloadImage(perlinNoise); UnloadImage(perlinNoise);
UnloadImage(cellular); UnloadImage(cellular);
int currentTexture = 0; int currentTexture = 0;
SetTargetFPS(60); SetTargetFPS(60);
//--------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------
// Main game loop // Main game loop
while (!WindowShouldClose()) while (!WindowShouldClose())
{ {
@ -67,19 +67,19 @@ public partial class textures_image_generation
currentTexture = (currentTexture + 1)%NUM_TEXTURES; // Cycle between the textures currentTexture = (currentTexture + 1)%NUM_TEXTURES; // Cycle between the textures
} }
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// Draw // Draw
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
BeginDrawing(); BeginDrawing();
ClearBackground(RAYWHITE); ClearBackground(RAYWHITE);
DrawTexture(textures[currentTexture], 0, 0, WHITE); DrawTexture(textures[currentTexture], 0, 0, WHITE);
DrawRectangle(30, 400, 325, 30, Fade(SKYBLUE, 0.5f)); DrawRectangle(30, 400, 325, 30, Fade(SKYBLUE, 0.5f));
DrawRectangleLines(30, 400, 325, 30, Fade(WHITE, 0.5f)); DrawRectangleLines(30, 400, 325, 30, Fade(WHITE, 0.5f));
DrawText("MOUSE LEFT BUTTON to CYCLE PROCEDURAL TEXTURES", 40, 410, 10, WHITE); DrawText("MOUSE LEFT BUTTON to CYCLE PROCEDURAL TEXTURES", 40, 410, 10, WHITE);
switch(currentTexture) switch(currentTexture)
{ {
case 0: DrawText("VERTICAL GRADIENT", 560, 10, 20, RAYWHITE); break; 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; case 6: DrawText("CELLULAR", 670, 10, 20, RAYWHITE); break;
default: break; default: break;
} }
EndDrawing(); EndDrawing();
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
} }
// De-Initialization // De-Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
// Unload textures data (GPU VRAM) // Unload textures data (GPU VRAM)
for (int i = 0; i < NUM_TEXTURES; i++) UnloadTexture(textures[i]); for (int i = 0; i < NUM_TEXTURES; i++) UnloadTexture(textures[i]);
CloseWindow(); // Close window and OpenGL context CloseWindow(); // Close window and OpenGL context
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
return 0; return 0;
} }
} }

View File

@ -15,25 +15,25 @@ public partial class textures_image_loading
* Copyright (c) 2015 Ramon Santamaria (@raysan5) * Copyright (c) 2015 Ramon Santamaria (@raysan5)
* *
********************************************************************************************/ ********************************************************************************************/
public static int Main() public static int Main()
{ {
// Initialization // Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
int screenWidth = 800; int screenWidth = 800;
int screenHeight = 450; int screenHeight = 450;
InitWindow(screenWidth, screenHeight, "raylib [textures] example - image loading"); InitWindow(screenWidth, screenHeight, "raylib [textures] example - image loading");
// NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required) // NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required)
Image image = LoadImage("resources/raylib_logo.png"); // Loaded in CPU memory (RAM) Image image = LoadImage("resources/raylib_logo.png"); // Loaded in CPU memory (RAM)
Texture2D texture = LoadTextureFromImage(image); // Image converted to texture, GPU memory (VRAM) 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 UnloadImage(image); // Once image has been converted to texture and uploaded to VRAM, it can be unloaded from RAM
//--------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------
// Main game loop // Main game loop
while (!WindowShouldClose()) // Detect window close button or ESC key while (!WindowShouldClose()) // Detect window close button or ESC key
{ {
@ -41,28 +41,28 @@ public partial class textures_image_loading
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// TODO: Update your variables here // TODO: Update your variables here
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// Draw // Draw
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
BeginDrawing(); BeginDrawing();
ClearBackground(RAYWHITE); ClearBackground(RAYWHITE);
DrawTexture(texture, screenWidth/2 - texture.width/2, screenHeight/2 - texture.height/2, WHITE); 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); DrawText("this IS a texture loaded from an image!", 300, 370, 10, GRAY);
EndDrawing(); EndDrawing();
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
} }
// De-Initialization // De-Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
UnloadTexture(texture); // Texture unloading UnloadTexture(texture); // Texture unloading
CloseWindow(); // Close window and OpenGL context CloseWindow(); // Close window and OpenGL context
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
return 0; return 0;
} }
} }

View File

@ -16,23 +16,23 @@ public partial class textures_image_processing
* Copyright (c) 2016 Ramon Santamaria (@raysan5) * Copyright (c) 2016 Ramon Santamaria (@raysan5)
* *
********************************************************************************************/ ********************************************************************************************/
public const int NUM_PROCESSES = 8; public const int NUM_PROCESSES = 8;
enum ImageProcess enum ImageProcess
{ {
NONE = 0, NONE = 0,
COLOR_GRAYSCALE, COLOR_GRAYSCALE,
COLOR_TINT, COLOR_TINT,
COLOR_INVERT, COLOR_INVERT,
COLOR_CONTRAST, COLOR_CONTRAST,
COLOR_BRIGHTNESS, COLOR_BRIGHTNESS,
FLIP_VERTICAL, FLIP_VERTICAL,
FLIP_HORIZONTAL FLIP_HORIZONTAL
} }
static string[] processText = { static string[] processText = {
"NO PROCESSING", "NO PROCESSING",
"COLOR GRAYSCALE", "COLOR GRAYSCALE",
@ -43,32 +43,32 @@ public partial class textures_image_processing
"FLIP VERTICAL", "FLIP VERTICAL",
"FLIP HORIZONTAL" "FLIP HORIZONTAL"
}; };
public static int Main() public static int Main()
{ {
// Initialization // Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
int screenWidth = 800; int screenWidth = 800;
int screenHeight = 450; int screenHeight = 450;
InitWindow(screenWidth, screenHeight, "raylib [textures] example - image processing"); InitWindow(screenWidth, screenHeight, "raylib [textures] example - image processing");
// NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required) // NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required)
Image image = LoadImage("resources/parrots.png"); // Loaded in CPU memory (RAM) 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 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) Texture2D texture = LoadTextureFromImage(image); // Image converted to texture, GPU memory (VRAM)
int currentProcess = (int)ImageProcess.NONE; int currentProcess = (int)ImageProcess.NONE;
bool textureReload = false; bool textureReload = false;
Rectangle[] selectRecs = new Rectangle[NUM_PROCESSES]; Rectangle[] selectRecs = new Rectangle[NUM_PROCESSES];
for (int i = 0; i < NUM_PROCESSES; i++) selectRecs[i] = new Rectangle( 40, 50 + 32*i, 150, 30 ); for (int i = 0; i < NUM_PROCESSES; i++) selectRecs[i] = new Rectangle( 40, 50 + 32*i, 150, 30 );
SetTargetFPS(60); SetTargetFPS(60);
//--------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------
// Main game loop // Main game loop
while (!WindowShouldClose()) // Detect window close button or ESC key while (!WindowShouldClose()) // Detect window close button or ESC key
{ {
@ -86,14 +86,14 @@ public partial class textures_image_processing
if (currentProcess < 0) currentProcess = 7; if (currentProcess < 0) currentProcess = 7;
textureReload = true; textureReload = true;
} }
if (textureReload) if (textureReload)
{ {
UnloadImage(image); // Unload current image data UnloadImage(image); // Unload current image data
image = LoadImage("resources/parrots.png"); // Re-load image data image = LoadImage("resources/parrots.png"); // Re-load image data
// NOTE: Image processing is a costly CPU process to be done every frame, // 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 // If image processing is required in a frame-basis, it should be done
// with a texture and by shaders // with a texture and by shaders
switch (currentProcess) switch (currentProcess)
{ {
@ -106,23 +106,23 @@ public partial class textures_image_processing
case (int)ImageProcess.FLIP_HORIZONTAL: ImageFlipHorizontal(ref image); break; case (int)ImageProcess.FLIP_HORIZONTAL: ImageFlipHorizontal(ref image); break;
default: break; default: break;
} }
Color[] pixels = GetImageData(image); // Get pixel data from image (RGBA 32bit) Color[] pixels = GetImageData(image); // Get pixel data from image (RGBA 32bit)
UpdateTexture(texture, pixels); // Update texture with new image data UpdateTexture(texture, pixels); // Update texture with new image data
// free(pixels); // Unload pixels data from RAM // free(pixels); // Unload pixels data from RAM
textureReload = false; textureReload = false;
} }
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// Draw // Draw
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
BeginDrawing(); BeginDrawing();
ClearBackground(RAYWHITE); ClearBackground(RAYWHITE);
DrawText("IMAGE PROCESSING:", 40, 30, 10, DARKGRAY); DrawText("IMAGE PROCESSING:", 40, 30, 10, DARKGRAY);
// Draw rectangles // Draw rectangles
for (int i = 0; i < NUM_PROCESSES; i++) 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); 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); 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); 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); DrawRectangleLines(screenWidth - texture.width - 60, screenHeight/2 - texture.height/2, texture.width, texture.height, BLACK);
EndDrawing(); EndDrawing();
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
} }
// De-Initialization // De-Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
UnloadTexture(texture); // Unload texture from VRAM UnloadTexture(texture); // Unload texture from VRAM
UnloadImage(image); // Unload image from RAM UnloadImage(image); // Unload image from RAM
CloseWindow(); // Close window and OpenGL context CloseWindow(); // Close window and OpenGL context
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
return 0; return 0;
} }
} }

View File

@ -13,35 +13,35 @@ public partial class textures_image_text
* Copyright (c) 2017 Ramon Santamaria (@raysan5) * Copyright (c) 2017 Ramon Santamaria (@raysan5)
* *
********************************************************************************************/ ********************************************************************************************/
public static int Main() public static int Main()
{ {
// Initialization // Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
int screenWidth = 800; int screenWidth = 800;
int screenHeight = 450; int screenHeight = 450;
InitWindow(screenWidth, screenHeight, "raylib [texture] example - image text drawing"); InitWindow(screenWidth, screenHeight, "raylib [texture] example - image text drawing");
// TTF Font loading with custom generation parameters // TTF Font loading with custom generation parameters
Font font = LoadFontEx("resources/KAISG.ttf", 64, 95, null); Font font = LoadFontEx("resources/KAISG.ttf", 64, 95, null);
Image parrots = LoadImage("resources/parrots.png"); // Load image in CPU memory (RAM) Image parrots = LoadImage("resources/parrots.png"); // Load image in CPU memory (RAM)
// Draw over image using custom font // Draw over image using custom font
ImageDrawTextEx(ref parrots, new Vector2( 20, 20 ), font, "[Parrots font drawing]", font.baseSize, 0, WHITE); 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) 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 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 ); Vector2 position = new Vector2( screenWidth/2 - texture.width/2, screenHeight/2 - texture.height/2 - 20 );
bool showFont = false; bool showFont = false;
SetTargetFPS(60); SetTargetFPS(60);
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
// Main game loop // Main game loop
while (!WindowShouldClose()) // Detect window close button or ESC key 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; if (IsKeyDown(KEY_SPACE)) showFont = true;
else showFont = false; else showFont = false;
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// Draw // Draw
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
BeginDrawing(); BeginDrawing();
ClearBackground(RAYWHITE); ClearBackground(RAYWHITE);
if (!showFont) if (!showFont)
{ {
// Draw texture with text already drawn inside // Draw texture with text already drawn inside
DrawTextureV(texture, position, WHITE); DrawTextureV(texture, position, WHITE);
// Draw text directly using sprite font // 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); position.y + 20 + 280 ), font.baseSize, 0, WHITE);
} }
else DrawTexture(font.texture, screenWidth/2 - font.texture.width/2, 50, BLACK); else DrawTexture(font.texture, screenWidth/2 - font.texture.width/2, 50, BLACK);
DrawText("PRESS SPACE to SEE USED SPRITEFONT ", 290, 420, 10, DARKGRAY); DrawText("PRESS SPACE to SEE USED SPRITEFONT ", 290, 420, 10, DARKGRAY);
EndDrawing(); EndDrawing();
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
} }
// De-Initialization // De-Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
UnloadTexture(texture); // Texture unloading UnloadTexture(texture); // Texture unloading
UnloadFont(font); // Unload custom spritefont UnloadFont(font); // Unload custom spritefont
CloseWindow(); // Close window and OpenGL context CloseWindow(); // Close window and OpenGL context
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
return 0; return 0;
} }
} }

View File

@ -13,21 +13,21 @@ public partial class textures_logo_raylib
* Copyright (c) 2014 Ramon Santamaria (@raysan5) * Copyright (c) 2014 Ramon Santamaria (@raysan5)
* *
********************************************************************************************/ ********************************************************************************************/
public static int Main() public static int Main()
{ {
// Initialization // Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
int screenWidth = 800; int screenWidth = 800;
int screenHeight = 450; int screenHeight = 450;
InitWindow(screenWidth, screenHeight, "raylib [textures] example - texture loading and drawing"); InitWindow(screenWidth, screenHeight, "raylib [textures] example - texture loading and drawing");
// NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required) // NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required)
Texture2D texture = LoadTexture("resources/raylib_logo.png"); // Texture loading Texture2D texture = LoadTexture("resources/raylib_logo.png"); // Texture loading
//--------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------
// Main game loop // Main game loop
while (!WindowShouldClose()) // Detect window close button or ESC key while (!WindowShouldClose()) // Detect window close button or ESC key
{ {
@ -35,28 +35,28 @@ public partial class textures_logo_raylib
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// TODO: Update your variables here // TODO: Update your variables here
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// Draw // Draw
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
BeginDrawing(); BeginDrawing();
ClearBackground(RAYWHITE); ClearBackground(RAYWHITE);
DrawTexture(texture, screenWidth/2 - texture.width/2, screenHeight/2 - texture.height/2, WHITE); DrawTexture(texture, screenWidth/2 - texture.width/2, screenHeight/2 - texture.height/2, WHITE);
DrawText("this IS a texture!", 360, 370, 10, GRAY); DrawText("this IS a texture!", 360, 370, 10, GRAY);
EndDrawing(); EndDrawing();
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
} }
// De-Initialization // De-Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
UnloadTexture(texture); // Texture unloading UnloadTexture(texture); // Texture unloading
CloseWindow(); // Close window and OpenGL context CloseWindow(); // Close window and OpenGL context
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
return 0; return 0;
} }
} }

View File

@ -14,8 +14,8 @@ public partial class textures_particles_blending
* Copyright (c) 2017 Ramon Santamaria (@raysan5) * Copyright (c) 2017 Ramon Santamaria (@raysan5)
* *
********************************************************************************************/ ********************************************************************************************/
public const int MAX_PARTICLES = 200; public const int MAX_PARTICLES = 200;
// Particle structure with basic data // Particle structure with basic data
@ -28,19 +28,19 @@ public partial class textures_particles_blending
public float rotation; public float rotation;
public bool active; // NOTE: Use it to activate/deactive particle public bool active; // NOTE: Use it to activate/deactive particle
} }
public static int Main() public static int Main()
{ {
// Initialization // Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
int screenWidth = 800; int screenWidth = 800;
int screenHeight = 450; int screenHeight = 450;
InitWindow(screenWidth, screenHeight, "raylib [textures] example - particles blending"); InitWindow(screenWidth, screenHeight, "raylib [textures] example - particles blending");
// Particles pool, reuse them! // Particles pool, reuse them!
Particle[] mouseTail = new Particle[MAX_PARTICLES]; Particle[] mouseTail = new Particle[MAX_PARTICLES];
// Initialize particles // Initialize particles
for (int i = 0; i < MAX_PARTICLES; i++) 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].rotation = GetRandomValue(0, 360);
mouseTail[i].active = false; mouseTail[i].active = false;
} }
float gravity = 3.0f; float gravity = 3.0f;
Texture2D smoke = LoadTexture("resources/smoke.png"); Texture2D smoke = LoadTexture("resources/smoke.png");
int blending = (int)BLEND_ALPHA; int blending = (int)BLEND_ALPHA;
SetTargetFPS(60); SetTargetFPS(60);
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
// Main game loop // Main game loop
while (!WindowShouldClose()) // Detect window close button or ESC key while (!WindowShouldClose()) // Detect window close button or ESC key
{ {
// Update // Update
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// Activate one particle every frame and Update active particles // Activate one particle every frame and Update active particles
// NOTE: Particles initial position should be mouse position when activated // 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) // 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; i = MAX_PARTICLES;
} }
} }
for (int i = 0; i < MAX_PARTICLES; i++) for (int i = 0; i < MAX_PARTICLES; i++)
{ {
if (mouseTail[i].active) if (mouseTail[i].active)
{ {
mouseTail[i].position.y += gravity; mouseTail[i].position.y += gravity;
mouseTail[i].alpha -= 0.01f; mouseTail[i].alpha -= 0.01f;
if (mouseTail[i].alpha <= 0.0f) mouseTail[i].active = false; if (mouseTail[i].alpha <= 0.0f) mouseTail[i].active = false;
mouseTail[i].rotation += 5.0f; mouseTail[i].rotation += 5.0f;
} }
} }
if (IsKeyPressed(KEY_SPACE)) if (IsKeyPressed(KEY_SPACE))
{ {
if (blending == (int)BLEND_ALPHA) blending = (int)BLEND_ADDITIVE; if (blending == (int)BLEND_ALPHA) blending = (int)BLEND_ADDITIVE;
else blending = (int)BLEND_ALPHA; else blending = (int)BLEND_ALPHA;
} }
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// Draw // Draw
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
BeginDrawing(); BeginDrawing();
ClearBackground(DARKGRAY); ClearBackground(DARKGRAY);
BeginBlendMode(blending); BeginBlendMode(blending);
// Draw active particles // Draw active particles
for (int i = 0; i < MAX_PARTICLES; i++) 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 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, new Vector2( smoke.width*mouseTail[i].size/2, smoke.height*mouseTail[i].size/2 ), mouseTail[i].rotation,
Fade(mouseTail[i].color, mouseTail[i].alpha)); Fade(mouseTail[i].color, mouseTail[i].alpha));
} }
EndBlendMode(); EndBlendMode();
DrawText("PRESS SPACE to CHANGE BLENDING MODE", 180, 20, 20, BLACK); DrawText("PRESS SPACE to CHANGE BLENDING MODE", 180, 20, 20, BLACK);
if (blending == (int)BLEND_ALPHA) DrawText("ALPHA BLENDING", 290, screenHeight - 40, 20, BLACK); if (blending == (int)BLEND_ALPHA) DrawText("ALPHA BLENDING", 290, screenHeight - 40, 20, BLACK);
else DrawText("ADDITIVE BLENDING", 280, screenHeight - 40, 20, RAYWHITE); else DrawText("ADDITIVE BLENDING", 280, screenHeight - 40, 20, RAYWHITE);
EndDrawing(); EndDrawing();
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
} }
// De-Initialization // De-Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
UnloadTexture(smoke); UnloadTexture(smoke);
CloseWindow(); // Close window and OpenGL context CloseWindow(); // Close window and OpenGL context
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
return 0; return 0;
} }
} }

View File

@ -16,33 +16,33 @@ public partial class textures_raw_data
* Copyright (c) 2015 Ramon Santamaria (@raysan5) * Copyright (c) 2015 Ramon Santamaria (@raysan5)
* *
********************************************************************************************/ ********************************************************************************************/
public static int Main() public static int Main()
{ {
// Initialization // Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
int screenWidth = 800; int screenWidth = 800;
int screenHeight = 450; int screenHeight = 450;
InitWindow(screenWidth, screenHeight, "raylib [textures] example - texture from raw data"); InitWindow(screenWidth, screenHeight, "raylib [textures] example - texture from raw data");
// NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required) // NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required)
// Load RAW image data (512x512, 32bit RGBA, no file header) // Load RAW image data (512x512, 32bit RGBA, no file header)
Image fudesumiRaw = LoadImageRaw("resources/fudesumi.raw", 384, 512, (int)UNCOMPRESSED_R8G8B8A8, 0); Image fudesumiRaw = LoadImageRaw("resources/fudesumi.raw", 384, 512, (int)UNCOMPRESSED_R8G8B8A8, 0);
Texture2D fudesumi = LoadTextureFromImage(fudesumiRaw); // Upload CPU (RAM) image to GPU (VRAM) Texture2D fudesumi = LoadTextureFromImage(fudesumiRaw); // Upload CPU (RAM) image to GPU (VRAM)
UnloadImage(fudesumiRaw); // Unload CPU (RAM) image data UnloadImage(fudesumiRaw); // Unload CPU (RAM) image data
// Generate a isChecked texture by code (1024x1024 pixels) // Generate a isChecked texture by code (1024x1024 pixels)
int width = 1024; int width = 1024;
int height = 1024; int height = 1024;
// Dynamic memory allocation to store pixels data (Color type) // Dynamic memory allocation to store pixels data (Color type)
// Color *pixels = (Color *)malloc(width*height*sizeof(Color)); // Color *pixels = (Color *)malloc(width*height*sizeof(Color));
Color[] pixels = new Color[width*height]; Color[] pixels = new Color[width*height];
for (int y = 0; y < height; y++) for (int y = 0; y < height; y++)
{ {
for (int x = 0; x < width; x++) for (int x = 0; x < width; x++)
@ -51,16 +51,16 @@ public partial class textures_raw_data
else pixels[y*height + x] = GOLD; else pixels[y*height + x] = GOLD;
} }
} }
// Load pixels data into an image structure and create texture // Load pixels data into an image structure and create texture
Image isCheckedIm = LoadImageEx(pixels, width, height); Image isCheckedIm = LoadImageEx(pixels, width, height);
Texture2D isChecked = LoadTextureFromImage(isCheckedIm); Texture2D isChecked = LoadTextureFromImage(isCheckedIm);
UnloadImage(isCheckedIm); // Unload CPU (RAM) image data UnloadImage(isCheckedIm); // Unload CPU (RAM) image data
// Dynamic memory must be freed after using it // Dynamic memory must be freed after using it
// free(pixels); // Unload CPU (RAM) pixels data // free(pixels); // Unload CPU (RAM) pixels data
//--------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------
// Main game loop // Main game loop
while (!WindowShouldClose()) // Detect window close button or ESC key while (!WindowShouldClose()) // Detect window close button or ESC key
{ {
@ -68,34 +68,34 @@ public partial class textures_raw_data
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// TODO: Update your variables here // TODO: Update your variables here
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// Draw // Draw
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
BeginDrawing(); BeginDrawing();
ClearBackground(RAYWHITE); ClearBackground(RAYWHITE);
DrawTexture(isChecked, screenWidth/2 - isChecked.width/2, screenHeight/2 - isChecked.height/2, Fade(WHITE, 0.5f)); DrawTexture(isChecked, screenWidth/2 - isChecked.width/2, screenHeight/2 - isChecked.height/2, Fade(WHITE, 0.5f));
DrawTexture(fudesumi, 430, -30, WHITE); DrawTexture(fudesumi, 430, -30, WHITE);
DrawText("CHECKED TEXTURE ", 84, 100, 30, BROWN); DrawText("CHECKED TEXTURE ", 84, 100, 30, BROWN);
DrawText("GENERATED by CODE", 72, 164, 30, BROWN); DrawText("GENERATED by CODE", 72, 164, 30, BROWN);
DrawText("and RAW IMAGE LOADING", 46, 226, 30, BROWN); DrawText("and RAW IMAGE LOADING", 46, 226, 30, BROWN);
DrawText("(c) Fudesumi sprite by Eiden Marsal", 310, screenHeight - 20, 10, BROWN); DrawText("(c) Fudesumi sprite by Eiden Marsal", 310, screenHeight - 20, 10, BROWN);
EndDrawing(); EndDrawing();
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
} }
// De-Initialization // De-Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
UnloadTexture(fudesumi); // Texture unloading UnloadTexture(fudesumi); // Texture unloading
UnloadTexture(isChecked); // Texture unloading UnloadTexture(isChecked); // Texture unloading
CloseWindow(); // Close window and OpenGL context CloseWindow(); // Close window and OpenGL context
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
return 0; return 0;
} }
} }

View File

@ -13,92 +13,92 @@ public partial class textures_rectangle
* Copyright (c) 2014 Ramon Santamaria (@raysan5) * Copyright (c) 2014 Ramon Santamaria (@raysan5)
* *
********************************************************************************************/ ********************************************************************************************/
public const int MAX_FRAME_SPEED = 15; public const int MAX_FRAME_SPEED = 15;
public const int MIN_FRAME_SPEED = 1; public const int MIN_FRAME_SPEED = 1;
public static int Main() public static int Main()
{ {
// Initialization // Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
int screenWidth = 800; int screenWidth = 800;
int screenHeight = 450; int screenHeight = 450;
InitWindow(screenWidth, screenHeight, "raylib [texture] example - texture rectangle"); InitWindow(screenWidth, screenHeight, "raylib [texture] example - texture rectangle");
// NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required) // NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required)
Texture2D scarfy = LoadTexture("resources/scarfy.png"); // Texture loading Texture2D scarfy = LoadTexture("resources/scarfy.png"); // Texture loading
Vector2 position = new Vector2( 350.0f, 280.0f ); Vector2 position = new Vector2( 350.0f, 280.0f );
Rectangle frameRec = new Rectangle( 0.0f, 0.0f, (float)scarfy.width/6, (float)scarfy.height ); Rectangle frameRec = new Rectangle( 0.0f, 0.0f, (float)scarfy.width/6, (float)scarfy.height );
int currentFrame = 0; int currentFrame = 0;
int framesCounter = 0; int framesCounter = 0;
int framesSpeed = 8; // Number of spritesheet frames shown by second int framesSpeed = 8; // Number of spritesheet frames shown by second
SetTargetFPS(60); // Set our game to run at 60 frames-per-second SetTargetFPS(60); // Set our game to run at 60 frames-per-second
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
// Main game loop // Main game loop
while (!WindowShouldClose()) // Detect window close button or ESC key while (!WindowShouldClose()) // Detect window close button or ESC key
{ {
// Update // Update
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
framesCounter++; framesCounter++;
if (framesCounter >= (60/framesSpeed)) if (framesCounter >= (60/framesSpeed))
{ {
framesCounter = 0; framesCounter = 0;
currentFrame++; currentFrame++;
if (currentFrame > 5) currentFrame = 0; if (currentFrame > 5) currentFrame = 0;
frameRec.x = (float)currentFrame*(float)scarfy.width/6; frameRec.x = (float)currentFrame*(float)scarfy.width/6;
} }
if (IsKeyPressed(KEY_RIGHT)) framesSpeed++; if (IsKeyPressed(KEY_RIGHT)) framesSpeed++;
else if (IsKeyPressed(KEY_LEFT)) framesSpeed--; else if (IsKeyPressed(KEY_LEFT)) framesSpeed--;
if (framesSpeed > MAX_FRAME_SPEED) framesSpeed = MAX_FRAME_SPEED; if (framesSpeed > MAX_FRAME_SPEED) framesSpeed = MAX_FRAME_SPEED;
else if (framesSpeed < MIN_FRAME_SPEED) framesSpeed = MIN_FRAME_SPEED; else if (framesSpeed < MIN_FRAME_SPEED) framesSpeed = MIN_FRAME_SPEED;
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// Draw // Draw
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
BeginDrawing(); BeginDrawing();
ClearBackground(RAYWHITE); ClearBackground(RAYWHITE);
DrawTexture(scarfy, 15, 40, WHITE); DrawTexture(scarfy, 15, 40, WHITE);
DrawRectangleLines(15, 40, scarfy.width, scarfy.height, LIME); DrawRectangleLines(15, 40, scarfy.width, scarfy.height, LIME);
DrawRectangleLines(15 + (int)frameRec.x, 40 + (int)frameRec.y, (int)frameRec.width, (int)frameRec.height, RED); DrawRectangleLines(15 + (int)frameRec.x, 40 + (int)frameRec.y, (int)frameRec.width, (int)frameRec.height, RED);
DrawText("FRAME SPEED: ", 165, 210, 10, DARKGRAY); DrawText("FRAME SPEED: ", 165, 210, 10, DARKGRAY);
DrawText(FormatText("%02i FPS", framesSpeed), 575, 210, 10, DARKGRAY); DrawText(FormatText("%02i FPS", framesSpeed), 575, 210, 10, DARKGRAY);
DrawText("PRESS RIGHT/LEFT KEYS to CHANGE SPEED!", 290, 240, 10, DARKGRAY); DrawText("PRESS RIGHT/LEFT KEYS to CHANGE SPEED!", 290, 240, 10, DARKGRAY);
for (int i = 0; i < MAX_FRAME_SPEED; i++) for (int i = 0; i < MAX_FRAME_SPEED; i++)
{ {
if (i < framesSpeed) DrawRectangle(250 + 21*i, 205, 20, 20, RED); if (i < framesSpeed) DrawRectangle(250 + 21*i, 205, 20, 20, RED);
DrawRectangleLines(250 + 21*i, 205, 20, 20, MAROON); DrawRectangleLines(250 + 21*i, 205, 20, 20, MAROON);
} }
DrawTextureRec(scarfy, frameRec, position, WHITE); // Draw part of the texture DrawTextureRec(scarfy, frameRec, position, WHITE); // Draw part of the texture
DrawText("(c) Scarfy sprite by Eiden Marsal", screenWidth - 200, screenHeight - 20, 10, GRAY); DrawText("(c) Scarfy sprite by Eiden Marsal", screenWidth - 200, screenHeight - 20, 10, GRAY);
EndDrawing(); EndDrawing();
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
} }
// De-Initialization // De-Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
UnloadTexture(scarfy); // Texture unloading UnloadTexture(scarfy); // Texture unloading
CloseWindow(); // Close window and OpenGL context CloseWindow(); // Close window and OpenGL context
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
return 0; return 0;
} }
} }

View File

@ -13,37 +13,37 @@ public partial class textures_srcrec_dstrec
* Copyright (c) 2015 Ramon Santamaria (@raysan5) * Copyright (c) 2015 Ramon Santamaria (@raysan5)
* *
********************************************************************************************/ ********************************************************************************************/
public static int Main() public static int Main()
{ {
// Initialization // Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
int screenWidth = 800; int screenWidth = 800;
int screenHeight = 450; int screenHeight = 450;
InitWindow(screenWidth, screenHeight, "raylib [textures] examples - texture source and destination rectangles"); InitWindow(screenWidth, screenHeight, "raylib [textures] examples - texture source and destination rectangles");
// NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required) // NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required)
Texture2D scarfy = LoadTexture("resources/scarfy.png"); // Texture loading Texture2D scarfy = LoadTexture("resources/scarfy.png"); // Texture loading
int frameWidth = scarfy.width/6; int frameWidth = scarfy.width/6;
int frameHeight = scarfy.height; int frameHeight = scarfy.height;
// NOTE: Source rectangle (part of the texture to use for drawing) // NOTE: Source rectangle (part of the texture to use for drawing)
Rectangle sourceRec = new Rectangle( 0, 0, frameWidth, frameHeight ); Rectangle sourceRec = new Rectangle( 0, 0, frameWidth, frameHeight );
// NOTE: Destination rectangle (screen rectangle where drawing part of texture) // NOTE: Destination rectangle (screen rectangle where drawing part of texture)
Rectangle destRec = new Rectangle( screenWidth/2, screenHeight/2, frameWidth*2, frameHeight*2 ); 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 // NOTE: Origin of the texture (rotation/scale point), it's relative to destination rectangle size
Vector2 origin = new Vector2( frameWidth, frameHeight ); Vector2 origin = new Vector2( frameWidth, frameHeight );
int rotation = 0; int rotation = 0;
SetTargetFPS(60); SetTargetFPS(60);
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
// Main game loop // Main game loop
while (!WindowShouldClose()) // Detect window close button or ESC key while (!WindowShouldClose()) // Detect window close button or ESC key
{ {
@ -51,36 +51,36 @@ public partial class textures_srcrec_dstrec
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
rotation++; rotation++;
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// Draw // Draw
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
BeginDrawing(); BeginDrawing();
ClearBackground(RAYWHITE); ClearBackground(RAYWHITE);
// NOTE: Using DrawTexturePro() we can easily rotate and scale the part of the texture we draw // 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 // 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) // 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 // origin defines the point of the texture used as reference for rotation and scaling
// rotation defines the texture rotation (using origin as rotation point) // rotation defines the texture rotation (using origin as rotation point)
DrawTexturePro(scarfy, sourceRec, destRec, origin, rotation, WHITE); DrawTexturePro(scarfy, sourceRec, destRec, origin, rotation, WHITE);
DrawLine((int)destRec.x, 0, (int)destRec.x, screenHeight, GRAY); DrawLine((int)destRec.x, 0, (int)destRec.x, screenHeight, GRAY);
DrawLine(0, (int)destRec.y, screenWidth, (int)destRec.y, GRAY); DrawLine(0, (int)destRec.y, screenWidth, (int)destRec.y, GRAY);
DrawText("(c) Scarfy sprite by Eiden Marsal", screenWidth - 200, screenHeight - 20, 10, GRAY); DrawText("(c) Scarfy sprite by Eiden Marsal", screenWidth - 200, screenHeight - 20, 10, GRAY);
EndDrawing(); EndDrawing();
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
} }
// De-Initialization // De-Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
UnloadTexture(scarfy); // Texture unloading UnloadTexture(scarfy); // Texture unloading
CloseWindow(); // Close window and OpenGL context CloseWindow(); // Close window and OpenGL context
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
return 0; return 0;
} }
} }

View File

@ -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) * 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) * Copyright (c) 2015 Ramon Santamaria (@raysan5)
* *
********************************************************************************************/ ********************************************************************************************/
public static int Main() public static int Main()
{ {
// Initialization // Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
int screenWidth = 800; int screenWidth = 800;
int screenHeight = 450; int screenHeight = 450;
InitWindow(screenWidth, screenHeight, "raylib [textures] example - texture to image"); InitWindow(screenWidth, screenHeight, "raylib [textures] example - texture to image");
// NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required) // 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) 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) Texture2D texture = LoadTextureFromImage(image); // Image converted to texture, GPU memory (RAM -> VRAM)
UnloadImage(image); // Unload image data from CPU memory (RAM) UnloadImage(image); // Unload image data from CPU memory (RAM)
image = GetTextureData(texture); // Retrieve image data from GPU memory (VRAM -> RAM) image = GetTextureData(texture); // Retrieve image data from GPU memory (VRAM -> RAM)
UnloadTexture(texture); // Unload texture from GPU memory (VRAM) UnloadTexture(texture); // Unload texture from GPU memory (VRAM)
texture = LoadTextureFromImage(image); // Recreate texture from retrieved image data (RAM -> VRAM) texture = LoadTextureFromImage(image); // Recreate texture from retrieved image data (RAM -> VRAM)
UnloadImage(image); // Unload retrieved image data from CPU memory (RAM) UnloadImage(image); // Unload retrieved image data from CPU memory (RAM)
//--------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------
// Main game loop // Main game loop
while (!WindowShouldClose()) // Detect window close button or ESC key while (!WindowShouldClose()) // Detect window close button or ESC key
{ {
@ -46,28 +46,28 @@ public partial class textures_to_image
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// TODO: Update your variables here // TODO: Update your variables here
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// Draw // Draw
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
BeginDrawing(); BeginDrawing();
ClearBackground(RAYWHITE); ClearBackground(RAYWHITE);
DrawTexture(texture, screenWidth/2 - texture.width/2, screenHeight/2 - texture.height/2, WHITE); 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); DrawText("this IS a texture loaded from an image!", 300, 370, 10, GRAY);
EndDrawing(); EndDrawing();
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
} }
// De-Initialization // De-Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
UnloadTexture(texture); // Texture unloading UnloadTexture(texture); // Texture unloading
CloseWindow(); // Close window and OpenGL context CloseWindow(); // Close window and OpenGL context
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
return 0; return 0;
} }
} }