OGRE Wiki
Support and community documentation for Ogre3D
Ogre Forums
ogre3d.org
Log in
Username:
Password:
CapsLock is on.
Remember me (for 1 year)
Log in
Home
Tutorials
Tutorials Home
Basic Tutorials
Intermediate Tutorials
Mad Marx Tutorials
In Depth Tutorials
Older Tutorials
External Tutorials
Cookbook
Cookbook Home
CodeBank
Snippets
Experiences
Ogre Articles
Libraries
Libraries Home
Alternative Languages
Assembling A Toolset
Development Tools
OGRE Libraries
List of Libraries
Tools
Tools Home
DCC Tools
DCC Tutorials
DCC Articles
DCC Resources
Assembling a production pipeline
Development
Development Home
Roadmap
Building Ogre
Installing the Ogre SDK
Setting Up An Application
Ogre Wiki Tutorial Framework
Frequently Asked Questions
Google Summer Of Code
Help Requested
Ogre Core Articles
Community
Community Home
Projects Using Ogre
Recommended Reading
Contractors
Wiki
Immediate Wiki Tasklist
Wiki Ideas
Wiki Guidelines
Article Writing Guidelines
Wiki Styles
Wiki Page Tracker
Ogre Wiki Help
Ogre Wiki Help Overview
Help - Basic Syntax
Help - Images
Help - Pages and Structures
Help - Wiki Plugins
Toolbox
Freetags
Categories
List Pages
Structures
Trackers
Statistics
Rankings
List Galleries
Ogre Lexicon
Comments
History: OpenGL Image Loader Using DevIL Image Library
View page
Source of version: 1
(current)
The OpenGL platform for MyGUI lacks a built-in image loading class. An abstract class is provided (OpenGLImageLoader) to allow you to create your own. I've taken it a step further by creating a class for you, using the excellent open source DevIL library! Note: the image format conversion code (e.g. MyGUI doesn't support BGR, so it gets converted to RGB) hasn't been tested (all the files so far have been of a supported format), but it should work, at least with a little tweaking. Enjoy! {CODE(caption="OpenGL DevIL Image Loader Class",wrap="1",colors="c++",wiki="0",rtl="0",ishtml="0")}#ifndef __OPENGL_IMAGE_LOADER_DEVIL__ #define __OPENGL_IMAGE_LOADER_DEVIL__ #include <algorithm> #include <cctype> #include <cstdlib> #include <MyGUI_DataManager.h> #include <MyGUI_OpenGLImageLoader.h> #include <IL/il.h> class OpenGLImageLoader_Devil : public MyGUI::OpenGLImageLoader { public: OpenGLImageLoader_Devil() : MyGUI::OpenGLImageLoader() { // Take this out of here if you initialise DevIL elsewhere ilInit(); } virtual ~OpenGLImageLoader_Devil() { } void* loadImage( int& _width, int& _height, MyGUI::PixelFormat& _format, const std::string& _filename) { // Generate an image name and bind it so we can use it ILuint image; ilGenImages(1, &image); ilBindImage(image); // Load the image as a resource MyGUI::IDataStream* stream = MyGUI::DataManager::getInstancePtr()->getData(_filename); size_t lumpSize = stream->size(); void* lumpData = malloc(lumpSize); stream->read(lumpData, lumpSize); #ifdef _UNICODE // Convert filename to a std::wstring std::wstring filename(_filename.length(), L' '); std::copy(_filename.begin(), _filename.end(), filename.begin()); #else std::string filename = _filename; #endif // Try to determine the image type ILenum imageType = ilDetermineType(filename.c_str()); if (imageType == IL_TYPE_UNKNOWN) { imageType = ilDetermineTypeL(lumpData, lumpSize); } // Try to load the image if (ilLoadL(imageType, lumpData, lumpSize) == IL_FALSE) { free(lumpData); return 0; } free(lumpData); // Retrieve image information _width = ilGetInteger(IL_IMAGE_WIDTH); _height = ilGetInteger(IL_IMAGE_HEIGHT); ILenum format = ilGetInteger(IL_IMAGE_FORMAT); ILenum type = ilGetInteger(IL_IMAGE_TYPE); // If the format is not supported, convert to a supported format // Also convert if the pixel type is not unsigned byte ILenum convertToFormat = format; switch (format) { case IL_COLOUR_INDEX: convertToFormat = IL_RGB; break; case IL_ALPHA: convertToFormat = IL_LUMINANCE_ALPHA; break; case IL_BGR: convertToFormat = IL_RGB; break; case IL_BGRA: convertToFormat = IL_RGBA; break; default: break; } if ((convertToFormat != format) || (type != IL_UNSIGNED_BYTE)) { if (ilConvertImage(convertToFormat, IL_UNSIGNED_BYTE) == IL_FALSE) { return 0; } } // Determine MyGUI pixel formats switch (format) { case IL_RGB: _format = MyGUI::PixelFormat::R8G8B8; break; case IL_RGBA: _format = MyGUI::PixelFormat::R8G8B8A8; break; case IL_LUMINANCE: _format = MyGUI::PixelFormat::L8; break; case IL_LUMINANCE_ALPHA: _format = MyGUI::PixelFormat::L8A8; break; default: _format = MyGUI::PixelFormat::Unknow; break; } // Copy the image data into some new memory ILint size = ilGetInteger(IL_IMAGE_SIZE_OF_DATA); void* _data = malloc(size); ILubyte* data = ilGetData(); memcpy(_data, data, size); return _data; } }; #endif // __OPENGL_IMAGE_LOADER_DEVIL__{CODE}
Search by Tags
Search Wiki by Freetags
Latest Changes
Easy Ogre Exporter
Mesh Viewer
Ogre Meshy
Custom Shadow Mapping
ETM
TheoraVideoPlugin
Video Overview
TheoraVideoPlugin Toolbar tpl
ogregallery
Contractors
...more
Search
Find
Advanced
Search Help
Online Users
111 online users