我一直在尝试测试 raylib,并且尝试以一定角度渲染矩形,但我不确定为什么它们不会渲染。尽管 DrawRectanglePro() 不起作用,但方法 DrawRectangle() 确实起作用。
#include <iostream>
#include "raylib.h"
int main() {
InitWindow(800, 800, "More Raylib Practice");
SetWindowState(FLAG_VSYNC_HINT);
while (!WindowShouldClose()) {
BeginDrawing();
ClearBackground(BLACK);
DrawRectangle(10, 10, 10, 10, RED); //normal rectangle DOES render
Rectangle rec = { 10, 10, 10, 10 };
DrawRectanglePro(rec, { 400, 400 }, (float)45, WHITE); //angled rectangle doesn't?
EndDrawing();
}
CloseWindow();
return 0;
}
最佳答案
看起来您滥用了 origin 参数,在您的情况下为 { 400, 400 }
。 origin 参数用于设置从引用的矩形开始绘制点的原点。
你的代码是说,在 10 x 10 的正方形上,向右移动 400,向下移动 400,然后在 10, 10 处绘制该。如果你设置一个 2d 相机,你会发现你的白色三角形屏幕外向左上方 400 左右像素。
大多数时候,您想要更改原点的是矩形或纹理的中心。这使您可以在中心而不是纹理的左上角旋转某些内容。
总而言之,这是更正后的代码:
#include <iostream>
#include "raylib.h"
int main() {
InitWindow(800, 800, "More Raylib Practice");
SetWindowState(FLAG_VSYNC_HINT);
while (!WindowShouldClose()) {
BeginDrawing();
ClearBackground(BLACK);
DrawRectangle(10, 10, 10, 10, RED);
Rectangle rec = { 10, 10, 10, 10 };
DrawRectanglePro(rec, { 0, 0 }, (float)45, WHITE); //Set origin to 0,0
EndDrawing();
}
CloseWindow();
return 0;
}
关于c++ - 方法 DrawRectanglePro() 不渲染矩形,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73095750/