utils.cpp 915 B

123456789101112131415161718192021222324252627282930313233
  1. #include "game.h"
  2. /** Loads a PNG file and creates VGImage using the 32bit image data.
  3. */
  4. VGImage loadVGImage(const char *filename)
  5. {
  6. QImage texture;
  7. if(!texture.load(filename))
  8. {
  9. qDebug("loadVGImage cannot load '%s'", filename);
  10. return VG_INVALID_HANDLE;
  11. }
  12. // make sure we have 32bit format
  13. texture = texture.convertToFormat(QImage::Format_ARGB32);
  14. int w=texture.width();
  15. int h=texture.height();
  16. qDebug("loadVGImage '%s' %dx%d", filename, w, h);
  17. VGImage image = vgCreateImage(VG_sARGB_8888, w, h, VG_IMAGE_QUALITY_FASTER);
  18. qDebug("vgCreateImage handle %x", image);
  19. if(image==VG_INVALID_HANDLE)
  20. {
  21. VGErrorCode err = vgGetError();
  22. qDebug("loadVGImage '%s' error 0x%x", filename, err);
  23. }
  24. vgImageSubData(image, (QRgb*)texture.bits(), w*4, VG_sARGB_8888, 0, 0, w, h);
  25. return image;
  26. }