Render tree to texture
This commit is contained in:
parent
2ae0839e4f
commit
bbf248bb9c
32
main.cpp
32
main.cpp
@ -1,6 +1,5 @@
|
||||
#include <cmath>
|
||||
#include "raylib.h"
|
||||
#include "raymath.h"
|
||||
|
||||
#define MAX_DEPTH 10
|
||||
|
||||
@ -34,25 +33,30 @@ int main(void)
|
||||
|
||||
InitWindow(screenWidth, screenHeight, "raylib");
|
||||
|
||||
Camera2D camera = {0};
|
||||
camera.target = (Vector2){0.0f, 0.0f};
|
||||
camera.offset = (Vector2){screenWidth / 2, screenHeight};
|
||||
camera.rotation = 0.0f;
|
||||
camera.zoom = 1.0f;
|
||||
|
||||
SetTargetFPS(60);
|
||||
Vector2 start = {0};
|
||||
|
||||
const int textureWidth = screenWidth;
|
||||
const int textureHeight = screenHeight;
|
||||
|
||||
RenderTexture2D target = LoadRenderTexture(textureWidth, textureHeight);
|
||||
Vector2 start = {textureWidth / 2, textureHeight};
|
||||
|
||||
BeginTextureMode(target);
|
||||
ClearBackground(WHITE);
|
||||
draw_branch(start, 0, textureHeight / 4, 0);
|
||||
EndTextureMode();
|
||||
|
||||
Rectangle source = {0, 0, (float)target.texture.width, (float)-target.texture.height};
|
||||
Rectangle dest = {0, 0, screenWidth, screenHeight};
|
||||
Vector2 position = {0, 0};
|
||||
Vector2 origin = {0.0f, 0.0f};
|
||||
|
||||
while (!WindowShouldClose())
|
||||
{
|
||||
|
||||
BeginDrawing();
|
||||
ClearBackground(RAYWHITE);
|
||||
BeginMode2D(camera);
|
||||
|
||||
DrawCircle(0, 0, 10.0f, RED);
|
||||
draw_branch(start, 0, screenHeight / 4, 0);
|
||||
DrawTexturePro(target.texture, source, dest, origin, 0.0f, WHITE);
|
||||
|
||||
EndMode2D();
|
||||
EndDrawing();
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user