Solved

gluScaleImage always return GL_OUT_OF_MEMORY while trying to resize image.

Posted on 2007-04-03
7
1,277 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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Compile GLUT with Visual Studio 2015 1 143
Visual Studio Community 2015 updates failed 5 85
Doc'in system (example?) BA 7 105
post4 challenge 28 99
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

816 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now