Replies: 1 comment
-
That's intresting. I also wanna know. Even though this was posted last month, but I anyway write the anwser for others. Shape drawing functions emit vertices using rlVertex*, rlTexCoord*, rlColor* functions. For older OpenGL APIs they immediately call gl* equivalents (immediate mode). Vertices are emitted between rlBegin() and rlEnd() calls which on old OpenGL with immediate mode just forwards to glBegin() and glEnd(). On newer OpenGL it justs modifes current Raylib rendering state. glEnd() is what actually performs rendering to the backbuffer. But on newer OpenGL raylib doesn't call that. It postpones rendering. EndDrawing(), before swapping screen buffers, will call rlDrawRenderBatchActive() which only on newer OpenGL draws active render batch (all queued verticies of rlVertex*, rlTexCoord*, rlColor* calls) manually without OpenGL's immediate mode. So it works like this on older OpenGL:
But on newer OpenGL:
What's also interesting.. Is that rlDrawRenderBatchActive() is called inside BeginMode2D(), EndMode2D(), BeginMode3D(), EndMode3D(), BeginTextureMode(), EndTextureMode(), BeginScissorMode(), EndScissorMode(). So if you call any of these after DrawRectangle() call, queued verticies will be rendered immediately. But you can just flush them manually: #include <raylib.h>
#include <rlgl.h>
int main() {
InitWindow(640, 480, "Clear background");
while (!WindowShouldClose()) {
BeginDrawing();
DrawRectangle(0, 0, 40, 40, RED);
rlDrawRenderBatchActive();
ClearBackground(GREEN);
EndDrawing();
}
} |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Why do I see a red square on the screen in this simple example?
Beta Was this translation helpful? Give feedback.
All reactions