I was working with a code to print pixels.
// C code
#include <graphics.h>
#include <conio.h>
int main()
{
int gd = DETECT, gm;
initgraph(&gd, &gm, "C:\\TC\\BGI");
for (int i = 0; i < 100; i++)
{
for(j = 0; j < 200; j++)
{
putpixel(i, j, GREEN);
}
}
getch();
closegraph();
return 0;
}
Is there any way of achieving faster response from C compiler while using putpixel() in this code? The speed with which console gets colored with the execution of putpixel() is pretty slow, so I was wondering if there was any other library which I could use to speed up the printing pixel process on the screen using C on a windows system or a Linux one?
putpixel()
is pretty slow, no matter which framework or library you use. Try to create a bitmap and calculate the memory address of each pixel yourself.
Cross-platform frameworks that allow you to do such a thing are SDL and Allegro.
See also: