Straight to the point: in C there are structures
that allow to work with multiple variables "at the same time". Now suppose to have:
struct point{
double x,y;
}
this will represent a point in a not-yet-defined space. Building from that we could create a segment:
struct segment{
struct point a;
struct point b;
};
And spanning this segment over the observable space we could create a line (with that then an actual 2d plan with finite point in it).
Knowing that now, I ask you, is there any way to show on screen (create graphics) of this geometrical entities (and even 2d gemological figure (rect, circle and so on...) and furthermore more complex one, like 3d objects) only using C from scratch? From scratch I mean without using any lib or in case write that on my own. I would like to emphasize that this is a learning process, hence respectful and pertinent answer will be really appreciate. Thanks.
CodePudding user response:
I dont know about writing them without any libraries, because you will ultimately have to use some library to interface with the GPU for graphics. The most common graphics APIs for C and C are OpenGL and Vulkan, both being great hardware accelerated APIs developed by Khronos, with the latter being lower level than the former. There's also SDL which isn't hardware accelerated, but it is easier to use.
CodePudding user response:
ISO C does not have a notion of computer graphics. It only has a notion of a stream, which may be connected to computer screen. How the data sent through this stream is interpreted (i.e. whether it is interpreted as ASCII codes for text or as coordinates for lines to be drawn) is out of the scope of the ISO C standard.
On most platforms, you require some kind of API provided by the operating system to draw graphics to the screen. For example, on Microsoft Windows, you can use Direct2D or Direct3D, and on Linux, you can use OpenGL.
You can also use a cross-platform library such as SDL, so that the code you write will run on different platforms. This library will then call the respective native API functions for you, so that you don't have to deal with the individual native APIs yourself.