refactor: restructure the project
6
languages/ada/Makefile
Normal file
@@ -0,0 +1,6 @@
|
||||
raylib_ada: main.adb
|
||||
gnatmake main.adb -o raylib_ada \
|
||||
-I../raylib-5.5_linux_amd64/include \
|
||||
-largs ../raylib-5.5_linux_amd64/lib/libraylib.a \
|
||||
-lm
|
||||
rm -f main.ali main.o
|
||||
BIN
languages/ada/ada_logo.png
Normal file
|
After Width: | Height: | Size: 70 KiB |
147
languages/ada/main.adb
Normal file
@@ -0,0 +1,147 @@
|
||||
with Interfaces.C; use Interfaces.C;
|
||||
with Interfaces.C.Strings; use Interfaces.C.Strings;
|
||||
with Ada.Calendar;
|
||||
with System;
|
||||
|
||||
procedure Main is
|
||||
|
||||
WINDOW_WIDTH : constant := 800;
|
||||
WINDOW_HEIGHT : constant := 600;
|
||||
LOGO_HEIGHT : constant := 64;
|
||||
LOGO_SPEED : constant float := 300.0;
|
||||
|
||||
type Unsigned_Char is mod 2 ** 8;
|
||||
for Unsigned_Char'Size use 8;
|
||||
|
||||
type Color is record
|
||||
R, G, B, A : Unsigned_Char;
|
||||
end record;
|
||||
pragma Convention (C_Pass_By_Copy, Color);
|
||||
|
||||
type Vector2 is record
|
||||
X, Y : float;
|
||||
end record;
|
||||
pragma Convention (C_Pass_By_Copy, Vector2);
|
||||
|
||||
type Image is record
|
||||
Data : System.Address;
|
||||
Width : int;
|
||||
Height : int;
|
||||
Mipmaps : int;
|
||||
Format : int;
|
||||
end record;
|
||||
pragma Convention (C_Pass_By_Copy, Image);
|
||||
|
||||
type Texture2D is record
|
||||
Id : unsigned;
|
||||
Width : int;
|
||||
Height : int;
|
||||
Mipmaps : int;
|
||||
Format : int;
|
||||
end record;
|
||||
pragma Convention (C_Pass_By_Copy, Texture2D);
|
||||
|
||||
BLACK : constant Color := (R => 0, G => 0, B => 0, A => 255);
|
||||
WHITE : constant Color := (R => 255, G => 255, B => 255, A => 255);
|
||||
|
||||
procedure Init_Window (Width : int; Height : int; Title : chars_ptr);
|
||||
pragma Import (C, Init_Window, "InitWindow");
|
||||
|
||||
procedure Set_Target_FPS (Fps : int);
|
||||
pragma Import (C, Set_Target_FPS, "SetTargetFPS");
|
||||
|
||||
procedure Set_Random_Seed (Seed : unsigned);
|
||||
pragma Import (C, Set_Random_Seed, "SetRandomSeed");
|
||||
|
||||
function Load_Image (File_Name : chars_ptr) return Image;
|
||||
pragma Import (C, Load_Image, "LoadImage");
|
||||
|
||||
procedure Image_Resize (Img : access Image; New_Width : int; New_Height : int);
|
||||
pragma Import (C, Image_Resize, "ImageResize");
|
||||
|
||||
function Load_Texture_From_Image (Img : Image) return Texture2D;
|
||||
pragma Import (C, Load_Texture_From_Image, "LoadTextureFromImage");
|
||||
|
||||
procedure Unload_Image (Img : Image);
|
||||
pragma Import (C, Unload_Image, "UnloadImage");
|
||||
|
||||
function Get_Random_Value (Min : int; Max : int) return int;
|
||||
pragma Import (C, Get_Random_Value, "GetRandomValue");
|
||||
|
||||
function Window_Should_Close return int;
|
||||
pragma Import (C, Window_Should_Close, "WindowShouldClose");
|
||||
|
||||
function Get_Frame_Time return float;
|
||||
pragma Import (C, Get_Frame_Time, "GetFrameTime");
|
||||
|
||||
procedure Begin_Drawing;
|
||||
pragma Import (C, Begin_Drawing, "BeginDrawing");
|
||||
|
||||
procedure End_Drawing;
|
||||
pragma Import (C, End_Drawing, "EndDrawing");
|
||||
|
||||
procedure Clear_Background (C : Color);
|
||||
pragma Import (C, Clear_Background, "ClearBackground");
|
||||
|
||||
procedure Draw_Texture_V (Tex : Texture2D; Pos : Vector2; Tint : Color);
|
||||
pragma Import (C, Draw_Texture_V, "DrawTextureV");
|
||||
|
||||
procedure Unload_Texture (Tex : Texture2D);
|
||||
pragma Import (C, Unload_Texture, "UnloadTexture");
|
||||
|
||||
procedure Close_Window;
|
||||
pragma Import (C, Close_Window, "CloseWindow");
|
||||
|
||||
use type System.Address;
|
||||
|
||||
Logo_Image : aliased Image;
|
||||
Logo_Texture : Texture2D;
|
||||
X, Y : float;
|
||||
Dx, Dy : float;
|
||||
Delta_Time : float;
|
||||
Seed : unsigned;
|
||||
|
||||
begin
|
||||
Init_Window (WINDOW_WIDTH, WINDOW_HEIGHT, New_String ("Raylib in Ada"));
|
||||
Set_Target_FPS (60);
|
||||
|
||||
Seed := unsigned (Ada.Calendar.Seconds (Ada.Calendar.Clock));
|
||||
Set_Random_Seed (Seed);
|
||||
|
||||
Logo_Image := Load_Image (New_String ("./ada_logo.png"));
|
||||
Image_Resize (Logo_Image'Access,
|
||||
Logo_Image.Width * LOGO_HEIGHT / Logo_Image.Height,
|
||||
LOGO_HEIGHT);
|
||||
Logo_Texture := Load_Texture_From_Image (Logo_Image);
|
||||
Unload_Image (Logo_Image);
|
||||
|
||||
X := float (Get_Random_Value (0, WINDOW_WIDTH - Logo_Texture.Width));
|
||||
Y := float (Get_Random_Value (0, WINDOW_HEIGHT - Logo_Texture.Height));
|
||||
|
||||
Dx := (if Get_Random_Value (0, 1) = 1 then -LOGO_SPEED else LOGO_SPEED);
|
||||
Dy := (if Get_Random_Value (0, 1) = 1 then -LOGO_SPEED else LOGO_SPEED);
|
||||
|
||||
while Window_Should_Close = 0 loop
|
||||
Delta_Time := Get_Frame_Time;
|
||||
|
||||
X := X + Dx * Delta_Time;
|
||||
Y := Y + Dy * Delta_Time;
|
||||
|
||||
if X < 0.0 or else X + float (Logo_Texture.Width) >= float (WINDOW_WIDTH) - 1.0 then
|
||||
Dx := -Dx;
|
||||
X := X + Dx * Delta_Time;
|
||||
end if;
|
||||
if Y < 0.0 or else Y + float (Logo_Texture.Height) >= float (WINDOW_HEIGHT) - 1.0 then
|
||||
Dy := -Dy;
|
||||
Y := Y + Dy * Delta_Time;
|
||||
end if;
|
||||
|
||||
Begin_Drawing;
|
||||
Clear_Background (BLACK);
|
||||
Draw_Texture_V (Logo_Texture, (X => X, Y => Y), WHITE);
|
||||
End_Drawing;
|
||||
end loop;
|
||||
|
||||
Unload_Texture (Logo_Texture);
|
||||
Close_Window;
|
||||
end Main;
|
||||
2
languages/c/Makefile
Normal file
@@ -0,0 +1,2 @@
|
||||
raylib_c: main.c
|
||||
gcc main.c -Wall -Wextra -Werror -pedantic -o raylib_c -I../raylib-5.5_linux_amd64/include -L../raylib-5.5_linux_amd64/lib -l:libraylib.a -lm
|
||||
8
languages/c/README.md
Normal file
@@ -0,0 +1,8 @@
|
||||
# Raylib in C
|
||||
|
||||
## Quick start
|
||||
|
||||
```sh
|
||||
$ make
|
||||
$ ./raylib_c
|
||||
```
|
||||
BIN
languages/c/c_logo.png
Normal file
|
After Width: | Height: | Size: 108 KiB |
57
languages/c/main.c
Normal file
@@ -0,0 +1,57 @@
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
#include <raylib.h>
|
||||
|
||||
#define WINDOW_WIDTH 800
|
||||
#define WINDOW_HEIGHT 600
|
||||
#define LOGO_HEIGHT 64
|
||||
#define LOGO_SPEED 300
|
||||
|
||||
int main()
|
||||
{
|
||||
InitWindow(WINDOW_WIDTH, WINDOW_HEIGHT, "Raylib in C");
|
||||
SetTargetFPS(60);
|
||||
SetRandomSeed(time(NULL));
|
||||
|
||||
Image logo_image = LoadImage("./c_logo.png");
|
||||
ImageResize(&logo_image, logo_image.width * LOGO_HEIGHT / logo_image.height, LOGO_HEIGHT);
|
||||
Texture2D logo_texture = LoadTextureFromImage(logo_image);
|
||||
UnloadImage(logo_image);
|
||||
|
||||
float x = GetRandomValue(0, WINDOW_WIDTH - logo_texture.width);
|
||||
float y = GetRandomValue(0, WINDOW_HEIGHT - logo_texture.height);
|
||||
|
||||
float dx = LOGO_SPEED * (GetRandomValue(0, 1) ? -1 : 1);
|
||||
float dy = LOGO_SPEED * (GetRandomValue(0, 1) ? -1 : 1);
|
||||
|
||||
while (!WindowShouldClose())
|
||||
{
|
||||
float delta_time = GetFrameTime();
|
||||
|
||||
x += dx * delta_time;
|
||||
y += dy * delta_time;
|
||||
|
||||
if (x < 0 || (x + logo_texture.width) >= WINDOW_WIDTH - 1)
|
||||
{
|
||||
dx *= -1;
|
||||
x += dx * delta_time;
|
||||
}
|
||||
if (y < 0 || (y + logo_texture.height) >= WINDOW_HEIGHT - 1)
|
||||
{
|
||||
dy *= -1;
|
||||
y += dy * delta_time;
|
||||
}
|
||||
|
||||
BeginDrawing();
|
||||
|
||||
ClearBackground(BLACK);
|
||||
DrawTextureV(logo_texture, (Vector2){x, y}, WHITE);
|
||||
|
||||
EndDrawing();
|
||||
}
|
||||
|
||||
UnloadTexture(logo_texture);
|
||||
CloseWindow();
|
||||
|
||||
return 0;
|
||||
}
|
||||
2
languages/csharp/Makefile
Normal file
@@ -0,0 +1,2 @@
|
||||
raylib_csharp: main.cs
|
||||
mcs main.cs -out:raylib_csharp.exe
|
||||
14
languages/csharp/README.md
Normal file
@@ -0,0 +1,14 @@
|
||||
# Raylib in C#
|
||||
|
||||
I'm using Mono because i don't like Microsoft.
|
||||
|
||||
## Quick start
|
||||
|
||||
```shell
|
||||
$ make
|
||||
$ mono raylib_csharp.exe
|
||||
```
|
||||
|
||||
## Credits
|
||||
|
||||
- Logo: [Wikipedia](https://wikipedia.org/wiki/File:Logo_C_sharp.svg)
|
||||
BIN
languages/csharp/csharp_logo.png
Normal file
|
After Width: | Height: | Size: 117 KiB |
118
languages/csharp/main.cs
Normal file
@@ -0,0 +1,118 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
static class Program
|
||||
{
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
struct Image
|
||||
{
|
||||
public IntPtr data;
|
||||
public int width;
|
||||
public int height;
|
||||
public int mipmaps;
|
||||
public int format;
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
struct Texture2D
|
||||
{
|
||||
public uint id;
|
||||
public int width;
|
||||
public int height;
|
||||
public int mipmaps;
|
||||
public int format;
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
struct Vector2
|
||||
{
|
||||
public float x;
|
||||
public float y;
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
struct Color
|
||||
{
|
||||
public byte r;
|
||||
public byte g;
|
||||
public byte b;
|
||||
public byte a;
|
||||
}
|
||||
|
||||
private const string RAYLIB = "../raylib-5.5_linux_amd64/lib/libraylib.so";
|
||||
|
||||
[DllImport(RAYLIB)] private static extern void InitWindow(int width, int height, string title);
|
||||
[DllImport(RAYLIB)] private static extern void CloseWindow();
|
||||
|
||||
[DllImport(RAYLIB)] private static extern void SetTargetFPS(int fps);
|
||||
[DllImport(RAYLIB)] private static extern void SetRandomSeed(uint seed);
|
||||
[DllImport(RAYLIB)] private static extern int GetRandomValue(int min, int max);
|
||||
|
||||
[DllImport(RAYLIB)] private static extern Image LoadImage(string file_name);
|
||||
[DllImport(RAYLIB)] private static extern void ImageResize(ref Image image, int new_width, int new_height);
|
||||
[DllImport(RAYLIB)] private static extern Texture2D LoadTextureFromImage(Image image);
|
||||
[DllImport(RAYLIB)] private static extern void UnloadImage(Image image);
|
||||
[DllImport(RAYLIB)] private static extern void UnloadTexture(Texture2D texture);
|
||||
|
||||
[DllImport(RAYLIB)] private static extern bool WindowShouldClose();
|
||||
[DllImport(RAYLIB)] private static extern float GetFrameTime();
|
||||
|
||||
[DllImport(RAYLIB)] private static extern void BeginDrawing();
|
||||
[DllImport(RAYLIB)] private static extern void ClearBackground(Color color);
|
||||
[DllImport(RAYLIB)] private static extern void DrawTextureV(Texture2D texture, Vector2 position, Color tint);
|
||||
[DllImport(RAYLIB)] private static extern void EndDrawing();
|
||||
|
||||
private const int WINDOW_WIDTH = 800;
|
||||
private const int WINDOW_HEIGHT = 600;
|
||||
private const int LOGO_HEIGHT = 64;
|
||||
private const float LOGO_SPEED = 300;
|
||||
|
||||
private static Color BLACK = new Color() { r = 0, g = 0, b = 0, a = 255 };
|
||||
private static Color WHITE = new Color() { r = 255, g = 255, b = 255, a = 255 };
|
||||
|
||||
public static void Main()
|
||||
{
|
||||
InitWindow(WINDOW_WIDTH, WINDOW_HEIGHT, "Raylib in C#");
|
||||
SetTargetFPS(60);
|
||||
|
||||
Image logo_image = LoadImage("./csharp_logo.png");
|
||||
ImageResize(ref logo_image, logo_image.width * LOGO_HEIGHT / logo_image.height, LOGO_HEIGHT);
|
||||
Texture2D logo_texture = LoadTextureFromImage(logo_image);
|
||||
UnloadImage(logo_image);
|
||||
|
||||
float x = GetRandomValue(0, WINDOW_WIDTH - logo_texture.width);
|
||||
float y = GetRandomValue(0, WINDOW_HEIGHT - logo_texture.height);
|
||||
|
||||
float dx = LOGO_SPEED * (GetRandomValue(0, 1) == 1 ? -1 : 1);
|
||||
float dy = LOGO_SPEED * (GetRandomValue(0, 1) == 1 ? -1 : 1);
|
||||
|
||||
while (!WindowShouldClose())
|
||||
{
|
||||
float delta_time = GetFrameTime();
|
||||
|
||||
x += dx * delta_time;
|
||||
y += dy * delta_time;
|
||||
|
||||
if (x < 0 || (x + logo_texture.width) >= WINDOW_WIDTH - 1)
|
||||
{
|
||||
dx *= -1;
|
||||
x += dx * delta_time;
|
||||
}
|
||||
if (y < 0 || (y + logo_texture.height) >= WINDOW_HEIGHT - 1)
|
||||
{
|
||||
dy *= -1;
|
||||
y += dy * delta_time;
|
||||
}
|
||||
|
||||
BeginDrawing();
|
||||
|
||||
ClearBackground(BLACK);
|
||||
DrawTextureV(logo_texture, new Vector2() { x = x, y = y }, WHITE);
|
||||
|
||||
EndDrawing();
|
||||
}
|
||||
|
||||
UnloadTexture(logo_texture);
|
||||
CloseWindow();
|
||||
}
|
||||
}
|
||||
3
languages/d/Makefile
Normal file
@@ -0,0 +1,3 @@
|
||||
raylib_d: main.d
|
||||
dmd main.d -of=./raylib_d ../raylib-5.5_linux_amd64/lib/libraylib.a
|
||||
rm ./raylib_d.o
|
||||
8
languages/d/README.md
Normal file
@@ -0,0 +1,8 @@
|
||||
# Raylib in D
|
||||
|
||||
## Quick start
|
||||
|
||||
```sh
|
||||
$ make
|
||||
$ ./raylib_d
|
||||
```
|
||||
BIN
languages/d/d_logo.png
Normal file
|
After Width: | Height: | Size: 76 KiB |
105
languages/d/main.d
Normal file
@@ -0,0 +1,105 @@
|
||||
import std.stdio;
|
||||
import std.datetime;
|
||||
|
||||
struct Image {
|
||||
void* data;
|
||||
int width;
|
||||
int height;
|
||||
int mipmaps;
|
||||
int format;
|
||||
}
|
||||
|
||||
struct Texture2D {
|
||||
uint id;
|
||||
int width;
|
||||
int height;
|
||||
int mipmaps;
|
||||
int format;
|
||||
}
|
||||
|
||||
struct Vector2 {
|
||||
float x;
|
||||
float y;
|
||||
}
|
||||
|
||||
struct Color {
|
||||
ubyte r;
|
||||
ubyte g;
|
||||
ubyte b;
|
||||
ubyte a;
|
||||
}
|
||||
|
||||
extern(C):
|
||||
void InitWindow(int width, int height, const char* title);
|
||||
void CloseWindow();
|
||||
|
||||
void SetTargetFPS(int fps);
|
||||
void SetRandomSeed(uint seed);
|
||||
int GetRandomValue(int min, int max);
|
||||
|
||||
Image LoadImage(const char* file_name);
|
||||
void ImageResize(Image* image, int new_width, int new_height);
|
||||
Texture2D LoadTextureFromImage(Image image);
|
||||
void UnloadImage(Image image);
|
||||
void UnloadTexture(Texture2D texture);
|
||||
|
||||
bool WindowShouldClose();
|
||||
float GetFrameTime();
|
||||
|
||||
void BeginDrawing();
|
||||
void ClearBackground(Color color);
|
||||
void DrawTextureV(Texture2D texture, Vector2 position, Color tint);
|
||||
void EndDrawing();
|
||||
|
||||
const int WINDOW_WIDTH = 800;
|
||||
const int WINDOW_HEIGHT = 600;
|
||||
const int LOGO_HEIGHT = 64;
|
||||
const float LOGO_SPEED = 300;
|
||||
|
||||
const Color BLACK = Color(0, 0, 0, 255);
|
||||
const Color WHITE = Color(255, 255, 255, 255);
|
||||
|
||||
void main() {
|
||||
InitWindow(WINDOW_WIDTH, WINDOW_HEIGHT, "Raylib in D");
|
||||
SetTargetFPS(60);
|
||||
SetRandomSeed(cast(uint)Clock.currStdTime());
|
||||
|
||||
Image logo_image = LoadImage("./d_logo.png");
|
||||
ImageResize(&logo_image, logo_image.width * LOGO_HEIGHT / logo_image.height, LOGO_HEIGHT);
|
||||
Texture2D logo_texture = LoadTextureFromImage(logo_image);
|
||||
UnloadImage(logo_image);
|
||||
|
||||
float x = GetRandomValue(0, WINDOW_WIDTH - logo_texture.width);
|
||||
float y = GetRandomValue(0, WINDOW_HEIGHT - logo_texture.height);
|
||||
|
||||
float dx = LOGO_SPEED * (GetRandomValue(0, 1) ? -1 : 1);
|
||||
float dy = LOGO_SPEED * (GetRandomValue(0, 1) ? -1 : 1);
|
||||
|
||||
while (!WindowShouldClose()) {
|
||||
float delta_time = GetFrameTime();
|
||||
|
||||
x += dx * delta_time;
|
||||
y += dy * delta_time;
|
||||
|
||||
if (x < 0 || (x + logo_texture.width) >= WINDOW_WIDTH - 1)
|
||||
{
|
||||
dx *= -1;
|
||||
x += dx * delta_time;
|
||||
}
|
||||
if (y < 0 || (y + logo_texture.height) >= WINDOW_HEIGHT - 1)
|
||||
{
|
||||
dy *= -1;
|
||||
y += dy * delta_time;
|
||||
}
|
||||
|
||||
BeginDrawing();
|
||||
|
||||
ClearBackground(BLACK);
|
||||
DrawTextureV(logo_texture, Vector2(x, y), WHITE);
|
||||
|
||||
EndDrawing();
|
||||
}
|
||||
|
||||
UnloadTexture(logo_texture);
|
||||
CloseWindow();
|
||||
}
|
||||
2
languages/go/Makefile
Normal file
@@ -0,0 +1,2 @@
|
||||
raylib_go: main.go
|
||||
go build -o raylib_go main.go
|
||||
8
languages/go/README.md
Normal file
@@ -0,0 +1,8 @@
|
||||
# Raylib in Go
|
||||
|
||||
## Quick start
|
||||
|
||||
```sh
|
||||
$ make
|
||||
$ ./raylib_go
|
||||
```
|
||||
BIN
languages/go/go_logo.png
Normal file
|
After Width: | Height: | Size: 1.0 MiB |
66
languages/go/main.go
Normal file
@@ -0,0 +1,66 @@
|
||||
package main
|
||||
|
||||
/*
|
||||
#cgo CFLAGS: -I../raylib-5.5_linux_amd64/include
|
||||
#cgo LDFLAGS: -L../raylib-5.5_linux_amd64/lib -l:libraylib.a -lm
|
||||
#include <raylib.h>
|
||||
*/
|
||||
import "C"
|
||||
import "time"
|
||||
|
||||
const (
|
||||
windowWidth = 800
|
||||
windowHeight = 600
|
||||
logoHeight = 64
|
||||
logoSpeed = 300.0
|
||||
)
|
||||
|
||||
func main() {
|
||||
C.InitWindow(windowWidth, windowHeight, C.CString("Raylib in Go"))
|
||||
C.SetTargetFPS(60)
|
||||
C.SetRandomSeed(C.uint(time.Now().Unix()))
|
||||
|
||||
logoImage := C.LoadImage(C.CString("./go_logo.png"))
|
||||
C.ImageResize(&logoImage, logoImage.width*logoHeight/logoImage.height, logoHeight)
|
||||
logoTexture := C.LoadTextureFromImage(logoImage)
|
||||
C.UnloadImage(logoImage)
|
||||
|
||||
x := float32(C.GetRandomValue(0, windowWidth-C.int(logoTexture.width)))
|
||||
y := float32(C.GetRandomValue(0, windowHeight-C.int(logoTexture.height)))
|
||||
|
||||
dx := float32(logoSpeed)
|
||||
if C.GetRandomValue(0, 1) == 1 {
|
||||
dx = -dx
|
||||
}
|
||||
dy := float32(logoSpeed)
|
||||
if C.GetRandomValue(0, 1) == 1 {
|
||||
dy = -dy
|
||||
}
|
||||
|
||||
black := C.Color{0, 0, 0, 255}
|
||||
white := C.Color{255, 255, 255, 255}
|
||||
|
||||
for !bool(C.WindowShouldClose()) {
|
||||
deltaTime := float32(C.GetFrameTime())
|
||||
|
||||
x += dx * deltaTime
|
||||
y += dy * deltaTime
|
||||
|
||||
if x < 0 || x+float32(logoTexture.width) >= windowWidth-1 {
|
||||
dx *= -1
|
||||
x += dx * deltaTime
|
||||
}
|
||||
if y < 0 || y+float32(logoTexture.height) >= windowHeight-1 {
|
||||
dy *= -1
|
||||
y += dy * deltaTime
|
||||
}
|
||||
|
||||
C.BeginDrawing()
|
||||
C.ClearBackground(black)
|
||||
C.DrawTextureV(logoTexture, C.Vector2{x: C.float(x), y: C.float(y)}, white)
|
||||
C.EndDrawing()
|
||||
}
|
||||
|
||||
C.UnloadTexture(logoTexture)
|
||||
C.CloseWindow()
|
||||
}
|
||||
2
languages/odin/Makefile
Normal file
@@ -0,0 +1,2 @@
|
||||
raylib_odin: main.odin
|
||||
odin build main.odin -file -out:raylib_odin
|
||||
8
languages/odin/README.md
Normal file
@@ -0,0 +1,8 @@
|
||||
# Raylib in Odin
|
||||
|
||||
## Quick start
|
||||
|
||||
```sh
|
||||
$ make
|
||||
$ ./raylib_odin
|
||||
```
|
||||
107
languages/odin/main.odin
Normal file
@@ -0,0 +1,107 @@
|
||||
package main
|
||||
|
||||
import "core:time"
|
||||
|
||||
foreign import raylib {
|
||||
"../raylib-5.5_linux_amd64/lib/libraylib.a",
|
||||
"system:m",
|
||||
}
|
||||
|
||||
Image :: struct {
|
||||
data: rawptr,
|
||||
width: i32,
|
||||
height: i32,
|
||||
mipmaps: i32,
|
||||
format: i32,
|
||||
}
|
||||
|
||||
Texture2D :: struct {
|
||||
id: u32,
|
||||
width: i32,
|
||||
height: i32,
|
||||
mipmaps: i32,
|
||||
format: i32,
|
||||
}
|
||||
|
||||
Vector2 :: struct {
|
||||
x: f32,
|
||||
y: f32,
|
||||
}
|
||||
|
||||
Color :: struct {
|
||||
r: u8,
|
||||
g: u8,
|
||||
b: u8,
|
||||
a: u8,
|
||||
}
|
||||
|
||||
@(default_calling_convention = "c")
|
||||
foreign raylib {
|
||||
InitWindow :: proc(width: i32, height: i32, title: cstring) ---
|
||||
CloseWindow :: proc() ---
|
||||
SetTargetFPS :: proc(fps: i32) ---
|
||||
SetRandomSeed :: proc(seed: u32) ---
|
||||
GetRandomValue :: proc(min: i32, max: i32) -> i32 ---
|
||||
LoadImage :: proc(file_name: cstring) -> Image ---
|
||||
ImageResize :: proc(image: ^Image, new_width: i32, new_height: i32) ---
|
||||
LoadTextureFromImage :: proc(image: Image) -> Texture2D ---
|
||||
UnloadImage :: proc(image: Image) ---
|
||||
UnloadTexture :: proc(texture: Texture2D) ---
|
||||
WindowShouldClose :: proc() -> bool ---
|
||||
GetFrameTime :: proc() -> f32 ---
|
||||
BeginDrawing :: proc() ---
|
||||
ClearBackground :: proc(color: Color) ---
|
||||
DrawTextureV :: proc(texture: Texture2D, position: Vector2, tint: Color) ---
|
||||
EndDrawing :: proc() ---
|
||||
}
|
||||
|
||||
WINDOW_WIDTH :: 800
|
||||
WINDOW_HEIGHT :: 600
|
||||
LOGO_HEIGHT :: 64
|
||||
LOGO_SPEED :: 300
|
||||
|
||||
BLACK :: Color{0, 0, 0, 255}
|
||||
WHITE :: Color{255, 255, 255, 255}
|
||||
|
||||
main :: proc() {
|
||||
InitWindow(WINDOW_WIDTH, WINDOW_HEIGHT, "Raylib in Odin")
|
||||
SetTargetFPS(60)
|
||||
SetRandomSeed(cast(u32)time.now()._nsec)
|
||||
|
||||
logo_image := LoadImage("./odin_logo.png")
|
||||
ImageResize(&logo_image, logo_image.width * LOGO_HEIGHT / logo_image.height, LOGO_HEIGHT)
|
||||
logo_texture := LoadTextureFromImage(logo_image)
|
||||
UnloadImage(logo_image)
|
||||
|
||||
x := f32(GetRandomValue(0, WINDOW_WIDTH - logo_texture.width))
|
||||
y := f32(GetRandomValue(0, WINDOW_HEIGHT - logo_texture.height))
|
||||
|
||||
dx: f32 = LOGO_SPEED
|
||||
if GetRandomValue(0, 1) == 1 do dx = -dx
|
||||
dy: f32 = LOGO_SPEED
|
||||
if GetRandomValue(0, 1) == 1 do dy = -dy
|
||||
|
||||
for !WindowShouldClose() {
|
||||
delta_time := GetFrameTime()
|
||||
|
||||
x += dx * delta_time
|
||||
y += dy * delta_time
|
||||
|
||||
if x < 0 || x + f32(logo_texture.width) >= WINDOW_WIDTH - 1 {
|
||||
dx *= -1
|
||||
x += dx * delta_time
|
||||
}
|
||||
if y < 0 || y + f32(logo_texture.height) >= WINDOW_HEIGHT - 1 {
|
||||
dy *= -1
|
||||
y += dy * delta_time
|
||||
}
|
||||
|
||||
BeginDrawing()
|
||||
ClearBackground(BLACK)
|
||||
DrawTextureV(logo_texture, Vector2{x, y}, WHITE)
|
||||
EndDrawing()
|
||||
}
|
||||
|
||||
UnloadTexture(logo_texture)
|
||||
CloseWindow()
|
||||
}
|
||||
BIN
languages/odin/odin_logo.png
Normal file
|
After Width: | Height: | Size: 75 KiB |
7
languages/python/README.md
Normal file
@@ -0,0 +1,7 @@
|
||||
# Raylib in Python
|
||||
|
||||
## Quick start
|
||||
|
||||
```sh
|
||||
$ python ./main.py
|
||||
```
|
||||
86
languages/python/main.py
Normal file
@@ -0,0 +1,86 @@
|
||||
from ctypes import *
|
||||
from time import time
|
||||
|
||||
rl = CDLL("../raylib-5.5_linux_amd64/lib/libraylib.so")
|
||||
|
||||
class Image(Structure):
|
||||
_fields_ = [
|
||||
("data", c_void_p),
|
||||
("width", c_int),
|
||||
("height", c_int),
|
||||
("mipmaps", c_int),
|
||||
("format", c_int),
|
||||
]
|
||||
|
||||
class Texture2D(Structure):
|
||||
_fields_ = [
|
||||
("id", c_uint),
|
||||
("width", c_int),
|
||||
("height", c_int),
|
||||
("mipmaps", c_int),
|
||||
("format", c_int),
|
||||
]
|
||||
|
||||
class Vector2(Structure):
|
||||
_fields_ = [
|
||||
("x", c_float),
|
||||
("y", c_float),
|
||||
]
|
||||
|
||||
class Color(Structure):
|
||||
_fields_ = [
|
||||
("r", c_ubyte),
|
||||
("g", c_ubyte),
|
||||
("b", c_ubyte),
|
||||
("a", c_ubyte),
|
||||
]
|
||||
|
||||
rl.LoadImage.restype = Image
|
||||
rl.LoadTextureFromImage.restype = Texture2D
|
||||
rl.GetFrameTime.restype = c_float
|
||||
|
||||
WINDOW_WIDTH = 800
|
||||
WINDOW_HEIGHT = 600
|
||||
LOGO_HEIGHT = 64
|
||||
LOGO_SPEED = 300
|
||||
BLACK = Color(r=0,g=0,b=0,a=255)
|
||||
WHITE = Color(r=255,g=255,b=255,a=255)
|
||||
|
||||
|
||||
rl.InitWindow(WINDOW_WIDTH, WINDOW_HEIGHT, b"Raylib in Python")
|
||||
rl.SetTargetFPS(60)
|
||||
rl.SetRandomSeed(int(time()))
|
||||
|
||||
logo_image = rl.LoadImage(b"./python_logo.png")
|
||||
rl.ImageResize(byref(logo_image), logo_image.width * LOGO_HEIGHT // logo_image.height, LOGO_HEIGHT)
|
||||
logo_texture = rl.LoadTextureFromImage(logo_image)
|
||||
rl.UnloadImage(logo_image)
|
||||
|
||||
x = rl.GetRandomValue(0, WINDOW_WIDTH - logo_texture.width)
|
||||
y = rl.GetRandomValue(0, WINDOW_HEIGHT - logo_texture.height)
|
||||
|
||||
dx = LOGO_SPEED * (-1 if rl.GetRandomValue(0, 1) else 1)
|
||||
dy = LOGO_SPEED * (-1 if rl.GetRandomValue(0, 1) else 1)
|
||||
|
||||
while not rl.WindowShouldClose():
|
||||
delta_time = rl.GetFrameTime()
|
||||
|
||||
x += dx * delta_time
|
||||
y += dy * delta_time
|
||||
|
||||
if x < 0 or (x + logo_texture.width) >= WINDOW_WIDTH - 1:
|
||||
dx *= -1
|
||||
x += dx * delta_time
|
||||
if y < 0 or (y + logo_texture.height) >= WINDOW_HEIGHT - 1:
|
||||
dy *= -1
|
||||
y += dy * delta_time
|
||||
|
||||
rl.BeginDrawing()
|
||||
|
||||
rl.ClearBackground(BLACK)
|
||||
rl.DrawTextureV(logo_texture, Vector2(x=x, y=y), WHITE)
|
||||
|
||||
rl.EndDrawing()
|
||||
|
||||
rl.UnloadTexture(logo_texture)
|
||||
rl.CloseWindow()
|
||||
BIN
languages/python/python_logo.png
Normal file
|
After Width: | Height: | Size: 78 KiB |
2
languages/rust/Makefile
Normal file
@@ -0,0 +1,2 @@
|
||||
raylib_rust: main.rs
|
||||
rustc --edition 2021 main.rs -C link-args="-L ../raylib-5.5_linux_amd64/lib -l:libraylib.a -lm" -o raylib_rust
|
||||
8
languages/rust/README.md
Normal file
@@ -0,0 +1,8 @@
|
||||
# Raylib in Rust
|
||||
|
||||
## Quick start
|
||||
|
||||
```sh
|
||||
$ make
|
||||
$ ./raylib_rust
|
||||
```
|
||||
133
languages/rust/main.rs
Normal file
@@ -0,0 +1,133 @@
|
||||
use std::{
|
||||
ffi::{c_char, c_float, c_int, c_uchar, c_uint, c_void},
|
||||
time::{SystemTime, UNIX_EPOCH},
|
||||
};
|
||||
|
||||
extern "C" {
|
||||
fn InitWindow(width: c_int, height: c_int, title: *const c_char);
|
||||
fn CloseWindow();
|
||||
|
||||
fn SetTargetFPS(fps: c_int);
|
||||
fn SetRandomSeed(seed: c_uint);
|
||||
fn GetRandomValue(min: c_int, max: c_int) -> c_int;
|
||||
|
||||
fn LoadImage(file_name: *const c_char) -> Image;
|
||||
fn ImageResize(image: *mut Image, new_width: c_int, new_height: c_int);
|
||||
fn LoadTextureFromImage(image: Image) -> Texture2D;
|
||||
fn UnloadImage(image: Image);
|
||||
fn UnloadTexture(texture: Texture2D);
|
||||
|
||||
fn WindowShouldClose() -> bool;
|
||||
fn GetFrameTime() -> c_float;
|
||||
|
||||
fn BeginDrawing();
|
||||
fn ClearBackground(color: Color);
|
||||
fn DrawTextureV(texture: Texture2D, position: Vector2, tint: Color);
|
||||
fn EndDrawing();
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
#[repr(C)]
|
||||
struct Image {
|
||||
data: *mut c_void,
|
||||
width: c_int,
|
||||
height: c_int,
|
||||
mipmaps: c_int,
|
||||
format: c_int,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
#[repr(C)]
|
||||
struct Texture2D {
|
||||
id: c_uint,
|
||||
width: c_int,
|
||||
height: c_int,
|
||||
mipmaps: c_int,
|
||||
format: c_int,
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
struct Vector2 {
|
||||
x: c_float,
|
||||
y: c_float,
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
struct Color {
|
||||
r: c_uchar,
|
||||
g: c_uchar,
|
||||
b: c_uchar,
|
||||
a: c_uchar,
|
||||
}
|
||||
|
||||
const WINDOW_WIDTH: c_int = 800;
|
||||
const WINDOW_HEIGHT: c_int = 600;
|
||||
const LOGO_HEIGHT: c_int = 64;
|
||||
const LOGO_SPEED: f32 = 300.0;
|
||||
|
||||
const BLACK: Color = Color {
|
||||
r: 0,
|
||||
g: 0,
|
||||
b: 0,
|
||||
a: 255,
|
||||
};
|
||||
const WHITE: Color = Color {
|
||||
r: 255,
|
||||
g: 255,
|
||||
b: 255,
|
||||
a: 255,
|
||||
};
|
||||
|
||||
fn main() {
|
||||
unsafe {
|
||||
InitWindow(WINDOW_WIDTH, WINDOW_HEIGHT, c"Raylib in Rust".as_ptr());
|
||||
SetTargetFPS(60);
|
||||
SetRandomSeed(
|
||||
SystemTime::now()
|
||||
.duration_since(UNIX_EPOCH)
|
||||
.unwrap()
|
||||
.as_secs() as u32,
|
||||
);
|
||||
|
||||
let mut logo_image = LoadImage(c"./rust_logo.png".as_ptr());
|
||||
ImageResize(
|
||||
&mut logo_image,
|
||||
logo_image.width * LOGO_HEIGHT / logo_image.height,
|
||||
LOGO_HEIGHT,
|
||||
);
|
||||
let logo_texture = LoadTextureFromImage(logo_image);
|
||||
UnloadImage(logo_image);
|
||||
|
||||
let mut x = GetRandomValue(0, WINDOW_WIDTH - logo_texture.width) as f32;
|
||||
let mut y = GetRandomValue(0, WINDOW_HEIGHT - logo_texture.height) as f32;
|
||||
|
||||
let mut dx = LOGO_SPEED * if GetRandomValue(0, 1) == 1 { -1.0 } else { 1.0 };
|
||||
let mut dy = LOGO_SPEED * if GetRandomValue(0, 1) == 1 { -1.0 } else { 1.0 };
|
||||
|
||||
while !WindowShouldClose() {
|
||||
let delta_time = GetFrameTime();
|
||||
|
||||
x += dx * delta_time;
|
||||
y += dy * delta_time;
|
||||
|
||||
if x < 0.0 || x + logo_texture.width as f32 >= WINDOW_WIDTH as f32 - 1.0 {
|
||||
dx *= -1.0;
|
||||
x += dx * delta_time;
|
||||
}
|
||||
if y < 0.0 || y + logo_texture.height as f32 >= WINDOW_HEIGHT as f32 - 1.0 {
|
||||
dy *= -1.0;
|
||||
y += dy * delta_time;
|
||||
}
|
||||
|
||||
BeginDrawing();
|
||||
|
||||
ClearBackground(BLACK);
|
||||
DrawTextureV(logo_texture, Vector2 { x, y }, WHITE);
|
||||
|
||||
EndDrawing();
|
||||
}
|
||||
|
||||
UnloadTexture(logo_texture);
|
||||
CloseWindow();
|
||||
}
|
||||
}
|
||||
BIN
languages/rust/rust_logo.png
Normal file
|
After Width: | Height: | Size: 16 MiB |
2
languages/zig/Makefile
Normal file
@@ -0,0 +1,2 @@
|
||||
raylib_zig: main.zig
|
||||
zig build-exe main.zig -I../raylib-5.5_linux_amd64/include ../raylib-5.5_linux_amd64/lib/libraylib.a -lm -femit-bin=raylib_zig
|
||||
8
languages/zig/README.md
Normal file
@@ -0,0 +1,8 @@
|
||||
# Raylib in Zig
|
||||
|
||||
## Quick start
|
||||
|
||||
```sh
|
||||
$ make
|
||||
$ ./raylib_zig
|
||||
```
|
||||
53
languages/zig/main.zig
Normal file
@@ -0,0 +1,53 @@
|
||||
const std = @import("std");
|
||||
const rl = @cImport({
|
||||
@cInclude("raylib.h");
|
||||
});
|
||||
|
||||
const WINDOW_WIDTH = 800;
|
||||
const WINDOW_HEIGHT = 600;
|
||||
const LOGO_HEIGHT = 64;
|
||||
const LOGO_SPEED: f32 = 300;
|
||||
|
||||
const BLACK = rl.Color{ .r = 0, .g = 0, .b = 0, .a = 255 };
|
||||
const WHITE = rl.Color{ .r = 255, .g = 255, .b = 255, .a = 255 };
|
||||
|
||||
pub fn main() void {
|
||||
rl.InitWindow(WINDOW_WIDTH, WINDOW_HEIGHT, "Raylib in Zig");
|
||||
rl.SetTargetFPS(60);
|
||||
rl.SetRandomSeed(@intCast(std.time.timestamp()));
|
||||
|
||||
var logo_image = rl.LoadImage("./zig_logo.png");
|
||||
rl.ImageResize(&logo_image, @divTrunc(logo_image.width * LOGO_HEIGHT, logo_image.height), LOGO_HEIGHT);
|
||||
const logo_texture = rl.LoadTextureFromImage(logo_image);
|
||||
rl.UnloadImage(logo_image);
|
||||
|
||||
var x: f32 = @floatFromInt(rl.GetRandomValue(0, WINDOW_WIDTH - logo_texture.width));
|
||||
var y: f32 = @floatFromInt(rl.GetRandomValue(0, WINDOW_HEIGHT - logo_texture.height));
|
||||
|
||||
var dx: f32 = if (rl.GetRandomValue(0, 1) == 1) -LOGO_SPEED else LOGO_SPEED;
|
||||
var dy: f32 = if (rl.GetRandomValue(0, 1) == 1) -LOGO_SPEED else LOGO_SPEED;
|
||||
|
||||
while (!rl.WindowShouldClose()) {
|
||||
const delta_time = rl.GetFrameTime();
|
||||
|
||||
x += dx * delta_time;
|
||||
y += dy * delta_time;
|
||||
|
||||
if (x < 0 or x + @as(f32, @floatFromInt(logo_texture.width)) >= WINDOW_WIDTH - 1) {
|
||||
dx *= -1;
|
||||
x += dx * delta_time;
|
||||
}
|
||||
if (y < 0 or y + @as(f32, @floatFromInt(logo_texture.height)) >= WINDOW_HEIGHT - 1) {
|
||||
dy *= -1;
|
||||
y += dy * delta_time;
|
||||
}
|
||||
|
||||
rl.BeginDrawing();
|
||||
rl.ClearBackground(BLACK);
|
||||
rl.DrawTextureV(logo_texture, rl.Vector2{ .x = x, .y = y }, WHITE);
|
||||
rl.EndDrawing();
|
||||
}
|
||||
|
||||
rl.UnloadTexture(logo_texture);
|
||||
rl.CloseWindow();
|
||||
}
|
||||
BIN
languages/zig/zig_logo.png
Normal file
|
After Width: | Height: | Size: 4.4 KiB |