examples review
Redesigns, deletes and renames Also noted authors propertly on contributed examples
This commit is contained in:
parent
2edec8ae28
commit
424d3ca8d9
36 changed files with 292 additions and 434 deletions
73
examples/core/core_3d_camera_mode.c
Normal file
73
examples/core/core_3d_camera_mode.c
Normal file
|
|
@ -0,0 +1,73 @@
|
||||||
|
/*******************************************************************************************
|
||||||
|
*
|
||||||
|
* raylib [core] example - Initialize 3d camera mode
|
||||||
|
*
|
||||||
|
* 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)
|
||||||
|
*
|
||||||
|
* Copyright (c) 2014 Ramon Santamaria (@raysan5)
|
||||||
|
*
|
||||||
|
********************************************************************************************/
|
||||||
|
|
||||||
|
#include "raylib.h"
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
// Initialization
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
const int screenWidth = 800;
|
||||||
|
const int screenHeight = 450;
|
||||||
|
|
||||||
|
InitWindow(screenWidth, screenHeight, "raylib [core] example - 3d camera mode");
|
||||||
|
|
||||||
|
// Define the camera to look into our 3d world
|
||||||
|
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
|
||||||
|
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.type = CAMERA_PERSPECTIVE; // Camera mode type
|
||||||
|
|
||||||
|
Vector3 cubePosition = { 0.0f, 0.0f, 0.0f };
|
||||||
|
|
||||||
|
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Main game loop
|
||||||
|
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||||
|
{
|
||||||
|
// Update
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
// TODO: Update your variables here
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Draw
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
BeginDrawing();
|
||||||
|
|
||||||
|
ClearBackground(RAYWHITE);
|
||||||
|
|
||||||
|
BeginMode3D(camera);
|
||||||
|
|
||||||
|
DrawCube(cubePosition, 2.0f, 2.0f, 2.0f, RED);
|
||||||
|
DrawCubeWires(cubePosition, 2.0f, 2.0f, 2.0f, MAROON);
|
||||||
|
|
||||||
|
DrawGrid(10, 1.0f);
|
||||||
|
|
||||||
|
EndMode3D();
|
||||||
|
|
||||||
|
DrawText("Welcome to the third dimension!", 10, 40, 20, DARKGRAY);
|
||||||
|
|
||||||
|
DrawFPS(10, 10);
|
||||||
|
|
||||||
|
EndDrawing();
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
}
|
||||||
|
|
||||||
|
// De-Initialization
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
CloseWindow(); // Close window and OpenGL context
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
BIN
examples/core/core_3d_camera_mode.png
Normal file
BIN
examples/core/core_3d_camera_mode.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 8.3 KiB |
|
|
@ -1,94 +0,0 @@
|
||||||
/*******************************************************************************************
|
|
||||||
*
|
|
||||||
* raylib [core] example - Color selection by mouse (collision detection)
|
|
||||||
*
|
|
||||||
* 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)
|
|
||||||
*
|
|
||||||
* Copyright (c) 2014 Ramon Santamaria (@raysan5)
|
|
||||||
*
|
|
||||||
********************************************************************************************/
|
|
||||||
|
|
||||||
#include "raylib.h"
|
|
||||||
|
|
||||||
int main()
|
|
||||||
{
|
|
||||||
// Initialization
|
|
||||||
//--------------------------------------------------------------------------------------
|
|
||||||
int screenWidth = 800;
|
|
||||||
int screenHeight = 450;
|
|
||||||
|
|
||||||
InitWindow(screenWidth, screenHeight, "raylib [core] example - color selection (collision detection)");
|
|
||||||
|
|
||||||
Color colors[21] = { DARKGRAY, MAROON, ORANGE, DARKGREEN, DARKBLUE, DARKPURPLE, DARKBROWN,
|
|
||||||
GRAY, RED, GOLD, LIME, BLUE, VIOLET, BROWN, LIGHTGRAY, PINK, YELLOW,
|
|
||||||
GREEN, SKYBLUE, PURPLE, BEIGE };
|
|
||||||
|
|
||||||
Rectangle colorsRecs[21]; // Rectangles array
|
|
||||||
|
|
||||||
// Fills colorsRecs data (for every rectangle)
|
|
||||||
for (int i = 0; i < 21; i++)
|
|
||||||
{
|
|
||||||
colorsRecs[i].x = 20 + 100*(i%7) + 10*(i%7);
|
|
||||||
colorsRecs[i].y = 60 + 100*(i/7) + 10*(i/7);
|
|
||||||
colorsRecs[i].width = 100;
|
|
||||||
colorsRecs[i].height = 100;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool selected[21] = { false }; // Selected rectangles indicator
|
|
||||||
|
|
||||||
Vector2 mousePoint;
|
|
||||||
|
|
||||||
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
|
||||||
//--------------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
// Main game loop
|
|
||||||
while (!WindowShouldClose()) // Detect window close button or ESC key
|
|
||||||
{
|
|
||||||
// Update
|
|
||||||
//----------------------------------------------------------------------------------
|
|
||||||
mousePoint = GetMousePosition();
|
|
||||||
|
|
||||||
for (int i = 0; i < 21; i++) // Iterate along all the rectangles
|
|
||||||
{
|
|
||||||
if (CheckCollisionPointRec(mousePoint, colorsRecs[i]))
|
|
||||||
{
|
|
||||||
colors[i].a = 120;
|
|
||||||
|
|
||||||
if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) selected[i] = !selected[i];
|
|
||||||
}
|
|
||||||
else colors[i].a = 255;
|
|
||||||
}
|
|
||||||
//----------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
// Draw
|
|
||||||
//----------------------------------------------------------------------------------
|
|
||||||
BeginDrawing();
|
|
||||||
|
|
||||||
ClearBackground(RAYWHITE);
|
|
||||||
|
|
||||||
for (int i = 0; i < 21; i++) // Draw all rectangles
|
|
||||||
{
|
|
||||||
DrawRectangleRec(colorsRecs[i], colors[i]);
|
|
||||||
|
|
||||||
// Draw four rectangles around selected rectangle
|
|
||||||
if (selected[i])
|
|
||||||
{
|
|
||||||
DrawRectangle(colorsRecs[i].x, colorsRecs[i].y, 100, 10, RAYWHITE); // Square top rectangle
|
|
||||||
DrawRectangle(colorsRecs[i].x, colorsRecs[i].y, 10, 100, RAYWHITE); // Square left rectangle
|
|
||||||
DrawRectangle(colorsRecs[i].x + 90, colorsRecs[i].y, 10, 100, RAYWHITE); // Square right rectangle
|
|
||||||
DrawRectangle(colorsRecs[i].x, colorsRecs[i].y + 90, 100, 10, RAYWHITE); // Square bottom rectangle
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
EndDrawing();
|
|
||||||
//----------------------------------------------------------------------------------
|
|
||||||
}
|
|
||||||
|
|
||||||
// De-Initialization
|
|
||||||
//--------------------------------------------------------------------------------------
|
|
||||||
CloseWindow(); // Close window and OpenGL context
|
|
||||||
//--------------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
Binary file not shown.
|
Before Width: | Height: | Size: 14 KiB |
|
|
@ -5,7 +5,9 @@
|
||||||
* This example has been created using raylib 2.1 (www.raylib.com)
|
* This example has been created using raylib 2.1 (www.raylib.com)
|
||||||
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
|
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
|
||||||
*
|
*
|
||||||
* Copyright (c) 2018 Ramon Santamaria (@raysan5) and Pablo Marcos Oltra (@pamarcos)
|
* Example contributed by Pablo Marcos Oltra (@pamarcos) and reviewed by Ramon Santamaria (@raysan5)
|
||||||
|
*
|
||||||
|
* Copyright (c) 2018 Pablo Marcos Oltra (@pamarcos) and Ramon Santamaria (@raysan5)
|
||||||
*
|
*
|
||||||
********************************************************************************************/
|
********************************************************************************************/
|
||||||
|
|
||||||
|
|
|
||||||
115
examples/core/core_input_gestures.c
Normal file
115
examples/core/core_input_gestures.c
Normal file
|
|
@ -0,0 +1,115 @@
|
||||||
|
/*******************************************************************************************
|
||||||
|
*
|
||||||
|
* raylib [core] example - Input Gestures Detection
|
||||||
|
*
|
||||||
|
* This example has been created using raylib 1.4 (www.raylib.com)
|
||||||
|
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
|
||||||
|
*
|
||||||
|
* Copyright (c) 2016 Ramon Santamaria (@raysan5)
|
||||||
|
*
|
||||||
|
********************************************************************************************/
|
||||||
|
|
||||||
|
#include "raylib.h"
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#define MAX_GESTURE_STRINGS 20
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
// Initialization
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
int screenWidth = 800;
|
||||||
|
int screenHeight = 450;
|
||||||
|
|
||||||
|
InitWindow(screenWidth, screenHeight, "raylib [core] example - input gestures");
|
||||||
|
|
||||||
|
Vector2 touchPosition = { 0, 0 };
|
||||||
|
Rectangle touchArea = { 220, 10, screenWidth - 230, screenHeight - 20 };
|
||||||
|
|
||||||
|
int gesturesCount = 0;
|
||||||
|
char gestureStrings[MAX_GESTURE_STRINGS][32];
|
||||||
|
|
||||||
|
int currentGesture = GESTURE_NONE;
|
||||||
|
int lastGesture = GESTURE_NONE;
|
||||||
|
|
||||||
|
//SetGesturesEnabled(0b0000000000001001); // Enable only some gestures to be detected
|
||||||
|
|
||||||
|
SetTargetFPS(60);
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Main game loop
|
||||||
|
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||||
|
{
|
||||||
|
// Update
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
lastGesture = currentGesture;
|
||||||
|
currentGesture = GetGestureDetected();
|
||||||
|
touchPosition = GetTouchPosition(0);
|
||||||
|
|
||||||
|
if (CheckCollisionPointRec(touchPosition, touchArea) && (currentGesture != GESTURE_NONE))
|
||||||
|
{
|
||||||
|
if (currentGesture != lastGesture)
|
||||||
|
{
|
||||||
|
// Store gesture string
|
||||||
|
switch (currentGesture)
|
||||||
|
{
|
||||||
|
case GESTURE_TAP: strcpy(gestureStrings[gesturesCount], "GESTURE TAP"); break;
|
||||||
|
case GESTURE_DOUBLETAP: strcpy(gestureStrings[gesturesCount], "GESTURE DOUBLETAP"); break;
|
||||||
|
case GESTURE_HOLD: strcpy(gestureStrings[gesturesCount], "GESTURE HOLD"); break;
|
||||||
|
case GESTURE_DRAG: strcpy(gestureStrings[gesturesCount], "GESTURE DRAG"); break;
|
||||||
|
case GESTURE_SWIPE_RIGHT: strcpy(gestureStrings[gesturesCount], "GESTURE SWIPE RIGHT"); break;
|
||||||
|
case GESTURE_SWIPE_LEFT: strcpy(gestureStrings[gesturesCount], "GESTURE SWIPE LEFT"); break;
|
||||||
|
case GESTURE_SWIPE_UP: strcpy(gestureStrings[gesturesCount], "GESTURE SWIPE UP"); break;
|
||||||
|
case GESTURE_SWIPE_DOWN: strcpy(gestureStrings[gesturesCount], "GESTURE SWIPE DOWN"); break;
|
||||||
|
case GESTURE_PINCH_IN: strcpy(gestureStrings[gesturesCount], "GESTURE PINCH IN"); break;
|
||||||
|
case GESTURE_PINCH_OUT: strcpy(gestureStrings[gesturesCount], "GESTURE PINCH OUT"); break;
|
||||||
|
default: break;
|
||||||
|
}
|
||||||
|
|
||||||
|
gesturesCount++;
|
||||||
|
|
||||||
|
// Reset gestures strings
|
||||||
|
if (gesturesCount >= MAX_GESTURE_STRINGS)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < MAX_GESTURE_STRINGS; i++) strcpy(gestureStrings[i], "\0");
|
||||||
|
|
||||||
|
gesturesCount = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Draw
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
BeginDrawing();
|
||||||
|
|
||||||
|
ClearBackground(RAYWHITE);
|
||||||
|
|
||||||
|
DrawRectangleRec(touchArea, GRAY);
|
||||||
|
DrawRectangle(225, 15, screenWidth - 240, screenHeight - 30, RAYWHITE);
|
||||||
|
|
||||||
|
DrawText("GESTURES TEST AREA", screenWidth - 270, screenHeight - 40, 20, Fade(GRAY, 0.5f));
|
||||||
|
|
||||||
|
for (int i = 0; i < gesturesCount; i++)
|
||||||
|
{
|
||||||
|
if (i%2 == 0) DrawRectangle(10, 30 + 20*i, 200, 20, Fade(LIGHTGRAY, 0.5f));
|
||||||
|
else DrawRectangle(10, 30 + 20*i, 200, 20, Fade(LIGHTGRAY, 0.3f));
|
||||||
|
|
||||||
|
if (i < gesturesCount - 1) DrawText(gestureStrings[i], 35, 36 + 20*i, 10, DARKGRAY);
|
||||||
|
else DrawText(gestureStrings[i], 35, 36 + 20*i, 10, MAROON);
|
||||||
|
}
|
||||||
|
|
||||||
|
DrawRectangleLines(10, 29, 200, screenHeight - 50, GRAY);
|
||||||
|
DrawText("DETECTED GESTURES", 50, 15, 10, GRAY);
|
||||||
|
|
||||||
|
if (currentGesture != GESTURE_NONE) DrawCircleV(touchPosition, 30, MAROON);
|
||||||
|
|
||||||
|
EndDrawing();
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
}
|
||||||
|
|
||||||
|
// De-Initialization
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
CloseWindow(); // Close window and OpenGL context
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
}
|
||||||
BIN
examples/core/core_input_gestures.png
Normal file
BIN
examples/core/core_input_gestures.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 19 KiB |
58
examples/core/core_input_mouse_wheel.c
Normal file
58
examples/core/core_input_mouse_wheel.c
Normal file
|
|
@ -0,0 +1,58 @@
|
||||||
|
/*******************************************************************************************
|
||||||
|
*
|
||||||
|
* raylib [core] examples - Mouse wheel input
|
||||||
|
*
|
||||||
|
* This test has been created using raylib 1.1 (www.raylib.com)
|
||||||
|
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
|
||||||
|
*
|
||||||
|
* Copyright (c) 2014 Ramon Santamaria (@raysan5)
|
||||||
|
*
|
||||||
|
********************************************************************************************/
|
||||||
|
|
||||||
|
#include "raylib.h"
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
// Initialization
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
int screenWidth = 800;
|
||||||
|
int screenHeight = 450;
|
||||||
|
|
||||||
|
InitWindow(screenWidth, screenHeight, "raylib [core] example - input mouse wheel");
|
||||||
|
|
||||||
|
int boxPositionY = screenHeight/2 - 40;
|
||||||
|
int scrollSpeed = 4; // Scrolling speed in pixels
|
||||||
|
|
||||||
|
SetTargetFPS(60);
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Main game loop
|
||||||
|
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||||
|
{
|
||||||
|
// Update
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
boxPositionY -= (GetMouseWheelMove()*scrollSpeed);
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Draw
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
BeginDrawing();
|
||||||
|
|
||||||
|
ClearBackground(RAYWHITE);
|
||||||
|
|
||||||
|
DrawRectangle(screenWidth/2 - 40, boxPositionY, 80, 80, MAROON);
|
||||||
|
|
||||||
|
DrawText("Use mouse wheel to move the cube up and down!", 10, 10, 20, GRAY);
|
||||||
|
DrawText(FormatText("Box position Y: %03i", boxPositionY), 10, 40, 20, LIGHTGRAY);
|
||||||
|
|
||||||
|
EndDrawing();
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
}
|
||||||
|
|
||||||
|
// De-Initialization
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
CloseWindow(); // Close window and OpenGL context
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
BIN
examples/core/core_input_mouse_wheel.png
Normal file
BIN
examples/core/core_input_mouse_wheel.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 15 KiB |
|
|
@ -5,7 +5,9 @@
|
||||||
* This example has been created using raylib 2.1 (www.raylib.com)
|
* This example has been created using raylib 2.1 (www.raylib.com)
|
||||||
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
|
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
|
||||||
*
|
*
|
||||||
* Copyright (c) 2014-2019 Berni and Ramon Santamaria (@raysan5)
|
* Example contributed by Berni (@Berni8k) and reviewed by Ramon Santamaria (@raysan5)
|
||||||
|
*
|
||||||
|
* Copyright (c) 2019 Berni (@Berni8k) and Ramon Santamaria (@raysan5)
|
||||||
*
|
*
|
||||||
********************************************************************************************/
|
********************************************************************************************/
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -15,10 +15,13 @@
|
||||||
#include "raylib.h"
|
#include "raylib.h"
|
||||||
|
|
||||||
#include "pthread.h" // POSIX style threads management
|
#include "pthread.h" // POSIX style threads management
|
||||||
#include <stdatomic.h>
|
|
||||||
|
|
||||||
#include <time.h> // Required for clock() function
|
#include <stdatomic.h> // C11 atomic data types
|
||||||
|
|
||||||
|
#include <time.h> // Required for: clock()
|
||||||
|
|
||||||
|
// Using C11 atomics for synchronization
|
||||||
|
// NOTE: A plain bool (or any plain data type for that matter) can't be used for inter-thread synchronization
|
||||||
static atomic_bool dataLoaded = ATOMIC_VAR_INIT(false); // Data Loaded completion indicator
|
static atomic_bool dataLoaded = ATOMIC_VAR_INIT(false); // Data Loaded completion indicator
|
||||||
static void *LoadDataThread(void *arg); // Loading data thread function declaration
|
static void *LoadDataThread(void *arg); // Loading data thread function declaration
|
||||||
|
|
||||||
|
|
@ -48,33 +51,37 @@ int main()
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
switch (state)
|
switch (state)
|
||||||
{
|
{
|
||||||
case STATE_WAITING:
|
case STATE_WAITING:
|
||||||
if (IsKeyPressed(KEY_ENTER))
|
|
||||||
{
|
{
|
||||||
int error = pthread_create(&threadId, NULL, &LoadDataThread, NULL);
|
if (IsKeyPressed(KEY_ENTER))
|
||||||
if (error != 0) TraceLog(LOG_ERROR, "Error creating loading thread");
|
{
|
||||||
else TraceLog(LOG_INFO, "Loading thread initialized successfully");
|
int error = pthread_create(&threadId, NULL, &LoadDataThread, NULL);
|
||||||
|
if (error != 0) TraceLog(LOG_ERROR, "Error creating loading thread");
|
||||||
|
else TraceLog(LOG_INFO, "Loading thread initialized successfully");
|
||||||
|
|
||||||
state = STATE_LOADING;
|
state = STATE_LOADING;
|
||||||
}
|
}
|
||||||
break;
|
} break;
|
||||||
case STATE_LOADING:
|
case STATE_LOADING:
|
||||||
framesCounter++;
|
|
||||||
if (atomic_load(&dataLoaded))
|
|
||||||
{
|
{
|
||||||
framesCounter = 0;
|
framesCounter++;
|
||||||
state = STATE_FINISHED;
|
if (atomic_load(&dataLoaded))
|
||||||
}
|
{
|
||||||
break;
|
framesCounter = 0;
|
||||||
case STATE_FINISHED:
|
state = STATE_FINISHED;
|
||||||
if (IsKeyPressed(KEY_ENTER))
|
}
|
||||||
|
} break;
|
||||||
|
case STATE_FINISHED:
|
||||||
{
|
{
|
||||||
// Reset everything to launch again
|
if (IsKeyPressed(KEY_ENTER))
|
||||||
atomic_store(&dataLoaded, false);
|
{
|
||||||
dataProgress = 0;
|
// Reset everything to launch again
|
||||||
state = STATE_WAITING;
|
atomic_store(&dataLoaded, false);
|
||||||
}
|
dataProgress = 0;
|
||||||
break;
|
state = STATE_WAITING;
|
||||||
|
}
|
||||||
|
} break;
|
||||||
|
default: break;
|
||||||
}
|
}
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
@ -84,19 +91,22 @@ int main()
|
||||||
|
|
||||||
ClearBackground(RAYWHITE);
|
ClearBackground(RAYWHITE);
|
||||||
|
|
||||||
switch(state) {
|
switch (state)
|
||||||
case STATE_WAITING:
|
{
|
||||||
DrawText("PRESS ENTER to START LOADING DATA", 150, 170, 20, DARKGRAY);
|
case STATE_WAITING: DrawText("PRESS ENTER to START LOADING DATA", 150, 170, 20, DARKGRAY); break;
|
||||||
break;
|
case STATE_LOADING:
|
||||||
case STATE_LOADING:
|
{
|
||||||
DrawRectangle(150, 200, dataProgress, 60, SKYBLUE);
|
DrawRectangle(150, 200, dataProgress, 60, SKYBLUE);
|
||||||
if ((framesCounter/15)%2)
|
if ((framesCounter/15)%2) DrawText("LOADING DATA...", 240, 210, 40, DARKBLUE);
|
||||||
DrawText("LOADING DATA...", 240, 210, 40, DARKBLUE);
|
|
||||||
break;
|
} break;
|
||||||
case STATE_FINISHED:
|
case STATE_FINISHED:
|
||||||
DrawRectangle(150, 200, 500, 60, LIME);
|
{
|
||||||
DrawText("DATA LOADED!", 250, 210, 40, GREEN);
|
DrawRectangle(150, 200, 500, 60, LIME);
|
||||||
break;
|
DrawText("DATA LOADED!", 250, 210, 40, GREEN);
|
||||||
|
|
||||||
|
} break;
|
||||||
|
default: break;
|
||||||
}
|
}
|
||||||
|
|
||||||
DrawRectangleLines(150, 200, 500, 60, DARKGRAY);
|
DrawRectangleLines(150, 200, 500, 60, DARKGRAY);
|
||||||
|
|
|
||||||
90
examples/core/core_window_letterbox.c
Normal file
90
examples/core/core_window_letterbox.c
Normal file
|
|
@ -0,0 +1,90 @@
|
||||||
|
/*******************************************************************************************
|
||||||
|
*
|
||||||
|
* raylib [core] example - window scale letterbox
|
||||||
|
*
|
||||||
|
* 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 Anata (@anatagawa) and reviewed by Ramon Santamaria (@raysan5)
|
||||||
|
*
|
||||||
|
* Copyright (c) 2019 Anata (@anatagawa) and Ramon Santamaria (@raysan5)
|
||||||
|
*
|
||||||
|
********************************************************************************************/
|
||||||
|
|
||||||
|
#include "raylib.h"
|
||||||
|
|
||||||
|
#define max(a, b) ((a)>(b)? (a) : (b))
|
||||||
|
#define min(a, b) ((a)<(b)? (a) : (b))
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
const int windowWidth = 800;
|
||||||
|
const int windowHeight = 450;
|
||||||
|
|
||||||
|
// Enable config flags for resizable window and vertical synchro
|
||||||
|
SetConfigFlags(FLAG_WINDOW_RESIZABLE | FLAG_VSYNC_HINT);
|
||||||
|
InitWindow(windowWidth, windowHeight, "raylib [core] example - window scale letterbox");
|
||||||
|
SetWindowMinSize(320, 240);
|
||||||
|
|
||||||
|
int gameScreenWidth = 640;
|
||||||
|
int gameScreenHeight = 480;
|
||||||
|
|
||||||
|
// Render texture initialization
|
||||||
|
RenderTexture2D target = LoadRenderTexture(gameScreenWidth, gameScreenHeight);
|
||||||
|
SetTextureFilter(target.texture, FILTER_BILINEAR); // Texture scale filter to use
|
||||||
|
|
||||||
|
Color colors[10] = { 0 };
|
||||||
|
for (int i = 0; i < 10; i++) colors[i] = (Color){ GetRandomValue(100, 250), GetRandomValue(50, 150), GetRandomValue(10, 100), 255 };
|
||||||
|
|
||||||
|
SetTargetFPS(60);
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Main game loop
|
||||||
|
while( !WindowShouldClose() ) // Detect window close button or ESC key
|
||||||
|
{
|
||||||
|
// Update
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
// Compute required framebuffer scaling
|
||||||
|
float scale = min((float)GetScreenWidth()/gameScreenWidth, (float)GetScreenHeight()/gameScreenHeight);
|
||||||
|
|
||||||
|
if (IsKeyPressed(KEY_SPACE))
|
||||||
|
{
|
||||||
|
// 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 };
|
||||||
|
}
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Draw
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
BeginDrawing();
|
||||||
|
ClearBackground(BLACK);
|
||||||
|
|
||||||
|
// Draw everything in the render texture
|
||||||
|
BeginTextureMode(target);
|
||||||
|
|
||||||
|
ClearBackground(RAYWHITE); // Clear render texture background color
|
||||||
|
|
||||||
|
for (int i = 0; i < 10; i++) DrawRectangle(0, (gameScreenHeight/10)*i, gameScreenWidth, gameScreenHeight/10, colors[i]);
|
||||||
|
|
||||||
|
DrawText("You can resize the window,\nand see the screen scaling!", 10, 25, 20, WHITE);
|
||||||
|
|
||||||
|
EndTextureMode();
|
||||||
|
|
||||||
|
// Draw RenderTexture2D to window, properly scaled
|
||||||
|
DrawTexturePro(target.texture, (Rectangle){ 0.0f, 0.0f, (float)target.texture.width, (float)-target.texture.height },
|
||||||
|
(Rectangle){ (GetScreenWidth() - ((float)gameScreenWidth*scale))*0.5, (GetScreenHeight() - ((float)gameScreenHeight*scale))*0.5,
|
||||||
|
(float)gameScreenWidth*scale, (float)gameScreenHeight*scale }, (Vector2){ 0, 0 }, 0.0f, WHITE);
|
||||||
|
|
||||||
|
EndDrawing();
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
}
|
||||||
|
|
||||||
|
// De-Initialization
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
UnloadRenderTexture(target); // Unload render texture
|
||||||
|
|
||||||
|
CloseWindow(); // Close window and OpenGL context
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
BIN
examples/core/core_window_letterbox.png
Normal file
BIN
examples/core/core_window_letterbox.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 18 KiB |
|
|
@ -4,10 +4,12 @@
|
||||||
*
|
*
|
||||||
* This program is heavily based on the geometric objects example
|
* This program is heavily based on the geometric objects example
|
||||||
*
|
*
|
||||||
* This example has been created using raylib 1.9.7 (www.raylib.com)
|
* This example has been created using raylib 2.0 (www.raylib.com)
|
||||||
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
|
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
|
||||||
*
|
*
|
||||||
* Copyright (c) 2018 Max Danielsson & Ramon Santamaria (@raysan5)
|
* Example contributed by Max Danielsson (@autious) and reviewed by Ramon Santamaria (@raysan5)
|
||||||
|
*
|
||||||
|
* Copyright (c) 2018 Max Danielsson (@autious) and Ramon Santamaria (@raysan5)
|
||||||
*
|
*
|
||||||
********************************************************************************************/
|
********************************************************************************************/
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,9 +5,9 @@
|
||||||
* This example has been created using raylib 1.8 (www.raylib.com)
|
* This example has been created using raylib 1.8 (www.raylib.com)
|
||||||
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
|
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
|
||||||
*
|
*
|
||||||
* Example based on Berni work on Raspberry Pi.
|
* Example contributed by Berni (@Berni8k) and reviewed by Ramon Santamaria (@raysan5)
|
||||||
*
|
*
|
||||||
* Copyright (c) 2017 Ramon Santamaria (@raysan5)
|
* Copyright (c) 2017 Berni (@Berni8k) and Ramon Santamaria (@raysan5)
|
||||||
*
|
*
|
||||||
********************************************************************************************/
|
********************************************************************************************/
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
/*******************************************************************************************
|
/*******************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib [shaders] example - Render julia sets using a shader.
|
* raylib [shaders] example - julia sets
|
||||||
*
|
*
|
||||||
* NOTE: This example requires raylib OpenGL 3.3 or ES2 versions for shaders support,
|
* NOTE: This example requires raylib OpenGL 3.3 or ES2 versions for shaders support,
|
||||||
* OpenGL 1.1 does not support shaders, recompile raylib to OpenGL 3.3 version.
|
* OpenGL 1.1 does not support shaders, recompile raylib to OpenGL 3.3 version.
|
||||||
|
|
@ -10,73 +10,68 @@
|
||||||
* This example has been created using raylib 2.5 (www.raylib.com)
|
* 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)
|
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
|
||||||
*
|
*
|
||||||
* Author: eggmund (https://github.com/eggmund)
|
* Example contributed by eggmund (@eggmund) and reviewed by Ramon Santamaria (@raysan5)
|
||||||
|
*
|
||||||
|
* Copyright (c) 2019 eggmund (@eggmund) and Ramon Santamaria (@raysan5)
|
||||||
*
|
*
|
||||||
********************************************************************************************/
|
********************************************************************************************/
|
||||||
|
|
||||||
#include "raylib.h"
|
#include "raylib.h"
|
||||||
#include <string.h> // For memcpy
|
|
||||||
|
|
||||||
// Speed when using auto
|
#include "raymath.h"
|
||||||
const float AUTO_SPEED = 0.0005;
|
|
||||||
|
|
||||||
// A few good julia sets
|
// A few good julia sets
|
||||||
const float POINTS_OF_INTEREST[6][2] =
|
const float POINTS_OF_INTEREST[6][2] =
|
||||||
{
|
{
|
||||||
{-0.348827, 0.607167},
|
{ -0.348827, 0.607167 },
|
||||||
{-0.786268, 0.169728},
|
{ -0.786268, 0.169728 },
|
||||||
{-0.8, 0.156},
|
{ -0.8, 0.156 },
|
||||||
{0.285, 0.0},
|
{ 0.285, 0.0 },
|
||||||
{-0.835, -0.2321},
|
{ -0.835, -0.2321 },
|
||||||
{-0.70176, -0.3842},
|
{ -0.70176, -0.3842 },
|
||||||
};
|
};
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
// Initialization
|
// Initialization
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
int screenWidth = 1280;
|
const int screenWidth = 800;
|
||||||
int screenHeight = 720;
|
const int screenHeight = 450;
|
||||||
|
|
||||||
InitWindow(screenWidth, screenHeight, "raylib [shaders] example - julia set renderer");
|
InitWindow(screenWidth, screenHeight, "raylib [shaders] example - julia sets");
|
||||||
|
|
||||||
// If julia set is rendered for this frame.
|
|
||||||
bool rendered = false;
|
|
||||||
|
|
||||||
bool showControls = true;
|
|
||||||
|
|
||||||
// Multiplier of speed to change c value. Set to 3 to start off with.
|
|
||||||
int incrementSpeed = 3;
|
|
||||||
|
|
||||||
// Offset and zoom to draw the julia set at. (centered on screen and 1.6 times smaller)
|
|
||||||
float offset[2] = { -(float)screenWidth/2, -(float)screenHeight/2 };
|
|
||||||
float zoom = 1.6;
|
|
||||||
|
|
||||||
// c constant to use in z^2 + c
|
|
||||||
float c[2];
|
|
||||||
// Copy a point of interest into the c variable. 4 bytes per float (32 bits).
|
|
||||||
memcpy(c, &POINTS_OF_INTEREST[0], 8);
|
|
||||||
|
|
||||||
// Load julia set shader
|
// Load julia set shader
|
||||||
// NOTE: Defining 0 (NULL) for vertex shader forces usage of internal default vertex shader
|
// NOTE: Defining 0 (NULL) for vertex shader forces usage of internal default vertex shader
|
||||||
Shader shader = LoadShader(0, "resources/shaders/glsl330/julia_shader.fs");
|
Shader shader = LoadShader(0, "resources/shaders/glsl330/julia_shader.fs");
|
||||||
|
|
||||||
// Get variable (uniform) location on the shader to connect with the program
|
// c constant to use in z^2 + c
|
||||||
|
float c[2] = { POINTS_OF_INTEREST[0][0], POINTS_OF_INTEREST[0][1] };
|
||||||
|
|
||||||
|
// Offset and zoom to draw the julia set at. (centered on screen and 1.6 times smaller)
|
||||||
|
float offset[2] = { -(float)screenWidth/2, -(float)screenHeight/2 };
|
||||||
|
float zoom = 1.6f;
|
||||||
|
|
||||||
|
// Get variable (uniform) locations on the shader to connect with the program
|
||||||
// NOTE: If uniform variable could not be found in the shader, function returns -1
|
// NOTE: If uniform variable could not be found in the shader, function returns -1
|
||||||
// The location of c will be stored since we will need to change this whenever c changes
|
|
||||||
int cLoc = GetShaderLocation(shader, "c");
|
int cLoc = GetShaderLocation(shader, "c");
|
||||||
|
int zoomLoc = GetShaderLocation(shader, "zoom");
|
||||||
|
int offsetLoc = GetShaderLocation(shader, "offset");
|
||||||
|
|
||||||
// Tell the shader what the screen dimensions, zoom, offset and c are
|
// Tell the shader what the screen dimensions, zoom, offset and c are
|
||||||
float screenDims[2] = { (float)screenWidth, (float)screenHeight };
|
float screenDims[2] = { (float)screenWidth, (float)screenHeight };
|
||||||
SetShaderValue(shader, GetShaderLocation(shader, "screenDims"), screenDims, UNIFORM_VEC2);
|
SetShaderValue(shader, GetShaderLocation(shader, "screenDims"), screenDims, UNIFORM_VEC2);
|
||||||
SetShaderValue(shader, GetShaderLocation(shader, "zoom"), &zoom, UNIFORM_FLOAT);
|
|
||||||
SetShaderValue(shader, GetShaderLocation(shader, "offset"), offset, UNIFORM_VEC2);
|
|
||||||
|
|
||||||
SetShaderValue(shader, cLoc, c, UNIFORM_VEC2);
|
SetShaderValue(shader, cLoc, c, UNIFORM_VEC2);
|
||||||
|
SetShaderValue(shader, zoomLoc, &zoom, UNIFORM_FLOAT);
|
||||||
|
SetShaderValue(shader, offsetLoc, offset, UNIFORM_VEC2);
|
||||||
|
|
||||||
// Create a RenderTexture2D to be used for render to texture
|
// Create a RenderTexture2D to be used for render to texture
|
||||||
RenderTexture2D target = LoadRenderTexture(screenWidth, screenHeight);
|
RenderTexture2D target = LoadRenderTexture(screenWidth, screenHeight);
|
||||||
|
|
||||||
|
int incrementSpeed = 3; // Multiplier of speed to change c value
|
||||||
|
bool showControls = true; // Show controls
|
||||||
|
bool pause = false; // Pause animation
|
||||||
|
|
||||||
SetTargetFPS(60); // Set the window to run at 60 frames-per-second
|
SetTargetFPS(60); // Set the window to run at 60 frames-per-second
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
@ -86,115 +81,86 @@ int main()
|
||||||
// Update
|
// Update
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
// Get input
|
// Press [1 - 6] to reset c to a point of interest
|
||||||
//----------------------------------------------------------------------------------
|
if (IsKeyPressed(KEY_ONE) ||
|
||||||
|
IsKeyPressed(KEY_TWO) ||
|
||||||
// Press 1 - 6 to reset c to a point of interest.
|
IsKeyPressed(KEY_THREE) ||
|
||||||
if (IsKeyPressed(KEY_ONE) || IsKeyPressed(KEY_TWO) || IsKeyPressed(KEY_THREE) || IsKeyPressed(KEY_FOUR) || IsKeyPressed(KEY_FIVE) || IsKeyPressed(KEY_SIX))
|
IsKeyPressed(KEY_FOUR) ||
|
||||||
|
IsKeyPressed(KEY_FIVE) ||
|
||||||
|
IsKeyPressed(KEY_SIX))
|
||||||
{
|
{
|
||||||
if (IsKeyPressed(KEY_ONE))
|
if (IsKeyPressed(KEY_ONE)) c[0] = POINTS_OF_INTEREST[0][0], c[1] = POINTS_OF_INTEREST[0][1];
|
||||||
{
|
else if (IsKeyPressed(KEY_TWO)) c[0] = POINTS_OF_INTEREST[1][0], c[1] = POINTS_OF_INTEREST[1][1];
|
||||||
memcpy(c, &POINTS_OF_INTEREST[0], 8);
|
else if (IsKeyPressed(KEY_THREE)) c[0] = POINTS_OF_INTEREST[2][0], c[1] = POINTS_OF_INTEREST[2][1];
|
||||||
}
|
else if (IsKeyPressed(KEY_FOUR)) c[0] = POINTS_OF_INTEREST[3][0], c[1] = POINTS_OF_INTEREST[3][1];
|
||||||
else if (IsKeyPressed(KEY_TWO))
|
else if (IsKeyPressed(KEY_FIVE)) c[0] = POINTS_OF_INTEREST[4][0], c[1] = POINTS_OF_INTEREST[4][1];
|
||||||
{
|
else if (IsKeyPressed(KEY_SIX)) c[0] = POINTS_OF_INTEREST[5][0], c[1] = POINTS_OF_INTEREST[5][1];
|
||||||
memcpy(c, &POINTS_OF_INTEREST[1], 8);
|
|
||||||
}
|
|
||||||
else if (IsKeyPressed(KEY_THREE))
|
|
||||||
{
|
|
||||||
memcpy(c, &POINTS_OF_INTEREST[2], 8);
|
|
||||||
}
|
|
||||||
else if (IsKeyPressed(KEY_FOUR))
|
|
||||||
{
|
|
||||||
memcpy(c, &POINTS_OF_INTEREST[3], 8);
|
|
||||||
}
|
|
||||||
else if (IsKeyPressed(KEY_FIVE))
|
|
||||||
{
|
|
||||||
memcpy(c, &POINTS_OF_INTEREST[4], 8);
|
|
||||||
}
|
|
||||||
else if (IsKeyPressed(KEY_SIX))
|
|
||||||
{
|
|
||||||
memcpy(c, &POINTS_OF_INTEREST[5], 8);
|
|
||||||
}
|
|
||||||
SetShaderValue(shader, cLoc, c, UNIFORM_VEC2);
|
SetShaderValue(shader, cLoc, c, UNIFORM_VEC2);
|
||||||
rendered = false; // c value has changed, so render the set again.
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Press "r" to stop changing c
|
if (IsKeyPressed(KEY_P)) pause = !pause; // Pause animation (c change)
|
||||||
if (IsKeyPressed(KEY_R))
|
if (IsKeyPressed(KEY_F1)) showControls = !showControls; // Toggle whether or not to show controls
|
||||||
{
|
|
||||||
incrementSpeed = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Toggle whether or not to show controls
|
if (!pause)
|
||||||
if (IsKeyPressed(KEY_H))
|
|
||||||
{
|
{
|
||||||
showControls = !showControls;
|
if (IsKeyDown(KEY_RIGHT)) incrementSpeed++;
|
||||||
}
|
else if (IsKeyDown(KEY_LEFT)) incrementSpeed--;
|
||||||
|
|
||||||
// Scroll to change c increment speed.
|
// Use mouse wheel to change zoom
|
||||||
int mouseMv = GetMouseWheelMove(); // Get the amount the mouse has moved this frame
|
zoom -= (float)GetMouseWheelMove()/10.f;
|
||||||
if (mouseMv != 0)
|
SetShaderValue(shader, zoomLoc, &zoom, UNIFORM_FLOAT);
|
||||||
{
|
|
||||||
if (IsKeyDown(KEY_LEFT_SHIFT))
|
// Use mouse button to change offset
|
||||||
|
if (IsMouseButtonDown(MOUSE_LEFT_BUTTON))
|
||||||
{
|
{
|
||||||
incrementSpeed += mouseMv * 10;
|
// TODO: Logic is not correct, the idea is getting zoom focus to pointed area
|
||||||
}
|
Vector2 mousePos = GetMousePosition();
|
||||||
else
|
|
||||||
{
|
|
||||||
incrementSpeed += mouseMv;
|
|
||||||
}
|
|
||||||
rendered = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (incrementSpeed != 0)
|
offset[0] = mousePos.x -(float)screenWidth;
|
||||||
{
|
offset[1] = mousePos.y -(float)screenHeight;
|
||||||
float amount = GetFrameTime() * incrementSpeed * AUTO_SPEED;
|
|
||||||
|
SetShaderValue(shader, offsetLoc, offset, UNIFORM_VEC2);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Increment c value with time
|
||||||
|
float amount = GetFrameTime()*incrementSpeed*0.0005f;
|
||||||
c[0] += amount;
|
c[0] += amount;
|
||||||
c[1] += amount;
|
c[1] += amount;
|
||||||
|
|
||||||
// Update the c value in the shader.
|
|
||||||
SetShaderValue(shader, cLoc, c, UNIFORM_VEC2);
|
SetShaderValue(shader, cLoc, c, UNIFORM_VEC2);
|
||||||
rendered = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
// Draw
|
// Draw
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
BeginDrawing();
|
BeginDrawing();
|
||||||
|
|
||||||
ClearBackground(BLACK); // Clear the screen of the previous frame.
|
ClearBackground(BLACK); // Clear the screen of the previous frame.
|
||||||
|
|
||||||
// If the c value has changed, redraw the julia set using the shader, onto the render texture.
|
// Using a render texture to draw Julia set
|
||||||
if (!rendered)
|
BeginTextureMode(target); // Enable drawing to texture
|
||||||
{
|
ClearBackground(BLACK); // Clear the render texture
|
||||||
BeginTextureMode(target); // Enable drawing to texture
|
|
||||||
|
|
||||||
ClearBackground(BLACK); // Clear the last frame drawn on the texture.
|
// Draw a rectangle in shader mode
|
||||||
|
// NOTE: This acts as a canvas for the shader to draw on
|
||||||
|
BeginShaderMode(shader);
|
||||||
|
DrawRectangle(0, 0, GetScreenWidth(), GetScreenHeight(), BLACK);
|
||||||
|
EndShaderMode();
|
||||||
|
EndTextureMode();
|
||||||
|
|
||||||
// Draw a rectangle in shader mode. This acts as a canvas for the shader to draw on.
|
// Draw the saved texture (rendered julia set)
|
||||||
BeginShaderMode(shader);
|
DrawTextureRec(target.texture, (Rectangle){ 0, 0, target.texture.width, -target.texture.height }, Vector2Zero(), WHITE);
|
||||||
DrawRectangle(0, 0, screenWidth, screenHeight, BLACK);
|
|
||||||
EndShaderMode();
|
|
||||||
|
|
||||||
EndTextureMode();
|
// Draw information
|
||||||
|
//DrawText( FormatText("cx: %f\ncy: %f\nspeed: %d", c[0], c[1], incrementSpeed), 10, 10, 10, RAYWHITE);
|
||||||
rendered = true; // The set is now rendered, so do not compute it again until it next changes.
|
|
||||||
}
|
|
||||||
|
|
||||||
// Draw the saved texture (rendered julia set).
|
|
||||||
DrawTextureRec(target.texture, (Rectangle){ 0, 0, target.texture.width, target.texture.height }, (Vector2){ 0, 0 }, WHITE);
|
|
||||||
|
|
||||||
// Print information.
|
|
||||||
DrawText( FormatText("cx: %f\ncy: %f\nspeed: %d", c[0], c[1], incrementSpeed), 10, 10, 20, RAYWHITE );
|
|
||||||
|
|
||||||
if (showControls)
|
if (showControls)
|
||||||
{
|
{
|
||||||
DrawText("Press keys 1 - 6 to change point of interest.", 10, screenHeight - 88, 20, RAYWHITE);
|
DrawText("Press keys [1 - 6] to change point of interest", 10, GetScreenHeight() - 60, 10, RAYWHITE);
|
||||||
DrawText("Use the scroll wheel to auto increment the c value. Hold shift while scrolling to increase speed by 10.", 10, screenHeight - 66, 20, RAYWHITE);
|
DrawText("Press KEY_LEFT | KEY_RIGHT to change speed", 10, GetScreenHeight() - 45, 10, RAYWHITE);
|
||||||
DrawText("Press 'r' to reset speed.", 10, screenHeight - 44, 20, RAYWHITE);
|
DrawText("Press KEY_P to pause movement animation", 10, GetScreenHeight() - 30, 10, RAYWHITE);
|
||||||
DrawText("Press 'h' to hide these controls.", 10, screenHeight - 22, 20, RAYWHITE);
|
DrawText("Press KEY_F1 to toggle these controls", 10, GetScreenHeight() - 15, 10, RAYWHITE);
|
||||||
}
|
}
|
||||||
|
|
||||||
EndDrawing();
|
EndDrawing();
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,9 @@
|
||||||
* This example has been created using raylib 2.3 (www.raylib.com)
|
* This example has been created using raylib 2.3 (www.raylib.com)
|
||||||
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
|
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
|
||||||
*
|
*
|
||||||
* Copyright (c) 2019 Ramon Santamaria (@raysan5)
|
* Example contributed by Marco Lizza (@MarcoLizza) and reviewed by Ramon Santamaria (@raysan5)
|
||||||
|
*
|
||||||
|
* Copyright (c) 2019 Marco Lizza (@MarcoLizza) and Ramon Santamaria (@raysan5)
|
||||||
*
|
*
|
||||||
********************************************************************************************/
|
********************************************************************************************/
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,8 @@
|
||||||
* This example has been created using raylib 2.0 (www.raylib.com)
|
* This example has been created using raylib 2.0 (www.raylib.com)
|
||||||
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
|
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
|
||||||
*
|
*
|
||||||
|
* Example contributed by Michał Ciesielski and reviewed by Ramon Santamaria (@raysan5)
|
||||||
|
*
|
||||||
* Copyright (c) 2019 Michał Ciesielski and Ramon Santamaria (@raysan5)
|
* Copyright (c) 2019 Michał Ciesielski and Ramon Santamaria (@raysan5)
|
||||||
*
|
*
|
||||||
********************************************************************************************/
|
********************************************************************************************/
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,9 @@
|
||||||
* This example has been created using raylib 2.5 (www.raylib.com)
|
* 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)
|
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
|
||||||
*
|
*
|
||||||
* Copyright (c) 2019 Anata (creator) and Ramon Santamaria (review) (@raysan5)
|
* Example contributed by Anata (@anatagawa) and reviewed by Ramon Santamaria (@raysan5)
|
||||||
|
*
|
||||||
|
* Copyright (c) 2019 Anata (@anatagawa) and Ramon Santamaria (@raysan5)
|
||||||
*
|
*
|
||||||
********************************************************************************************/
|
********************************************************************************************/
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,26 +1,53 @@
|
||||||
/*******************************************************************************************
|
/*******************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib [shapes] example - Draw raylib custom color palette
|
* raylib [shapes] example - Colors palette
|
||||||
*
|
*
|
||||||
* This example has been created using raylib 1.0 (www.raylib.com)
|
* 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)
|
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
|
||||||
*
|
*
|
||||||
* Copyright (c) 2014 Ramon Santamaria (@raysan5)
|
* Copyright (c) 2014-2019 Ramon Santamaria (@raysan5)
|
||||||
*
|
*
|
||||||
********************************************************************************************/
|
********************************************************************************************/
|
||||||
|
|
||||||
#include "raylib.h"
|
#include "raylib.h"
|
||||||
|
|
||||||
|
#define MAX_COLORS_COUNT 21 // Number of colors available
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
// Initialization
|
// Initialization
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
int screenWidth = 800;
|
const int screenWidth = 800;
|
||||||
int screenHeight = 450;
|
const int screenHeight = 450;
|
||||||
|
|
||||||
InitWindow(screenWidth, screenHeight, "raylib [shapes] example - raylib color palette");
|
InitWindow(screenWidth, screenHeight, "raylib [shapes] example - colors palette");
|
||||||
|
|
||||||
SetTargetFPS(60);
|
Color colors[MAX_COLORS_COUNT] = {
|
||||||
|
DARKGRAY, MAROON, ORANGE, DARKGREEN, DARKBLUE, DARKPURPLE, DARKBROWN,
|
||||||
|
GRAY, RED, GOLD, LIME, BLUE, VIOLET, BROWN, LIGHTGRAY, PINK, YELLOW,
|
||||||
|
GREEN, SKYBLUE, PURPLE, BEIGE };
|
||||||
|
|
||||||
|
const char *colorNames[MAX_COLORS_COUNT] = {
|
||||||
|
"DARKGRAY", "MAROON", "ORANGE", "DARKGREEN", "DARKBLUE", "DARKPURPLE",
|
||||||
|
"DARKBROWN", "GRAY", "RED", "GOLD", "LIME", "BLUE", "VIOLET", "BROWN",
|
||||||
|
"LIGHTGRAY", "PINK", "YELLOW", "GREEN", "SKYBLUE", "PURPLE", "BEIGE" };
|
||||||
|
|
||||||
|
Rectangle colorsRecs[MAX_COLORS_COUNT] = { 0 }; // Rectangles array
|
||||||
|
|
||||||
|
// Fills colorsRecs data (for every rectangle)
|
||||||
|
for (int i = 0; i < MAX_COLORS_COUNT; i++)
|
||||||
|
{
|
||||||
|
colorsRecs[i].x = 20 + 100*(i%7) + 10*(i%7);
|
||||||
|
colorsRecs[i].y = 80 + 100*(i/7) + 10*(i/7);
|
||||||
|
colorsRecs[i].width = 100;
|
||||||
|
colorsRecs[i].height = 100;
|
||||||
|
}
|
||||||
|
|
||||||
|
int colorState[MAX_COLORS_COUNT] = { 0 }; // Color state: 0-DEFAULT, 1-MOUSE_HOVER
|
||||||
|
|
||||||
|
Vector2 mousePoint;
|
||||||
|
|
||||||
|
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
// Main game loop
|
// Main game loop
|
||||||
|
|
@ -28,7 +55,13 @@ int main()
|
||||||
{
|
{
|
||||||
// Update
|
// Update
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
// TODO: Update your variables here
|
mousePoint = GetMousePosition();
|
||||||
|
|
||||||
|
for (int i = 0; i < MAX_COLORS_COUNT; i++)
|
||||||
|
{
|
||||||
|
if (CheckCollisionPointRec(mousePoint, colorsRecs[i])) colorState[i] = 1;
|
||||||
|
else colorState[i] = 0;
|
||||||
|
}
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
// Draw
|
// Draw
|
||||||
|
|
@ -37,52 +70,21 @@ int main()
|
||||||
|
|
||||||
ClearBackground(RAYWHITE);
|
ClearBackground(RAYWHITE);
|
||||||
|
|
||||||
DrawText("raylib color palette", 28, 42, 20, BLACK);
|
DrawText("raylib colors palette", 28, 42, 20, BLACK);
|
||||||
|
DrawText("press SPACE to see all colors", GetScreenWidth() - 180, GetScreenHeight() - 40, 10, GRAY);
|
||||||
|
|
||||||
DrawRectangle(26, 80, 100, 100, DARKGRAY);
|
for (int i = 0; i < MAX_COLORS_COUNT; i++) // Draw all rectangles
|
||||||
DrawRectangle(26, 188, 100, 100, GRAY);
|
{
|
||||||
DrawRectangle(26, 296, 100, 100, LIGHTGRAY);
|
DrawRectangleRec(colorsRecs[i], Fade(colors[i], colorState[i]? 0.6f : 1.0f));
|
||||||
DrawRectangle(134, 80, 100, 100, MAROON);
|
|
||||||
DrawRectangle(134, 188, 100, 100, RED);
|
|
||||||
DrawRectangle(134, 296, 100, 100, PINK);
|
|
||||||
DrawRectangle(242, 80, 100, 100, ORANGE);
|
|
||||||
DrawRectangle(242, 188, 100, 100, GOLD);
|
|
||||||
DrawRectangle(242, 296, 100, 100, YELLOW);
|
|
||||||
DrawRectangle(350, 80, 100, 100, DARKGREEN);
|
|
||||||
DrawRectangle(350, 188, 100, 100, LIME);
|
|
||||||
DrawRectangle(350, 296, 100, 100, GREEN);
|
|
||||||
DrawRectangle(458, 80, 100, 100, DARKBLUE);
|
|
||||||
DrawRectangle(458, 188, 100, 100, BLUE);
|
|
||||||
DrawRectangle(458, 296, 100, 100, SKYBLUE);
|
|
||||||
DrawRectangle(566, 80, 100, 100, DARKPURPLE);
|
|
||||||
DrawRectangle(566, 188, 100, 100, VIOLET);
|
|
||||||
DrawRectangle(566, 296, 100, 100, PURPLE);
|
|
||||||
DrawRectangle(674, 80, 100, 100, DARKBROWN);
|
|
||||||
DrawRectangle(674, 188, 100, 100, BROWN);
|
|
||||||
DrawRectangle(674, 296, 100, 100, BEIGE);
|
|
||||||
|
|
||||||
|
if (IsKeyDown(KEY_SPACE) || colorState[i])
|
||||||
DrawText("DARKGRAY", 65, 166, 10, BLACK);
|
{
|
||||||
DrawText("GRAY", 93, 274, 10, BLACK);
|
DrawRectangle(colorsRecs[i].x, colorsRecs[i].y + colorsRecs[i].height - 26, colorsRecs[i].width, 20, BLACK);
|
||||||
DrawText("LIGHTGRAY", 61, 382, 10, BLACK);
|
DrawRectangleLinesEx(colorsRecs[i], 6, Fade(BLACK, 0.3f));
|
||||||
DrawText("MAROON", 186, 166, 10, BLACK);
|
DrawText(colorNames[i], colorsRecs[i].x + colorsRecs[i].width - MeasureText(colorNames[i], 10) - 12,
|
||||||
DrawText("RED", 208, 274, 10, BLACK);
|
colorsRecs[i].y + colorsRecs[i].height - 20, 10, colors[i]);
|
||||||
DrawText("PINK", 204, 382, 10, BLACK);
|
}
|
||||||
DrawText("ORANGE", 295, 166, 10, BLACK);
|
}
|
||||||
DrawText("GOLD", 310, 274, 10, BLACK);
|
|
||||||
DrawText("YELLOW", 300, 382, 10, BLACK);
|
|
||||||
DrawText("DARKGREEN", 382, 166, 10, BLACK);
|
|
||||||
DrawText("LIME", 420, 274, 10, BLACK);
|
|
||||||
DrawText("GREEN", 410, 382, 10, BLACK);
|
|
||||||
DrawText("DARKBLUE", 498, 166, 10, BLACK);
|
|
||||||
DrawText("BLUE", 526, 274, 10, BLACK);
|
|
||||||
DrawText("SKYBLUE", 505, 382, 10, BLACK);
|
|
||||||
DrawText("DARKPURPLE", 592, 166, 10, BLACK);
|
|
||||||
DrawText("VIOLET", 621, 274, 10, BLACK);
|
|
||||||
DrawText("PURPLE", 620, 382, 10, BLACK);
|
|
||||||
DrawText("DARKBROWN", 705, 166, 10, BLACK);
|
|
||||||
DrawText("BROWN", 733, 274, 10, BLACK);
|
|
||||||
DrawText("BEIGE", 737, 382, 10, BLACK);
|
|
||||||
|
|
||||||
EndDrawing();
|
EndDrawing();
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|
@ -90,7 +92,7 @@ int main()
|
||||||
|
|
||||||
// De-Initialization
|
// De-Initialization
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
CloseWindow(); // Close window and OpenGL context
|
CloseWindow(); // Close window and OpenGL context
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
||||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue