Solved

gluScaleImage always return GL_OUT_OF_MEMORY while trying to resize image.

Posted on 2007-04-03
7
1,280 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
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
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
.Net Errors Service Crashing 5 130
sum28 challenge 31 115
sumHeights  challenge 17 73
Not needed 13 119
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
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.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

839 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