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(hBitma p);
bmpObj->GetBitmap(bmpData) ;
_image->Destroy();
_image->Attach(hBitmap);
return ret;
Anyone here can help me?
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
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(hBitma
bmpObj->GetBitmap(bmpData)
_image->Destroy();
_image->Attach(hBitmap);
return ret;
Anyone here can help me?
Have you defined a rendering context?
ASKER
I am new in Graphic programming as well as VS C++. :)
How can I define a rendering context?
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);//t his creates the rendering context
where ogld is your OpenGLDevice instance.
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);//t
where ogld is your OpenGLDevice instance.
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
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
ASKER
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.
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks davebytes. That's what I need so far.
Thanks all of you for answering this question.
Best regards.
Thanks all of you for answering this question.
Best regards.