Solved

gluScaleImage always return GL_OUT_OF_MEMORY while trying to resize image.

Posted on 2007-04-03
7
1,287 Views
Last Modified: 2013-12-06
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?
0
Comment
Question by:huyntminh
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 25

Expert Comment

by:InteractiveMind
ID: 18854355
Have you defined a rendering context?
0
 

Author Comment

by:huyntminh
ID: 18855240
I am new in Graphic programming as well as VS C++. :)
How can I define a rendering context?
0
 
LVL 25

Expert Comment

by:InteractiveMind
ID: 18856994
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.
0
[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

 
LVL 20

Expert Comment

by:ikework
ID: 18860566
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

0
 

Author Comment

by:huyntminh
ID: 18862770
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.
0
 
LVL 17

Accepted Solution

by:
davebytes earned 125 total points
ID: 18872699
Few things:
1. Why are you using glu functions for this?  GDI can do this at least three or four different ways including stretchblt of bitmaps.  But for a longer solution, I found this discussion
http://www.codeguru.com/forum/showthread.php?t=289821
2. have you tried adding a printf right before the call, and can you tell us what the source and dest width/height are?
3. have you tried other sizes, multiple images, verified the incoming data is valid, etc.?

Seems like you have no need to be using GLU functions (I avoid them whenever possible, they are NOT designed for performance, and in some cases not for accuracy either!).  If you are actually pushing stuff to GL, there may be other approaches to achieve your end goal -- if you tell us your end goal! ;)

-d
0
 

Author Comment

by:huyntminh
ID: 18918231
Thanks davebytes. That's what I need so far.
Thanks all of you for answering this question.
Best regards.
0

Featured Post

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

624 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question