Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 481
  • Last Modified:

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.
0
n_fortynine
Asked:
n_fortynine
  • 4
1 Solution
 
info_expertCommented:
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().
0
 
info_expertCommented:
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
0
 
info_expertCommented:
Ok, here is the method illustration:

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

Got?

Regards.
0
 
n_fortynineAuthor Commented:
Thanks for the responses. I will look into them ASAP (when I get off work later tonight).
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now