Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: OpenGLImageLoader - myGUI (What's wrong?)  (Read 3632 times)

0 Members and 1 Guest are viewing this topic.

codder

  • Newbie
  • *
  • Posts: 8
    • View Profile
OpenGLImageLoader - myGUI (What's wrong?)
« on: December 28, 2011, 04:01:37 pm »
Hi,

im going to use myGUI as gui library for a tiny project

but the problem is:
http://www7.escoflip.com/tikiwiki/OpenGL+Image+Loader+Using+DevIL+Image+Library&structure=Libraries

i have to change this with sfml functions

actually im doing this:

-loading image
-pass image.GetWidth(); to _width
-pass image.GetHeight(); to _height

but what about pixel format?
and getting raw image and return it?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
OpenGLImageLoader - myGUI (What's wrong?)
« Reply #1 on: December 28, 2011, 04:24:31 pm »
Hi

The pixel format is fixed in SFML: MyGUI::PixelFormat::R8G8B8A8.

The raw pixel data is image.GetPixelsPtr() (don't forget to memcpy it, don't return it directly).
Laurent Gomila - SFML developer

codder

  • Newbie
  • *
  • Posts: 8
    • View Profile
OpenGLImageLoader - myGUI (What's wrong?)
« Reply #2 on: December 28, 2011, 04:27:15 pm »
Thanks

codder

  • Newbie
  • *
  • Posts: 8
    • View Profile
OpenGLImageLoader - myGUI (What's wrong?)
« Reply #3 on: December 28, 2011, 05:54:06 pm »
Code: [Select]
void* ImgLoader::loadImage(int& _width, int& _height, MyGUI::PixelFormat& _format, const std::string& _filename)
{
if (!mImage.LoadFromFile(_filename))
return NULL;

_width = mImage.GetWidth();
_height = mImage.GetHeight();
_format = MyGUI::PixelFormat::R8G8B8A8;

size_t size = _width * _height ;
void* data = new unsigned char[size];
memcpy(data, mImage.GetPixelsPtr(), size);
return data;
}


it doesn't load the image

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
OpenGLImageLoader - myGUI (What's wrong?)
« Reply #4 on: December 28, 2011, 07:08:29 pm »
The pixel data size is width * height * 4 (there are 4 components per pixel).

And who frees the allocated memory which is returned? If it's not you, I guess that you must use a specific allocation function, that matches the deallocation function that myGUI uses. For example, if it uses free, the behaviour will be undefined on your memory allocated with new.
Laurent Gomila - SFML developer

codder

  • Newbie
  • *
  • Posts: 8
    • View Profile
OpenGLImageLoader - myGUI (What's wrong?)
« Reply #5 on: December 28, 2011, 08:18:52 pm »
i'm looking an official example
and here is the code:

Code: [Select]
void* BaseManager::loadImage(int& _width, int& _height, MyGUI::PixelFormat& _format, const std::string& _filename)
{
std::string fullname = MyGUI::OpenGLDataManager::getInstance().getDataPath(_filename);

void* result = 0;

Gdiplus::Bitmap* image = Gdiplus::Bitmap::FromFile(MyGUI::UString(fullname).asWStr_c_str());
if (image)
{
_width = image->GetWidth();
_height = image->GetHeight();
Gdiplus::PixelFormat format = image->GetPixelFormat();

if (format == PixelFormat24bppRGB)
_format = MyGUI::PixelFormat::R8G8B8;
else if (format == PixelFormat32bppARGB)
_format = MyGUI::PixelFormat::R8G8B8A8;
else
_format = MyGUI::PixelFormat::Unknow;

if (_format != MyGUI::PixelFormat::Unknow)
{
Gdiplus::Rect rect(0, 0, _width, _height);
Gdiplus::BitmapData out_data;
image->LockBits(&rect, Gdiplus::ImageLockModeRead, format, &out_data);

size_t size = out_data.Height * out_data.Stride;
result = new unsigned char[size];

convertRawData(&out_data, result, size, _format);

image->UnlockBits(&out_data);
}

delete image;
}

return result;
}

btw let my try width*height*4
edit:

it give me

Code: [Select]
20:20:11  |  Platform  |  Critical  |  Error lock vertex buffer  |  MyGUI_OpenGLVertexBuffer.cpp  |  61


Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
OpenGLImageLoader - myGUI (What's wrong?)
« Reply #6 on: December 28, 2011, 08:24:38 pm »
The vertex buffer error doesn't seem to be related to your image loading function.
Laurent Gomila - SFML developer

codder

  • Newbie
  • *
  • Posts: 8
    • View Profile
OpenGLImageLoader - myGUI (What's wrong?)
« Reply #7 on: December 28, 2011, 08:54:39 pm »
maybe a it's a myGUI bug?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
OpenGLImageLoader - myGUI (What's wrong?)
« Reply #8 on: December 28, 2011, 08:59:31 pm »
Maybe. But it's a totally different problem anyway, you should probably report it to the developers or ask on the official forum.
Laurent Gomila - SFML developer

 

anything