-
Notifications
You must be signed in to change notification settings - Fork 1
DrawingStuff
Now that we have a window set up, let's learn how to draw different shapes and render textures.
- Drawing a Rectangle
To draw a simple rectangle, use the
ech::DrawRectangle
function.
ech::DrawRectangle(x, y, width, height, ech::RED);
Note
The color parameter in Echlib follows this format: ech::Color
You can use built-in colors like ech::RED
, ech::BLUE
, or define custom colors.
Drawing a Pro Rectangle A pro rectangle allows you to add rotation and transparency.
ech::DrawProRectangle(x, y, width, height, ech::BLUE, angle, transparency);
angle: Rotates the rectangle by the specified degrees.
transparency: A value between 0 (fully transparent) and 1 (fully visible).
- Drawing a Triangle To draw a triangle, use:
ech::DrawTriangle(x, y, width, height, ech::GREEN);
This draws a green triangle at (x, y) with the given width and height.
Drawing a Pro Triangle A pro triangle lets you control transparency:
ech::DrawProTriangle(x, y, width, height, ech::YELLOW, transparency);
- Drawing a Circle To draw a circle:
ech::DrawCircle(centerX, centerY, radius, ech::PURPLE);
centerX, centerY: Position of the circle.
radius: Size of the circle.
Drawing a Pro Circle A pro circle allows additional control over segments and transparency.
ech::DrawProCircle(centerX, centerY, radius, ech::WHITE, segments, transparency);
segments: The number of points used to draw the circle. A higher value makes it smoother.
transparency: Adjusts visibility.
- Drawing Textures To draw a texture, you must first load it using ech::LoadTexture.
ech::LoadTexture("image.png", "myTexture");
Then, draw it with:
ech::DrawTexturedRectangle(x, y, width, height, "myTexture");
Drawing a Pro Textured Rectangle A pro textured rectangle lets you rotate and control transparency.
ech::DrawProTexturedRectangle(x, y, width, height, rotation, alpha, "myTexture");
rotation: Rotates the texture.
alpha: Transparency (0-1).
Full Example Here’s an example that draws all the shapes and a texture:
#include "echlib.h"
int main() {
ech::initWindow(800, 600, "Drawing Shapes and Textures");
ech::SetTargetFps(60);
ech::LoadTexture("image.png", "myTexture");
while (!ech::WindowShouldClose()) {
ech::StartDrawing();
ech::ClearBackground(ech::BLACK);
ech::DrawRectangle(100, 100, 200, 150, ech::RED);
ech::DrawProRectangle(400, 100, 200, 150, ech::BLUE, 45, 0.5f);
ech::DrawTriangle(200, 300, 100, 100, ech::GREEN);
ech::DrawProTriangle(400, 300, 100, 100, ech::YELLOW, 0.7f);
ech::DrawCircle(200, 500, 50, ech::PURPLE);
ech::DrawProCircle(400, 500, 50, ech::WHITE, 36, 0.8f);
ech::DrawTexturedRectangle(600, 100, 150, 150, "myTexture");
ech::DrawProTexturedRectangle(600, 300, 150, 150, 30, 0.9f, "myTexture");
ech::EndDrawing();
}
ech::CloseWindow();
return 0;
}
This will: ✅ Draw different shapes with and without transparency. ✅ Load and render a texture. ✅ Keep everything inside a game loop.
Yo