Basic Shapes
bar3d() in graphics.h
bar3d() draws a filled 3D-style rectangular box. It is useful when you want depth-like visual effect in old-school graphics screens.
On This Page
Syntax
void bar3d(int left, int top, int right, int bottom, int depth, int topflag);
Draws a bar with a 3D face using depth offset.
Parameters
left, top, right, bottom: rectangle cornersdepth: thickness of 3D effecttopflag: if non-zero, draws top face; if 0, top face hidden
bar3d(100, 100, 280, 220, 20, 1);
Higher depth values create stronger pseudo-3D perspective.
Full Program
#include <graphics.h>
#include <conio.h>
int main() {
int gd = DETECT, gm;
initgraph(&gd, &gm, "");
bar3d(80, 100, 260, 220, 20, 1);
bar3d(320, 120, 520, 260, 30, 1);
getch();
closegraph();
return 0;
}
Common Mistakes
- Using very large depth values causing clipping.
- Expecting real 3D rendering (this is a 2D illusion).
- Incorrect coordinate order and missing initialization.