doodle
0.2
Intended to support teaching C++, doodle is a simple library that helps make a window and makes it easy to do some drawing.
|
Image class to store a 2D array of RGBA colors. Also manages an image on the Graphics Card. More...
#include <image.hpp>
Public Types | |
enum class | FileType { PNG , BMP , TGA } |
Lists all of the supported image file formats. More... | |
Public Member Functions | |
Image (int width, int height, bool smooth_it=false) | |
Construct an empty image with a provided resolution. More... | |
Image (const std::filesystem::path &file_path, bool smooth_it=false) | |
Create an Image based off of an image file. The supported image formats are defined by the Image::FileType enum. More... | |
Image () | |
Creates an empty image. More... | |
void | SaveToFile (const std::filesystem::path &file_path, FileType file_type=FileType::PNG) const |
Save the Image as an image file on disk. More... | |
int | GetWidth () const noexcept |
Return the width of the image. More... | |
int | GetHeight () const noexcept |
Return the height of the image. More... | |
int | GetNumberOfColors () const noexcept |
Return the total number of colors in the image. More... | |
bool | IsSmooth () const noexcept |
Tell whether the smooth filter is enabled or not. More... | |
Color | operator[] (int index) const |
Get a specific color from the image. More... | |
Color & | operator[] (int index) |
Get a specific color from the image, so that you can change the image contents. Usage of this will trigger creating a new GPU texture when the Image is drawn via draw_image(). More... | |
Color | operator() (int column, int row) const |
Get a specific color from the image. More... | |
Color & | operator() (int column, int row) |
Get a specific color from the image, so that you can change the image contents. Usage of this will trigger creating a new GPU texture when the Image is drawn via draw_image(). More... | |
Color * | begin () |
Returns an iterator to the first color of the Image. More... | |
Color * | end () |
Returns an iterator to the color following the last color of the Image. More... | |
const Color * | begin () const |
Returns a const iterator to the first color of the Image. More... | |
const Color * | end () const |
Returns a const iterator to the color following the last color of the Image. More... | |
Static Public Member Functions | |
static int | MaxImageSize () noexcept |
Get the maximum image size allowed. More... | |
Friends | |
void | draw_image (const Image &image, double x, double y) noexcept |
Draw an entire image to the screen. More... | |
void | draw_image (const Image &image, double x, double y, double width, double height) noexcept |
Draw an entire image to the screen and resize it to a custom size. More... | |
void | draw_image (const Image &image, double x, double y, double width, double height) noexcept |
Draw an entire image to the screen and resize it to a custom size. More... | |
void | draw_image (const Image &image, double x, double y, double width, double height, int texel_x, int texel_y) noexcept |
Draw a subsection of the image to the screen. More... | |
void | draw_image (const Image &image, double x, double y, double width, double height, int texel_x, int texel_y, int texel_width, int texel_height) noexcept |
Draw a subsection of the image to the screen. More... | |
Image | end_drawing_to_image (bool smooth_texture) |
End a session of drawing to an image. More... | |
Image class to store a 2D array of RGBA colors. Also manages an image on the Graphics Card.
The Image class is useful for creating images programmatically. It is also useful for loading and creating image files
|
strong |
doodle::Image::Image | ( | int | width, |
int | height, | ||
bool | smooth_it = false |
||
) |
Construct an empty image with a provided resolution.
width | how wide to make the image |
height | how tall to make the image |
smooth_it | When the filter is activated, the texture appears smoother so that pixels are less noticeable. However if you want the texture to look exactly the same as its source file, you should leave it disabled. The smooth filter is disabled by default. |
std::runtime_error | if width/height is <= 0 or is too large |
|
explicit |
Create an Image based off of an image file. The supported image formats are defined by the Image::FileType enum.
file_path | path to an image file |
smooth_it | When the filter is activated, the texture appears smoother so that pixels are less noticeable. However if you want the texture to look exactly the same as its source file, you should leave it disabled. The smooth filter is disabled by default. |
std::runtime_error | if it cannot find the file or if it can't read it |
The following example uses this orange hero image file.
doodle::Image::Image | ( | ) |
Creates an empty image.
Color* doodle::Image::begin | ( | ) |
Returns an iterator to the first color of the Image.
Usage of this will trigger creating a new GPU texture when the Image is drawn via draw_image().
Having a begin/end interface enables the Image class to be used with for range loops and the std <algorithm>
functions.
The following example uses this orange hero image file.
const Color* doodle::Image::begin | ( | ) | const |
Returns a const iterator to the first color of the Image.
Having a begin/end interface enables the Image class to be used with for range loops and the std <algorithm>
functions.
The following example uses this orange hero image file.
Color* doodle::Image::end | ( | ) |
Returns an iterator to the color following the last color of the Image.
This color acts as a placeholder; attempting to access it results in undefined behavior.
Having a begin/end interface enables the Image class to be used with for range loops and the std <algorithm>
functions.
The following example uses this orange hero image file.
const Color* doodle::Image::end | ( | ) | const |
Returns a const iterator to the color following the last color of the Image.
This color acts as a placeholder; attempting to access it results in undefined behavior.
Having a begin/end interface enables the Image class to be used with for range loops and the std <algorithm>
functions.
The following example uses this orange hero image file.
|
noexcept |
Return the height of the image.
|
noexcept |
Return the total number of colors in the image.
|
noexcept |
Return the width of the image.
|
noexcept |
Tell whether the smooth filter is enabled or not.
|
staticnoexcept |
Get the maximum image size allowed.
This maximum size is defined by the graphics driver. You can expect a value of 1024 pixels for low-end graphics card, and up to 8192 pixels or more for newer hardware.
Color& doodle::Image::operator() | ( | int | column, |
int | row | ||
) |
Get a specific color from the image, so that you can change the image contents. Usage of this will trigger creating a new GPU texture when the Image is drawn via draw_image().
column | Should be 0 \(\leq\) column \(<\) GetWidth() |
row | Should be 0 \(\leq\) row \(<\) GetHeight() |
std::out_of_range | if column or row is out of range. |
The following example uses this orange hero image file.
Color doodle::Image::operator() | ( | int | column, |
int | row | ||
) | const |
Get a specific color from the image.
column | Should be 0 \(\leq\) column \(<\) GetWidth() |
row | Should be 0 \(\leq\) row \(<\) GetHeight() |
std::out_of_range | if column or row is out of range. |
The following example uses this orange hero image file.
Color& doodle::Image::operator[] | ( | int | index | ) |
Get a specific color from the image, so that you can change the image contents. Usage of this will trigger creating a new GPU texture when the Image is drawn via draw_image().
index | Should be 0 \(\leq\) index \(<\) GetNumberOfColors() |
std::out_of_range | if index is out of range. |
The following example uses this orange hero image file.
Color doodle::Image::operator[] | ( | int | index | ) | const |
Get a specific color from the image.
index | Should be 0 \(\leq\) index \(<\) GetNumberOfColors() |
std::out_of_range | if index is out of range. |
The following example uses this orange hero image file.
void doodle::Image::SaveToFile | ( | const std::filesystem::path & | file_path, |
FileType | file_type = FileType::PNG |
||
) | const |
Save the Image as an image file on disk.
You should not be giving a directory file path and you will need to add the image extension yourself.
file_path | file path to save the image file to. |
file_type | the type of the image file to create |
|
friend |
Draw an entire image to the screen.
The width and height of the image will be based off of the image width and image height.
image | image object to draw |
x | x-coordinate of the rectangle to draw the image. |
y | y-coordinate of the rectangle to draw the image. |
The following example uses this orange hero image file.
|
friend |
Draw an entire image to the screen and resize it to a custom size.
image | image object to draw |
x | x-coordinate of the rectangle to draw the image. |
y | y-coordinate of the rectangle to draw the image. |
width | how wide to draw the image |
height | how tall to draw the image |
The following example uses this orange hero image file.
|
friend |
Draw an entire image to the screen and resize it to a custom size.
image | image object to draw |
x | x-coordinate of the rectangle to draw the image. |
y | y-coordinate of the rectangle to draw the image. |
width | how wide to draw the image |
height | how tall to draw the image |
The following example uses this orange hero image file.
|
friend |
Draw a subsection of the image to the screen.
The subsection is defined is defined by the box
Image (0,0) +---------------------------------------------------------------------+ | | |(texel_x,texel_y) | | o--------------------------------+ | | | | | | | | | | | | | | | | | | | | | | +--------------------------------o | | (texel_x+width,texel_y+height) | | | | | | | +---------------------------------------------------------------------+ (image_width,image_height)
image | image object to draw |
x | x-coordinate of the rectangle to draw the image. |
y | y-coordinate of the rectangle to draw the image. |
width | how wide to draw the image |
height | how tall to draw the image |
texel_x | Horizontally, where in image to start reading colors from the image. 0 is the far left and image width is the far right. |
texel_y | Vertically, where in image to start reading colors from the image. 0 is the far top and image height is the far bottom. |
The following example uses this orange hero image file.
|
friend |
Draw a subsection of the image to the screen.
The subsection is defined is defined by the box
Image (0,0) +---------------------------------------------------------------------+ | | |(texel_x,texel_y) | | o--------------------------------+ | | | | | | | | | | | | | | | | | | | | | | +--------------------------------o | | (texel_x+texel_width,texel_y+texel_height) | | | | | | | +---------------------------------------------------------------------+ (image_width,image_height)
image | image object to draw |
x | x-coordinate of the rectangle to draw the image. |
y | y-coordinate of the rectangle to draw the image. |
width | how wide to draw the image |
height | how tall to draw the image |
texel_x | Horizontally, where in image to start reading colors from the image. 0 is the far left and image width is the far right. |
texel_y | Vertically, where in image to start reading colors from the image. 0 is the far top and image height is the far bottom. |
texel_width | width of image subsection to read the colors from |
texel_height | height of image subsection to read the colors from |
The following example uses this orange hero image file.
|
friend |
End a session of drawing to an image.
smooth_texture | Should the texture use a smooth filtering when being drawn |