X3DTK::Image
is made to be easy-use with OpenGL. To use the X3DTK::Image
class, include <X3DTK/kernel.h>.// To load an image from file Image *image = new Image("file.jpg"); // To get informations unsigned short width = image->getWidth(); unsigned short height = image->getHeight(); int pixelSize = image->getPixelSize(); // To get the GL pixel format GLenum type = image->getGLType(); // To get the data unsigned char *data = image->getData();
You can resize the image by two ways: You can specify new width and new height, or use it as an OpenGL texture.
// Resizing to 800*600 image->resize(800, 600); // Automatic resize for OpenGL. A texture transform is given to modify the OpenGL texture matrix. float textureTransform[16]; image->resizeGL(textureTransform);
You can read pixels from the image:
// unsigned byte RGB struct RGB_UB { unsigned char r; unsigned char g; unsigned char b; }; // reading pixel x, y RGB_UB *p = Memory<RGB_UB>::access(image, x, y)); p->r = 128; p->g = 32; p->b = 0; ...
You can create your own image:
// Allocating a memory block. image->allocate(800, 600, GL_RGB, GL_FLOAT); // Reading pixels from image buffer. glReadPixels(0, 0, screenWidth, screenHeight, image->getGLFormat(), image->getGLType(), image->getData());
You can save the image:
// Saving the image with quality 0.5 image->saveAs("myfile.jpg", 0.5f);