X3DToolKit manages images for different reasons. First of all, when a model has textures, the image textures have to be loaded before applied. Furthermore, a user can define images of its own, for example by copying the image buffer and then save in an appropriate format (compressed or not). The X3DTK::Image is made to be easy-use with OpenGL. To use the X3DTK::Image class, include <X3DTK/kernel.h>.

Using the Image class

You can use the Image class like this:
// 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);

Generated on Fri Jul 30 12:02:31 2004 for X3DToolKit by doxygen 1.3.6