I'm trying to batch some textures together in raylib (2d game) and so it tried using the 2d rlgl and for some reason that I can't figure out why nothing is getting drawn. I looked at examples and couldn't find any 2d rlgl. And also raylib is initializing correctly and there is not errors in the logs.
this is the code:
#include "raylib.h"
#include "rlgl.h"
int main(void)
{
InitWindow(800, 450, "rlgl + 2D camera rectangle");
SetTargetFPS(60);
Camera2D cam;
cam.target = { 0, 0 };
cam.offset = { 0, 0 };
cam.rotation = 0.0f;
cam.zoom = 0.2f;
while (!WindowShouldClose())
{
BeginDrawing();
ClearBackground(RAYWHITE);
BeginMode2D(cam);
rlBegin(RL_TRIANGLES);
rlColor4ub(255, 0, 0, 255);
rlVertex2f(100, 100);
rlVertex2f(300, 100);
rlVertex2f(300, 300);
rlEnd();
EndMode2D();
EndDrawing();
}
CloseWindow();
}
Raylib is built on top of OpenGL and with backface culling enabled. To distinguish the back from the front face the vertex order is used.
This means that you need to specify your vertices in counter-clockwise order.
You just need to swap
rlVertex2f(100, 100);
rlVertex2f(300, 100);
around. So:
BeginDrawing();
ClearBackground(RAYWHITE);
BeginMode2D(cam);
rlBegin(RL_TRIANGLES);
rlColor4ub(255, 0, 0, 255);
rlVertex2f(300, 100);
rlVertex2f(100, 100);
rlVertex2f(300, 300);
rlEnd();
EndMode2D();
EndDrawing()