Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 11 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,22 @@
Bindings for [Vala](https://vala.dev/) to use the simple and easy to use graphics library [Raylib](https://github.com/raysan5/raylib).

## Description
Ralib VAPI currently supports the core module of Raylib using a C style API for ease of code porting.
Raylib VAPI currently supports the core module of Raylib using a C style API for ease of code porting.

Some VAPI's will be released to follow a more [OOP design](https://en.wikipedia.org/wiki/Object-oriented_programming) as well if you wish to use them in a more traditional Vala style.

## Supported Modules

| Module | Supported | OOP Available | VAPI Name | Version |
|:-------:|:------------------:|:------------------:|:-----------:|:-------:|
| raylib | :heavy_check_mark: | :construction: | raylib.vapi | 5.0 |
| rlgl | :heavy_check_mark: | :x: | rlgl.vapi | 4.5 |
| raymath | :x: | :x: | | |
| raudio | :x: | :x: | | |
| raygui | :x: | :x: | | |
| rpng | :x: | :x: | | |
| rini | :heavy_check_mark: | :x: | rini.vapi | 1.0 |
| rres | :x: | :x: | | |
| Module | Supported | OOP Available | VAPI Name | Version |
|:-------:|:-------------------:|:-------------:|:------------:|:-------:|
| raylib | :heavy_check_mark: | :x: | raylib.vapi | 6.0 |
| rlgl | :heavy_check_mark: | :x: | rlgl.vapi | 6.0 |
| raymath | :heavy_check_mark: | :x: | raymath.vapi | 2.0 |
| raygui | :heavy_check_mark: | :x: | raygui.vapi | 5.0 |
| rpng | :x: | :x: | | |
| rres | :x: | :x: | | |
| rini | :heavy_check_mark: | :x: | rini.vapi | 3.0 |
| physac | :heavy_check_mark: | :x: | physac.vapi | 1.1 |

## Example
```vala
Expand All @@ -47,16 +47,3 @@ public static int main (string[] args) {
return 0;
}
```

## Compiling Included Examples
```bash
cd examples

meson build -C build

cd build/

Camera3D/application # To run the 3D camera example
# or
SmoothPixel/application # To run the smooth pixel perfect example
```
39 changes: 39 additions & 0 deletions examples/Core/BasicWindow/Main.vala
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using Raylib;

public static int main () {
// Initialization
//--------------------------------------------------------------------------------------
const int SCREEN_WIDTH = 800;
const int SCREEN_HEIGHT = 450;

init_window (SCREEN_WIDTH, SCREEN_HEIGHT, "Vala raylib [core] example - basic window");

set_target_fps (60); // Set our game to run at 60 frames-per-second
//--------------------------------------------------------------------------------------

// Main game loop
while (!window_should_close ()) { // Detect window close button or ESC key
// Update
//----------------------------------------------------------------------------------

// Update your variables here

//----------------------------------------------------------------------------------

// Draw
//----------------------------------------------------------------------------------
begin_drawing ();
{
clear_background (RAYWHITE);
draw_text ("Congrats! You created your first window!", 190, 200, 20, LIGHTGRAY);
}
end_drawing ();
//----------------------------------------------------------------------------------
}

// De-Initialization
//--------------------------------------------------------------------------------------
close_window (); // Close window and OpenGL context
//--------------------------------------------------------------------------------------
return 0;
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
executable (
'application',

'core-basic-window',
'Main.vala',

dependencies: project_dependency
)
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Raylib;
using Raymath;

public const int MAX_COLUMNS = 20;
public const int SCREEN_WIDTH = 800;
Expand Down Expand Up @@ -34,7 +35,7 @@ public static int main (string[] args) {

clear_background (RAYWHITE);

begin_mode_3D (camera);
begin_mode_3d (camera);

draw_plane ({ 0.0f, 0.0f, 0.0f }, { 32.0f, 32.0f }, { 200, 200, 200, 255 });
draw_cube ({ -16.0f, 2.5f, 0.0f }, 1.0f, 5.0f, 32.0f, BLUE);
Expand All @@ -47,7 +48,7 @@ public static int main (string[] args) {
draw_cube_wires (positions[i], 2.0f, heights[i], 2.0f, MAROON);
}

end_mode_3D ();
end_mode_3d ();

draw_rectangle ( 10, 10, 220, 70, fade (SKYBLUE, 0.5f));
draw_rectangle_lines ( 10, 10, 220, 70, BLUE);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
executable (
'application',

'core-camera-3d',
'Main.vala',

dependencies: project_dependency
)
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Raylib;
using Raymath;

public const int SCREEN_WIDTH = 800;
public const int SCREEN_HEIGHT = 450;
Expand All @@ -24,7 +25,10 @@ public static int main () {
Rectangle rec03 = { 80.0f, 65.0f, 15.0f, 25.0f };

Rectangle source_rectangle = { 0.0f, 0.0f, target.texture.width, -target.texture.height };
Rectangle destination_rectangle = { -VIRTUAL_RATIO, -VIRTUAL_RATIO, SCREEN_WIDTH + (VIRTUAL_RATIO * 2), SCREEN_HEIGHT + (VIRTUAL_RATIO * 2) };
Rectangle destination_rectangle = { -VIRTUAL_RATIO,
-VIRTUAL_RATIO,
SCREEN_WIDTH + (VIRTUAL_RATIO * 2),
SCREEN_HEIGHT + (VIRTUAL_RATIO * 2) };

Vector2 origin = { 0.0f, 0.0f };

Expand Down Expand Up @@ -56,25 +60,31 @@ public static int main () {
screen_space_camera.target.y *= VIRTUAL_RATIO;

begin_texture_mode (target);
{
clear_background (RAYWHITE);

begin_mode_2D (world_space_camera);
begin_mode_2d (world_space_camera);
{
draw_rectangle_pro (rec01, origin, rotation, BLACK);
draw_rectangle_pro (rec02, origin, -rotation, RED);
draw_rectangle_pro (rec02, origin, - rotation, RED);
draw_rectangle_pro (rec03, origin, rotation + 45.0f, BLUE);
end_mode_2D ();
end_texture_mode();
}
end_mode_2d ();
}
end_texture_mode ();

begin_drawing ();
{
clear_background (RED);

begin_mode_2D (screen_space_camera);
begin_mode_2d (screen_space_camera);
{
draw_texture_pro (target.texture, source_rectangle, destination_rectangle, origin, 0.0f, WHITE);
end_mode_2D ();
}
end_mode_2d ();

draw_text (@"Screen resolution: $(SCREEN_WIDTH)x$(SCREEN_HEIGHT)", 10, 10, 20, DARKBLUE);
draw_text (@"World resolution: $(VIRTUAL_SCREEN_WIDTH)x$(VIRTUAL_SCREEN_HEIGHT)", 10, 40, 20, DARKGREEN);
draw_fps ( get_screen_width () - 95, 10);
}
end_drawing ();
}

Expand Down
5 changes: 5 additions & 0 deletions examples/Core/SmoothPixelPerfect/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
executable (
'core-smooth-pixel-perfect',
'Main.vala',
dependencies: project_dependency
)
111 changes: 111 additions & 0 deletions examples/Physac/Demo/Main.vala
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
using Raylib;
using Raymath;
using Physac;

public static int main () {
// Initialization
//--------------------------------------------------------------------------------------
const int SCREEN_WIDTH = 800;
const int SCREEN_HEIGHT = 450;

set_config_flags (ConfigFlags.MSAA_4X_HINT);
init_window (SCREEN_WIDTH, SCREEN_HEIGHT, "Vala raylib [physac] example - physics demo");

// Physac logo drawing position
int logo_x = SCREEN_WIDTH - measure_text ("Physac", 30) - 10;
int logo_y = 15;

Vector2 rectangle_body_pos = { SCREEN_WIDTH / 2.0f, SCREEN_HEIGHT };
Vector2 circle_body_pos = { SCREEN_WIDTH / 2.0f, SCREEN_HEIGHT / 2.0f };

// Initialize physics and default physics bodies
init_physics ();

// Create floor rectangle physics body
var floor = create_physics_body_rectangle (rectangle_body_pos, 500, 100, 10);
floor.enabled = false; // Disable body state to convert it to static (no dynamics, but collisions)

// Create obstacle circle physics body
var circle = create_physics_body_circle (circle_body_pos, 45, 10);
circle.enabled = false; // Disable body state to convert it to static (no dynamics, but collisions)

set_target_fps (60); // Set our game to run at 60 frames-per-second
//--------------------------------------------------------------------------------------

// Main game loop
while (!window_should_close ()) { // Detect window close button or ESC key
// Update
//----------------------------------------------------------------------------------
update_physics (); // Update physics system

if (is_key_pressed (KeyboardKey.R)) { // Reset physics system
reset_physics ();
floor = create_physics_body_rectangle (rectangle_body_pos, 500, 100, 10);
floor.enabled = false;

circle = create_physics_body_circle (circle_body_pos, 45, 10);
circle.enabled = false;
}

// Physics body creation inputs
if (is_mouse_button_pressed (MouseButton.LEFT)) {
create_physics_body_polygon (get_mouse_position (), get_random_value (20, 80), get_random_value (3, 8), 10);
} else if (is_mouse_button_pressed (MouseButton.RIGHT)) {
create_physics_body_circle (get_mouse_position (), get_random_value (10, 45), 10);
}

// Destroy falling physics bodies
int bodies_count = get_physics_bodies_count ();
for (int i = bodies_count - 1; i >= 0; i--) {
var body = get_physics_body (i);
if (body != null && (body.position.y > SCREEN_HEIGHT * 2)) {
destroy_physics_body (body);
}
}
//----------------------------------------------------------------------------------

// Draw
//----------------------------------------------------------------------------------
begin_drawing ();

clear_background (BLACK);

draw_fps (SCREEN_WIDTH - 90, SCREEN_HEIGHT - 30);

// Draw created physics bodies
bodies_count = get_physics_bodies_count ();
for (int i = 0; i < bodies_count; i++) {
var body = get_physics_body (i);
if (body != null) {
int vertex_count = get_physics_shape_vertices_count (i);
for (int j = 0; j < vertex_count; j++) {
// Get physics bodies shape vertices to draw lines
// Note: get_physics_shape_vertex () already calculates rotation transformations
Vector2 vertex_a = get_physics_shape_vertex (body, j);

int jj = (((j + 1) < vertex_count) ? (j + 1) : 0); // Get next vertex or first to close the shape
Vector2 vertex_b = get_physics_shape_vertex (body, jj);

draw_line_vector (vertex_a, vertex_b, GREEN); // Draw a line between two vertex positions
}
}
}

draw_text ("Left mouse button to create a polygon", 10, 10, 10, WHITE);
draw_text ("Right mouse button to create a circle", 10, 25, 10, WHITE);
draw_text ("Press 'R' to reset example", 10, 40, 10, WHITE);

draw_text ("Physac", logo_x, logo_y, 30, WHITE);
draw_text ("Powered by", logo_x + 50, logo_y - 7, 10, WHITE);

end_drawing ();
//----------------------------------------------------------------------------------
}

// De-Initialization
//--------------------------------------------------------------------------------------
close_physics (); // Unitialize physics
close_window (); // Close window and OpenGL context
//--------------------------------------------------------------------------------------
return 0;
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
executable (
'application',

'physac-demo',
'Main.vala',

dependencies: project_dependency
)
43 changes: 0 additions & 43 deletions examples/Physac/Main.vala

This file was deleted.

Loading