Help with a C++/C Project (Ray Tracer, Canvas)

Posted 21 August 2013 - 01:28 PM

Hey guys. Me and my teacher are working on a project to make a simple Ray Tracer application (give realistic lightning effects to simple 3D objects, like spheres and cubes from various angles). Before he gives me any kind of code of the ray tracer he asked me to create a simple application on visual studio that when i run it, will open a empty white/black window which will be a canvas or even give to each pixel of this canvas a random colour. He told me that on the web there are huge ammounts of examples for something like this but i searched a lot and didn't find anything. Probably because i don't know how to search or what to search for as it's something very specific.
Does any of you programming master's have any idea's to help me or give me some good starting tips or even useful links with examples that i can follow? I will greatly appreciate it!
Thanks in advance and have a nice day!

However,
If you want directX there is the SimpleDirect2dApplication in the directX SDK, this includes an example using Windows Imaging Component (WIC) to display a bitmap on screen.

If you want OpenGL you might be better looking at my example in the Tutorial pointed to by baavgai.
as you need the (LPBYTE) lpBits from the PBITMAPINFOHEADER using GetDIBits for displaying a Bitmap in OpenGL.

Re: Help with a C++/C Project (Ray Tracer, Canvas)

You can do so much more now with shaders vs. ray tracing. Even non-realtime rendering work is done with them now.

Because ray tracing fundamentally hasn't changed. It still provides the most realistic rendering at the simple cost of time. A whole lot of time. Other methods ask the questions "is that time worth it" and "how close can we get to ray tracing without actually paying the same cost as ray tracing."

Of course, that amazing 3D simulation generated is ultimately squished down into a finite 2D view port. At that time, it often comes out that the effort really wasn't worth the reward. However, the results of ray tracing are still the goal of other methods.

Note, I've enjoyed may hours of amusement with POV-Ray. Prior to that, I wrote a simple ray tracer for college ( Turbo Pascal .)

Re: Help with a C++/C Project (Ray Tracer, Canvas)

Posted 22 August 2013 - 08:12 AM

The easiest way to do it, avoiding all of the nasty microsoft gui code, is to create a array of pixels to represent the output image, and display it using opengl. I suggest simply writing the image to a file first.

Re: Help with a C++/C Project (Ray Tracer, Canvas)

Posted 28 August 2013 - 02:02 PM

ok guys i found this code that allows me to make a simple small window without even using OpenGL, cause i can't seem to make it work as it doesn't recognise a lot of it's functions when i try to run my program.

where memhdc is a memory hdc that is the return value of your function.
of course all of this is just rough code, you will have to fill in the blanks a bit, but it will give you a good idea on how to approach this.

Re: Help with a C++/C Project (Ray Tracer, Canvas)

Posted 30 August 2013 - 12:45 PM

I understood how im gonna do it..and i had the same idea about the dual loop in order to give a random color for each pixel on the screen..the outer loop for height and the inner for the width..the only thing that i can't understand is where to integrate this raw code in my programm and making it compilable...i also understood that i have to call the HDC that includes the loop in the WM_CREATE cause it's when the window will be created, so at the same time it will assign a random color for each pixel of the window. What i didn't understand is the last part about WM_PAINT..where do i have to put this code and how i will call it? I am asking cause i didn't understand in what sense it helps me and why its neccesary.

And i really appreciate your help Snoopy. Your post helped a lot and every help is appreciated deeply. What if i should change it to something more simple? For example just view something in that window like a message or color a specific pixel or number of pixels? Don't know what other kind of stuff i can do on a window. What im trying to do it view practically anything on a window as a comfirmation...it can be a pixel , an image, a phrase...

Re: Help with a C++/C Project (Ray Tracer, Canvas)

Posted 30 August 2013 - 06:21 PM

Heartl3ss, on 30 August 2013 - 07:45 PM, said:

the only thing that i can't understand is where to integrate this raw code in my programm and making it compilable...i also understood that i have to call the HDC that includes the loop in the WM_CREATE cause it's when the window will be created, so at the same time it will assign a random color for each pixel of the window. What i didn't understand is the last part about WM_PAINT..where do i have to put this code and how i will call it? I am asking cause i didn't understand in what sense it helps me and why its neccesary.

Now our Window Procedure is responsible for handling those window messages if process one we return 0;
if we do not process a message we return DefWindowProc(hwnd, msg, wParam, lParam);
and let the OS handle it.

So WM_CREATE this message is sent by the OS to the function when our application is started.

WM_PAINT this message is sent by the OS to the function when our application requires repainting perhaps another window has been dragged across it, perhaps it has been minimised etc.

We want to do our painting here as if we do it elsewhere our drawing wont stick, it will be temporary, if we drag a window across it etc it will be wiped out.

Remember this Procedure is just a normal function, so dont panic. We will go back to it.