Link to home
Start Free TrialLog in
Avatar of n_fortynine
n_fortynine

asked on

Output to a bitmap (needs to work with OpenGL)

I am working on a ray tracer with OpenGL, and thinking about including an option to save the generated image to a, say, bitmap file. While looking around I have seen a few suggestions to include API calls (SetPixel, etc.), so I would like to know if anybody could show me how to properly incorporate such calls to realize this idea.

Thanks.
Avatar of info_expert
info_expert
Flag of Pakistan image

Ok you have to use the windows GDI Object. i.e. a bitmap.
First you have to create an empty bitmap. then you can set the value of any pixel by telling its location and color, using SetPixel and can also get the value of any pixel by using GetPixel().
You first create a DIBSection using pointer to a BITMAPINFO Structure variable (i.e. &bminfo):

hPBitmap=CreateDIBSection (NULL, &bminfo, DIB_RGB_COLORS, NULL, NULL, 0) ;
                              
hdc=GetDC(hwnd);
hdcMem = CreateCompatibleDC (hdc) ;
ReleaseDC(hwnd,hdc);
//Then you select the bitmap in memory context.            
SelectObject (hdcMem, hPBitmap) ;
now you can use SetPixel to set any pixel value.
You better see MSDN for set pixel
Ok, here is the method illustration:

SetPixel(hdcMem,x,y,RGB(redvalue,greenvalue,bluevalue));

Got?

Regards.
ASKER CERTIFIED SOLUTION
Avatar of info_expert
info_expert
Flag of Pakistan image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of n_fortynine
n_fortynine

ASKER

Thanks for the responses. I will look into them ASAP (when I get off work later tonight).