Link to home
Start Free TrialLog in
Avatar of huyntminh
huyntminh

asked on

gluScaleImage always return GL_OUT_OF_MEMORY while trying to resize image.

I'm trying to resize image by using OpenGL function gluScaleImage, writen with VC++ MFC Windows App. However, it always return GL_OUT_OF_MEMORY.
Here is my code:
CImage* ResizeImage(UINT width, UINT height, std::string& error){
CString fileName
CImage *_image;
HRESULT hResult = _image->Load(fileName);
if (FAILED(hResult)) {
    return false;
}      
bool ret=false;
CBitmap *bmpObj = CBitmap::FromHandle(_image->operator HBITMAP());
BITMAP* bmpData = new BITMAP;
bmpObj->GetBitmap(bmpData);
      
BYTE* outBuf = (BYTE*)malloc(width * height * 4 * sizeof(BYTE));;

int iError = gluScaleImage(GL_RGB, _image.GetWidth(), _image.GetHeight(), GL_BITMAP, bmpData->bmBits, width, height, GL_BITMAP, outBuf);
      
HBITMAP hBitmap = CreateBitmap(width, height, bmpData->bmPlanes, bmpData->bmBitsPixel, outBuf);
bmpObj = CBitmap::FromHandle(hBitmap);
bmpObj->GetBitmap(bmpData);
_image->Destroy();
_image->Attach(hBitmap);
return ret;

Anyone here can help me?
Avatar of InteractiveMind
InteractiveMind
Flag of United Kingdom of Great Britain and Northern Ireland image

Have you defined a rendering context?
Avatar of huyntminh
huyntminh

ASKER

I am new in Graphic programming as well as VS C++. :)
How can I define a rendering context?
Well, in Win32 you generally use the wglCreateContext() and wglMakeCurrent() functions

HDC hDC = GetDC( hWnd );
HGLRC hRC;
hRC = wglCreateContext( hDC );
wglMakeCurrent( hDC, hRC );

And then to clean up:

wglMakeCurrent( NULL, NULL );
wglDeleteContext( hRC );


However, if you cannot use Win32, then I think you can do something like this:

dc = new CClientDC(this);
ogld.create(dc->m_hDC);//this creates the rendering context

where ogld is your OpenGLDevice instance.
Avatar of ikework
hi huyntminh,

here is an example of gluScaleImage using glut:

http://profs.sci.univr.it/~colombar/html_openGL_tutorial/en/10texturemapping_016.html

you can download the glut-library here:

http://www.cs.uaf.edu/~cs381/GLUT/

tell us, if you need help implementing the "read_texture"-func in the example or anything else ..


good luck :)

ike

To InteractiveMind:
   I have tried as you said but gluScaleImage still return GL_OUT_OF_MEMORY value.
To ikework:
   I'm still looking at your samples. :) Please give me more time to reply you.
Thanks all.
ASKER CERTIFIED SOLUTION
Avatar of davebytes
davebytes
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks davebytes. That's what I need so far.
Thanks all of you for answering this question.
Best regards.