samedi 11 septembre 2021

How do I draw and write to a ppm file using C++?

Pretty much the title. I want to draw lines/shapes and output to a ppm file, but I don't know how to even draw individual pixels. I know how to output to a file and that there's a nested for loop method for drawing pixels (found this code online), but I was wondering if there's an easier way to handle it.

for (auto j = 0u; j < dimy; ++j)
        for (auto i = 0u; i < dimx; ++i)
            ofs << (char) (i % 256) << (char) (j % 256) << (char) ((i * j) % 256);

I'm taking a class that uses C++, but it's my first time working with the language, so please make your answers somewhat simple to understand (I've coded in Java before if that helps). Also, please don't list any features past C++ 11. Thank you in advance! :)

Aucun commentaire:

Enregistrer un commentaire