AGL
A graphics library
|
Implements loading, modifying, and saving RGBA images. More...
#include <image.h>
Public Member Functions | |
Image (int width, int height) | |
Image (const Image &orig) | |
Image & | operator= (const Image &orig) |
bool | load (const std::string &filename) |
Load the given filename (.png) More... | |
bool | save (const std::string &filename, bool flip=true) const |
Save the image to the given filename (.png) More... | |
int | width () const |
Return the image width in pixels. | |
int | height () const |
Return the image height in pixels. | |
unsigned char * | data () const |
Return the RGBA data. More... | |
void | set (int width, int height, unsigned char *data) |
Replace image RGBA data. More... | |
Pixel | get (int row, int col) const |
Get the pixel at index (row, col) More... | |
void | set (int row, int col, const Pixel &color) |
Set the pixel RGBA color at index (row, col) More... | |
void | setVec4 (int row, int col, const glm::vec4 &color) |
Set the pixel RGBA color at index (row, col) More... | |
glm::vec4 | getVec4 (int row, int col) const |
Get the pixel RGBA color at index (row, col) More... | |
Implements loading, modifying, and saving RGBA images.
|
inline |
Return the RGBA data.
Data will have size width * height * 4 (RGBA)
Pixel agl::Image::get | ( | int | row, |
int | col | ||
) | const |
Get the pixel at index (row, col)
row | The row (value between 0 and height) |
col | The col (value between 0 and width) |
Pixel colors are unsigned char, e.g. in range 0 to 255
vec4 agl::Image::getVec4 | ( | int | row, |
int | col | ||
) | const |
Get the pixel RGBA color at index (row, col)
row | The row (value between 0 and height) |
col | The col (value between 0 and width) |
vec4 colors are in range [0,1]
bool agl::Image::load | ( | const std::string & | filename | ) |
Load the given filename (.png)
filename | The file to load, relative to the running directory |
// Copyright 2020, Savvy Sine, Aline Normoyle #include "agl/window.h" using glm::vec3; class MyWindow : public agl::Window { void setup() { renderer.loadTexture("cloud", "../textures/cloud.png", 0); renderer.loadTexture("particle", "../textures/particle.png", 0); renderer.blendMode(agl::ADD); } void draw() { renderer.beginShader("sprite"); renderer.texture("image", "cloud"); renderer.sprite(vec3(-0.5f, 0.0f, 0.0f), red, 0.25f); renderer.sprite(vec3(0.5f, 0.0f, 0.0f), green, 0.25f); renderer.texture("image", "particle"); renderer.sprite(vec3(0.0f, 0.25f, 0.0f), blue, 0.25f); renderer.endShader(); } const glm::vec4 red = glm::vec4(1, 0, 0, 1); const glm::vec4 green = glm::vec4(0, 1, 0, 1); const glm::vec4 blue = glm::vec4(0, 0, 1, 1); }; int main() { MyWindow window; window.run(); }
bool agl::Image::save | ( | const std::string & | filename, |
bool | flip = true |
||
) | const |
Save the image to the given filename (.png)
filename | The file to load, relative to the running directory |
flip | Whether the file should flipped vertally before being saved |
void agl::Image::set | ( | int | row, |
int | col, | ||
const Pixel & | color | ||
) |
Set the pixel RGBA color at index (row, col)
row | The row (value between 0 and height) |
col | The col (value between 0 and width) |
Pixel colors are unsigned char, e.g. in range 0 to 255
// Copyright 2020, Savvy Sine, Aline Normoyle #include "agl/window.h" using glm::vec2; using glm::vec3; using glm::vec4; class MyWindow : public agl::Window { void setup() { renderer.setUniform("Fog.enabled", true); renderer.setUniform("Fog.color", vec3(0.9f)); renderer.setUniform("Fog.minDist", 5.0f); renderer.setUniform("Fog.maxDist", 9.0f); renderer.setUniform("Material.specular", vec3(0.0)); renderer.setUniform("MainTexture.enabled", true); renderer.setUniform("MainTexture.tile", vec2(10.0)); int halfw = 32; int halfh = 32; agl::Image checker(halfw*2, halfh*2); for (int i = 0; i < checker.height(); i++) { for (int j = 0; j < checker.width(); j++) { if ((i < halfh && j < halfw) || (i > halfh && j > halfw)) { checker.setVec4(i, j, vec4(0, 0, 0, 1)); } else { checker.setVec4(i, j, vec4(1, 1, 1, 1)); } } } renderer.loadTexture("checker", checker, 0); renderer.texture("MainTexture.texture", "checker"); setupPerspectiveScene(vec3(0.0), vec3(10.0)); background(vec3(0.9f)); } void draw() { renderer.scale(vec3(20.0f)); renderer.plane(); } }; int main() { MyWindow window; window.run(); }
void agl::Image::set | ( | int | width, |
int | height, | ||
unsigned char * | data | ||
) |
Replace image RGBA data.
width | The new image width |
height | The new image height |
This call will replace the old data with the new data. Data should match the size width * height * 4
void agl::Image::setVec4 | ( | int | row, |
int | col, | ||
const glm::vec4 & | color | ||
) |
Set the pixel RGBA color at index (row, col)
row | The row (value between 0 and height) |
col | The col (value between 0 and width) |
vec4 colors are in range [0,1]