1

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();
}
New contributor
ישי סירקיס is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.

1 Answer 1

0

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()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.