This commit is contained in:
Tobias Berger 2021-11-16 13:51:37 +01:00
parent a56e05f1bd
commit 7edd606fee
2 changed files with 68 additions and 11 deletions

View file

@ -3030,7 +3030,7 @@ extern "C"
fnl_state fnlCreateState()
{
fnl_state newState;
newState.seed = 1337;
newState.seed = 0;
newState.frequency = 0.01f;
newState.noise_type = FNL_NOISE_OPENSIMPLEX2;
newState.rotation_type_3d = FNL_ROTATION_NONE;

View file

@ -3,26 +3,49 @@
#define FNL_IMPL
#include "FastNoiseLite.h"
#define initialScreenWidth 900
#define initialScreenHeight 900
#define INITIAL_SCREEN_WIDTH 900
#define INITIAL_SCREEN_HEIGHT 900
#define SCALE 64
int main(void)
{
// Initialization
//--------------------------------------------------------------------------------------
SetTraceLogLevel(LOG_ALL);
SetConfigFlags(FLAG_WINDOW_RESIZABLE | FLAG_VSYNC_HINT);
InitWindow(initialScreenWidth, initialScreenHeight, "raylib [core] example - basic window");
InitWindow(INITIAL_SCREEN_WIDTH, INITIAL_SCREEN_HEIGHT, "raylib [core] example - basic window");
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
SetTargetFPS(5); // Set our game to run at 60 frames-per-second
fnl_state state = fnlCreateState();
state.seed = 0;
state.frequency = 1.0f / (float)SCALE;
state.octaves = 1;
state.noise_type = FNL_NOISE_PERLIN;
//--------------------------------------------------------------------------------------
TraceLog(LOG_INFO, TextFormat("%i", GetScreenWidth()));
int virtualScreenWidth = GetScreenWidth() / SCALE;
int virtualScreenHeight = GetScreenHeight() / SCALE;
float virtualRatio = (float)virtualScreenWidth / (float)virtualScreenHeight;
RenderTexture2D *target = (RenderTexture2D *)MemAlloc(sizeof(RenderTexture2D));
*target = LoadRenderTexture(virtualScreenWidth, virtualScreenHeight);
Camera2D camera = {0};
camera.zoom = 1.0f;
Rectangle sourceRec = {0.0f,
0.0f,
(float)target->texture.width,
-(float)target->texture.height};
Rectangle destRec = {-virtualRatio,
-virtualRatio,
GetScreenWidth() + (virtualRatio * 2.0f),
GetScreenHeight() + (virtualRatio * 2.0f)};
//--------------------------------------------------------------------------------------
double offset = 0.0;
@ -38,6 +61,27 @@ int main(void)
TraceLog(LOG_INFO, TextFormat("Noisetype: %i", state.noise_type));
}
if (IsWindowResized())
{
TraceLog(LOG_DEBUG, "Resized.");
int virtualScreenWidth = GetScreenWidth() / SCALE;
int virtualScreenHeight = GetScreenHeight() / SCALE;
float virtualRatio = (float)virtualScreenWidth / (float)virtualScreenHeight;
UnloadRenderTexture(*target);
*target = LoadRenderTexture(virtualScreenWidth, virtualScreenHeight);
sourceRec = (Rectangle){0.0f,
0.0f,
(float)target->texture.width,
(float)target->texture.height};
destRec = (Rectangle){0.0f,
0.0f,
GetScreenWidth(),
GetScreenHeight()};
}
if (IsKeyPressed(KEY_UP))
{
state.octaves++;
@ -59,26 +103,39 @@ int main(void)
// Draw
//----------------------------------------------------------------------------------
BeginDrawing();
BeginTextureMode(*target);
ClearBackground(RAYWHITE);
for (int x = 0; x < GetScreenWidth(); x++)
for (int x = 0; x < virtualScreenWidth; x++)
{
for (int y = 0; y < GetScreenHeight(); y++)
for (int y = 0; y < virtualScreenHeight; y++)
{
int noise = (fnlGetNoise2D(&state, ((double)x) + offset, ((double)y) + offset / 2.0) + 1.0) / 2.0 * 255.0; //(noise2(simplexEnv, simplexGradiants, x / 64.0 + offset, y / 64.0 + offset / 2.0) + 1.0) / 2 * 255;
DrawPixel(x, y, (Color){noise, noise, noise, 255});
DrawPixel(x, y, (Color){0, noise, noise, 255});
}
}
EndTextureMode();
BeginDrawing();
{
ClearBackground(RAYWHITE);
// BeginMode2D();
{
DrawTexturePro(target->texture, sourceRec, destRec, (Vector2){0.0f, 0.0f}, 0.0f, WHITE);
}
// EndMode2D();
}
EndDrawing();
//----------------------------------------------------------------------------------
}
// De-Initialization
//--------------------------------------------------------------------------------------
MemFree(target);
CloseWindow(); // Close window and OpenGL context
//--------------------------------------------------------------------------------------