Solved

Output to a bitmap (needs to work with OpenGL)

Posted on 2004-03-26
6
447 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
0
 
LVL 4

Author Comment

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

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
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.

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