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.
Thanks.
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
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(re dvalue,gre envalue,bl uevalue));
Got?
Regards.
SetPixel(hdcMem,x,y,RGB(re
Got?
Regards.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for the responses. I will look into them ASAP (when I get off work later tonight).
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().