I am trying to do ray tracing. I need to create a 2D array of pixels, then do the math of ray tracing. After that I need to draw it to screen. What is the best method to draw 2D array of points?
Use one of the many existing libraries. I usually point people at CImg first, because it's so easy to get started with. Here's drawing an image to screen. It's just a block of coloured pixels.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
#include "CImg.h"
#include <iostream>
usingnamespace cimg_library;
int main() {
// create image size 500x400x1,3 channels (RGB) default colour white
CImg<unsignedchar> theImage(500,400,1,3,1);
for (int i=10; i<50; i++)
{
for (int j = 10; j<70; j++)
{
theImage(i,j,1) = 255; // different colour on a pixel - green to max
}
}
CImgDisplay main_disp(theImage); // display it
theImage.save_bmp("output.bmp"); // write it
std::cin.ignore();
}