Solved

gluScaleImage always return GL_OUT_OF_MEMORY while trying to resize image.

Posted on 2007-04-03
7
1,269 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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Tab order 16 54
centeredAverage challenge 8 124
Paint/Redraw window while dragging 16 57
Problem to open Excel file 15 45
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
What is RenderMan: RenderMan is a not any particular piece of software. RenderMan is an industry standard, defining set of rules that any rendering software should use, to be RenderMan-compliant. Pixar's RenderMan is a flagship implementation of …
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.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

743 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

13 Experts available now in Live!

Get 1:1 Help Now