I can draw text, but I cannot seem to figure out how to draw shapes in raylib c:
Here is my code:
#include "raylib.h"
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
struct Boid {
int x;
int y;
float dir;
float speed;
};
int main(void)
{
const int screenWidth = 800;
const int screenHeight = 450;
const int numBoids = 50;
struct Boid boidSet[numBoids];
srand(time(NULL));
for(int i=0; i<numBoids; i++)
{
boidSet[i].x = rand() % screenWidth;
boidSet[i].y = rand() % screenHeight;
printf("%d, %dn", boidSet[i].x, boidSet[i].y);
}
printf("nnnn");
InitWindow(screenWidth, screenHeight, "raylib example window");
SetTargetFPS(60);
while (!WindowShouldClose())
{
BeginDrawing();
ClearBackground(RAYWHITE);
DrawText("window open", 190, 200, 20, BLUE);
DrawTriangle(
(Vector2){105, 95},
(Vector2){110, 100},
(Vector2){105, 110},
BLACK
);
DrawTriangle(
(Vector2){boidSet[0].x - 10, boidSet[0].y},
(Vector2){boidSet[0].x + 10, boidSet[0].y},
(Vector2){boidSet[0].x, boidSet[0].y + 10},
RED
);
for (int i = 0; i < numBoids; i++) {
DrawTriangle(
(Vector2){boidSet[i].x - 10, boidSet[i].y},
(Vector2){boidSet[i].x + 10, boidSet[i].y},
(Vector2){boidSet[i].x, boidSet[i].y + 10},
BLACK
);
}
EndDrawing();
}
CloseWindow();
return 0;
}
The output is the blue text drawn on screen but nothing else, I expect that 50(+2 other simple shapes would get drawn on screen) triangles would get drawn on screen in random places
New contributor
Oliver Giordano is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.