Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Output to a bitmap (needs to work with OpenGL)

Posted on 2004-03-26
6
456 Views
Last Modified: 2008-03-03
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
Comment
Question by:n_fortynine
  • 4
6 Comments
 
LVL 5

Expert Comment

by:info_expert
ID: 10695248
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
 
LVL 5

Expert Comment

by:info_expert
ID: 10695263
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
 
LVL 5

Expert Comment

by:info_expert
ID: 10695272
Ok, here is the method illustration:

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

Got?

Regards.
0
 
LVL 5

Accepted Solution

by:
info_expert earned 250 total points
ID: 10695276
0
 
LVL 4

Author Comment

by:n_fortynine
ID: 10695710
Thanks for the responses. I will look into them ASAP (when I get off work later tonight).
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

839 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