mirror of https://github.com/raysan5/raylib
Remove trail spaces
This commit is contained in:
parent
f92ee46d86
commit
dcf52c132f
|
@ -87,7 +87,7 @@ int main(void)
|
|||
|
||||
if (IsKeyDown(KEY_DOWN)) pitch -= 0.01f;
|
||||
else if (IsKeyDown(KEY_UP)) pitch += 0.01f;
|
||||
|
||||
|
||||
SetMusicPitch(music, pitch);
|
||||
|
||||
// Get timePlayed scaled to bar dimensions
|
||||
|
|
|
@ -26,7 +26,7 @@ int main(void)
|
|||
|
||||
Sound fxWav = LoadSound("resources/sound.wav"); // Load WAV audio file
|
||||
Sound fxOgg = LoadSound("resources/target.ogg"); // Load OGG audio file
|
||||
|
||||
|
||||
SetSoundVolume(fxWav, 0.2f);
|
||||
|
||||
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||
|
@ -46,7 +46,7 @@ int main(void)
|
|||
BeginDrawing();
|
||||
|
||||
ClearBackground(RAYWHITE);
|
||||
|
||||
|
||||
DrawText("MULTICHANNEL SOUND PLAYING", 20, 20, 20, GRAY);
|
||||
DrawText("Press SPACE to play new ogg instance!", 200, 120, 20, LIGHTGRAY);
|
||||
DrawText("Press ENTER to play new wav instance!", 200, 180, 20, LIGHTGRAY);
|
||||
|
|
|
@ -54,7 +54,7 @@ int main(void)
|
|||
{
|
||||
// Update
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Player movement
|
||||
if (IsKeyDown(KEY_RIGHT)) player.x += 2;
|
||||
else if (IsKeyDown(KEY_LEFT)) player.x -= 2;
|
||||
|
|
|
@ -46,7 +46,7 @@ int main(void)
|
|||
//--------------------------------------------------------------------------------------
|
||||
const int screenWidth = 800;
|
||||
const int screenHeight = 450;
|
||||
|
||||
|
||||
InitWindow(screenWidth, screenHeight, "raylib [core] example - 2d camera");
|
||||
|
||||
Player player = { 0 };
|
||||
|
@ -60,7 +60,7 @@ int main(void)
|
|||
{{ 250, 300, 100, 10 }, 1, GRAY },
|
||||
{{ 650, 300, 100, 10 }, 1, GRAY }
|
||||
};
|
||||
|
||||
|
||||
int envItemsLength = sizeof(envItems)/sizeof(envItems[0]);
|
||||
|
||||
Camera2D camera = { 0 };
|
||||
|
@ -77,10 +77,10 @@ int main(void)
|
|||
UpdateCameraEvenOutOnLanding,
|
||||
UpdateCameraPlayerBoundsPush
|
||||
};
|
||||
|
||||
|
||||
int cameraOption = 0;
|
||||
int cameraUpdatersLength = sizeof(cameraUpdaters)/sizeof(cameraUpdaters[0]);
|
||||
|
||||
|
||||
char *cameraDescriptions[] = {
|
||||
"Follow player center",
|
||||
"Follow player center, but clamp to map edges",
|
||||
|
@ -88,25 +88,25 @@ int main(void)
|
|||
"Follow player center horizontally; updateplayer center vertically after landing",
|
||||
"Player push camera on getting too close to screen edge"
|
||||
};
|
||||
|
||||
|
||||
SetTargetFPS(60);
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
// Main game loop
|
||||
while (!WindowShouldClose())
|
||||
while (!WindowShouldClose())
|
||||
{
|
||||
// Update
|
||||
//----------------------------------------------------------------------------------
|
||||
float deltaTime = GetFrameTime();
|
||||
|
||||
|
||||
UpdatePlayer(&player, envItems, envItemsLength, deltaTime);
|
||||
|
||||
camera.zoom += ((float)GetMouseWheelMove()*0.05f);
|
||||
|
||||
|
||||
if (camera.zoom > 3.0f) camera.zoom = 3.0f;
|
||||
else if (camera.zoom < 0.25f) camera.zoom = 0.25f;
|
||||
|
||||
if (IsKeyPressed(KEY_R))
|
||||
|
||||
if (IsKeyPressed(KEY_R))
|
||||
{
|
||||
camera.zoom = 1.0f;
|
||||
player.position = (Vector2){ 400, 280 };
|
||||
|
@ -125,12 +125,12 @@ int main(void)
|
|||
ClearBackground(LIGHTGRAY);
|
||||
|
||||
BeginMode2D(camera);
|
||||
|
||||
|
||||
for (int i = 0; i < envItemsLength; i++) DrawRectangleRec(envItems[i].rect, envItems[i].color);
|
||||
|
||||
Rectangle playerRect = { player.position.x - 20, player.position.y - 40, 40, 40 };
|
||||
DrawRectangleRec(playerRect, RED);
|
||||
|
||||
|
||||
EndMode2D();
|
||||
|
||||
DrawText("Controls:", 20, 20, 10, BLACK);
|
||||
|
@ -140,7 +140,7 @@ int main(void)
|
|||
DrawText("- C to change camera mode", 40, 100, 10, DARKGRAY);
|
||||
DrawText("Current camera mode:", 20, 120, 10, BLACK);
|
||||
DrawText(cameraDescriptions[cameraOption], 40, 140, 10, DARKGRAY);
|
||||
|
||||
|
||||
EndDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
|
@ -157,35 +157,35 @@ void UpdatePlayer(Player *player, EnvItem *envItems, int envItemsLength, float d
|
|||
{
|
||||
if (IsKeyDown(KEY_LEFT)) player->position.x -= PLAYER_HOR_SPD*delta;
|
||||
if (IsKeyDown(KEY_RIGHT)) player->position.x += PLAYER_HOR_SPD*delta;
|
||||
if (IsKeyDown(KEY_SPACE) && player->canJump)
|
||||
if (IsKeyDown(KEY_SPACE) && player->canJump)
|
||||
{
|
||||
player->speed = -PLAYER_JUMP_SPD;
|
||||
player->canJump = false;
|
||||
}
|
||||
|
||||
int hitObstacle = 0;
|
||||
for (int i = 0; i < envItemsLength; i++)
|
||||
for (int i = 0; i < envItemsLength; i++)
|
||||
{
|
||||
EnvItem *ei = envItems + i;
|
||||
Vector2 *p = &(player->position);
|
||||
if (ei->blocking &&
|
||||
ei->rect.x <= p->x &&
|
||||
ei->rect.x <= p->x &&
|
||||
ei->rect.x + ei->rect.width >= p->x &&
|
||||
ei->rect.y >= p->y &&
|
||||
ei->rect.y < p->y + player->speed*delta)
|
||||
ei->rect.y < p->y + player->speed*delta)
|
||||
{
|
||||
hitObstacle = 1;
|
||||
player->speed = 0.0f;
|
||||
p->y = ei->rect.y;
|
||||
}
|
||||
}
|
||||
|
||||
if (!hitObstacle)
|
||||
|
||||
if (!hitObstacle)
|
||||
{
|
||||
player->position.y += player->speed*delta;
|
||||
player->speed += G*delta;
|
||||
player->canJump = false;
|
||||
}
|
||||
}
|
||||
else player->canJump = true;
|
||||
}
|
||||
|
||||
|
@ -200,7 +200,7 @@ void UpdateCameraCenterInsideMap(Camera2D *camera, Player *player, EnvItem *envI
|
|||
camera->target = player->position;
|
||||
camera->offset = (Vector2){ width/2.0f, height/2.0f };
|
||||
float minX = 1000, minY = 1000, maxX = -1000, maxY = -1000;
|
||||
|
||||
|
||||
for (int i = 0; i < envItemsLength; i++)
|
||||
{
|
||||
EnvItem *ei = envItems + i;
|
||||
|
@ -209,10 +209,10 @@ void UpdateCameraCenterInsideMap(Camera2D *camera, Player *player, EnvItem *envI
|
|||
minY = fminf(ei->rect.y, minY);
|
||||
maxY = fmaxf(ei->rect.y + ei->rect.height, maxY);
|
||||
}
|
||||
|
||||
|
||||
Vector2 max = GetWorldToScreen2D((Vector2){ maxX, maxY }, *camera);
|
||||
Vector2 min = GetWorldToScreen2D((Vector2){ minX, minY }, *camera);
|
||||
|
||||
|
||||
if (max.x < width) camera->offset.x = width - (max.x - width/2);
|
||||
if (max.y < height) camera->offset.y = height - (max.y - height/2);
|
||||
if (min.x > 0) camera->offset.x = width/2 - min.x;
|
||||
|
@ -224,11 +224,11 @@ void UpdateCameraCenterSmoothFollow(Camera2D *camera, Player *player, EnvItem *e
|
|||
static float minSpeed = 30;
|
||||
static float minEffectLength = 10;
|
||||
static float fractionSpeed = 0.8f;
|
||||
|
||||
|
||||
camera->offset = (Vector2){ width/2.0f, height/2.0f };
|
||||
Vector2 diff = Vector2Subtract(player->position, camera->target);
|
||||
float length = Vector2Length(diff);
|
||||
|
||||
|
||||
if (length > minEffectLength)
|
||||
{
|
||||
float speed = fmaxf(fractionSpeed*length, minSpeed);
|
||||
|
@ -241,34 +241,34 @@ void UpdateCameraEvenOutOnLanding(Camera2D *camera, Player *player, EnvItem *env
|
|||
static float evenOutSpeed = 700;
|
||||
static int eveningOut = false;
|
||||
static float evenOutTarget;
|
||||
|
||||
|
||||
camera->offset = (Vector2){ width/2.0f, height/2.0f };
|
||||
camera->target.x = player->position.x;
|
||||
|
||||
|
||||
if (eveningOut)
|
||||
{
|
||||
if (evenOutTarget > camera->target.y)
|
||||
if (evenOutTarget > camera->target.y)
|
||||
{
|
||||
camera->target.y += evenOutSpeed*delta;
|
||||
|
||||
if (camera->target.y > evenOutTarget)
|
||||
{
|
||||
camera->target.y = evenOutTarget;
|
||||
eveningOut = 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
camera->target.y -= evenOutSpeed*delta;
|
||||
|
||||
if (camera->target.y < evenOutTarget)
|
||||
|
||||
if (camera->target.y > evenOutTarget)
|
||||
{
|
||||
camera->target.y = evenOutTarget;
|
||||
eveningOut = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
else
|
||||
{
|
||||
camera->target.y -= evenOutSpeed*delta;
|
||||
|
||||
if (camera->target.y < evenOutTarget)
|
||||
{
|
||||
camera->target.y = evenOutTarget;
|
||||
eveningOut = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (player->canJump && (player->speed == 0) && (player->position.y != camera->target.y))
|
||||
{
|
||||
|
@ -278,7 +278,7 @@ void UpdateCameraEvenOutOnLanding(Camera2D *camera, Player *player, EnvItem *env
|
|||
}
|
||||
}
|
||||
|
||||
void UpdateCameraPlayerBoundsPush(Camera2D *camera, Player *player, EnvItem *envItems, int envItemsLength, float delta, int width, int height)
|
||||
void UpdateCameraPlayerBoundsPush(Camera2D *camera, Player *player, EnvItem *envItems, int envItemsLength, float delta, int width, int height)
|
||||
{
|
||||
static Vector2 bbox = { 0.2f, 0.2f };
|
||||
|
||||
|
|
|
@ -46,7 +46,7 @@ int main()
|
|||
#else
|
||||
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Main game loop
|
||||
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||
{
|
||||
|
|
|
@ -26,7 +26,7 @@ int main(void)
|
|||
const int screenHeight = 450;
|
||||
|
||||
InitWindow(screenWidth, screenHeight, "raylib [core] example - quat conversions");
|
||||
|
||||
|
||||
Camera3D camera = { 0 };
|
||||
camera.position = (Vector3){ 0.0f, 10.0f, 10.0f }; // Camera position
|
||||
camera.target = (Vector3){ 0.0f, 0.0f, 0.0f }; // Camera looking at point
|
||||
|
@ -34,9 +34,9 @@ int main(void)
|
|||
camera.fovy = 45.0f; // Camera field-of-view Y
|
||||
camera.projection = CAMERA_PERSPECTIVE; // Camera mode type
|
||||
|
||||
Mesh mesh = GenMeshCylinder(0.2f, 1.0f, 32);
|
||||
Mesh mesh = GenMeshCylinder(0.2f, 1.0f, 32);
|
||||
Model model = LoadModelFromMesh(mesh);
|
||||
|
||||
|
||||
// Some required variables
|
||||
Quaternion q1 = { 0 };
|
||||
Matrix m1 = { 0 }, m2 = { 0 }, m3 = { 0 }, m4 = { 0 };
|
||||
|
@ -44,7 +44,7 @@ int main(void)
|
|||
|
||||
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Main game loop
|
||||
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||
{
|
||||
|
@ -60,28 +60,28 @@ int main(void)
|
|||
if (v1.x > PI*2) v1.x -= PI*2;
|
||||
if (v1.y > PI*2) v1.y -= PI*2;
|
||||
if (v1.z > PI*2) v1.z -= PI*2;
|
||||
|
||||
|
||||
q1 = QuaternionFromEuler(v1.x, v1.y, v1.z);
|
||||
m1 = MatrixRotateZYX(v1);
|
||||
m2 = QuaternionToMatrix(q1);
|
||||
|
||||
q1 = QuaternionFromMatrix(m1);
|
||||
m3 = QuaternionToMatrix(q1);
|
||||
|
||||
v2 = QuaternionToEuler(q1);
|
||||
v2.x *= DEG2RAD;
|
||||
v2.y *= DEG2RAD;
|
||||
v2.z *= DEG2RAD;
|
||||
|
||||
|
||||
v2 = QuaternionToEuler(q1);
|
||||
v2.x *= DEG2RAD;
|
||||
v2.y *= DEG2RAD;
|
||||
v2.z *= DEG2RAD;
|
||||
|
||||
m4 = MatrixRotateZYX(v2);
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
BeginDrawing();
|
||||
|
||||
ClearBackground(RAYWHITE);
|
||||
|
||||
|
||||
BeginMode3D(camera);
|
||||
|
||||
model.transform = m1;
|
||||
|
@ -94,19 +94,19 @@ int main(void)
|
|||
DrawModel(model, (Vector3){ 0, 0, -1 }, 1.0f, RED);
|
||||
|
||||
DrawGrid(10, 1.0f);
|
||||
|
||||
|
||||
EndMode3D();
|
||||
|
||||
|
||||
if (v2.x < 0) v2.x += PI*2;
|
||||
if (v2.y < 0) v2.y += PI*2;
|
||||
if (v2.z < 0) v2.z += PI*2;
|
||||
|
||||
|
||||
Color cx,cy,cz;
|
||||
cx = cy = cz = BLACK;
|
||||
if (v1.x == v2.x) cx = GREEN;
|
||||
if (v1.y == v2.y) cy = GREEN;
|
||||
if (v1.z == v2.z) cz = GREEN;
|
||||
|
||||
|
||||
DrawText(TextFormat("%2.3f", v1.x), 20, 20, 20, cx);
|
||||
DrawText(TextFormat("%2.3f", v1.y), 20, 40, 20, cy);
|
||||
DrawText(TextFormat("%2.3f", v1.z), 20, 60, 20, cz);
|
||||
|
@ -122,7 +122,7 @@ int main(void)
|
|||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
UnloadModel(model); // Unload model data (mesh and materials)
|
||||
|
||||
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
|
|
@ -38,9 +38,9 @@ int main(void)
|
|||
.eyeToScreenDistance = 0.041f, // Distance between eye and display in meters
|
||||
.lensSeparationDistance = 0.07f, // Lens separation distance in meters
|
||||
.interpupillaryDistance = 0.07f, // IPD (distance between pupils) in meters
|
||||
|
||||
|
||||
// NOTE: CV1 uses fresnel-hybrid-asymmetric lenses with specific compute shaders
|
||||
// Following parameters are just an approximation to CV1 distortion stereo rendering
|
||||
// Following parameters are just an approximation to CV1 distortion stereo rendering
|
||||
.lensDistortionValues[0] = 1.0f, // Lens distortion constant parameter 0
|
||||
.lensDistortionValues[1] = 0.22f, // Lens distortion constant parameter 1
|
||||
.lensDistortionValues[2] = 0.24f, // Lens distortion constant parameter 2
|
||||
|
@ -50,32 +50,32 @@ int main(void)
|
|||
.chromaAbCorrection[2] = 1.014f, // Chromatic aberration correction parameter 2
|
||||
.chromaAbCorrection[3] = 0.0f, // Chromatic aberration correction parameter 3
|
||||
};
|
||||
|
||||
|
||||
// Load VR stereo config for VR device parameteres (Oculus Rift CV1 parameters)
|
||||
VrStereoConfig config = LoadVrStereoConfig(device);
|
||||
|
||||
// Distortion shader (uses device lens distortion and chroma)
|
||||
Shader distortion = LoadShader(0, TextFormat("resources/distortion%i.fs", GLSL_VERSION));
|
||||
|
||||
|
||||
// Update distortion shader with lens and distortion-scale parameters
|
||||
SetShaderValue(distortion, GetShaderLocation(distortion, "leftLensCenter"),
|
||||
SetShaderValue(distortion, GetShaderLocation(distortion, "leftLensCenter"),
|
||||
config.leftLensCenter, SHADER_UNIFORM_VEC2);
|
||||
SetShaderValue(distortion, GetShaderLocation(distortion, "rightLensCenter"),
|
||||
SetShaderValue(distortion, GetShaderLocation(distortion, "rightLensCenter"),
|
||||
config.rightLensCenter, SHADER_UNIFORM_VEC2);
|
||||
SetShaderValue(distortion, GetShaderLocation(distortion, "leftScreenCenter"),
|
||||
SetShaderValue(distortion, GetShaderLocation(distortion, "leftScreenCenter"),
|
||||
config.leftScreenCenter, SHADER_UNIFORM_VEC2);
|
||||
SetShaderValue(distortion, GetShaderLocation(distortion, "rightScreenCenter"),
|
||||
SetShaderValue(distortion, GetShaderLocation(distortion, "rightScreenCenter"),
|
||||
config.rightScreenCenter, SHADER_UNIFORM_VEC2);
|
||||
|
||||
SetShaderValue(distortion, GetShaderLocation(distortion, "scale"),
|
||||
SetShaderValue(distortion, GetShaderLocation(distortion, "scale"),
|
||||
config.scale, SHADER_UNIFORM_VEC2);
|
||||
SetShaderValue(distortion, GetShaderLocation(distortion, "scaleIn"),
|
||||
SetShaderValue(distortion, GetShaderLocation(distortion, "scaleIn"),
|
||||
config.scaleIn, SHADER_UNIFORM_VEC2);
|
||||
SetShaderValue(distortion, GetShaderLocation(distortion, "deviceWarpParam"),
|
||||
SetShaderValue(distortion, GetShaderLocation(distortion, "deviceWarpParam"),
|
||||
device.lensDistortionValues, SHADER_UNIFORM_VEC4);
|
||||
SetShaderValue(distortion, GetShaderLocation(distortion, "chromaAbParam"),
|
||||
device.chromaAbCorrection, SHADER_UNIFORM_VEC4);
|
||||
|
||||
|
||||
// Initialize framebuffer for stereo rendering
|
||||
// NOTE: Screen size should match HMD aspect ratio
|
||||
RenderTexture2D target = LoadRenderTexture(GetScreenWidth(), GetScreenHeight());
|
||||
|
@ -121,9 +121,9 @@ int main(void)
|
|||
EndMode3D();
|
||||
EndVrStereoMode();
|
||||
EndTextureMode();
|
||||
|
||||
|
||||
BeginShaderMode(distortion);
|
||||
DrawTextureRec(target.texture, (Rectangle){ 0, 0, (float)target.texture.width,
|
||||
DrawTextureRec(target.texture, (Rectangle){ 0, 0, (float)target.texture.width,
|
||||
(float)-target.texture.height }, (Vector2){ 0.0f, 0.0f }, WHITE);
|
||||
EndShaderMode();
|
||||
|
||||
|
@ -136,7 +136,7 @@ int main(void)
|
|||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
UnloadVrStereoConfig(config); // Unload stereo config
|
||||
|
||||
|
||||
UnloadRenderTexture(target); // Unload stereo render fbo
|
||||
UnloadShader(distortion); // Unload distortion shader
|
||||
|
||||
|
|
|
@ -64,13 +64,13 @@ int main(void)
|
|||
// Recalculate random colors for the bars
|
||||
for (int i = 0; i < 10; i++) colors[i] = (Color){ GetRandomValue(100, 250), GetRandomValue(50, 150), GetRandomValue(10, 100), 255 };
|
||||
}
|
||||
|
||||
|
||||
// Update virtual mouse (clamped mouse value behind game screen)
|
||||
Vector2 mouse = GetMousePosition();
|
||||
Vector2 virtualMouse = { 0 };
|
||||
virtualMouse.x = (mouse.x - (GetScreenWidth() - (gameScreenWidth*scale))*0.5f)/scale;
|
||||
virtualMouse.y = (mouse.y - (GetScreenHeight() - (gameScreenHeight*scale))*0.5f)/scale;
|
||||
virtualMouse = ClampValue(virtualMouse, (Vector2){ 0, 0 }, (Vector2){ gameScreenWidth, gameScreenHeight });
|
||||
virtualMouse = ClampValue(virtualMouse, (Vector2){ 0, 0 }, (Vector2){ gameScreenWidth, gameScreenHeight });
|
||||
|
||||
// Apply the same transformation as the virtual mouse to the real mouse (i.e. to work with raygui)
|
||||
//SetMouseOffset(-(GetScreenWidth() - (gameScreenWidth*scale))*0.5f, -(GetScreenHeight() - (gameScreenHeight*scale))*0.5f);
|
||||
|
@ -90,7 +90,7 @@ int main(void)
|
|||
for (int i = 0; i < 10; i++) DrawRectangle(0, (gameScreenHeight/10)*i, gameScreenWidth, gameScreenHeight/10, colors[i]);
|
||||
|
||||
DrawText("If executed inside a window,\nyou can resize the window,\nand see the screen scaling!", 10, 25, 20, WHITE);
|
||||
|
||||
|
||||
DrawText(TextFormat("Default Mouse: [%i , %i]", (int)mouse.x, (int)mouse.y), 350, 25, 20, GREEN);
|
||||
DrawText(TextFormat("Virtual Mouse: [%i , %i]", (int)virtualMouse.x, (int)virtualMouse.y), 350, 55, 20, YELLOW);
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
WELCOME raylib EXAMPLES CONTRIBUTOR!
|
||||
|
||||
|
||||
This is a bsasic template to anyone ready to contribute with some code example for the library,
|
||||
here there are some guidelines on how to create an example to be included in raylib
|
||||
|
||||
|
@ -8,32 +8,32 @@
|
|||
no more than 3-4 words in total to describe the example. <module> referes to the primary
|
||||
raylib module the example is more related with (code, shapes, textures, models, shaders, raudio).
|
||||
i.e: core_input_multitouch, shapes_lines_bezier, shaders_palette_switch
|
||||
|
||||
|
||||
2. Follow below template structure, example info should list the module, the short description
|
||||
and the author of the example, twitter or github info could be also provided for the author.
|
||||
Short description should also be used on the title of the window.
|
||||
|
||||
|
||||
3. Code should be organized by sections:[Initialization]- [Update] - [Draw] - [De-Initialization]
|
||||
Place your code between the dotted lines for every section, please don't mix update logic with drawing
|
||||
and remember to unload all loaded resources.
|
||||
|
||||
|
||||
4. Code should follow raylib conventions: https://github.com/raysan5/raylib/wiki/raylib-coding-conventions
|
||||
Try to be very organized, using line-breaks appropiately.
|
||||
|
||||
|
||||
5. Add comments to the specific parts of code the example is focus on.
|
||||
Don't abuse with comments, try to be clear and impersonal on the comments.
|
||||
|
||||
|
||||
6. Try to keep the example simple, under 300 code lines if possible. Try to avoid external dependencies.
|
||||
Try to avoid defining functions outside the main(). Example should be as self-contained as possible.
|
||||
|
||||
|
||||
7. About external resources, they should be placed in a [resources] folder and those resources
|
||||
should be open and free for use and distribution. Avoid propietary content.
|
||||
|
||||
|
||||
8. Try to keep the example simple but with a creative touch.
|
||||
Simple but beautiful examples are more appealing to users!
|
||||
|
||||
|
||||
9. In case of additional information is required, just come to raylib Discord channel: example-contributions
|
||||
|
||||
|
||||
10. Have fun!
|
||||
*/
|
||||
|
||||
|
@ -58,9 +58,9 @@ int main()
|
|||
const int screenHeight = 450;
|
||||
|
||||
InitWindow(screenWidth, screenHeight, "raylib [core] example - basic window");
|
||||
|
||||
// TODO: Load resources / Initialize variables at this point
|
||||
|
||||
|
||||
// TODO: Load resources / Initialize variables at this point
|
||||
|
||||
SetTargetFPS(60);
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
@ -79,7 +79,7 @@ int main()
|
|||
ClearBackground(RAYWHITE);
|
||||
|
||||
// TODO: Draw everything that requires to be drawn at this point:
|
||||
|
||||
|
||||
DrawText("Congrats! You created your first window!", 190, 200, 20, LIGHTGRAY); // Example
|
||||
|
||||
EndDrawing();
|
||||
|
@ -88,9 +88,9 @@ int main()
|
|||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// TODO: Unload all loaded resources at this point
|
||||
|
||||
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
*
|
||||
********************************************************************************************
|
||||
*
|
||||
* To export a model from blender, make sure it is not posed, the vertices need to be in the
|
||||
* To export a model from blender, make sure it is not posed, the vertices need to be in the
|
||||
* same position as they would be in edit mode.
|
||||
* and that the scale of your models is set to 0. Scaling can be done from the export menu.
|
||||
*
|
||||
|
@ -100,7 +100,7 @@ int main(void)
|
|||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
UnloadTexture(texture); // Unload texture
|
||||
|
||||
|
||||
// Unload model animations data
|
||||
for (int i = 0; i < animsCount; i++) UnloadModelAnimation(anims[i]);
|
||||
RL_FREE(anims);
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
*
|
||||
********************************************************************************************
|
||||
*
|
||||
* To export a model from blender, make sure it is not posed, the vertices need to be in the
|
||||
* To export a model from blender, make sure it is not posed, the vertices need to be in the
|
||||
* same position as they would be in edit mode.
|
||||
* and that the scale of your models is set to 0. Scaling can be done from the export menu.
|
||||
*
|
||||
|
@ -68,13 +68,13 @@ int main(void)
|
|||
if (IsKeyDown(KEY_SPACE))
|
||||
{
|
||||
animFrameCounter += animationDirection;
|
||||
|
||||
|
||||
if (animFrameCounter >= anims[0].frameCount || animFrameCounter <= 0)
|
||||
{
|
||||
animationDirection *= -1;
|
||||
animFrameCounter += animationDirection;
|
||||
}
|
||||
|
||||
|
||||
UpdateModelAnimation(model, anims[0], animFrameCounter);
|
||||
}
|
||||
//----------------------------------------------------------------------------------
|
||||
|
@ -108,7 +108,7 @@ int main(void)
|
|||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
// UnloadTexture(texture); // Unload texture
|
||||
|
||||
|
||||
// Unload model animations data
|
||||
for (int i = 0; i < animsCount; i++) UnloadModelAnimation(anims[i]);
|
||||
RL_FREE(anims);
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
*
|
||||
********************************************************************************************
|
||||
*
|
||||
* To export a model from blender, make sure it is not posed, the vertices need to be in the
|
||||
* To export a model from blender, make sure it is not posed, the vertices need to be in the
|
||||
* same position as they would be in edit mode.
|
||||
* and that the scale of your models is set to 0. Scaling can be done from the export menu.
|
||||
*
|
||||
|
@ -41,14 +41,14 @@ int main(void)
|
|||
camera.projection = CAMERA_PERSPECTIVE; // Camera mode type
|
||||
|
||||
Model model[MAX_MODELS] = { 0 };
|
||||
|
||||
|
||||
model[0] = LoadModel("resources/gltf/raylib_32x32.glb");
|
||||
model[1] = LoadModel("resources/gltf/rigged_figure.glb");
|
||||
model[2] = LoadModel("resources/gltf/GearboxAssy.glb");
|
||||
model[3] = LoadModel("resources/gltf/BoxAnimated.glb");
|
||||
model[4] = LoadModel("resources/gltf/AnimatedTriangle.gltf");
|
||||
model[5] = LoadModel("resources/gltf/AnimatedMorphCube.glb");
|
||||
|
||||
|
||||
int currentModel = 0;
|
||||
|
||||
Vector3 position = { 0.0f, 0.0f, 0.0f }; // Set model position
|
||||
|
@ -64,13 +64,13 @@ int main(void)
|
|||
// Update
|
||||
//----------------------------------------------------------------------------------
|
||||
UpdateCamera(&camera);
|
||||
|
||||
|
||||
if (IsKeyReleased(KEY_RIGHT))
|
||||
{
|
||||
currentModel++;
|
||||
if (currentModel == MAX_MODELS) currentModel = 0;
|
||||
}
|
||||
|
||||
|
||||
if (IsKeyReleased(KEY_LEFT))
|
||||
{
|
||||
currentModel--;
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
* - GLTF > Modern text/binary file format, includes lot of information and it could
|
||||
* also reference external files, raylib will try loading mesh and materials data
|
||||
* - IQM > Binary file format including mesh vertex data but also animation data,
|
||||
* raylib can load .iqm animations.
|
||||
* raylib can load .iqm animations.
|
||||
*
|
||||
* This example has been created using raylib 2.6 (www.raylib.com)
|
||||
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
|
||||
|
@ -42,7 +42,7 @@ int main(void)
|
|||
model.materials[0].maps[MATERIAL_MAP_DIFFUSE].texture = texture; // Set map diffuse texture
|
||||
|
||||
Vector3 position = { 0.0f, 0.0f, 0.0f }; // Set model position
|
||||
|
||||
|
||||
BoundingBox bounds = MeshBoundingBox(model.meshes[0]); // Set model bounds
|
||||
|
||||
// NOTE: bounds are calculated from the original size of the model,
|
||||
|
@ -61,7 +61,7 @@ int main(void)
|
|||
// Update
|
||||
//----------------------------------------------------------------------------------
|
||||
UpdateCamera(&camera);
|
||||
|
||||
|
||||
// Load new models/textures on drag&drop
|
||||
if (IsFileDropped())
|
||||
{
|
||||
|
@ -79,7 +79,7 @@ int main(void)
|
|||
model.materials[0].maps[MATERIAL_MAP_DIFFUSE].texture = texture; // Set current map diffuse texture
|
||||
|
||||
bounds = MeshBoundingBox(model.meshes[0]);
|
||||
|
||||
|
||||
// TODO: Move camera position from target enough distance to visualize model properly
|
||||
}
|
||||
else if (IsFileExtension(droppedFiles[0], ".png")) // Texture file formats supported
|
||||
|
@ -118,7 +118,7 @@ int main(void)
|
|||
if (selected) DrawBoundingBox(bounds, GREEN); // Draw selection box
|
||||
|
||||
EndMode3D();
|
||||
|
||||
|
||||
DrawText("Drag & drop model to load mesh/texture.", 10, GetScreenHeight() - 20, 10, DARKGRAY);
|
||||
if (selected) DrawText("MODEL SELECTED", GetScreenWidth() - 110, 10, 10, GREEN);
|
||||
|
||||
|
|
|
@ -133,7 +133,7 @@ static Material LoadMaterialPBR(Color albedo, float metalness, float roughness)
|
|||
Material mat = LoadMaterialDefault(); // Initialize material to default
|
||||
|
||||
// Load PBR shader (requires several maps)
|
||||
mat.shader = LoadShader(TextFormat("resources/shaders/glsl%i/pbr.vs", GLSL_VERSION),
|
||||
mat.shader = LoadShader(TextFormat("resources/shaders/glsl%i/pbr.vs", GLSL_VERSION),
|
||||
TextFormat("resources/shaders/glsl%i/pbr.fs", GLSL_VERSION));
|
||||
|
||||
// Get required locations points for PBR material
|
||||
|
@ -160,14 +160,14 @@ static Material LoadMaterialPBR(Color albedo, float metalness, float roughness)
|
|||
mat.maps[MATERIAL_MAP_METALNESS].texture = LoadTexture("resources/pbr/trooper_metalness.png");
|
||||
mat.maps[MATERIAL_MAP_ROUGHNESS].texture = LoadTexture("resources/pbr/trooper_roughness.png");
|
||||
mat.maps[MATERIAL_MAP_OCCLUSION].texture = LoadTexture("resources/pbr/trooper_ao.png");
|
||||
|
||||
|
||||
// Set textures filtering for better quality
|
||||
SetTextureFilter(mat.maps[MATERIAL_MAP_ALBEDO].texture, FILTER_BILINEAR);
|
||||
SetTextureFilter(mat.maps[MATERIAL_MAP_NORMAL].texture, FILTER_BILINEAR);
|
||||
SetTextureFilter(mat.maps[MATERIAL_MAP_METALNESS].texture, FILTER_BILINEAR);
|
||||
SetTextureFilter(mat.maps[MATERIAL_MAP_ROUGHNESS].texture, FILTER_BILINEAR);
|
||||
SetTextureFilter(mat.maps[MATERIAL_MAP_OCCLUSION].texture, FILTER_BILINEAR);
|
||||
|
||||
|
||||
// Enable sample usage in shader for assigned textures
|
||||
SetShaderValue(mat.shader, GetShaderLocation(mat.shader, "albedo.useSampler"), (int[1]){ 1 }, SHADER_UNIFORM_INT);
|
||||
SetShaderValue(mat.shader, GetShaderLocation(mat.shader, "normals.useSampler"), (int[1]){ 1 }, SHADER_UNIFORM_INT);
|
||||
|
@ -186,13 +186,13 @@ static Material LoadMaterialPBR(Color albedo, float metalness, float roughness)
|
|||
mat.maps[MATERIAL_MAP_OCCLUSION].value = 1.0f;
|
||||
mat.maps[MATERIAL_MAP_EMISSION].value = 0.5f;
|
||||
mat.maps[MATERIAL_MAP_HEIGHT].value = 0.5f;
|
||||
|
||||
|
||||
// Generate cubemap from panorama texture
|
||||
//--------------------------------------------------------------------------------------------------------
|
||||
Texture2D panorama = LoadTexture("resources/dresden_square_2k.hdr");
|
||||
|
||||
|
||||
// Load equirectangular to cubemap shader
|
||||
Shader shdrCubemap = LoadShader(TextFormat("resources/shaders/glsl%i/pbr.vs", GLSL_VERSION),
|
||||
Shader shdrCubemap = LoadShader(TextFormat("resources/shaders/glsl%i/pbr.vs", GLSL_VERSION),
|
||||
TextFormat("resources/shaders/glsl%i/pbr.fs", GLSL_VERSION));
|
||||
|
||||
SetShaderValue(shdrCubemap, GetShaderLocation(shdrCubemap, "equirectangularMap"), (int[1]){ 0 }, SHADER_UNIFORM_INT);
|
||||
|
@ -200,33 +200,33 @@ static Material LoadMaterialPBR(Color albedo, float metalness, float roughness)
|
|||
UnloadTexture(panorama);
|
||||
UnloadShader(shdrCubemap);
|
||||
//--------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Generate irradiance map from cubemap texture
|
||||
//--------------------------------------------------------------------------------------------------------
|
||||
// Load irradiance (GI) calculation shader
|
||||
Shader shdrIrradiance = LoadShader(TextFormat("resources/shaders/glsl%i/skybox.vs", GLSL_VERSION),
|
||||
Shader shdrIrradiance = LoadShader(TextFormat("resources/shaders/glsl%i/skybox.vs", GLSL_VERSION),
|
||||
TextFormat("resources/shaders/glsl%i/irradiance.fs", GLSL_VERSION));
|
||||
|
||||
SetShaderValue(shdrIrradiance, GetShaderLocation(shdrIrradiance, "environmentMap"), (int[1]){ 0 }, SHADER_UNIFORM_INT);
|
||||
mat.maps[MATERIAL_MAP_IRRADIANCE].texture = GenTextureIrradiance(shdrIrradiance, cubemap, IRRADIANCE_SIZE);
|
||||
UnloadShader(shdrIrradiance);
|
||||
//--------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Generate prefilter map from cubemap texture
|
||||
//--------------------------------------------------------------------------------------------------------
|
||||
// Load reflection prefilter calculation shader
|
||||
Shader shdrPrefilter = LoadShader(TextFormat("resources/shaders/glsl%i/skybox.vs", GLSL_VERSION),
|
||||
Shader shdrPrefilter = LoadShader(TextFormat("resources/shaders/glsl%i/skybox.vs", GLSL_VERSION),
|
||||
TextFormat("resources/shaders/glsl%i/prefilter.fs", GLSL_VERSION));
|
||||
|
||||
|
||||
SetShaderValue(shdrPrefilter, GetShaderLocation(shdrPrefilter, "environmentMap"), (int[1]){ 0 }, SHADER_UNIFORM_INT);
|
||||
mat.maps[MATERIAL_MAP_PREFILTER].texture = GenTexturePrefilter(shdrPrefilter, cubemap, PREFILTERED_SIZE);
|
||||
UnloadTexture(cubemap);
|
||||
UnloadShader(shdrPrefilter);
|
||||
//--------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Generate BRDF (bidirectional reflectance distribution function) texture (using shader)
|
||||
//--------------------------------------------------------------------------------------------------------
|
||||
Shader shdrBRDF = LoadShader(TextFormat("resources/shaders/glsl%i/brdf.vs", GLSL_VERSION),
|
||||
Shader shdrBRDF = LoadShader(TextFormat("resources/shaders/glsl%i/brdf.vs", GLSL_VERSION),
|
||||
TextFormat("resources/shaders/glsl%i/brdf.fs", GLSL_VERSION));
|
||||
|
||||
mat.maps[MATERIAL_MAP_BRDG].texture = GenTextureBRDF(shdrBRDF, BRDF_SIZE);
|
||||
|
@ -453,7 +453,7 @@ static TextureCubemap GenTexturePrefilter(Shader shader, TextureCubemap cubemap,
|
|||
{
|
||||
rlSetUniformMatrix(shader.locs[SHADER_LOC_MATRIX_VIEW], fboViews[i]);
|
||||
rlFramebufferAttach(fbo, prefilter.id, RL_ATTACHMENT_COLOR_CHANNEL0, RL_ATTACHMENT_CUBEMAP_POSITIVE_X + i, mip);
|
||||
|
||||
|
||||
rlClearScreenBuffers();
|
||||
rlLoadDrawCube();
|
||||
}
|
||||
|
|
|
@ -135,7 +135,7 @@ void DrawSphereBasic(Color color)
|
|||
{
|
||||
int rings = 16;
|
||||
int slices = 16;
|
||||
|
||||
|
||||
// Make sure there is enough space in the internal render batch
|
||||
// buffer to store all required vertex, batch is reseted if required
|
||||
rlCheckRenderBatchLimit((rings + 2)*slices*6);
|
||||
|
|
|
@ -36,12 +36,12 @@ int main(void)
|
|||
// Load skybox model
|
||||
Mesh cube = GenMeshCube(1.0f, 1.0f, 1.0f);
|
||||
Model skybox = LoadModelFromMesh(cube);
|
||||
|
||||
|
||||
bool useHDR = false;
|
||||
|
||||
// Load skybox shader and set required locations
|
||||
// NOTE: Some locations are automatically set at shader loading
|
||||
skybox.materials[0].shader = LoadShader(TextFormat("resources/shaders/glsl%i/skybox.vs", GLSL_VERSION),
|
||||
skybox.materials[0].shader = LoadShader(TextFormat("resources/shaders/glsl%i/skybox.vs", GLSL_VERSION),
|
||||
TextFormat("resources/shaders/glsl%i/skybox.fs", GLSL_VERSION));
|
||||
|
||||
SetShaderValue(skybox.materials[0].shader, GetShaderLocation(skybox.materials[0].shader, "environmentMap"), (int[1]){ MATERIAL_MAP_CUBEMAP }, SHADER_UNIFORM_INT);
|
||||
|
@ -49,7 +49,7 @@ int main(void)
|
|||
SetShaderValue(skybox.materials[0].shader, GetShaderLocation(skybox.materials[0].shader, "vflipped"), (int[1]){ useHDR ? 1 : 0 }, SHADER_UNIFORM_INT);
|
||||
|
||||
// Load cubemap shader and setup required shader locations
|
||||
Shader shdrCubemap = LoadShader(TextFormat("resources/shaders/glsl%i/cubemap.vs", GLSL_VERSION),
|
||||
Shader shdrCubemap = LoadShader(TextFormat("resources/shaders/glsl%i/cubemap.vs", GLSL_VERSION),
|
||||
TextFormat("resources/shaders/glsl%i/cubemap.fs", GLSL_VERSION));
|
||||
|
||||
SetShaderValue(shdrCubemap, GetShaderLocation(shdrCubemap, "equirectangularMap"), (int[1]){ 0 }, SHADER_UNIFORM_INT);
|
||||
|
@ -89,7 +89,7 @@ int main(void)
|
|||
// Update
|
||||
//----------------------------------------------------------------------------------
|
||||
UpdateCamera(&camera); // Update camera
|
||||
|
||||
|
||||
// Load new cubemap texture on drag&drop
|
||||
if (IsFileDropped())
|
||||
{
|
||||
|
@ -105,7 +105,7 @@ int main(void)
|
|||
if (useHDR)
|
||||
{
|
||||
Texture2D panorama = LoadTexture(droppedFiles[0]);
|
||||
|
||||
|
||||
// Generate cubemap from panorama texture
|
||||
skybox.materials[0].maps[MATERIAL_MAP_CUBEMAP].texture = GenTextureCubemap(shdrCubemap, panorama, 1024, PIXELFORMAT_UNCOMPRESSED_R8G8B8A8);
|
||||
UnloadTexture(panorama);
|
||||
|
@ -132,16 +132,16 @@ int main(void)
|
|||
ClearBackground(RAYWHITE);
|
||||
|
||||
BeginMode3D(camera);
|
||||
|
||||
|
||||
// We are inside the cube, we need to disable backface culling!
|
||||
rlDisableBackfaceCulling();
|
||||
rlDisableDepthMask();
|
||||
DrawModel(skybox, (Vector3){0, 0, 0}, 1.0f, WHITE);
|
||||
rlEnableBackfaceCulling();
|
||||
rlEnableDepthMask();
|
||||
|
||||
|
||||
DrawGrid(10, 1.0f);
|
||||
|
||||
|
||||
EndMode3D();
|
||||
|
||||
if (useHDR)
|
||||
|
@ -159,7 +159,7 @@ int main(void)
|
|||
//--------------------------------------------------------------------------------------
|
||||
UnloadShader(skybox.materials[0].shader);
|
||||
UnloadTexture(skybox.materials[0].maps[MATERIAL_MAP_CUBEMAP].texture);
|
||||
|
||||
|
||||
UnloadModel(skybox); // Unload skybox model
|
||||
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
|
|
|
@ -53,7 +53,7 @@ int main()
|
|||
camera.position.x = (float)cos(cameraTime)*40.0f;
|
||||
camera.position.z = (float)sin(cameraTime)*40.0f;
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
BeginDrawing();
|
||||
|
@ -64,11 +64,11 @@ int main()
|
|||
|
||||
DrawGrid(10, 5.0f);
|
||||
|
||||
for (int x = 0; x < numBlocks; x++)
|
||||
for (int x = 0; x < numBlocks; x++)
|
||||
{
|
||||
for (int y = 0; y < numBlocks; y++)
|
||||
for (int y = 0; y < numBlocks; y++)
|
||||
{
|
||||
for (int z = 0; z < numBlocks; z++)
|
||||
for (int z = 0; z < numBlocks; z++)
|
||||
{
|
||||
// Scale of the blocks depends on x/y/z positions
|
||||
float blockScale = (x + y + z)/30.0f;
|
||||
|
@ -94,9 +94,9 @@ int main()
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
EndMode3D();
|
||||
|
||||
|
||||
DrawFPS(10, 10);
|
||||
|
||||
EndDrawing();
|
||||
|
|
|
@ -30,7 +30,7 @@ int main(void)
|
|||
camera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; // Camera up vector (rotation towards target)
|
||||
camera.fovy = 30.0f; // Camera field-of-view Y
|
||||
camera.projection = CAMERA_PERSPECTIVE; // Camera type
|
||||
|
||||
|
||||
// Model loading
|
||||
// NOTE: Diffuse map loaded automatically
|
||||
Model model = LoadModel("resources/plane/plane.gltf");
|
||||
|
@ -77,8 +77,8 @@ int main(void)
|
|||
// Tranformation matrix for rotations
|
||||
model.transform = MatrixRotateXYZ((Vector3){ DEG2RAD*pitch, DEG2RAD*yaw, DEG2RAD*roll });
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
|
||||
// Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
BeginDrawing();
|
||||
|
@ -92,7 +92,7 @@ int main(void)
|
|||
DrawGrid(10, 10.0f);
|
||||
|
||||
EndMode3D();
|
||||
|
||||
|
||||
// Draw controls info
|
||||
DrawRectangle(30, 370, 260, 70, Fade(GREEN, 0.5f));
|
||||
DrawRectangleLines(30, 370, 260, 70, Fade(DARKGREEN, 0.5f));
|
||||
|
@ -107,7 +107,7 @@ int main(void)
|
|||
}
|
||||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
//--------------------------------------------------------------------------------------
|
||||
UnloadModel(model); // Unload model data
|
||||
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
|
|
|
@ -40,16 +40,16 @@ static void NetworkConnect(void)
|
|||
{
|
||||
ping = true;
|
||||
connected = true;
|
||||
}
|
||||
else
|
||||
}
|
||||
else
|
||||
{
|
||||
// If the client is connected, run the server code to check for a connection
|
||||
if (clientConnected)
|
||||
if (clientConnected)
|
||||
{
|
||||
int active = CheckSockets(socketSet, 0);
|
||||
if (active != 0) TraceLog(LOG_INFO, "There are currently %d socket(s) with data to be processed.", active);
|
||||
|
||||
if (active > 0)
|
||||
if (active > 0)
|
||||
{
|
||||
if ((connection = SocketAccept(serverResult->socket, &connectionConfig)) != NULL)
|
||||
{
|
||||
|
@ -58,7 +58,7 @@ static void NetworkConnect(void)
|
|||
ping = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Check if we're connected every _delay_ seconds
|
||||
|
@ -66,7 +66,7 @@ static void NetworkConnect(void)
|
|||
if (elapsed > delay)
|
||||
{
|
||||
if (IsSocketConnected(clientResult->socket)) clientConnected = true;
|
||||
|
||||
|
||||
elapsed = 0.0f;
|
||||
}
|
||||
}
|
||||
|
@ -88,7 +88,7 @@ static void UpdateNetwork(void)
|
|||
{
|
||||
if (IsSocketReady(clientResult->socket)) bytesRecv = SocketReceive(clientResult->socket, receiveBuffer, msglen);
|
||||
if (IsSocketReady(serverResult->socket)) bytesRecv = SocketReceive(serverResult->socket, receiveBuffer, msglen);
|
||||
}
|
||||
}
|
||||
else if (IsSocketReady(connection)) bytesRecv = SocketReceive(connection, receiveBuffer, msglen);
|
||||
|
||||
// If we received data, was that data a "Ping!" or a "Pong!"
|
||||
|
@ -107,14 +107,14 @@ static void UpdateNetwork(void)
|
|||
ping = false;
|
||||
if (serverConfig.type == SOCKET_UDP && clientConfig.type == SOCKET_UDP) SocketSend(clientResult->socket, pingmsg, msglen);
|
||||
else SocketSend(clientResult->socket, pingmsg, msglen);
|
||||
}
|
||||
}
|
||||
else if (pong)
|
||||
{
|
||||
pong = false;
|
||||
if (serverConfig.type == SOCKET_UDP && clientConfig.type == SOCKET_UDP) SocketSend(clientResult->socket, pongmsg, msglen);
|
||||
else SocketSend(clientResult->socket, pongmsg, msglen);
|
||||
}
|
||||
|
||||
|
||||
elapsed = 0.0f;
|
||||
}
|
||||
}
|
||||
|
@ -132,7 +132,7 @@ int main(void)
|
|||
|
||||
// Create the server: getaddrinfo + socket + setsockopt + bind + listen
|
||||
serverResult = LoadSocketResult();
|
||||
if (!SocketCreate(&serverConfig, serverResult))
|
||||
if (!SocketCreate(&serverConfig, serverResult))
|
||||
{
|
||||
TraceLog(LOG_WARNING, "Failed to open server: status %d, errno %d", serverResult->status, serverResult->socket->status);
|
||||
}
|
||||
|
@ -141,7 +141,7 @@ int main(void)
|
|||
if (!SocketBind(&serverConfig, serverResult))
|
||||
{
|
||||
TraceLog(LOG_WARNING, "Failed to bind server: status %d, errno %d", serverResult->status, serverResult->socket->status);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!(serverConfig.type == SOCKET_UDP))
|
||||
|
@ -156,7 +156,7 @@ int main(void)
|
|||
|
||||
// Create the client: getaddrinfo + socket + setsockopt + connect (TCP only)
|
||||
clientResult = LoadSocketResult();
|
||||
if (!SocketCreate(&clientConfig, clientResult))
|
||||
if (!SocketCreate(&clientConfig, clientResult))
|
||||
{
|
||||
TraceLog(LOG_WARNING, "Failed to open client: status %d, errno %d", clientResult->status, clientResult->socket->status);
|
||||
}
|
||||
|
@ -194,7 +194,7 @@ int main(void)
|
|||
BeginDrawing();
|
||||
|
||||
ClearBackground(RAYWHITE);
|
||||
|
||||
|
||||
// TODO: Draw relevant connection info
|
||||
|
||||
EndDrawing();
|
||||
|
@ -204,7 +204,7 @@ int main(void)
|
|||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
CloseNetworkDevice(); // Close network communication
|
||||
|
||||
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
|
|
@ -22,17 +22,17 @@ int main(void)
|
|||
const int screenHeight = 450;
|
||||
|
||||
InitWindow(screenWidth, screenHeight, "raylib [network] example - resolve host");
|
||||
|
||||
|
||||
InitNetworkDevice(); // Init network communications
|
||||
|
||||
|
||||
char buffer[ADDRESS_IPV6_ADDRSTRLEN];
|
||||
unsigned short port = 0;
|
||||
|
||||
AddressInformation *address = LoadAddressList(1);
|
||||
|
||||
|
||||
// Address info flags
|
||||
// ADDRESS_INFO_NUMERICHOST // or try them in conjunction to
|
||||
// ADDRESS_INFO_NUMERICSERV // specify custom behaviour from
|
||||
// ADDRESS_INFO_NUMERICSERV // specify custom behaviour from
|
||||
// ADDRESS_INFO_DNS_ONLY // the function getaddrinfo()
|
||||
// ADDRESS_INFO_ALL //
|
||||
// ADDRESS_INFO_FQDN // e.g. ADDRESS_INFO_CANONNAME | ADDRESS_INFO_NUMERICSERV
|
||||
|
@ -70,7 +70,7 @@ int main(void)
|
|||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
CloseNetworkDevice(); // Close network communication
|
||||
|
||||
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
|
|
@ -24,10 +24,10 @@ int main(void)
|
|||
InitWindow(screenWidth, screenHeight, "raylib [network] example - tcp client");
|
||||
|
||||
InitNetworkDevice(); // Init network communications
|
||||
|
||||
|
||||
const char *pingmsg = "Ping!";
|
||||
const char *pongmsg = "Pong!";
|
||||
|
||||
|
||||
bool ping = false;
|
||||
bool pong = false;
|
||||
float elapsed = 0.0f;
|
||||
|
@ -35,12 +35,12 @@ int main(void)
|
|||
bool connected = false;
|
||||
|
||||
SocketConfig clientConfig = {
|
||||
.host = "127.0.0.1",
|
||||
.port = "4950",
|
||||
.type = SOCKET_TCP,
|
||||
.host = "127.0.0.1",
|
||||
.port = "4950",
|
||||
.type = SOCKET_TCP,
|
||||
.nonblocking = true
|
||||
};
|
||||
|
||||
|
||||
SocketSet *socketSet = NULL;
|
||||
SocketResult *clientResult = NULL;
|
||||
char receiveBuffer[512] = { 0 };
|
||||
|
@ -48,9 +48,9 @@ int main(void)
|
|||
// Create the client: getaddrinfo + socket + setsockopt + connect (TCP only)
|
||||
clientResult = LoadSocketResult();
|
||||
if (!SocketCreate(&clientConfig, clientResult)) TraceLog(LOG_WARNING, "Failed to open client: status %d, errno %d", clientResult->status, clientResult->socket->status);
|
||||
else
|
||||
else
|
||||
{
|
||||
if (!(clientConfig.type == SOCKET_UDP))
|
||||
if (!(clientConfig.type == SOCKET_UDP))
|
||||
{
|
||||
if (!SocketConnect(&clientConfig, clientResult)) TraceLog(LOG_WARNING, "Failed to connect to server: status %d, errno %d", clientResult->status, clientResult->socket->status);
|
||||
}
|
||||
|
@ -83,7 +83,7 @@ int main(void)
|
|||
if (IsSocketReady(clientResult->socket)) bytesRecv = SocketReceive(clientResult->socket, receiveBuffer, (int)strlen(pingmsg) + 1);
|
||||
|
||||
// If we received data, was that data a "Ping!" or a "Pong!"
|
||||
if (bytesRecv > 0)
|
||||
if (bytesRecv > 0)
|
||||
{
|
||||
if (strcmp(receiveBuffer, pingmsg) == 0) { pong = true; }
|
||||
if (strcmp(receiveBuffer, pongmsg) == 0) { ping = true; }
|
||||
|
@ -91,19 +91,19 @@ int main(void)
|
|||
|
||||
// After each delay has expired, send a response "Ping!" for a "Pong!" and vice versa
|
||||
elapsed += GetFrameTime();
|
||||
if (elapsed > delay)
|
||||
if (elapsed > delay)
|
||||
{
|
||||
if (ping)
|
||||
if (ping)
|
||||
{
|
||||
ping = false;
|
||||
SocketSend(clientResult->socket, pingmsg, (int)strlen(pingmsg) + 1);
|
||||
}
|
||||
else if (pong)
|
||||
else if (pong)
|
||||
{
|
||||
pong = false;
|
||||
SocketSend(clientResult->socket, pongmsg, (int)strlen(pingmsg) + 1);
|
||||
}
|
||||
|
||||
|
||||
elapsed = 0.0f;
|
||||
}
|
||||
}
|
||||
|
@ -124,7 +124,7 @@ int main(void)
|
|||
BeginDrawing();
|
||||
|
||||
ClearBackground(RAYWHITE);
|
||||
|
||||
|
||||
// TODO: Draw relevant connection info
|
||||
|
||||
EndDrawing();
|
||||
|
@ -134,7 +134,7 @@ int main(void)
|
|||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
CloseNetworkDevice(); // Close network communication
|
||||
|
||||
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
|
|
@ -24,10 +24,10 @@ int main(void)
|
|||
InitWindow(screenWidth, screenHeight, "raylib [network] example - tcp server");
|
||||
|
||||
InitNetworkDevice(); // Init network communications
|
||||
|
||||
|
||||
const char *pingmsg = "Ping!";
|
||||
const char *pongmsg = "Pong!";
|
||||
|
||||
|
||||
bool ping = false;
|
||||
bool pong = false;
|
||||
float elapsed = 0.0f;
|
||||
|
@ -35,32 +35,32 @@ int main(void)
|
|||
bool connected = false;
|
||||
|
||||
SocketConfig serverConfig = {
|
||||
.host = "127.0.0.1",
|
||||
.port = "4950",
|
||||
.host = "127.0.0.1",
|
||||
.port = "4950",
|
||||
.type = SOCKET_TCP,
|
||||
.server = true,
|
||||
.nonblocking = true
|
||||
};
|
||||
|
||||
|
||||
SocketConfig connectionConfig = { .nonblocking = true };
|
||||
|
||||
|
||||
Socket *connection = NULL;
|
||||
SocketSet *socketSet = NULL;
|
||||
SocketResult *serverResult = NULL;
|
||||
char receiveBuffer[512] = { 0 };
|
||||
|
||||
|
||||
// Create the server: getaddrinfo + socket + setsockopt + bind + listen
|
||||
serverResult = LoadSocketResult();
|
||||
if (!SocketCreate(&serverConfig, serverResult))
|
||||
if (!SocketCreate(&serverConfig, serverResult))
|
||||
{
|
||||
TraceLog(LOG_WARNING, "Failed to open server: status %d, errno %d", serverResult->status, serverResult->socket->status);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!SocketBind(&serverConfig, serverResult))
|
||||
{
|
||||
TraceLog(LOG_WARNING, "Failed to bind server: status %d, errno %d", serverResult->status, serverResult->socket->status);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!(serverConfig.type == SOCKET_UDP))
|
||||
|
@ -107,17 +107,17 @@ int main(void)
|
|||
elapsed += GetFrameTime();
|
||||
if (elapsed > delay)
|
||||
{
|
||||
if (ping)
|
||||
if (ping)
|
||||
{
|
||||
ping = false;
|
||||
SocketSend(connection, pingmsg, (int)strlen(pingmsg) + 1);
|
||||
}
|
||||
}
|
||||
else if (pong)
|
||||
{
|
||||
pong = false;
|
||||
SocketSend(connection, pongmsg, (int)strlen(pingmsg) + 1);
|
||||
}
|
||||
|
||||
|
||||
elapsed = 0.0f;
|
||||
}
|
||||
}
|
||||
|
@ -127,9 +127,9 @@ int main(void)
|
|||
int active = CheckSockets(socketSet, 0);
|
||||
if (active != 0) TraceLog(LOG_DEBUG, "There are currently %d socket(s) with data to be processed.", active);
|
||||
|
||||
if (active > 0)
|
||||
if (active > 0)
|
||||
{
|
||||
if ((connection = SocketAccept(serverResult->socket, &connectionConfig)) != NULL)
|
||||
if ((connection = SocketAccept(serverResult->socket, &connectionConfig)) != NULL)
|
||||
{
|
||||
AddSocket(socketSet, connection);
|
||||
connected = true;
|
||||
|
@ -144,7 +144,7 @@ int main(void)
|
|||
BeginDrawing();
|
||||
|
||||
ClearBackground(RAYWHITE);
|
||||
|
||||
|
||||
// TODO: Draw relevant connection info
|
||||
|
||||
EndDrawing();
|
||||
|
@ -154,7 +154,7 @@ int main(void)
|
|||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
CloseNetworkDevice(); // Close network communication
|
||||
|
||||
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
|
|
@ -85,7 +85,7 @@ void test_resolve_host()
|
|||
const char *address = "localhost";
|
||||
const char *port = "80";
|
||||
AddressInformation *addr = LoadAddressList(3);
|
||||
int count = ResolveHost(address, port, ADDRESS_TYPE_ANY, 0, addr);
|
||||
int count = ResolveHost(address, port, ADDRESS_TYPE_ANY, 0, addr);
|
||||
|
||||
assert(GetAddressFamily(addr[0]) == ADDRESS_TYPE_IPV6);
|
||||
assert(GetAddressFamily(addr[1]) == ADDRESS_TYPE_IPV4);
|
||||
|
@ -122,9 +122,9 @@ int main(void)
|
|||
const int screenHeight = 450;
|
||||
|
||||
InitWindow(screenWidth, screenHeight, "raylib [network] example - network test");
|
||||
|
||||
|
||||
InitNetworkDevice(); // Init network communications
|
||||
|
||||
|
||||
// Run some tests
|
||||
test_resolve_host();
|
||||
//test_socket_create();
|
||||
|
@ -146,7 +146,7 @@ int main(void)
|
|||
BeginDrawing();
|
||||
|
||||
ClearBackground(RAYWHITE);
|
||||
|
||||
|
||||
// TODO: Draw relevant connection info
|
||||
|
||||
EndDrawing();
|
||||
|
@ -156,7 +156,7 @@ int main(void)
|
|||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
CloseNetworkDevice(); // Close network communication
|
||||
|
||||
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
|
|
@ -24,22 +24,22 @@ int main(void)
|
|||
InitWindow(screenWidth, screenHeight, "raylib [network] example - udp client");
|
||||
|
||||
InitNetworkDevice(); // Init network communications
|
||||
|
||||
|
||||
const char *pingmsg = "Ping!";
|
||||
const char *pongmsg = "Pong!";
|
||||
|
||||
|
||||
bool ping = true;
|
||||
bool pong = false;
|
||||
float elapsed = 0.0f;
|
||||
float delay = 1.0f;
|
||||
|
||||
SocketConfig clientConfig = {
|
||||
.host = "127.0.0.1",
|
||||
.port = "4950",
|
||||
.type = SOCKET_UDP,
|
||||
.host = "127.0.0.1",
|
||||
.port = "4950",
|
||||
.type = SOCKET_UDP,
|
||||
.nonblocking = true
|
||||
};
|
||||
|
||||
|
||||
SocketResult *clientResult = NULL;
|
||||
SocketSet *socketSet = NULL;
|
||||
char receiveBuffer[512] = { 0 };
|
||||
|
@ -76,7 +76,7 @@ int main(void)
|
|||
if (IsSocketReady(clientResult->socket)) bytesRecv = SocketReceive(clientResult->socket, receiveBuffer, (int)strlen(pingmsg) + 1);
|
||||
|
||||
// If we received data, was that data a "Ping!" or a "Pong!"
|
||||
if (bytesRecv > 0)
|
||||
if (bytesRecv > 0)
|
||||
{
|
||||
if (strcmp(receiveBuffer, pingmsg) == 0) { pong = true; }
|
||||
if (strcmp(receiveBuffer, pongmsg) == 0) { ping = true; }
|
||||
|
@ -86,17 +86,17 @@ int main(void)
|
|||
elapsed += GetFrameTime();
|
||||
if (elapsed > delay)
|
||||
{
|
||||
if (ping)
|
||||
if (ping)
|
||||
{
|
||||
ping = false;
|
||||
SocketSend(clientResult->socket, pingmsg, (int)strlen(pingmsg) + 1);
|
||||
}
|
||||
}
|
||||
else if (pong)
|
||||
{
|
||||
pong = false;
|
||||
SocketSend(clientResult->socket, pongmsg, (int)strlen(pongmsg) + 1);
|
||||
}
|
||||
|
||||
|
||||
elapsed = 0.0f;
|
||||
}
|
||||
//----------------------------------------------------------------------------------
|
||||
|
@ -106,7 +106,7 @@ int main(void)
|
|||
BeginDrawing();
|
||||
|
||||
ClearBackground(RAYWHITE);
|
||||
|
||||
|
||||
// TODO: Draw relevant connection info
|
||||
|
||||
EndDrawing();
|
||||
|
@ -116,7 +116,7 @@ int main(void)
|
|||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
CloseNetworkDevice(); // Close network communication
|
||||
|
||||
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
|
|
@ -24,30 +24,30 @@ int main(void)
|
|||
InitWindow(screenWidth, screenHeight, "raylib [network] example - udp server");
|
||||
|
||||
InitNetworkDevice(); // Init network communications
|
||||
|
||||
|
||||
const char *pingmsg = "Ping!";
|
||||
const char *pongmsg = "Pong!";
|
||||
|
||||
|
||||
bool ping = false;
|
||||
bool pong = false;
|
||||
float elapsed = 0.0f;
|
||||
float delay = 1.0f;
|
||||
|
||||
SocketConfig serverConfig = {
|
||||
.host = "127.0.0.1",
|
||||
.port = "4950",
|
||||
.server = true,
|
||||
.type = SOCKET_UDP,
|
||||
.host = "127.0.0.1",
|
||||
.port = "4950",
|
||||
.server = true,
|
||||
.type = SOCKET_UDP,
|
||||
.nonblocking = true
|
||||
};
|
||||
|
||||
|
||||
SocketResult *serverResult = NULL;
|
||||
SocketSet *socketSet = NULL;
|
||||
char receiveBuffer[512] = { 0 };
|
||||
|
||||
// Create the server: getaddrinfo + socket + setsockopt + bind + listen
|
||||
serverResult = LoadSocketResult();
|
||||
|
||||
|
||||
if (!SocketCreate(&serverConfig, serverResult)) TraceLog(LOG_WARNING, "Failed to open server: status %d, errno %d", serverResult->status, serverResult->socket->status);
|
||||
else if (!SocketBind(&serverConfig, serverResult)) TraceLog(LOG_WARNING, "Failed to bind server: status %d, errno %d", serverResult->status, serverResult->socket->status);
|
||||
|
||||
|
@ -65,7 +65,7 @@ int main(void)
|
|||
//----------------------------------------------------------------------------------
|
||||
// Once connected to the network, check the sockets for pending information
|
||||
// and when information is ready, send either a Ping or a Pong.
|
||||
|
||||
|
||||
// CheckSockets, if any of the sockets in the set are pending (received data, or requests)
|
||||
// then mark the socket as being ready. You can check this with IsSocketReady(client_res->socket)
|
||||
int active = CheckSockets(socketSet, 0);
|
||||
|
@ -79,7 +79,7 @@ int main(void)
|
|||
int bytesRecv = SocketReceive(serverResult->socket, receiveBuffer, (int)strlen(pingmsg) + 1);
|
||||
|
||||
// If we received data, is that data a "Ping!" or a "Pong!"?
|
||||
if (bytesRecv > 0)
|
||||
if (bytesRecv > 0)
|
||||
{
|
||||
if (strcmp(receiveBuffer, pingmsg) == 0) { pong = true; }
|
||||
if (strcmp(receiveBuffer, pongmsg) == 0) { ping = true; }
|
||||
|
@ -87,20 +87,20 @@ int main(void)
|
|||
|
||||
// After each delay has expired, send a response "Ping!" for a "Pong!" and vice-versa
|
||||
elapsed += GetFrameTime();
|
||||
|
||||
|
||||
if (elapsed > delay)
|
||||
{
|
||||
if (ping)
|
||||
if (ping)
|
||||
{
|
||||
ping = false;
|
||||
SocketSend(serverResult->socket, pingmsg, (int)strlen(pingmsg) + 1);
|
||||
}
|
||||
else if (pong)
|
||||
}
|
||||
else if (pong)
|
||||
{
|
||||
pong = false;
|
||||
SocketSend(serverResult->socket, pongmsg, (int)strlen(pongmsg) + 1);
|
||||
}
|
||||
|
||||
|
||||
elapsed = 0.0f;
|
||||
}
|
||||
//----------------------------------------------------------------------------------
|
||||
|
@ -120,7 +120,7 @@ int main(void)
|
|||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
CloseNetworkDevice(); // Close network communication
|
||||
|
||||
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
|
|
@ -107,7 +107,7 @@ int main(void)
|
|||
InitWindow(screenWidth, screenHeight, "raylib [easings] example - easings testbed");
|
||||
|
||||
Vector2 ballPosition = { 100.0f, 200.0f };
|
||||
|
||||
|
||||
float t = 0.0f; // Current time (in any unit measure, but same unit as duration)
|
||||
float d = 300.0f; // Total time it should take to complete (duration)
|
||||
bool paused = true;
|
||||
|
|
|
@ -28,7 +28,7 @@ int main(void)
|
|||
InitAudioDevice(); // Initialize audio device
|
||||
|
||||
// Loaded in CPU memory (RAM) from header file (audio_data.h)
|
||||
// Same as: Wave wave = LoadWave("sound.wav");
|
||||
// Same as: Wave wave = LoadWave("sound.wav");
|
||||
Wave wave = {
|
||||
.data = AUDIO_DATA,
|
||||
.sampleCount = AUDIO_SAMPLE_COUNT,
|
||||
|
@ -39,14 +39,14 @@ int main(void)
|
|||
|
||||
// Wave converted to Sound to be played
|
||||
Sound sound = LoadSoundFromWave(wave);
|
||||
|
||||
|
||||
// With a Wave loaded from file, after Sound is loaded, we can unload Wave
|
||||
// but in our case, Wave is embedded in executable, in program .data segment
|
||||
// we can not (and should not) try to free that private memory region
|
||||
//UnloadWave(wave); // Do not unload wave data!
|
||||
|
||||
// Loaded in CPU memory (RAM) from header file (image_data.h)
|
||||
// Same as: Image image = LoadImage("raylib_logo.png");
|
||||
// Same as: Image image = LoadImage("raylib_logo.png");
|
||||
Image image = {
|
||||
.data = IMAGE_DATA,
|
||||
.width = IMAGE_WIDTH,
|
||||
|
@ -54,15 +54,15 @@ int main(void)
|
|||
.format = IMAGE_FORMAT,
|
||||
.mipmaps = 1
|
||||
};
|
||||
|
||||
|
||||
// Image converted to Texture (VRAM) to be drawn
|
||||
Texture2D texture = LoadTextureFromImage(image);
|
||||
|
||||
Texture2D texture = LoadTextureFromImage(image);
|
||||
|
||||
// With an Image loaded from file, after Texture is loaded, we can unload Image
|
||||
// but in our case, Image is embedded in executable, in program .data segment
|
||||
// we can not (and should not) try to free that private memory region
|
||||
//UnloadImage(image); // Do not unload image data!
|
||||
|
||||
|
||||
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
* This example has been created using raylib 2ad3eb1 (www.raylib.com)
|
||||
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
|
||||
*
|
||||
* Example contributed by Stephan Soller (@arkanis - http://arkanis.de/)
|
||||
* Example contributed by Stephan Soller (@arkanis - http://arkanis.de/)
|
||||
* and reviewed by Ramon Santamaria (@raysan5)
|
||||
*
|
||||
* Copyright (c) 2021 Stephan Soller (@arkanis) and Ramon Santamaria (@raysan5)
|
||||
|
@ -14,10 +14,10 @@
|
|||
*
|
||||
* Mixes raylib and plain OpenGL code to draw a GL_POINTS based particle system. The
|
||||
* primary point is to demonstrate raylib and OpenGL interop.
|
||||
*
|
||||
*
|
||||
* rlgl batched draw operations internally so we have to flush the current batch before
|
||||
* doing our own OpenGL work (rlDrawRenderBatchActive()).
|
||||
*
|
||||
*
|
||||
* The example also demonstrates how to get the current model view projection matrix of
|
||||
* raylib. That way raylib cameras and so on work as expected.
|
||||
*
|
||||
|
@ -39,15 +39,15 @@ int main()
|
|||
//--------------------------------------------------------------------------------------
|
||||
const int screenWidth = 800;
|
||||
const int screenHeight = 450;
|
||||
|
||||
|
||||
InitWindow(screenWidth, screenHeight, "raylib - point particles");
|
||||
|
||||
|
||||
Shader shader = LoadShader(
|
||||
TextFormat("resources/shaders/glsl%i/point_particle.vs", GLSL_VERSION),
|
||||
TextFormat("resources/shaders/glsl%i/point_particle.fs", GLSL_VERSION));
|
||||
int currentTimeLoc = GetShaderLocation(shader, "currentTime");
|
||||
int colorLoc = GetShaderLocation(shader, "color");
|
||||
|
||||
|
||||
// Initialize the vertex buffer for the particles and assign each particle random values
|
||||
struct { float x, y, period; } particles[10000];
|
||||
const size_t particleCount = sizeof(particles) / sizeof(particles[0]);
|
||||
|
@ -59,7 +59,7 @@ int main()
|
|||
// every so often and you get a glimps of what is going on.
|
||||
particles[i].period = GetRandomValue(10, 30) / 10.0f;
|
||||
}
|
||||
|
||||
|
||||
// Create a plain OpenGL vertex buffer with the data and an vertex array object that feeds the data from the buffer
|
||||
// into the vertexPosition shader attribute.
|
||||
GLuint vao = 0, vbo = 0;
|
||||
|
@ -73,13 +73,13 @@ int main()
|
|||
glEnableVertexAttribArray(0);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
glBindVertexArray(0);
|
||||
|
||||
|
||||
// Allows the vertex shader to set the point size of each particle individually
|
||||
glEnable(GL_PROGRAM_POINT_SIZE);
|
||||
|
||||
|
||||
SetTargetFPS(60);
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Main game loop
|
||||
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||
{
|
||||
|
@ -87,46 +87,46 @@ int main()
|
|||
//----------------------------------------------------------------------------------
|
||||
BeginDrawing();
|
||||
ClearBackground(WHITE);
|
||||
|
||||
|
||||
DrawRectangle(10, 10, 210, 30, MAROON);
|
||||
DrawText(TextFormat("%zu particles in one vertex buffer", particleCount), 20, 20, 10, RAYWHITE);
|
||||
|
||||
|
||||
// Switch to plain OpenGL
|
||||
//------------------------------------------------------------------------------
|
||||
// rlglDraw() in raylib 3.5
|
||||
rlDrawRenderBatchActive();
|
||||
glUseProgram(shader.id);
|
||||
glUniform1f(currentTimeLoc, GetTime());
|
||||
|
||||
|
||||
Vector4 color = ColorNormalize((Color){ 255, 0, 0, 128 });
|
||||
glUniform4fv(colorLoc, 1, (float*)&color);
|
||||
|
||||
|
||||
// The the current model view projection matrix so the particle system is displayed and transformed
|
||||
// (e.g. by cameras) just like everything else.
|
||||
// GetMatrixModelview() and GetMatrixProjection() in raylib 3.5
|
||||
Matrix modelViewProjection = MatrixMultiply(rlGetMatrixModelview(), rlGetMatrixProjection());
|
||||
glUniformMatrix4fv(shader.locs[SHADER_LOC_MATRIX_MVP], 1, false, MatrixToFloat(modelViewProjection));
|
||||
|
||||
|
||||
glBindVertexArray(vao);
|
||||
glDrawArrays(GL_POINTS, 0, particleCount);
|
||||
glBindVertexArray(0);
|
||||
glUseProgram(0);
|
||||
|
||||
|
||||
// And back to raylib again
|
||||
//------------------------------------------------------------------------------
|
||||
DrawFPS(screenWidth - 100, 10);
|
||||
EndDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
|
||||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
glDeleteBuffers(1, &vbo);
|
||||
glDeleteVertexArrays(1, &vao);
|
||||
|
||||
|
||||
UnloadShader(shader);
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -15,7 +15,7 @@
|
|||
*
|
||||
* COMPILATION:
|
||||
* gcc -o raudio_standalone.exe raudio_standalone.c ..\..\src\raudio.c /
|
||||
* -I..\..\src -I..\..\src\external -L. -Wall -std=c99 -DRAUDIO_STANDALONE /
|
||||
* -I..\..\src -I..\..\src\external -L. -Wall -std=c99 -DRAUDIO_STANDALONE /
|
||||
* -DSUPPORT_FILEFORMAT_WAV -DSUPPORT_FILEFORMAT_OGG -DSUPPORT_FILEFORMAT_MP3
|
||||
*
|
||||
* LICENSE: zlib/libpng
|
||||
|
@ -96,7 +96,7 @@ int main(int argc, char *argv[])
|
|||
|
||||
if ((key == 's') || (key == 'S')) PlaySound(fxWav);
|
||||
if ((key == 'd') || (key == 'D')) PlaySound(fxOgg);
|
||||
|
||||
|
||||
key = 0;
|
||||
|
||||
UpdateMusicStream(music);
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
* rlgl.h - OpenGL 1.1 immediate-mode style coding translation layer
|
||||
* glad.h - OpenGL extensions initialization library (required by rlgl)
|
||||
* raymath.h - 3D math library (required by rlgl)
|
||||
* glfw3 - Windows and context initialization library
|
||||
* glfw3 - Windows and context initialization library
|
||||
*
|
||||
* rlgl library is provided as a single-file header-only library, this library
|
||||
* allows coding in a pseudo-OpenGL 1.1 style while translating calls to multiple
|
||||
|
@ -95,18 +95,18 @@ int main(void)
|
|||
//--------------------------------------------------------------------------------------
|
||||
const int screenWidth = 800;
|
||||
const int screenHeight = 450;
|
||||
|
||||
|
||||
// GLFW3 Initialization + OpenGL 3.3 Context + Extensions
|
||||
//--------------------------------------------------------
|
||||
glfwSetErrorCallback(ErrorCallback);
|
||||
|
||||
|
||||
if (!glfwInit())
|
||||
{
|
||||
printf("GLFW3: Can not initialize GLFW\n");
|
||||
return 1;
|
||||
}
|
||||
else printf("GLFW3: GLFW initialized successfully\n");
|
||||
|
||||
|
||||
glfwWindowHint(GLFW_SAMPLES, 4);
|
||||
glfwWindowHint(GLFW_DEPTH_BITS, 16);
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
|
||||
|
@ -117,27 +117,27 @@ int main(void)
|
|||
glfwWindowHint( GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE );
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
GLFWwindow *window = glfwCreateWindow(screenWidth, screenHeight, "rlgl standalone", NULL, NULL);
|
||||
|
||||
|
||||
if (!window)
|
||||
{
|
||||
glfwTerminate();
|
||||
return 2;
|
||||
}
|
||||
else printf("GLFW3: Window created successfully\n");
|
||||
|
||||
|
||||
glfwSetWindowPos(window, 200, 200);
|
||||
|
||||
|
||||
glfwSetKeyCallback(window, KeyCallback);
|
||||
|
||||
|
||||
glfwMakeContextCurrent(window);
|
||||
glfwSwapInterval(0);
|
||||
|
||||
|
||||
// Load OpenGL 3.3 supported extensions
|
||||
rlLoadExtensions(glfwGetProcAddress);
|
||||
//--------------------------------------------------------
|
||||
|
||||
|
||||
// Initialize OpenGL context (states and resources)
|
||||
rlglInit(screenWidth, screenHeight);
|
||||
|
||||
|
@ -151,18 +151,18 @@ int main(void)
|
|||
|
||||
rlClearColor(245, 245, 245, 255); // Define clear color
|
||||
rlEnableDepthTest(); // Enable DEPTH_TEST for 3D
|
||||
|
||||
|
||||
Camera camera = { 0 };
|
||||
camera.position = (Vector3){ 5.0f, 5.0f, 5.0f }; // Camera position
|
||||
camera.target = (Vector3){ 0.0f, 0.0f, 0.0f }; // Camera looking at point
|
||||
camera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; // Camera up vector (rotation towards target)
|
||||
camera.fovy = 45.0f; // Camera field-of-view Y
|
||||
|
||||
Vector3 cubePosition = { 0.0f, 0.0f, 0.0f }; // Cube default position (center)
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
// Main game loop
|
||||
while (!glfwWindowShouldClose(window))
|
||||
Vector3 cubePosition = { 0.0f, 0.0f, 0.0f }; // Cube default position (center)
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
// Main game loop
|
||||
while (!glfwWindowShouldClose(window))
|
||||
{
|
||||
// Update
|
||||
//----------------------------------------------------------------------------------
|
||||
|
@ -189,14 +189,14 @@ int main(void)
|
|||
// Draw internal render batch buffers (3D data)
|
||||
rlDrawRenderBatchActive();
|
||||
//-----------------------------------------------
|
||||
|
||||
|
||||
// Draw '2D' elements in the scene (GUI)
|
||||
//-----------------------------------------------
|
||||
#define RLGL_CREATE_MATRIX_MANUALLY
|
||||
#if defined(RLGL_CREATE_MATRIX_MANUALLY)
|
||||
matProj = MatrixOrtho(0.0, screenWidth, screenHeight, 0.0, 0.0, 1.0);
|
||||
matView = MatrixIdentity();
|
||||
|
||||
|
||||
rlSetMatrixModelview(matView); // Set internal modelview matrix (default shader)
|
||||
rlSetMatrixProjection(matProj); // Set internal projection matrix (default shader)
|
||||
|
||||
|
@ -213,7 +213,7 @@ int main(void)
|
|||
// Draw internal render batch buffers (3D data)
|
||||
rlDrawRenderBatchActive();
|
||||
//-----------------------------------------------
|
||||
|
||||
|
||||
glfwSwapBuffers(window);
|
||||
glfwPollEvents();
|
||||
//----------------------------------------------------------------------------------
|
||||
|
@ -222,11 +222,11 @@ int main(void)
|
|||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
rlglClose(); // Unload rlgl internal buffers and default shader/texture
|
||||
|
||||
|
||||
glfwDestroyWindow(window); // Close window
|
||||
glfwTerminate(); // Free GLFW3 resources
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -54,7 +54,7 @@ int main(void)
|
|||
if (IsKeyPressed(KEY_R)) // Reset physics system
|
||||
{
|
||||
ResetPhysics();
|
||||
|
||||
|
||||
floor = CreatePhysicsBodyRectangle((Vector2){ screenWidth/2, screenHeight }, 500, 100, 10);
|
||||
floor->enabled = false;
|
||||
|
||||
|
|
|
@ -48,7 +48,7 @@ int main(void)
|
|||
|
||||
// Restitution demo needs a very tiny physics time step for a proper simulation
|
||||
SetPhysicsTimeStep(1.0/60.0/100*1000);
|
||||
|
||||
|
||||
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
@ -119,7 +119,7 @@ int main(void)
|
|||
DestroyPhysicsBody(circleB);
|
||||
DestroyPhysicsBody(circleC);
|
||||
DestroyPhysicsBody(floor);
|
||||
|
||||
|
||||
ClosePhysics(); // Unitialize physics
|
||||
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
|
|
|
@ -45,7 +45,7 @@ int main(void)
|
|||
{
|
||||
//----------------------------------------------------------------------------------
|
||||
UpdatePhysics(); // Update physics system
|
||||
|
||||
|
||||
if (IsKeyPressed(KEY_R)) // Reset physics input
|
||||
{
|
||||
ResetPhysics();
|
||||
|
@ -59,7 +59,7 @@ int main(void)
|
|||
for (int i = count - 1; i >= 0; i--)
|
||||
{
|
||||
PhysicsBody currentBody = GetPhysicsBody(i);
|
||||
|
||||
|
||||
if (currentBody != NULL) PhysicsShatter(currentBody, GetMousePosition(), 10/currentBody->inverseMass);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -69,9 +69,9 @@ int main(void)
|
|||
modelB.materials[0].maps[MATERIAL_MAP_DIFFUSE].texture = texture;
|
||||
modelC.materials[0].maps[MATERIAL_MAP_DIFFUSE].texture = texture;
|
||||
|
||||
Shader shader = LoadShader(TextFormat("resources/shaders/glsl%i/base_lighting.vs", GLSL_VERSION),
|
||||
Shader shader = LoadShader(TextFormat("resources/shaders/glsl%i/base_lighting.vs", GLSL_VERSION),
|
||||
TextFormat("resources/shaders/glsl%i/lighting.fs", GLSL_VERSION));
|
||||
|
||||
|
||||
// Get some shader loactions
|
||||
shader.locs[SHADER_LOC_MATRIX_MODEL] = GetShaderLocation(shader, "matModel");
|
||||
shader.locs[SHADER_LOC_VECTOR_VIEW] = GetShaderLocation(shader, "viewPos");
|
||||
|
@ -79,7 +79,7 @@ int main(void)
|
|||
// ambient light level
|
||||
int ambientLoc = GetShaderLocation(shader, "ambient");
|
||||
SetShaderValue(shader, ambientLoc, (float[4]){ 0.2f, 0.2f, 0.2f, 1.0f }, SHADER_UNIFORM_VEC4);
|
||||
|
||||
|
||||
float angle = 6.282f;
|
||||
|
||||
// All models use the same shader
|
||||
|
@ -121,7 +121,7 @@ int main(void)
|
|||
lights[2].position.z = sinf(angle*0.2f)*4.0f;
|
||||
lights[3].position.y = cosf(-angle*0.35f)*4.0f;
|
||||
lights[3].position.z = sinf(-angle*0.35f)*4.0f;
|
||||
|
||||
|
||||
UpdateLightValues(shader, lights[0]);
|
||||
UpdateLightValues(shader, lights[1]);
|
||||
UpdateLightValues(shader, lights[2]);
|
||||
|
@ -160,7 +160,7 @@ int main(void)
|
|||
EndMode3D();
|
||||
|
||||
DrawFPS(10, 10);
|
||||
|
||||
|
||||
DrawText("Use keys RGBW to toggle lights", 10, 30, 20, DARKGRAY);
|
||||
|
||||
EndDrawing();
|
||||
|
@ -172,7 +172,7 @@ int main(void)
|
|||
UnloadModel(modelA); // Unload the modelA
|
||||
UnloadModel(modelB); // Unload the modelB
|
||||
UnloadModel(modelC); // Unload the modelC
|
||||
|
||||
|
||||
UnloadTexture(texture); // Unload the texture
|
||||
UnloadShader(shader); // Unload shader
|
||||
|
||||
|
|
|
@ -41,7 +41,7 @@ int main(void)
|
|||
InitWindow(screenWidth, screenHeight, "raylib [shaders] example - Sieve of Eratosthenes");
|
||||
|
||||
RenderTexture2D target = LoadRenderTexture(screenWidth, screenHeight);
|
||||
|
||||
|
||||
// Load Eratosthenes shader
|
||||
// NOTE: Defining 0 (NULL) for vertex shader forces usage of internal default vertex shader
|
||||
Shader shader = LoadShader(0, TextFormat("resources/shaders/glsl%i/eratosthenes.fs", GLSL_VERSION));
|
||||
|
|
|
@ -49,7 +49,7 @@ int main(void)
|
|||
InitWindow(screenWidth, screenHeight, "raylib [shaders] example - fog");
|
||||
|
||||
// Define the camera to look into our 3d world
|
||||
Camera camera = {
|
||||
Camera camera = {
|
||||
(Vector3){ 2.0f, 2.0f, 6.0f }, // position
|
||||
(Vector3){ 0.0f, 0.5f, 0.0f }, // target
|
||||
(Vector3){ 0.0f, 1.0f, 0.0f }, // up
|
||||
|
@ -67,7 +67,7 @@ int main(void)
|
|||
modelC.materials[0].maps[MATERIAL_MAP_DIFFUSE].texture = texture;
|
||||
|
||||
// Load shader and set up some uniforms
|
||||
Shader shader = LoadShader(TextFormat("resources/shaders/glsl%i/base_lighting.vs", GLSL_VERSION),
|
||||
Shader shader = LoadShader(TextFormat("resources/shaders/glsl%i/base_lighting.vs", GLSL_VERSION),
|
||||
TextFormat("resources/shaders/glsl%i/fog.fs", GLSL_VERSION));
|
||||
shader.locs[SHADER_LOC_MATRIX_MODEL] = GetShaderLocation(shader, "matModel");
|
||||
shader.locs[SHADER_LOC_VECTOR_VIEW] = GetShaderLocation(shader, "viewPos");
|
||||
|
@ -75,7 +75,7 @@ int main(void)
|
|||
// Ambient light level
|
||||
int ambientLoc = GetShaderLocation(shader, "ambient");
|
||||
SetShaderValue(shader, ambientLoc, (float[4]){ 0.2f, 0.2f, 0.2f, 1.0f }, SHADER_UNIFORM_VEC4);
|
||||
|
||||
|
||||
float fogDensity = 0.15f;
|
||||
int fogDensityLoc = GetShaderLocation(shader, "fogDensity");
|
||||
SetShaderValue(shader, fogDensityLoc, &fogDensity, SHADER_UNIFORM_FLOAT);
|
||||
|
@ -100,18 +100,18 @@ int main(void)
|
|||
//----------------------------------------------------------------------------------
|
||||
UpdateCamera(&camera); // Update camera
|
||||
|
||||
if (IsKeyDown(KEY_UP))
|
||||
if (IsKeyDown(KEY_UP))
|
||||
{
|
||||
fogDensity += 0.001;
|
||||
if (fogDensity > 1.0) fogDensity = 1.0;
|
||||
}
|
||||
|
||||
|
||||
if (IsKeyDown(KEY_DOWN))
|
||||
{
|
||||
fogDensity -= 0.001;
|
||||
if (fogDensity < 0.0) fogDensity = 0.0;
|
||||
}
|
||||
|
||||
|
||||
SetShaderValue(shader, fogDensityLoc, &fogDensity, SHADER_UNIFORM_FLOAT);
|
||||
|
||||
// Rotate the torus
|
||||
|
|
|
@ -65,36 +65,36 @@ int main(void)
|
|||
// Set shader required uniform values
|
||||
SetShaderValue(shader, timeLoc, &totalTime, SHADER_UNIFORM_FLOAT);
|
||||
SetShaderValue(shader, mouseLoc, mousePos, SHADER_UNIFORM_VEC2);
|
||||
|
||||
|
||||
// Hot shader reloading
|
||||
if (shaderAutoReloading || (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)))
|
||||
{
|
||||
long currentFragShaderModTime = GetFileModTime(TextFormat(fragShaderFileName, GLSL_VERSION));
|
||||
|
||||
|
||||
// Check if shader file has been modified
|
||||
if (currentFragShaderModTime != fragShaderFileModTime)
|
||||
{
|
||||
// Try reloading updated shader
|
||||
Shader updatedShader = LoadShader(0, TextFormat(fragShaderFileName, GLSL_VERSION));
|
||||
|
||||
|
||||
if (updatedShader.id != rlGetShaderDefault().id) // It was correctly loaded
|
||||
{
|
||||
UnloadShader(shader);
|
||||
shader = updatedShader;
|
||||
|
||||
|
||||
// Get shader locations for required uniforms
|
||||
resolutionLoc = GetShaderLocation(shader, "resolution");
|
||||
mouseLoc = GetShaderLocation(shader, "mouse");
|
||||
timeLoc = GetShaderLocation(shader, "time");
|
||||
|
||||
|
||||
// Reset required uniforms
|
||||
SetShaderValue(shader, resolutionLoc, resolution, SHADER_UNIFORM_VEC2);
|
||||
}
|
||||
|
||||
|
||||
fragShaderFileModTime = currentFragShaderModTime;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (IsKeyPressed(KEY_A)) shaderAutoReloading = !shaderAutoReloading;
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
|
@ -109,10 +109,10 @@ int main(void)
|
|||
DrawRectangle(0, 0, screenWidth, screenHeight, WHITE);
|
||||
EndShaderMode();
|
||||
|
||||
DrawText(TextFormat("PRESS [A] to TOGGLE SHADER AUTOLOADING: %s",
|
||||
DrawText(TextFormat("PRESS [A] to TOGGLE SHADER AUTOLOADING: %s",
|
||||
shaderAutoReloading? "AUTO" : "MANUAL"), 10, 10, 10, shaderAutoReloading? RED : BLACK);
|
||||
if (!shaderAutoReloading) DrawText("MOUSE CLICK to SHADER RE-LOADING", 10, 30, 10, BLACK);
|
||||
|
||||
|
||||
DrawText(TextFormat("Shader last modification: %s", asctime(localtime(&fragShaderFileModTime))), 10, 430, 10, BLACK);
|
||||
|
||||
EndDrawing();
|
||||
|
|
|
@ -48,7 +48,7 @@ int main(void)
|
|||
// Load julia set shader
|
||||
// NOTE: Defining 0 (NULL) for vertex shader forces usage of internal default vertex shader
|
||||
Shader shader = LoadShader(0, TextFormat("resources/shaders/glsl%i/julia_set.fs", GLSL_VERSION));
|
||||
|
||||
|
||||
// Create a RenderTexture2D to be used for render to texture
|
||||
RenderTexture2D target = LoadRenderTexture(GetScreenWidth(), GetScreenHeight());
|
||||
|
||||
|
@ -74,7 +74,7 @@ int main(void)
|
|||
SetShaderValue(shader, cLoc, c, SHADER_UNIFORM_VEC2);
|
||||
SetShaderValue(shader, zoomLoc, &zoom, SHADER_UNIFORM_FLOAT);
|
||||
SetShaderValue(shader, offsetLoc, offset, SHADER_UNIFORM_VEC2);
|
||||
|
||||
|
||||
int incrementSpeed = 0; // Multiplier of speed to change c value
|
||||
bool showControls = true; // Show controls
|
||||
bool pause = false; // Pause animation
|
||||
|
|
|
@ -56,7 +56,7 @@ int main(void)
|
|||
camera.fovy = 45.0f;
|
||||
camera.projection = CAMERA_PERSPECTIVE;
|
||||
|
||||
const int instances = 10000; // Number of instances to display
|
||||
const int instances = 10000; // Number of instances to display
|
||||
Mesh cube = GenMeshCube(1.0f, 1.0f, 1.0f);
|
||||
|
||||
Matrix *rotations = RL_MALLOC(instances*sizeof(Matrix)); // Rotation state of instances
|
||||
|
@ -69,7 +69,7 @@ int main(void)
|
|||
x = GetRandomValue(-50, 50);
|
||||
y = GetRandomValue(-50, 50);
|
||||
z = GetRandomValue(-50, 50);
|
||||
translations[i] = MatrixTranslate(x, y, z);
|
||||
translations[i] = MatrixTranslate(x, y, z);
|
||||
|
||||
x = GetRandomValue(0, 360);
|
||||
y = GetRandomValue(0, 360);
|
||||
|
@ -83,7 +83,7 @@ int main(void)
|
|||
|
||||
Matrix *transforms = RL_MALLOC(instances*sizeof(Matrix)); // Pre-multiplied transformations passed to rlgl
|
||||
|
||||
Shader shader = LoadShader(TextFormat("resources/shaders/glsl%i/base_lighting_instanced.vs", GLSL_VERSION),
|
||||
Shader shader = LoadShader(TextFormat("resources/shaders/glsl%i/base_lighting_instanced.vs", GLSL_VERSION),
|
||||
TextFormat("resources/shaders/glsl%i/lighting.fs", GLSL_VERSION));
|
||||
|
||||
// Get some shader loactions
|
||||
|
@ -102,7 +102,7 @@ int main(void)
|
|||
Material material = LoadMaterialDefault();
|
||||
material.shader = shader;
|
||||
material.maps[MATERIAL_MAP_DIFFUSE].color = RED;
|
||||
|
||||
|
||||
SetCameraMode(camera, CAMERA_ORBITAL); // Set an orbital camera mode
|
||||
|
||||
int textPositionY = 300;
|
||||
|
@ -134,10 +134,10 @@ int main(void)
|
|||
if (IsKeyDown(KEY_EIGHT)) groups = 8;
|
||||
if (IsKeyDown(KEY_NINE)) groups = 9;
|
||||
if (IsKeyDown(KEY_W)) { groups = 7; amp = 25; speed = 18; variance = 0.70f; }
|
||||
|
||||
|
||||
if (IsKeyDown(KEY_EQUAL)) speed = (speed <= (fps*0.25f))? (fps*0.25f) : (speed*0.95f);
|
||||
if (IsKeyDown(KEY_KP_ADD)) speed = (speed <= (fps*0.25f))? (fps*0.25f) : (speed*0.95f);
|
||||
|
||||
|
||||
if (IsKeyDown(KEY_MINUS)) speed = fmaxf(speed*1.02f, speed + 1);
|
||||
if (IsKeyDown(KEY_KP_SUBTRACT)) speed = fmaxf(speed*1.02f, speed + 1);
|
||||
|
||||
|
@ -150,19 +150,19 @@ int main(void)
|
|||
{
|
||||
rotations[i] = MatrixMultiply(rotations[i], rotationsInc[i]);
|
||||
transforms[i] = MatrixMultiply(rotations[i], translations[i]);
|
||||
|
||||
|
||||
// Get the animation cycle's framesCounter for this instance
|
||||
loop = (float)((framesCounter + (int)(((float)(i%groups)/groups)*speed))%speed)/speed;
|
||||
|
||||
|
||||
// Calculate the y according to loop cycle
|
||||
y = (sinf(loop*PI*2))*amp*((1 - variance) + (variance*(float)(i%(groups*10))/(groups*10)));
|
||||
|
||||
|
||||
// Clamp to floor
|
||||
y = (y < 0)? 0.0f : y;
|
||||
|
||||
|
||||
transforms[i] = MatrixMultiply(transforms[i], MatrixTranslate(0.0f, y, 0.0f));
|
||||
}
|
||||
|
||||
|
||||
UpdateCamera(&camera);
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
|
@ -179,35 +179,35 @@ int main(void)
|
|||
|
||||
DrawText("A CUBE OF DANCING CUBES!", 490, 10, 20, MAROON);
|
||||
DrawText("PRESS KEYS:", 10, textPositionY, 20, BLACK);
|
||||
|
||||
DrawText("1 - 9", 10, textPositionY += 25, 10, BLACK);
|
||||
|
||||
DrawText("1 - 9", 10, textPositionY += 25, 10, BLACK);
|
||||
DrawText(": Number of groups", 50, textPositionY , 10, BLACK);
|
||||
DrawText(TextFormat(": %d", groups), 160, textPositionY , 10, BLACK);
|
||||
|
||||
DrawText("UP", 10, textPositionY += 15, 10, BLACK);
|
||||
|
||||
DrawText("UP", 10, textPositionY += 15, 10, BLACK);
|
||||
DrawText(": increase amplitude", 50, textPositionY, 10, BLACK);
|
||||
DrawText(TextFormat(": %.2f", amp), 160, textPositionY , 10, BLACK);
|
||||
|
||||
DrawText("DOWN", 10, textPositionY += 15, 10, BLACK);
|
||||
|
||||
DrawText("DOWN", 10, textPositionY += 15, 10, BLACK);
|
||||
DrawText(": decrease amplitude", 50, textPositionY, 10, BLACK);
|
||||
|
||||
DrawText("LEFT", 10, textPositionY += 15, 10, BLACK);
|
||||
|
||||
DrawText("LEFT", 10, textPositionY += 15, 10, BLACK);
|
||||
DrawText(": decrease variance", 50, textPositionY, 10, BLACK);
|
||||
DrawText(TextFormat(": %.2f", variance), 160, textPositionY , 10, BLACK);
|
||||
|
||||
DrawText("RIGHT", 10, textPositionY += 15, 10, BLACK);
|
||||
|
||||
DrawText("RIGHT", 10, textPositionY += 15, 10, BLACK);
|
||||
DrawText(": increase variance", 50, textPositionY, 10, BLACK);
|
||||
|
||||
DrawText("+/=", 10, textPositionY += 15, 10, BLACK);
|
||||
|
||||
DrawText("+/=", 10, textPositionY += 15, 10, BLACK);
|
||||
DrawText(": increase speed", 50, textPositionY, 10, BLACK);
|
||||
DrawText(TextFormat(": %d = %f loops/sec", speed, ((float)fps / speed)), 160, textPositionY , 10, BLACK);
|
||||
|
||||
DrawText("-", 10, textPositionY += 15, 10, BLACK);
|
||||
|
||||
DrawText("-", 10, textPositionY += 15, 10, BLACK);
|
||||
DrawText(": decrease speed", 50, textPositionY, 10, BLACK);
|
||||
|
||||
DrawText("W", 10, textPositionY += 15, 10, BLACK);
|
||||
|
||||
DrawText("W", 10, textPositionY += 15, 10, BLACK);
|
||||
DrawText(": Wild setup!", 50, textPositionY, 10, BLACK);
|
||||
|
||||
|
||||
DrawFPS(10, 10);
|
||||
|
||||
EndDrawing();
|
||||
|
|
|
@ -42,10 +42,10 @@ int main(void)
|
|||
UnloadImage(imBlue);
|
||||
|
||||
Shader shader = LoadShader(0, TextFormat("resources/shaders/glsl%i/color_mix.fs", GLSL_VERSION));
|
||||
|
||||
|
||||
// Get an additional sampler2D location to be enabled on drawing
|
||||
int texBlueLoc = GetShaderLocation(shader, "texture1");
|
||||
|
||||
|
||||
// Get shader uniform for divider
|
||||
int dividerLoc = GetShaderLocation(shader, "divider");
|
||||
float dividerValue = 0.5f;
|
||||
|
@ -60,34 +60,34 @@ int main(void)
|
|||
//----------------------------------------------------------------------------------
|
||||
if (IsKeyDown(KEY_RIGHT)) dividerValue += 0.01f;
|
||||
else if (IsKeyDown(KEY_LEFT)) dividerValue -= 0.01f;
|
||||
|
||||
|
||||
if (dividerValue < 0.0f) dividerValue = 0.0f;
|
||||
else if (dividerValue > 1.0f) dividerValue = 1.0f;
|
||||
|
||||
|
||||
SetShaderValue(shader, dividerLoc, ÷rValue, SHADER_UNIFORM_FLOAT);
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
BeginDrawing();
|
||||
|
||||
|
||||
ClearBackground(RAYWHITE);
|
||||
|
||||
BeginShaderMode(shader);
|
||||
|
||||
|
||||
// WARNING: Additional samplers are enabled for all draw calls in the batch,
|
||||
// EndShaderMode() forces batch drawing and consequently resets active textures
|
||||
// to let other sampler2D to be activated on consequent drawings (if required)
|
||||
SetShaderValueTexture(shader, texBlueLoc, texBlue);
|
||||
|
||||
|
||||
// We are drawing texRed using default sampler2D texture0 but
|
||||
// an additional texture units is enabled for texBlue (sampler2D texture1)
|
||||
DrawTexture(texRed, 0, 0, WHITE);
|
||||
|
||||
|
||||
EndShaderMode();
|
||||
|
||||
|
||||
DrawText("Use KEY_LEFT/KEY_RIGHT to move texture mixing in shader!", 80, GetScreenHeight() - 40, 20, RAYWHITE);
|
||||
|
||||
|
||||
EndDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
|
|
|
@ -73,7 +73,7 @@ int main(void)
|
|||
SetShaderValue(shader, viewEyeLoc, cameraPos, SHADER_UNIFORM_VEC3);
|
||||
SetShaderValue(shader, viewCenterLoc, cameraTarget, SHADER_UNIFORM_VEC3);
|
||||
SetShaderValue(shader, runTimeLoc, &runTime, SHADER_UNIFORM_FLOAT);
|
||||
|
||||
|
||||
// Check if screen is resized
|
||||
if (IsWindowResized())
|
||||
{
|
||||
|
|
|
@ -57,7 +57,7 @@ int main(void)
|
|||
|
||||
// Load the shader
|
||||
Shader shader = LoadShader(0, TextFormat("resources/shaders/glsl%i/mask.fs", GLSL_VERSION));
|
||||
|
||||
|
||||
// Load and apply the diffuse texture (colour map)
|
||||
Texture texDiffuse = LoadTexture("resources/plasma.png");
|
||||
model1.materials[0].maps[MATERIAL_MAP_DIFFUSE].texture = texDiffuse;
|
||||
|
@ -131,10 +131,10 @@ int main(void)
|
|||
UnloadModel(model1);
|
||||
UnloadModel(model2);
|
||||
UnloadModel(model3);
|
||||
|
||||
|
||||
UnloadTexture(texDiffuse); // Unload default diffuse texture
|
||||
UnloadTexture(texMask); // Unload texture mask
|
||||
|
||||
|
||||
UnloadShader(shader); // Unload shader
|
||||
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
* This example has been created using raylib 2.5 (www.raylib.com)
|
||||
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
|
||||
*
|
||||
* Example contributed by Chris Camacho (@chriscamacho - http://bedroomcoders.co.uk/)
|
||||
* Example contributed by Chris Camacho (@chriscamacho - http://bedroomcoders.co.uk/)
|
||||
* and reviewed by Ramon Santamaria (@raysan5)
|
||||
*
|
||||
* Copyright (c) 2019 Chris Camacho (@chriscamacho) and Ramon Santamaria (@raysan5)
|
||||
|
@ -14,13 +14,13 @@
|
|||
*
|
||||
* The shader makes alpha holes in the forground to give the apearance of a top
|
||||
* down look at a spotlight casting a pool of light...
|
||||
*
|
||||
*
|
||||
* The right hand side of the screen there is just enough light to see whats
|
||||
* going on without the spot light, great for a stealth type game where you
|
||||
* have to avoid the spotlights.
|
||||
*
|
||||
*
|
||||
* The left hand side of the screen is in pitch dark except for where the spotlights are.
|
||||
*
|
||||
*
|
||||
* Although this example doesn't scale like the letterbox example, you could integrate
|
||||
* the two techniques, but by scaling the actual colour of the render texture rather
|
||||
* than using alpha as a mask.
|
||||
|
@ -43,12 +43,12 @@
|
|||
#define MAX_STARS 400
|
||||
|
||||
// Spot data
|
||||
typedef struct {
|
||||
typedef struct {
|
||||
Vector2 pos;
|
||||
Vector2 vel;
|
||||
float inner;
|
||||
float radius;
|
||||
|
||||
|
||||
// Shader locations
|
||||
unsigned int posLoc;
|
||||
unsigned int innerLoc;
|
||||
|
@ -75,26 +75,26 @@ int main(void)
|
|||
HideCursor();
|
||||
|
||||
Texture texRay = LoadTexture("resources/raysan.png");
|
||||
|
||||
|
||||
Star stars[MAX_STARS] = { 0 };
|
||||
|
||||
for (int n = 0; n < MAX_STARS; n++) ResetStar(&stars[n]);
|
||||
|
||||
// Progress all the stars on, so they don't all start in the centre
|
||||
for (int m = 0; m < screenWidth/2.0; m++)
|
||||
for (int m = 0; m < screenWidth/2.0; m++)
|
||||
{
|
||||
for (int n = 0; n < MAX_STARS; n++) UpdateStar(&stars[n]);
|
||||
}
|
||||
|
||||
int frameCounter = 0;
|
||||
|
||||
|
||||
// Use default vert shader
|
||||
Shader shdrSpot = LoadShader(0, TextFormat("resources/shaders/glsl%i/spotlight.fs", GLSL_VERSION));
|
||||
|
||||
|
||||
// Get the locations of spots in the shader
|
||||
Spot spots[MAX_SPOTS];
|
||||
|
||||
for (int i = 0; i < MAX_SPOTS; i++)
|
||||
for (int i = 0; i < MAX_SPOTS; i++)
|
||||
{
|
||||
char posName[32] = "spots[x].pos\0";
|
||||
char innerName[32] = "spots[x].inner\0";
|
||||
|
@ -103,13 +103,13 @@ int main(void)
|
|||
posName[6] = '0' + i;
|
||||
innerName[6] = '0' + i;
|
||||
radiusName[6] = '0' + i;
|
||||
|
||||
|
||||
spots[i].posLoc = GetShaderLocation(shdrSpot, posName);
|
||||
spots[i].innerLoc = GetShaderLocation(shdrSpot, innerName);
|
||||
spots[i].radiusLoc = GetShaderLocation(shdrSpot, radiusName);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
// Tell the shader how wide the screen is so we can have
|
||||
// a pitch black half and a dimly lit half.
|
||||
unsigned int wLoc = GetShaderLocation(shdrSpot, "screenWidth");
|
||||
|
@ -123,16 +123,16 @@ int main(void)
|
|||
spots[i].pos.x = GetRandomValue(64, screenWidth - 64);
|
||||
spots[i].pos.y = GetRandomValue(64, screenHeight - 64);
|
||||
spots[i].vel = (Vector2){ 0, 0 };
|
||||
|
||||
|
||||
while ((fabs(spots[i].vel.x) + fabs(spots[i].vel.y)) < 2)
|
||||
{
|
||||
spots[i].vel.x = GetRandomValue(-40, 40)/10.0;
|
||||
spots[i].vel.y = GetRandomValue(-40, 40)/10.0;
|
||||
}
|
||||
|
||||
|
||||
spots[i].inner = 28 * (i + 1);
|
||||
spots[i].radius = 48 * (i + 1);
|
||||
|
||||
|
||||
SetShaderValue(shdrSpot, spots[i].posLoc, &spots[i].pos.x, SHADER_UNIFORM_VEC2);
|
||||
SetShaderValue(shdrSpot, spots[i].innerLoc, &spots[i].inner, SHADER_UNIFORM_FLOAT);
|
||||
SetShaderValue(shdrSpot, spots[i].radiusLoc, &spots[i].radius, SHADER_UNIFORM_FLOAT);
|
||||
|
@ -140,7 +140,7 @@ int main(void)
|
|||
|
||||
SetTargetFPS(60); // Set to run at 60 frames-per-second
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Main game loop
|
||||
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||
{
|
||||
|
@ -157,23 +157,23 @@ int main(void)
|
|||
if (i == 0)
|
||||
{
|
||||
Vector2 mp = GetMousePosition();
|
||||
spots[i].pos.x = mp.x;
|
||||
spots[i].pos.x = mp.x;
|
||||
spots[i].pos.y = screenHeight - mp.y;
|
||||
}
|
||||
else
|
||||
{
|
||||
spots[i].pos.x += spots[i].vel.x;
|
||||
spots[i].pos.x += spots[i].vel.x;
|
||||
spots[i].pos.y += spots[i].vel.y;
|
||||
|
||||
if (spots[i].pos.x < 64) spots[i].vel.x = -spots[i].vel.x;
|
||||
if (spots[i].pos.x > (screenWidth - 64)) spots[i].vel.x = -spots[i].vel.x;
|
||||
if (spots[i].pos.y < 64) spots[i].vel.y = -spots[i].vel.y;
|
||||
|
||||
if (spots[i].pos.x < 64) spots[i].vel.x = -spots[i].vel.x;
|
||||
if (spots[i].pos.x > (screenWidth - 64)) spots[i].vel.x = -spots[i].vel.x;
|
||||
if (spots[i].pos.y < 64) spots[i].vel.y = -spots[i].vel.y;
|
||||
if (spots[i].pos.y > (screenHeight - 64)) spots[i].vel.y = -spots[i].vel.y;
|
||||
}
|
||||
|
||||
SetShaderValue(shdrSpot, spots[i].posLoc, &spots[i].pos.x, SHADER_UNIFORM_VEC2);
|
||||
|
||||
SetShaderValue(shdrSpot, spots[i].posLoc, &spots[i].pos.x, SHADER_UNIFORM_VEC2);
|
||||
}
|
||||
|
||||
|
||||
// Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
BeginDrawing();
|
||||
|
@ -204,11 +204,11 @@ int main(void)
|
|||
EndShaderMode();
|
||||
|
||||
DrawFPS(10, 10);
|
||||
|
||||
|
||||
DrawText("Move the mouse!", 10, 30, 20, GREEN);
|
||||
DrawText("Pitch Black", screenWidth*0.2f, screenHeight/2, 20, GREEN);
|
||||
DrawText("Dark", screenWidth*.66f, screenHeight/2, 20, GREEN);
|
||||
|
||||
|
||||
|
||||
EndDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
|
@ -229,21 +229,21 @@ int main(void)
|
|||
void ResetStar(Star *s)
|
||||
{
|
||||
s->pos = (Vector2){ GetScreenWidth()/2.0f, GetScreenHeight()/2.0f };
|
||||
|
||||
|
||||
do
|
||||
{
|
||||
s->vel.x = (float)GetRandomValue(-1000, 1000)/100.0f;
|
||||
s->vel.y = (float)GetRandomValue(-1000, 1000)/100.0f;
|
||||
|
||||
|
||||
} while (!(fabs(s->vel.x) + (fabs(s->vel.y) > 1)));
|
||||
|
||||
|
||||
s->pos = Vector2Add(s->pos, Vector2Multiply(s->vel, (Vector2){ 8.0f, 8.0f }));
|
||||
}
|
||||
|
||||
void UpdateStar(Star *s)
|
||||
{
|
||||
s->pos = Vector2Add(s->pos, s->vel);
|
||||
|
||||
|
||||
if ((s->pos.x < 0) || (s->pos.x > GetScreenWidth()) ||
|
||||
(s->pos.y < 0) || (s->pos.y > GetScreenHeight()))
|
||||
{
|
||||
|
|
|
@ -34,10 +34,10 @@ int main(void)
|
|||
const int screenHeight = 450;
|
||||
|
||||
InitWindow(screenWidth, screenHeight, "raylib [shaders] example - texture waves");
|
||||
|
||||
|
||||
// Load texture texture to apply shaders
|
||||
Texture2D texture = LoadTexture("resources/space.png");
|
||||
|
||||
|
||||
// Load shader and setup location points and values
|
||||
Shader shader = LoadShader(0, TextFormat("resources/shaders/glsl%i/wave.fs", GLSL_VERSION));
|
||||
|
||||
|
@ -77,7 +77,7 @@ int main(void)
|
|||
// Update
|
||||
//----------------------------------------------------------------------------------
|
||||
seconds += GetFrameTime();
|
||||
|
||||
|
||||
SetShaderValue(shader, secondsLoc, &seconds, SHADER_UNIFORM_FLOAT);
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
|
@ -88,10 +88,10 @@ int main(void)
|
|||
ClearBackground(RAYWHITE);
|
||||
|
||||
BeginShaderMode(shader);
|
||||
|
||||
|
||||
DrawTexture(texture, 0, 0, WHITE);
|
||||
DrawTexture(texture, texture.width, 0, WHITE);
|
||||
|
||||
|
||||
EndShaderMode();
|
||||
|
||||
EndDrawing();
|
||||
|
@ -102,7 +102,7 @@ int main(void)
|
|||
//--------------------------------------------------------------------------------------
|
||||
UnloadShader(shader); // Unload shader
|
||||
UnloadTexture(texture); // Unload texture
|
||||
|
||||
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
|
|
@ -43,39 +43,39 @@ int main(void)
|
|||
//----------------------------------------------------------------------------------
|
||||
// NOTE: All variables update happens inside GUI control functions
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
BeginDrawing();
|
||||
|
||||
|
||||
ClearBackground(RAYWHITE);
|
||||
|
||||
|
||||
DrawLine(500, 0, 500, GetScreenHeight(), Fade(LIGHTGRAY, 0.6f));
|
||||
DrawRectangle(500, 0, GetScreenWidth() - 500, GetScreenHeight(), Fade(LIGHTGRAY, 0.3f));
|
||||
|
||||
DrawCircleSector(center, outerRadius, startAngle, endAngle, segments, Fade(MAROON, 0.3));
|
||||
DrawCircleSectorLines(center, outerRadius, startAngle, endAngle, segments, Fade(MAROON, 0.6));
|
||||
|
||||
|
||||
// Draw GUI controls
|
||||
//------------------------------------------------------------------------------
|
||||
startAngle = GuiSliderBar((Rectangle){ 600, 40, 120, 20}, "StartAngle", NULL, startAngle, 0, 720);
|
||||
endAngle = GuiSliderBar((Rectangle){ 600, 70, 120, 20}, "EndAngle", NULL, endAngle, 0, 720);
|
||||
|
||||
|
||||
outerRadius = GuiSliderBar((Rectangle){ 600, 140, 120, 20}, "Radius", NULL, outerRadius, 0, 200);
|
||||
segments = GuiSliderBar((Rectangle){ 600, 170, 120, 20}, "Segments", NULL, segments, 0, 100);
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
|
||||
minSegments = (int)ceilf((endAngle - startAngle) / 90);
|
||||
DrawText(TextFormat("MODE: %s", (segments >= minSegments)? "MANUAL" : "AUTO"), 600, 200, 10, (segments >= minSegments)? MAROON : DARKGRAY);
|
||||
|
||||
|
||||
DrawFPS(10, 10);
|
||||
|
||||
|
||||
EndDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
//--------------------------------------------------------------------------------------
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
|
|
@ -3,17 +3,17 @@
|
|||
* raylib [text] example - Draw 2D text in 3D
|
||||
*
|
||||
* Draw a 2D text in 3D space, each letter is drawn in a quad (or 2 quads if backface is set)
|
||||
* where the texture coodinates of each quad map to the texture coordinates of the glyphs
|
||||
* inside the font texture.
|
||||
* A more efficient approach, i believe, would be to render the text in a render texture and
|
||||
* map that texture to a plane and render that, or maybe a shader but my method allows more
|
||||
* flexibility...for example to change position of each letter individually to make somethink
|
||||
* where the texture coodinates of each quad map to the texture coordinates of the glyphs
|
||||
* inside the font texture.
|
||||
* A more efficient approach, i believe, would be to render the text in a render texture and
|
||||
* map that texture to a plane and render that, or maybe a shader but my method allows more
|
||||
* flexibility...for example to change position of each letter individually to make somethink
|
||||
* like a wavy text effect.
|
||||
*
|
||||
* Special thanks to:
|
||||
* Special thanks to:
|
||||
* @Nighten for the DrawTextStyle() code https://github.com/NightenDushi/Raylib_DrawTextStyle
|
||||
* Chris Camacho (codifies - http://bedroomcoders.co.uk/) for the alpha discard shader
|
||||
*
|
||||
*
|
||||
* This example has been created using raylib 3.5 (www.raylib.com)
|
||||
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
|
||||
*
|
||||
|
@ -26,7 +26,7 @@
|
|||
#include "raylib.h"
|
||||
#include "rlgl.h"
|
||||
|
||||
#include <stddef.h> // Required for: NULL
|
||||
#include <stddef.h> // Required for: NULL
|
||||
#include <math.h> // Required for: sinf()
|
||||
|
||||
// To make it work with the older RLGL module just comment the line below
|
||||
|
@ -80,13 +80,13 @@ int main(void)
|
|||
//--------------------------------------------------------------------------------------
|
||||
const int screenWidth = 800;
|
||||
const int screenHeight = 450;
|
||||
|
||||
|
||||
SetConfigFlags(FLAG_MSAA_4X_HINT|FLAG_VSYNC_HINT);
|
||||
InitWindow(screenWidth, screenHeight, "raylib [text] example - draw 2D text in 3D");
|
||||
|
||||
bool spin = true; // Spin the camera?
|
||||
bool multicolor = false; // Multicolor mode
|
||||
|
||||
|
||||
// Define the camera to look into our 3d world
|
||||
Camera3D camera = { 0 };
|
||||
camera.position = (Vector3){ -10.0f, 15.0f, -10.0f }; // Camera position
|
||||
|
@ -94,41 +94,41 @@ int main(void)
|
|||
camera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; // Camera up vector (rotation towards target)
|
||||
camera.fovy = 45.0f; // Camera field-of-view Y
|
||||
camera.projection = CAMERA_PERSPECTIVE; // Camera mode type
|
||||
|
||||
|
||||
SetCameraMode(camera, CAMERA_ORBITAL);
|
||||
|
||||
Vector3 cubePosition = { 0.0f, 1.0f, 0.0f };
|
||||
Vector3 cubeSize = { 2.0f, 2.0f, 2.0f };
|
||||
|
||||
|
||||
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||
|
||||
|
||||
// Use the default font
|
||||
Font font = GetFontDefault();
|
||||
float fontSize = 8.0f;
|
||||
float fontSpacing = 0.5f;
|
||||
float lineSpacing = -1.0f;
|
||||
|
||||
|
||||
// Set the text (using markdown!)
|
||||
char text[64] = "Hello ~~World~~ in 3D!";
|
||||
Vector3 tbox = {0};
|
||||
int layers = 1;
|
||||
int quads = 0;
|
||||
float layerDistance = 0.01f;
|
||||
|
||||
|
||||
WaveTextConfig wcfg;
|
||||
wcfg.waveSpeed.x = wcfg.waveSpeed.y = 3.0f; wcfg.waveSpeed.z = 0.5f;
|
||||
wcfg.waveOffset.x = wcfg.waveOffset.y = wcfg.waveOffset.z = 0.35f;
|
||||
wcfg.waveRange.x = wcfg.waveRange.y = wcfg.waveRange.z = 0.45f;
|
||||
|
||||
|
||||
float time = 0.0f;
|
||||
|
||||
|
||||
// Setup a light and dark color
|
||||
Color light = MAROON;
|
||||
Color dark = RED;
|
||||
|
||||
|
||||
// Load the alpha discard shader
|
||||
Shader alphaDiscard = LoadShader(NULL, "resources/shaders/glsl330/alpha_discard.fs");
|
||||
|
||||
|
||||
// Array filled with multiple random colors (when multicolor mode is set)
|
||||
Color multi[TEXT_MAX_LAYERS] = {0};
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
@ -150,7 +150,7 @@ int main(void)
|
|||
UnloadFont(font);
|
||||
font = LoadFontEx(droppedFiles[0], fontSize, 0, 0);
|
||||
}
|
||||
else if (IsFileExtension(droppedFiles[0], ".fnt"))
|
||||
else if (IsFileExtension(droppedFiles[0], ".fnt"))
|
||||
{
|
||||
UnloadFont(font);
|
||||
font = LoadFont(droppedFiles[0]);
|
||||
|
@ -158,33 +158,33 @@ int main(void)
|
|||
}
|
||||
ClearDroppedFiles();
|
||||
}
|
||||
|
||||
|
||||
// Handle Events
|
||||
if (IsKeyPressed(KEY_F1)) SHOW_LETTER_BOUNDRY = !SHOW_LETTER_BOUNDRY;
|
||||
if (IsKeyPressed(KEY_F2)) SHOW_TEXT_BOUNDRY = !SHOW_TEXT_BOUNDRY;
|
||||
if (IsKeyPressed(KEY_F3))
|
||||
{
|
||||
if (IsKeyPressed(KEY_F3))
|
||||
{
|
||||
// Handle camera change
|
||||
spin = !spin;
|
||||
spin = !spin;
|
||||
// we need to reset the camera when changing modes
|
||||
camera = (Camera3D){ 0 };
|
||||
camera.target = (Vector3){ 0.0f, 0.0f, 0.0f }; // Camera looking at point
|
||||
camera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; // Camera up vector (rotation towards target)
|
||||
camera.fovy = 45.0f; // Camera field-of-view Y
|
||||
camera.projection = CAMERA_PERSPECTIVE; // Camera mode type
|
||||
|
||||
if (spin)
|
||||
|
||||
if (spin)
|
||||
{
|
||||
camera.position = (Vector3){ -10.0f, 15.0f, -10.0f }; // Camera position
|
||||
SetCameraMode(camera, CAMERA_ORBITAL);
|
||||
}
|
||||
else
|
||||
{
|
||||
else
|
||||
{
|
||||
camera.position = (Vector3){ 10.0f, 10.0f, -10.0f }; // Camera position
|
||||
SetCameraMode(camera, CAMERA_FREE);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Handle clicking the cube
|
||||
if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON))
|
||||
{
|
||||
|
@ -194,18 +194,18 @@ int main(void)
|
|||
bool collision = CheckCollisionRayBox(ray,
|
||||
(BoundingBox){(Vector3){ cubePosition.x - cubeSize.x/2, cubePosition.y - cubeSize.y/2, cubePosition.z - cubeSize.z/2 },
|
||||
(Vector3){ cubePosition.x + cubeSize.x/2, cubePosition.y + cubeSize.y/2, cubePosition.z + cubeSize.z/2 }});
|
||||
if (collision)
|
||||
if (collision)
|
||||
{
|
||||
// Generate new random colors
|
||||
light = GenerateRandomColor(0.5f, 0.78f);
|
||||
dark = GenerateRandomColor(0.4f, 0.58f);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Handle text layers changes
|
||||
if (IsKeyPressed(KEY_HOME)) { if (layers > 1) --layers; }
|
||||
else if (IsKeyPressed(KEY_END)) { if (layers < TEXT_MAX_LAYERS) ++layers; }
|
||||
|
||||
|
||||
// Handle text changes
|
||||
if (IsKeyPressed(KEY_LEFT)) fontSize -= 0.5f;
|
||||
else if (IsKeyPressed(KEY_RIGHT)) fontSize += 0.5f;
|
||||
|
@ -215,53 +215,53 @@ int main(void)
|
|||
else if (IsKeyPressed(KEY_PAGE_DOWN)) lineSpacing += 0.1f;
|
||||
else if (IsKeyDown(KEY_INSERT)) layerDistance -= 0.001f;
|
||||
else if (IsKeyDown(KEY_DELETE)) layerDistance += 0.001f;
|
||||
else if (IsKeyPressed(KEY_TAB))
|
||||
else if (IsKeyPressed(KEY_TAB))
|
||||
{
|
||||
multicolor = !multicolor; // Enable /disable multicolor mode
|
||||
|
||||
if (multicolor)
|
||||
|
||||
if (multicolor)
|
||||
{
|
||||
// Fill color array with random colors
|
||||
for (int i = 0; i < TEXT_MAX_LAYERS; ++i)
|
||||
for (int i = 0; i < TEXT_MAX_LAYERS; ++i)
|
||||
{
|
||||
multi[i] = GenerateRandomColor(0.5f, 0.8f);
|
||||
multi[i].a = GetRandomValue(0, 255);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Handle text input
|
||||
int ch = GetCharPressed();
|
||||
if (IsKeyPressed(KEY_BACKSPACE))
|
||||
if (IsKeyPressed(KEY_BACKSPACE))
|
||||
{
|
||||
// Remove last char
|
||||
int len = TextLength(text);
|
||||
if (len > 0) text[len - 1] = '\0';
|
||||
}
|
||||
else if (IsKeyPressed(KEY_ENTER))
|
||||
}
|
||||
else if (IsKeyPressed(KEY_ENTER))
|
||||
{
|
||||
// handle newline
|
||||
int len = TextLength(text);
|
||||
if (len < sizeof(text) - 1)
|
||||
{
|
||||
text[len] = '\n';
|
||||
text[len] = '\n';
|
||||
text[len+1] ='\0';
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// append only printable chars
|
||||
int len = TextLength(text);
|
||||
if (len < sizeof(text) - 1)
|
||||
{
|
||||
text[len] = ch;
|
||||
text[len] = ch;
|
||||
text[len+1] ='\0';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Measure 3D text so we can center it
|
||||
tbox = MeasureTextWave3D(font, text, fontSize, fontSpacing, lineSpacing);
|
||||
|
||||
|
||||
UpdateCamera(&camera); // Update camera
|
||||
quads = 0; // Reset quad counter
|
||||
time += GetFrameTime(); // Update timer needed by `DrawTextWave3D()`
|
||||
|
@ -272,37 +272,37 @@ int main(void)
|
|||
BeginDrawing();
|
||||
|
||||
ClearBackground(RAYWHITE);
|
||||
|
||||
|
||||
BeginMode3D(camera);
|
||||
DrawCubeV(cubePosition, cubeSize, dark);
|
||||
DrawCubeWires(cubePosition, 2.1f, 2.1f, 2.1f, light);
|
||||
|
||||
|
||||
DrawGrid(10, 2.0f);
|
||||
|
||||
|
||||
// Use a shader to handle the depth buffer issue with transparent textures
|
||||
// NOTE: more info at https://bedroomcoders.co.uk/raylib-billboards-advanced-use/
|
||||
BeginShaderMode(alphaDiscard);
|
||||
|
||||
|
||||
// Draw the 3D text above the red cube
|
||||
rlPushMatrix();
|
||||
rlRotatef(90.0f, 1.0f, 0.0f, 0.0f);
|
||||
rlRotatef(90.0f, 0.0f, 0.0f, -1.0f);
|
||||
|
||||
for (int i = 0; i < layers; ++i)
|
||||
|
||||
for (int i = 0; i < layers; ++i)
|
||||
{
|
||||
Color clr = light;
|
||||
if(multicolor) clr = multi[i];
|
||||
DrawTextWave3D(font, text, (Vector3){ -tbox.x/2.0f, layerDistance*i, -4.5f }, fontSize, fontSpacing, lineSpacing, true, &wcfg, time, clr);
|
||||
}
|
||||
|
||||
|
||||
// Draw the text boundry if set
|
||||
if (SHOW_TEXT_BOUNDRY) DrawCubeWiresV((Vector3){ 0.0f, 0.0f, -4.5f + tbox.z/2 }, tbox, dark);
|
||||
rlPopMatrix();
|
||||
|
||||
|
||||
// Don't draw the letter boundries for the 3D text below
|
||||
bool slb = SHOW_LETTER_BOUNDRY;
|
||||
SHOW_LETTER_BOUNDRY = false;
|
||||
|
||||
|
||||
// Draw 3D options (use default font)
|
||||
//-------------------------------------------------------------------------
|
||||
rlPushMatrix();
|
||||
|
@ -313,35 +313,35 @@ int main(void)
|
|||
Vector3 pos = { -m.x/2.0f, 0.01f, 2.0f};
|
||||
DrawText3D(GetFontDefault(), opt, pos, 8.0f, 1.0f, 0.0f, false, BLUE);
|
||||
pos.z += 0.5f + m.z;
|
||||
|
||||
|
||||
opt = (char *)TextFormat("< SPACING: %2.1f >", fontSpacing);
|
||||
quads += TextLength(opt);
|
||||
m = MeasureText3D(GetFontDefault(), opt, 8.0f, 1.0f, 0.0f);
|
||||
pos.x = -m.x/2.0f;
|
||||
DrawText3D(GetFontDefault(), opt, pos, 8.0f, 1.0f, 0.0f, false, BLUE);
|
||||
pos.z += 0.5f + m.z;
|
||||
|
||||
|
||||
opt = (char *)TextFormat("< LINE: %2.1f >", lineSpacing);
|
||||
quads += TextLength(opt);
|
||||
m = MeasureText3D(GetFontDefault(), opt, 8.0f, 1.0f, 0.0f);
|
||||
pos.x = -m.x/2.0f;
|
||||
DrawText3D(GetFontDefault(), opt, pos, 8.0f, 1.0f, 0.0f, false, BLUE);
|
||||
pos.z += 1.0f + m.z;
|
||||
|
||||
|
||||
opt = (char *)TextFormat("< LBOX: %3s >", slb? "ON" : "OFF");
|
||||
quads += TextLength(opt);
|
||||
m = MeasureText3D(GetFontDefault(), opt, 8.0f, 1.0f, 0.0f);
|
||||
pos.x = -m.x/2.0f;
|
||||
DrawText3D(GetFontDefault(), opt, pos, 8.0f, 1.0f, 0.0f, false, RED);
|
||||
pos.z += 0.5f + m.z;
|
||||
|
||||
|
||||
opt = (char *)TextFormat("< TBOX: %3s >", SHOW_TEXT_BOUNDRY? "ON" : "OFF");
|
||||
quads += TextLength(opt);
|
||||
m = MeasureText3D(GetFontDefault(), opt, 8.0f, 1.0f, 0.0f);
|
||||
pos.x = -m.x/2.0f;
|
||||
DrawText3D(GetFontDefault(), opt, pos, 8.0f, 1.0f, 0.0f, false, RED);
|
||||
pos.z += 0.5f + m.z;
|
||||
|
||||
|
||||
opt = (char *)TextFormat("< LAYER DISTANCE: %.3f >", layerDistance);
|
||||
quads += TextLength(opt);
|
||||
m = MeasureText3D(GetFontDefault(), opt, 8.0f, 1.0f, 0.0f);
|
||||
|
@ -349,7 +349,7 @@ int main(void)
|
|||
DrawText3D(GetFontDefault(), opt, pos, 8.0f, 1.0f, 0.0f, false, DARKPURPLE);
|
||||
rlPopMatrix();
|
||||
//-------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Draw 3D info text (use default font)
|
||||
//-------------------------------------------------------------------------
|
||||
opt = "All the text displayed here is in 3D";
|
||||
|
@ -358,74 +358,74 @@ int main(void)
|
|||
pos = (Vector3){-m.x/2.0f, 0.01f, 2.0f};
|
||||
DrawText3D(GetFontDefault(), opt, pos, 10.0f, 0.5f, 0.0f, false, DARKBLUE);
|
||||
pos.z += 1.5f + m.z;
|
||||
|
||||
|
||||
opt = "press [Left]/[Right] to change the font size";
|
||||
quads += 44;
|
||||
m = MeasureText3D(GetFontDefault(), opt, 6.0f, 0.5f, 0.0f);
|
||||
pos.x = -m.x/2.0f;
|
||||
DrawText3D(GetFontDefault(), opt, pos, 6.0f, 0.5f, 0.0f, false, DARKBLUE);
|
||||
pos.z += 0.5f + m.z;
|
||||
|
||||
|
||||
opt = "press [Up]/[Down] to change the font spacing";
|
||||
quads += 44;
|
||||
m = MeasureText3D(GetFontDefault(), opt, 6.0f, 0.5f, 0.0f);
|
||||
pos.x = -m.x/2.0f;
|
||||
DrawText3D(GetFontDefault(), opt, pos, 6.0f, 0.5f, 0.0f, false, DARKBLUE);
|
||||
pos.z += 0.5f + m.z;
|
||||
|
||||
|
||||
opt = "press [PgUp]/[PgDown] to change the line spacing";
|
||||
quads += 48;
|
||||
m = MeasureText3D(GetFontDefault(), opt, 6.0f, 0.5f, 0.0f);
|
||||
pos.x = -m.x/2.0f;
|
||||
DrawText3D(GetFontDefault(), opt, pos, 6.0f, 0.5f, 0.0f, false, DARKBLUE);
|
||||
pos.z += 0.5f + m.z;
|
||||
|
||||
|
||||
opt = "press [F1] to toggle the letter boundry";
|
||||
quads += 39;
|
||||
m = MeasureText3D(GetFontDefault(), opt, 6.0f, 0.5f, 0.0f);
|
||||
pos.x = -m.x/2.0f;
|
||||
DrawText3D(GetFontDefault(), opt, pos, 6.0f, 0.5f, 0.0f, false, DARKBLUE);
|
||||
pos.z += 0.5f + m.z;
|
||||
|
||||
|
||||
opt = "press [F2] to toggle the text boundry";
|
||||
quads += 37;
|
||||
m = MeasureText3D(GetFontDefault(), opt, 6.0f, 0.5f, 0.0f);
|
||||
pos.x = -m.x/2.0f;
|
||||
DrawText3D(GetFontDefault(), opt, pos, 6.0f, 0.5f, 0.0f, false, DARKBLUE);
|
||||
//-------------------------------------------------------------------------
|
||||
|
||||
|
||||
SHOW_LETTER_BOUNDRY = slb;
|
||||
EndShaderMode();
|
||||
|
||||
|
||||
EndMode3D();
|
||||
|
||||
|
||||
// Draw 2D info text & stats
|
||||
//-------------------------------------------------------------------------
|
||||
DrawText("Drag & drop a font file to change the font!\nType something, see what happens!\n\n"
|
||||
"Press [F3] to toggle the camera", 10, 35, 10, BLACK);
|
||||
|
||||
|
||||
quads += TextLength(text)*2*layers;
|
||||
char *tmp = (char *)TextFormat("%2i layer(s) | %s camera | %4i quads (%4i verts)", layers, spin? "ORBITAL" : "FREE", quads, quads*4);
|
||||
int width = MeasureText(tmp, 10);
|
||||
DrawText(tmp, screenWidth - 20 - width, 10, 10, DARKGREEN);
|
||||
|
||||
|
||||
tmp = "[Home]/[End] to add/remove 3D text layers";
|
||||
width = MeasureText(tmp, 10);
|
||||
DrawText(tmp, screenWidth - 20 - width, 25, 10, DARKGRAY);
|
||||
|
||||
|
||||
tmp = "[Insert]/[Delete] to increase/decrease distance between layers";
|
||||
width = MeasureText(tmp, 10);
|
||||
DrawText(tmp, screenWidth - 20 - width, 40, 10, DARKGRAY);
|
||||
|
||||
|
||||
tmp = "click the [CUBE] for a random color";
|
||||
width = MeasureText(tmp, 10);
|
||||
DrawText(tmp, screenWidth - 20 - width, 55, 10, DARKGRAY);
|
||||
|
||||
|
||||
tmp = "[Tab] to toggle multicolor mode";
|
||||
width = MeasureText(tmp, 10);
|
||||
DrawText(tmp, screenWidth - 20 - width, 70, 10, DARKGRAY);
|
||||
//-------------------------------------------------------------------------
|
||||
|
||||
|
||||
DrawFPS(10, 10);
|
||||
|
||||
EndDrawing();
|
||||
|
@ -461,22 +461,22 @@ void DrawTextCodepoint3D(Font font, int codepoint, Vector3 position, float fontS
|
|||
// NOTE: We consider chars padding when drawing, it could be required for outline/glow shader effects
|
||||
Rectangle srcRec = { font.recs[index].x - (float)font.charsPadding, font.recs[index].y - (float)font.charsPadding,
|
||||
font.recs[index].width + 2.0f*font.charsPadding, font.recs[index].height + 2.0f*font.charsPadding };
|
||||
|
||||
|
||||
float width = (float)(font.recs[index].width + 2.0f*font.charsPadding)/(float)font.baseSize*scale;
|
||||
float height = (float)(font.recs[index].height + 2.0f*font.charsPadding)/(float)font.baseSize*scale;
|
||||
|
||||
|
||||
if(font.texture.id > 0)
|
||||
{
|
||||
const float x = 0.0f;
|
||||
const float y = 0.0f;
|
||||
const float z = 0.0f;
|
||||
|
||||
|
||||
// normalized texture coordinates of the glyph inside the font texture (0.0f -> 1.0f)
|
||||
const float tx = srcRec.x/font.texture.width;
|
||||
const float ty = srcRec.y/font.texture.height;
|
||||
const float tw = (srcRec.x+srcRec.width)/font.texture.width;
|
||||
const float th = (srcRec.y+srcRec.height)/font.texture.height;
|
||||
|
||||
|
||||
if(SHOW_LETTER_BOUNDRY)
|
||||
DrawCubeWiresV((Vector3){ position.x + width/2, position.y, position.z + height/2}, (Vector3){ width, LETTER_BOUNDRY_SIZE, height }, LETTER_BOUNDRY_COLOR);
|
||||
|
||||
|
@ -489,17 +489,17 @@ void DrawTextCodepoint3D(Font font, int codepoint, Vector3 position, float fontS
|
|||
#endif
|
||||
rlPushMatrix();
|
||||
rlTranslatef(position.x, position.y, position.z);
|
||||
|
||||
|
||||
rlBegin(RL_QUADS);
|
||||
rlColor4ub(tint.r, tint.g, tint.b, tint.a);
|
||||
|
||||
|
||||
// Front Face
|
||||
rlNormal3f(0.0f, 1.0f, 0.0f); // Normal Pointing Up
|
||||
rlTexCoord2f(tx, ty); rlVertex3f(x, y, z); // Top Left Of The Texture and Quad
|
||||
rlTexCoord2f(tx, th); rlVertex3f(x, y, z + height); // Bottom Left Of The Texture and Quad
|
||||
rlTexCoord2f(tw, th); rlVertex3f(x + width, y, z + height); // Bottom Right Of The Texture and Quad
|
||||
rlTexCoord2f(tw, ty); rlVertex3f(x + width, y, z); // Top Right Of The Texture and Quad
|
||||
|
||||
|
||||
if (backface)
|
||||
{
|
||||
// Back Face
|
||||
|
@ -526,9 +526,9 @@ void DrawText3D(Font font, const char *text, Vector3 position, float fontSize, f
|
|||
|
||||
float textOffsetY = 0.0f; // Offset between lines (on line break '\n')
|
||||
float textOffsetX = 0.0f; // Offset X to next character to draw
|
||||
|
||||
|
||||
float scale = fontSize/(float)font.baseSize;
|
||||
|
||||
|
||||
for (int i = 0; i < length;)
|
||||
{
|
||||
// Get next codepoint from byte string and glyph index in font
|
||||
|
@ -562,12 +562,12 @@ void DrawText3D(Font font, const char *text, Vector3 position, float fontSize, f
|
|||
}
|
||||
}
|
||||
|
||||
Vector3 MeasureText3D(Font font, const char* text, float fontSize, float fontSpacing, float lineSpacing)
|
||||
Vector3 MeasureText3D(Font font, const char* text, float fontSize, float fontSpacing, float lineSpacing)
|
||||
{
|
||||
int len = TextLength(text);
|
||||
int tempLen = 0; // Used to count longer text line num chars
|
||||
int lenCounter = 0;
|
||||
|
||||
|
||||
float tempTextWidth = 0.0f; // Used to count longer text line width
|
||||
|
||||
float scale = fontSize/(float)font.baseSize;
|
||||
|
@ -623,9 +623,9 @@ void DrawTextWave3D(Font font, const char *text, Vector3 position, float fontSiz
|
|||
|
||||
float textOffsetY = 0.0f; // Offset between lines (on line break '\n')
|
||||
float textOffsetX = 0.0f; // Offset X to next character to draw
|
||||
|
||||
|
||||
float scale = fontSize/(float)font.baseSize;
|
||||
|
||||
|
||||
bool wave = false;
|
||||
|
||||
for (int i = 0, k = 0; i < length; ++k)
|
||||
|
@ -649,7 +649,7 @@ void DrawTextWave3D(Font font, const char *text, Vector3 position, float fontSiz
|
|||
}
|
||||
else if (codepoint == '~')
|
||||
{
|
||||
if (GetNextCodepoint(&text[i+1], &codepointByteCount) == '~')
|
||||
if (GetNextCodepoint(&text[i+1], &codepointByteCount) == '~')
|
||||
{
|
||||
codepointByteCount += 1;
|
||||
wave = !wave;
|
||||
|
@ -666,7 +666,7 @@ void DrawTextWave3D(Font font, const char *text, Vector3 position, float fontSiz
|
|||
pos.y += sinf(time*config->waveSpeed.y-k*config->waveOffset.y)*config->waveRange.y;
|
||||
pos.z += sinf(time*config->waveSpeed.z-k*config->waveOffset.z)*config->waveRange.z;
|
||||
}
|
||||
|
||||
|
||||
DrawTextCodepoint3D(font, codepoint, (Vector3){ pos.x + textOffsetX, pos.y, pos.z + textOffsetY }, fontSize, backface, tint);
|
||||
}
|
||||
|
||||
|
@ -678,12 +678,12 @@ void DrawTextWave3D(Font font, const char *text, Vector3 position, float fontSiz
|
|||
}
|
||||
}
|
||||
|
||||
Vector3 MeasureTextWave3D(Font font, const char* text, float fontSize, float fontSpacing, float lineSpacing)
|
||||
Vector3 MeasureTextWave3D(Font font, const char* text, float fontSize, float fontSpacing, float lineSpacing)
|
||||
{
|
||||
int len = TextLength(text);
|
||||
int tempLen = 0; // Used to count longer text line num chars
|
||||
int lenCounter = 0;
|
||||
|
||||
|
||||
float tempTextWidth = 0.0f; // Used to count longer text line width
|
||||
|
||||
float scale = fontSize/(float)font.baseSize;
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
* - BMFonts > Angel code font fileformat, sprite font image must be provided
|
||||
* together with the .fnt file, font generation cna not be configured
|
||||
* - XNA Spritefont > Sprite font image, following XNA Spritefont conventions,
|
||||
* Characters in image must follow some spacing and order rules
|
||||
* Characters in image must follow some spacing and order rules
|
||||
*
|
||||
* This example has been created using raylib 2.6 (www.raylib.com)
|
||||
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
|
||||
|
|
|
@ -31,7 +31,7 @@ int main(void)
|
|||
// NOTE: Textures/Fonts MUST be loaded after Window initialization (OpenGL context is required)
|
||||
|
||||
const char msg[50] = "Signed Distance Fields";
|
||||
|
||||
|
||||
// Loading file to memory
|
||||
unsigned int fileSize = 0;
|
||||
unsigned char *fileData = LoadFileData("resources/anonymous_pro_bold.ttf", &fileSize);
|
||||
|
@ -40,7 +40,7 @@ int main(void)
|
|||
Font fontDefault = { 0 };
|
||||
fontDefault.baseSize = 16;
|
||||
fontDefault.charsCount = 95;
|
||||
|
||||
|
||||
// Loading font data from memory data
|
||||
// Parameters > font size: 16, no chars array provided (0), chars count: 95 (autogenerate chars array)
|
||||
fontDefault.chars = LoadFontData(fileData, fileSize, 16, 0, 95, FONT_DEFAULT);
|
||||
|
@ -59,7 +59,7 @@ int main(void)
|
|||
atlas = GenImageFontAtlas(fontSDF.chars, &fontSDF.recs, 95, 16, 0, 1);
|
||||
fontSDF.texture = LoadTextureFromImage(atlas);
|
||||
UnloadImage(atlas);
|
||||
|
||||
|
||||
UnloadFileData(fileData); // Free memory from loaded file
|
||||
|
||||
// Load SDF required shader (we use default vertex shader)
|
||||
|
@ -70,7 +70,7 @@ int main(void)
|
|||
Vector2 textSize = { 0.0f, 0.0f };
|
||||
float fontSize = 16.0f;
|
||||
int currentFont = 0; // 0 - fontDefault, 1 - fontSDF
|
||||
|
||||
|
||||
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
|
|
@ -8,8 +8,8 @@
|
|||
* - Every character and every line must be separated the same distance
|
||||
* - Rectangles must be defined by a MAGENTA color background
|
||||
*
|
||||
* If following this constraints, a font can be provided just by an image,
|
||||
* this is quite handy to avoid additional information files (like BMFonts use).
|
||||
* If following this constraints, a font can be provided just by an image,
|
||||
* this is quite handy to avoid additional information files (like BMFonts use).
|
||||
*
|
||||
* This example has been created using raylib 1.0 (www.raylib.com)
|
||||
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
|
||||
|
|
|
@ -58,7 +58,7 @@ int main(void)
|
|||
name[letterCount] = (char)key;
|
||||
letterCount++;
|
||||
}
|
||||
|
||||
|
||||
key = GetCharPressed(); // Check next character in the queue
|
||||
}
|
||||
|
||||
|
|
|
@ -62,7 +62,7 @@ int main(void)
|
|||
positions[7].y -= 8;
|
||||
|
||||
Color colors[MAX_FONTS] = { MAROON, ORANGE, DARKGREEN, DARKBLUE, DARKPURPLE, LIME, GOLD, RED };
|
||||
|
||||
|
||||
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
|
|
@ -100,15 +100,15 @@ tempor incididunt ut labore et dolore magna aliqua. Nec ullamcorper sit amet ris
|
|||
// Draw bottom info
|
||||
DrawRectangle(0, screenHeight - 54, screenWidth, 54, GRAY);
|
||||
DrawRectangleRec((Rectangle){ 382, screenHeight - 34, 12, 12 }, MAROON);
|
||||
|
||||
|
||||
DrawText("Word Wrap: ", 313, screenHeight-115, 20, BLACK);
|
||||
if (wordWrap) DrawText("ON", 447, screenHeight - 115, 20, RED);
|
||||
else DrawText("OFF", 447, screenHeight - 115, 20, BLACK);
|
||||
|
||||
|
||||
DrawText("Press [SPACE] to toggle word wrap", 218, screenHeight - 86, 20, GRAY);
|
||||
|
||||
DrawText("Click hold & drag the to resize the container", 155, screenHeight - 38, 20, RAYWHITE);
|
||||
|
||||
|
||||
EndDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
|
|
|
@ -32,12 +32,12 @@ int main(void)
|
|||
Texture2D fgTexture = LoadTextureFromImage(fgImage); // Image converted to texture, GPU memory (VRAM)
|
||||
|
||||
// Once image has been converted to texture and uploaded to VRAM, it can be unloaded from RAM
|
||||
UnloadImage(bgImage);
|
||||
UnloadImage(bgImage);
|
||||
UnloadImage(fgImage);
|
||||
|
||||
const int blendCountMax = 4;
|
||||
BlendMode blendMode = 0;
|
||||
|
||||
|
||||
// Main game loop
|
||||
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||
{
|
||||
|
@ -49,7 +49,7 @@ int main(void)
|
|||
else blendMode++;
|
||||
}
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
BeginDrawing();
|
||||
|
@ -65,7 +65,7 @@ int main(void)
|
|||
|
||||
// Draw the texts
|
||||
DrawText("Press SPACE to change blend modes.", 310, 350, 10, GRAY);
|
||||
|
||||
|
||||
switch (blendMode)
|
||||
{
|
||||
case BLEND_ALPHA: DrawText("Current: BLEND_ALPHA", (screenWidth / 2) - 60, 370, 10, GRAY); break;
|
||||
|
@ -74,7 +74,7 @@ int main(void)
|
|||
case BLEND_ADD_COLORS: DrawText("Current: BLEND_ADD_COLORS", (screenWidth / 2) - 60, 370, 10, GRAY); break;
|
||||
default: break;
|
||||
}
|
||||
|
||||
|
||||
DrawText("(c) Cyberpunk Street Environment by Luis Zuno (@ansimuz)", screenWidth - 330, screenHeight - 20, 10, GRAY);
|
||||
|
||||
EndDrawing();
|
||||
|
@ -88,6 +88,6 @@ int main(void)
|
|||
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -21,24 +21,24 @@ int main(int argc, char **argv)
|
|||
//--------------------------------------------------------------------------------------
|
||||
int screenWidth = 800;
|
||||
int screenHeight = 450;
|
||||
|
||||
|
||||
SetConfigFlags(FLAG_WINDOW_RESIZABLE); // Make the window resizable
|
||||
InitWindow(screenWidth, screenHeight, "raylib [textures] example - Draw part of a texture tiled");
|
||||
|
||||
// NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required)
|
||||
Texture texPattern = LoadTexture("resources/patterns.png");
|
||||
SetTextureFilter(texPattern, TEXTURE_FILTER_TRILINEAR); // Makes the texture smoother when upscaled
|
||||
|
||||
|
||||
// Coordinates for all patterns inside the texture
|
||||
const Rectangle recPattern[] = {
|
||||
(Rectangle){ 3, 3, 66, 66 },
|
||||
(Rectangle){ 75, 3, 100, 100 },
|
||||
const Rectangle recPattern[] = {
|
||||
(Rectangle){ 3, 3, 66, 66 },
|
||||
(Rectangle){ 75, 3, 100, 100 },
|
||||
(Rectangle){ 3, 75, 66, 66 },
|
||||
(Rectangle){ 7, 156, 50, 50 },
|
||||
(Rectangle){ 85, 106, 90, 45 },
|
||||
(Rectangle){ 75, 154, 100, 60}
|
||||
};
|
||||
|
||||
|
||||
// Setup colors
|
||||
const Color colors[] = { BLACK, MAROON, ORANGE, BLUE, PURPLE, BEIGE, LIME, RED, DARKGRAY, SKYBLUE };
|
||||
enum { MAX_COLORS = SIZEOF(colors) };
|
||||
|
@ -51,21 +51,21 @@ int main(int argc, char **argv)
|
|||
colorRec[i].y = 22.0f + 256.0f + MARGIN_SIZE + y;
|
||||
colorRec[i].width = COLOR_SIZE*2.0f;
|
||||
colorRec[i].height = (float)COLOR_SIZE;
|
||||
|
||||
|
||||
if (i == (MAX_COLORS/2 - 1))
|
||||
{
|
||||
x = 0;
|
||||
x = 0;
|
||||
y += COLOR_SIZE + MARGIN_SIZE;
|
||||
}
|
||||
}
|
||||
else x += (COLOR_SIZE*2 + MARGIN_SIZE);
|
||||
}
|
||||
|
||||
int activePattern = 0, activeCol = 0;
|
||||
float scale = 1.0f, rotation = 0.0f;
|
||||
|
||||
|
||||
SetTargetFPS(60);
|
||||
//---------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Main game loop
|
||||
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||
{
|
||||
|
@ -73,22 +73,22 @@ int main(int argc, char **argv)
|
|||
//----------------------------------------------------------------------------------
|
||||
screenWidth = GetScreenWidth();
|
||||
screenHeight = GetScreenHeight();
|
||||
|
||||
|
||||
// Handle mouse
|
||||
if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON))
|
||||
{
|
||||
const Vector2 mouse = GetMousePosition();
|
||||
|
||||
|
||||
// Check which pattern was clicked and set it as the active pattern
|
||||
for (int i = 0; i < SIZEOF(recPattern); i++)
|
||||
{
|
||||
if (CheckCollisionPointRec(mouse, (Rectangle){ 2 + MARGIN_SIZE + recPattern[i].x, 40 + MARGIN_SIZE + recPattern[i].y, recPattern[i].width, recPattern[i].height }))
|
||||
{
|
||||
activePattern = i;
|
||||
break;
|
||||
{
|
||||
activePattern = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Check to see which color was clicked and set it as the active color
|
||||
for (int i = 0; i < MAX_COLORS; ++i)
|
||||
{
|
||||
|
@ -99,67 +99,67 @@ int main(int argc, char **argv)
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Handle keys
|
||||
|
||||
|
||||
// Change scale
|
||||
if (IsKeyPressed(KEY_UP)) scale += 0.25f;
|
||||
if (IsKeyPressed(KEY_DOWN)) scale -= 0.25f;
|
||||
if (scale > 10.0f) scale = 10.0f;
|
||||
else if ( scale <= 0.0f) scale = 0.25f;
|
||||
|
||||
|
||||
// Change rotation
|
||||
if (IsKeyPressed(KEY_LEFT)) rotation -= 25.0f;
|
||||
if (IsKeyPressed(KEY_RIGHT)) rotation += 25.0f;
|
||||
|
||||
|
||||
// Reset
|
||||
if (IsKeyPressed(KEY_SPACE)) { rotation = 0.0f; scale = 1.0f; }
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
BeginDrawing();
|
||||
ClearBackground(RAYWHITE);
|
||||
|
||||
|
||||
// Draw the tiled area
|
||||
DrawTextureTiled(texPattern, recPattern[activePattern], (Rectangle){(float)OPT_WIDTH+MARGIN_SIZE, (float)MARGIN_SIZE, screenWidth - OPT_WIDTH - 2.0f*MARGIN_SIZE, screenHeight - 2.0f*MARGIN_SIZE},
|
||||
(Vector2){0.0f, 0.0f}, rotation, scale, colors[activeCol]);
|
||||
|
||||
|
||||
// Draw options
|
||||
DrawRectangle(MARGIN_SIZE, MARGIN_SIZE, OPT_WIDTH - MARGIN_SIZE, screenHeight - 2*MARGIN_SIZE, ColorAlpha(LIGHTGRAY, 0.5f));
|
||||
|
||||
|
||||
DrawText("Select Pattern", 2 + MARGIN_SIZE, 30 + MARGIN_SIZE, 10, BLACK);
|
||||
DrawTexture(texPattern, 2 + MARGIN_SIZE, 40 + MARGIN_SIZE, BLACK);
|
||||
DrawRectangle(2 + MARGIN_SIZE + (int)recPattern[activePattern].x, 40 + MARGIN_SIZE + (int)recPattern[activePattern].y, (int)recPattern[activePattern].width, (int)recPattern[activePattern].height, ColorAlpha(DARKBLUE, 0.3f));
|
||||
|
||||
|
||||
DrawText("Select Color", 2+MARGIN_SIZE, 10+256+MARGIN_SIZE, 10, BLACK);
|
||||
for (int i = 0; i < MAX_COLORS; i++)
|
||||
{
|
||||
DrawRectangleRec(colorRec[i], colors[i]);
|
||||
if (activeCol == i) DrawRectangleLinesEx(colorRec[i], 3, ColorAlpha(WHITE, 0.5f));
|
||||
}
|
||||
|
||||
|
||||
DrawText("Scale (UP/DOWN to change)", 2 + MARGIN_SIZE, 80 + 256 + MARGIN_SIZE, 10, BLACK);
|
||||
DrawText(TextFormat("%.2fx", scale), 2 + MARGIN_SIZE, 92 + 256 + MARGIN_SIZE, 20, BLACK);
|
||||
|
||||
|
||||
DrawText("Rotation (LEFT/RIGHT to change)", 2 + MARGIN_SIZE, 122 + 256 + MARGIN_SIZE, 10, BLACK);
|
||||
DrawText(TextFormat("%.0f degrees", rotation), 2 + MARGIN_SIZE, 134 + 256 + MARGIN_SIZE, 20, BLACK);
|
||||
|
||||
|
||||
DrawText("Press [SPACE] to reset", 2 + MARGIN_SIZE, 164 + 256 + MARGIN_SIZE, 10, DARKBLUE);
|
||||
|
||||
|
||||
// Draw FPS
|
||||
DrawText(TextFormat("%i FPS", GetFPS()), 2 + MARGIN_SIZE, 2 + MARGIN_SIZE, 20, BLACK);
|
||||
EndDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
|
||||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
UnloadTexture(texPattern); // Unload texture
|
||||
|
||||
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -53,7 +53,7 @@ int main(void)
|
|||
Image imOrigin = LoadImage("resources/parrots.png"); // Loaded in CPU memory (RAM)
|
||||
ImageFormat(&imOrigin, PIXELFORMAT_UNCOMPRESSED_R8G8B8A8); // Format image to RGBA 32bit (required for texture update) <-- ISSUE
|
||||
Texture2D texture = LoadTextureFromImage(imOrigin); // Image converted to texture, GPU memory (VRAM)
|
||||
|
||||
|
||||
Image imCopy = ImageCopy(imOrigin);
|
||||
|
||||
int currentProcess = NONE;
|
||||
|
@ -72,7 +72,7 @@ int main(void)
|
|||
{
|
||||
// Update
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Mouse toggle group logic
|
||||
for (int i = 0; i < NUM_PROCESSES; i++)
|
||||
{
|
||||
|
@ -89,7 +89,7 @@ int main(void)
|
|||
}
|
||||
else mouseHoverRec = -1;
|
||||
}
|
||||
|
||||
|
||||
// Keyboard toggle group logic
|
||||
if (IsKeyPressed(KEY_DOWN))
|
||||
{
|
||||
|
@ -109,7 +109,7 @@ int main(void)
|
|||
{
|
||||
UnloadImage(imCopy); // Unload image-copy data
|
||||
imCopy = ImageCopy(imOrigin); // Restore image-copy from image-origin
|
||||
|
||||
|
||||
// NOTE: Image processing is a costly CPU process to be done every frame,
|
||||
// If image processing is required in a frame-basis, it should be done
|
||||
// with a texture and by shaders
|
||||
|
|
|
@ -19,7 +19,7 @@ int main(void)
|
|||
const int screenHeight = 450;
|
||||
|
||||
InitWindow(screenWidth, screenHeight, "raylib [texture] example - image text drawing");
|
||||
|
||||
|
||||
Image parrots = LoadImage("resources/parrots.png"); // Load image in CPU memory (RAM)
|
||||
|
||||
// TTF Font loading with custom generation parameters
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
* This example has been created using raylib 3.7 (www.raylib.com)
|
||||
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
|
||||
*
|
||||
* Example contributed by Chris Camacho (@codifies - bedroomcoders.co.uk) and
|
||||
* Example contributed by Chris Camacho (@codifies - bedroomcoders.co.uk) and
|
||||
* reviewed by Ramon Santamaria (@raysan5)
|
||||
*
|
||||
* Copyright (c) 2021 Chris Camacho (@codifies) and Ramon Santamaria (@raysan5)
|
||||
|
@ -52,7 +52,7 @@ int main(void)
|
|||
InitWindow(screenWidth, screenHeight, "raylib [textures] example - textured polygon");
|
||||
|
||||
Texture texture = LoadTexture("resources/cat.png");
|
||||
|
||||
|
||||
float ang = 0;
|
||||
|
||||
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||
|
@ -64,9 +64,9 @@ int main(void)
|
|||
// Update
|
||||
//----------------------------------------------------------------------------------
|
||||
ang++;
|
||||
|
||||
|
||||
Vector2 positions[MAX_POINTS] = { 0 };
|
||||
|
||||
|
||||
for (int i = 0; i < MAX_POINTS; i++) positions[i] = Vector2Rotate(points[i], ang);
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
|
@ -77,8 +77,8 @@ int main(void)
|
|||
ClearBackground(RAYWHITE);
|
||||
|
||||
DrawText("textured polygon", 20, 20, 20, DARKGRAY);
|
||||
|
||||
DrawTexturePoly(texture, (Vector2){ GetScreenWidth()/2, GetScreenHeight()/2 },
|
||||
|
||||
DrawTexturePoly(texture, (Vector2){ GetScreenWidth()/2, GetScreenHeight()/2 },
|
||||
positions, texcoords, MAX_POINTS, WHITE);
|
||||
|
||||
EndDrawing();
|
||||
|
@ -88,7 +88,7 @@ int main(void)
|
|||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
UnloadTexture(texture); // Unload texture
|
||||
|
||||
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
|
|
@ -54,8 +54,8 @@ int main(void)
|
|||
.height = height,
|
||||
.format = PIXELFORMAT_UNCOMPRESSED_R8G8B8A8,
|
||||
.mipmaps = 1
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
Texture2D checked = LoadTextureFromImage(checkedIm);
|
||||
UnloadImage(checkedIm); // Unload CPU (RAM) image data (pixels)
|
||||
//---------------------------------------------------------------------------------------
|
||||
|
|
|
@ -30,7 +30,7 @@ int main(void)
|
|||
|
||||
// Load explosion texture
|
||||
Texture2D explosion = LoadTexture("resources/explosion.png");
|
||||
|
||||
|
||||
// Init variables for animation
|
||||
int frameWidth = explosion.width/NUM_FRAMES_PER_LINE; // Sprite one frame rectangle width
|
||||
int frameHeight = explosion.height/NUM_LINES; // Sprite one frame rectangle height
|
||||
|
|
|
@ -21,7 +21,7 @@ int main(void)
|
|||
InitWindow(screenWidth, screenHeight, "raylib [textures] examples - texture source and destination rectangles");
|
||||
|
||||
// NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required)
|
||||
|
||||
|
||||
Texture2D scarfy = LoadTexture("resources/scarfy.png"); // Texture loading
|
||||
|
||||
int frameWidth = scarfy.width/6;
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
*
|
||||
* FEATURES:
|
||||
* - NO external dependencies, all required libraries included with raylib
|
||||
* - Multiplatform: Windows, Linux, FreeBSD, OpenBSD, NetBSD, DragonFly,
|
||||
* - Multiplatform: Windows, Linux, FreeBSD, OpenBSD, NetBSD, DragonFly,
|
||||
* MacOS, Haiku, UWP, Android, Raspberry Pi, HTML5.
|
||||
* - Written in plain C code (C99) in PascalCase/camelCase notation
|
||||
* - Hardware accelerated with OpenGL (1.1, 2.1, 3.3 or ES2 - choose at compile)
|
||||
|
|
Loading…
Reference in New Issue