Home » Community » Forums » General Programming » [C++] Ray Tracing Problem
  Intel sponsors gamedev.net search:   
[Control Panel] [Register] [Bookmarks] [Who's Online] [Active Topics] [Stats] [FAQ] [Search]

Add Forum to Favorites |  Send Topic To a Friend | View Forum FAQ | Track this topic


 Last Thread Next Thread 
 [C++] Ray Tracing Problem
Post New Topic  Post Reply 
Hi guys, I am attempting to follow the book "Ray Tracing From The Ground Up" in an attempt to make my own ray tracer and am now in Chapter 3 where we are to make a skeleton ray tracer given some code snippets and utility files. Unfortunately I get the following errors upon attempting to build the project in Visual Studio 2008:

1>------ Build started: Project: RayTracingv2, Configuration: Debug Win32 ------
1>Compiling...
1>Matrix.cpp
1>Normal.cpp
1>Point3D.cpp
1>RGBColor.cpp
1>c:\users\spacemonkey49\documents\visual studio 2008\projects\raytracingv2\raytracingv2\rgbcolor.h(142) : warning C4244: 'return' : conversion from 'double' to 'float', possible loss of data
1>Tracer.cpp
1>c:\users\spacemonkey49\documents\visual studio 2008\projects\raytracingv2\raytracingv2\rgbcolor.h(142) : warning C4244: 'return' : conversion from 'double' to 'float', possible loss of data
1>c:\users\spacemonkey49\documents\visual studio 2008\projects\raytracingv2\raytracingv2\constants.h(20) : warning C4305: 'initializing' : truncation from 'double' to 'const float'
1>Vector3D.cpp
1>World.cpp
1>c:\users\spacemonkey49\documents\visual studio 2008\projects\raytracingv2\raytracingv2\viewplane.h(80) : warning C4244: '=' : conversion from 'double' to 'float', possible loss of data
1>c:\users\spacemonkey49\documents\visual studio 2008\projects\raytracingv2\raytracingv2\rgbcolor.h(142) : warning C4244: 'return' : conversion from 'double' to 'float', possible loss of data
1>c:\users\spacemonkey49\documents\visual studio 2008\projects\raytracingv2\raytracingv2\constants.h(20) : warning C4305: 'initializing' : truncation from 'double' to 'const float'
1>Generating Code...
1>Compiling manifest to resources...
1>Microsoft (R) Windows (R) Resource Compiler Version 6.1.6723.1
1>Copyright (C) Microsoft Corporation. All rights reserved.
1>Linking...
1>World.obj : error LNK2001: unresolved external symbol "private: static double const Sphere::kEpsilon" (?kEpsilon@Sphere@@0NB)
1>World.obj : error LNK2019: unresolved external symbol "public: void __thiscall Sphere::set_radius(double)" (?set_radius@Sphere@@QAEXN@Z) referenced in function "public: void __thiscall World::build(void)" (?build@World@@QAEXXZ)
1>World.obj : error LNK2019: unresolved external symbol "public: void __thiscall Sphere::set_center(class Point3D const &)" (?set_center@Sphere@@QAEXABVPoint3D@@@Z) referenced in function "public: void __thiscall World::build(void)" (?build@World@@QAEXXZ)
1>World.obj : error LNK2019: unresolved external symbol "public: __thiscall SingleSphere::SingleSphere(class World *)" (??0SingleSphere@@QAE@PAVWorld@@@Z) referenced in function "public: void __thiscall World::build(void)" (?build@World@@QAEXXZ)
1>World.obj : error LNK2019: unresolved external symbol "public: __thiscall Ray::~Ray(void)" (??1Ray@@QAE@XZ) referenced in function "public: void __thiscall World::render_scene(void)const " (?render_scene@World@@QBEXXZ)
1>World.obj : error LNK2019: unresolved external symbol "public: void __thiscall World::display_pixel(int,int,class RGBColor const &)const " (?display_pixel@World@@QBEXHHABVRGBColor@@@Z) referenced in function "public: void __thiscall World::render_scene(void)const " (?render_scene@World@@QBEXXZ)
1>World.obj : error LNK2019: unresolved external symbol "public: void __thiscall World::open_window(int,int)const " (?open_window@World@@QBEXHH@Z) referenced in function "public: void __thiscall World::render_scene(void)const " (?render_scene@World@@QBEXXZ)
1>World.obj : error LNK2019: unresolved external symbol "public: __thiscall Ray::Ray(void)" (??0Ray@@QAE@XZ) referenced in function "public: void __thiscall World::render_scene(void)const " (?render_scene@World@@QBEXXZ)
1>World.obj : error LNK2001: unresolved external symbol "private: static double const Plane::kEpsilon" (?kEpsilon@Plane@@0NB)
1>World.obj : error LNK2019: unresolved external symbol "public: __thiscall World::~World(void)" (??1World@@QAE@XZ) referenced in function _main
1>World.obj : error LNK2019: unresolved external symbol "public: __thiscall World::World(void)" (??0World@@QAE@XZ) referenced in function _main
1>C:\Users\Spacemonkey49\Documents\Visual Studio 2008\Projects\RayTracingv2\Debug\RayTracingv2.exe : fatal error LNK1120: 11 unresolved externals
1>Build log was saved at "file://c:\Users\Spacemonkey49\Documents\Visual Studio 2008\Projects\RayTracingv2\RayTracingv2\Debug\BuildLog.htm"
1>RayTracingv2 - 12 error(s), 6 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========


And am unsure how to cope with these errors, I've looked in the MSDN knowledge base for what the link errors relate to and don't quite follow how they relate to the program at hand, any insight would be greatly appreciated. I've uploaded the project in RAR form for those would like to see what I am doing (you have to remove SingleSphere.h and Singlesphere.cpp from the project or else you will receive 23 errors).

http://rapidshare.com/files/299590189/RayTracingv2.rar

 User Rating: 1013   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

Those linker errors (LNK2019/LNK2001) are the linker complaining about not being able to find symbols. Basically, you have declared a method/member of a class,
class C {
    void f();
};



..but you have never actually defined it, like this:
void C::f() {
    // ...
}



As an example,
Quote:
1>World.obj : error LNK2019: unresolved external symbol "public: void __thiscall Sphere::set_radius(double)" (?set_radius@Sphere@@QAEXN@Z) referenced in function "public: void __thiscall World::build(void)" (?build@World@@QAEXXZ)


The linker can't find the definition of Sphere::set_radius, which is referred to (called) by World::build.

In this case, there appears to be large chunks of code missing, like from the Sphere class (only Sphere::hit is defined), and the Ray class (nothing defined!)

Are you missing parts of code?

Also, the way some methods are actually defined in header files (like Sphere::hit) is a bit strange.. you are more than likely going to get 'symbols mutiply defined' linker errors after you resolve these current ones (like from World.cpp and MyMain.cpp both including Sphere.h)

 User Rating: 1631   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

Ya we only get snippets of the important parts in the book, so it makes it a bit hard to know what he meant to be put in, especially since you only get the final ray tracer as reference which has considerably more files and functions.

 User Rating: 1013   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

It look like the book's website has downloads of relevant source code; that CodeVersion1.zip looked useful (it has sphere.cpp, for example!)

 User Rating: 1631   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

Alright so I fixed a lot of the issues with the program and now have everything done pretty well but still have one issue:

1>SingleSphere.obj : error LNK2019: unresolved external symbol "public: __thiscall ShadeRec::~ShadeRec(void)" (??1ShadeRec@@QAE@XZ) referenced in function "public: virtual class RGBColor __thiscall SingleSphere::trace_ray(class Ray const &)const " (?trace_ray@SingleSphere@@UBE?AVRGBColor@@ABVRay@@@Z)
1>MSVCRTD.lib(crtexew.obj) : error LNK2019: unresolved external symbol _WinMain@16 referenced in function ___tmainCRTStartup

But I don't see what could be causing this, as I've defined all the functions as far as I know like the book and code snippets mention, I didn't use the full program from the site because it's the fully built tracer and I am trying to understand it from the basics all the way up to the advanced stuff and right now I am doing the basics :( If you could help me again mattd or anyone I would be grateful.

Code:

http://rapidshare.com/files/300506621/RayTracev4.rar

 User Rating: 1013   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

I understand it's coming from this line:

ShadeRec sr(*world_ptr); // not used

But this file is from the actual site, and is required for the skeleton ray tracer so I am unsure as to what to do.

 User Rating: 1013   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

Looks like ShadeRec is missing its destructor definition.

You sure you've got a function like
ShadeRec::~ShadeRec() {
   // ...
}

somewhere?

Also, WinMain is missing.. is it meant to be a Windows application? If it's meant to be a console-based application, you'll need to change your project's settings.

I'm trying to download your RAR, however it says Rapidshare is currently overloaded, and you need to be a paid member or similar.

 User Rating: 1631   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

Was missing ShadeRec destructor like you pointed out mattd :P

http://www.mediafire.com/?sharekey=bc90bbe59c76c2cd8d78a0e555291609e04e75f6e8ebb871

is another upload location, and I forgot which application type I set it as in Visual Studio :(

 User Rating: 1013   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

Quote:
Original post by Spacemonkey49
I forgot which application type I set it as in Visual Studio :(

This is the option you use to check/can change. It shows where to get at it down the bottom of that page.

 User Rating: 1631   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

It's a windows application.

 User Rating: 1013   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

You have a wxraytracer.cpp file in your project directory, but it's not included in the project itself. It has IMPLEMENT_APP in it, which is a wxWidgets macro that eventually expands out to a int main(..) entry point. So try adding it to your project, and setting the SUBSYSTEM option to CONSOLE.

 User Rating: 1631   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

That's what the book recommends, but it for someone reason I get the following error:

1>c:\users\spacemonkey49\documents\visual studio 2008\projects\raytracev4\raytracev4\wxraytracer.cpp(108) : error C2308: concatenating mismatched strings
1> Concatenating wide "BMP files (*.bmp)|*.bmp|" with narrow "PNG files (*.png)|*.png|"
1>c:\users\spacemonkey49\documents\visual studio 2008\projects\raytracev4\raytracev4\wxraytracer.cpp(108) : error C2308: concatenating mismatched strings
1> Concatenating wide "BMP files (*.bmp)|*.bmp|" with narrow "JPEG files (*.jpg)|*.jpg|"
1>c:\users\spacemonkey49\documents\visual studio 2008\projects\raytracev4\raytracev4\wxraytracer.cpp(108) : error C2308: concatenating mismatched strings
1> Concatenating wide "BMP files (*.bmp)|*.bmp|" with narrow "TIFF files (*.tif)|*.tif"
1>c:\users\spacemonkey49\documents\visual studio 2008\projects\raytracev4\raytracev4\wxraytracer.cpp(133) : error C2308: concatenating mismatched strings
1> Concatenating wide "BMP files (*.bmp)|*.bmp|" with narrow "PNG files (*.png)|*.png|"
1>c:\users\spacemonkey49\documents\visual studio 2008\projects\raytracev4\raytracev4\wxraytracer.cpp(133) : error C2308: concatenating mismatched strings
1> Concatenating wide "BMP files (*.bmp)|*.bmp|" with narrow "JPEG files (*.jpg)|*.jpg|"
1>c:\users\spacemonkey49\documents\visual studio 2008\projects\raytracev4\raytracev4\wxraytracer.cpp(133) : error C2308: concatenating mismatched strings
1> Concatenating wide "BMP files (*.bmp)|*.bmp|" with narrow "TIFF files (*.tif)|*.tif"

from the following snippet of code:

wxString wildcard = wxT("BMP files (*.bmp)|*.bmp|"
"PNG files (*.png)|*.png|"
"JPEG files (*.jpg)|*.jpg|"
"TIFF files (*.tif)|*.tif");

And had no clue how to deal with that so was trying to make my own main, obvious to me now that I should just identify the issue with this error than make my own main, but again I am completely in unfamiliar waters here.

 User Rating: 1013   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

wxT is a macro that turns string literals into wide versions if Unicode is set, otherwise does nothing.

Try changing the snippet to:

wxString wildcard = wxT("BMP files (*.bmp)|*.bmp|")
                    wxT("PNG files (*.png)|*.png|")
                    wxT("JPEG files (*.jpg)|*.jpg|")
                    wxT("TIFF files (*.tif)|*.tif");


(You are getting good mileage out of this thread!)

 User Rating: 1631   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

No good, results in 553 errors! :( All relating to unresolved external symbols.

All of which are LINK2001 and LINK2019 (unresolved external symbols) :\

 User Rating: 1013   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

Quote:
Original post by Spacemonkey49
No good, results in 553 errors! :( All relating to unresolved external symbols.

All of which are LINK2001 and LINK2019 (unresolved external symbols) :\


That is good!

LNK errors means that you have successfully passed the compile stage. What are the new errors?


blog

 User Rating: 1915   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

1>wxraytracer.obj : error LNK2019: unresolved external symbol "public: void __thiscall wxThread::SetPriority(unsigned int)" (?SetPriority@wxThread@@QAEXI@Z) referenced in function "public: void __thiscall RenderCanvas::renderStart(void)" (?renderStart@RenderCanvas@@QAEXXZ)
1>wxraytracer.obj : error LNK2019: unresolved external symbol "public: enum wxThreadError __thiscall wxThread::Create(unsigned int)" (?Create@wxThread@@QAE?AW4wxThreadError@@I@Z) referenced in function "public: void __thiscall RenderCanvas::renderStart(void)" (?renderStart@RenderCanvas@@QAEXXZ)
1>wxraytracer.obj : error LNK2019: unresolved external symbol "public: __thiscall wxBitmap::wxBitmap(char const * const *)" (??0wxBitmap@@QAE@PBQBD@Z) referenced in function "public: void __thiscall RenderCanvas::renderStart(void)" (?renderStart@RenderCanvas@@QAEXXZ)
1>wxraytracer.obj : error LNK2019: unresolved external symbol "public: __thiscall wxBitmap::wxBitmap(int,int,int)" (??0wxBitmap@@QAE@HHH@Z) referenced in function "public: void __thiscall RenderCanvas::renderStart(void)" (?renderStart@RenderCanvas@@QAEXXZ)
1>wxraytracer.obj : error LNK2019: unresolved external symbol "protected: void __thiscall wxObject::AllocExclusive(void)" (?AllocExclusive@wxObject@@IAEXXZ) referenced in function "public: void __thiscall wxObject::UnShare(void)" (?UnShare@wxObject@@QAEXXZ)
1>wxraytracer.obj : error LNK2019: unresolved external symbol "public: virtual __thiscall wxThread::~wxThread(void)" (??1wxThread@@UAE@XZ) referenced in function __unwindfunclet$??0RenderThread@@QAE@PAVRenderCanvas@@PAVWorld@@@Z$0
1>wxraytracer.obj : error LNK2019: unresolved external symbol "public: __thiscall wxThread::wxThread(enum wxThreadKind)" (??0wxThread@@QAE@W4wxThreadKind@@@Z) referenced in function "public: __thiscall RenderThread::RenderThread(class RenderCanvas *,class World *)" (??0RenderThread@@QAE@PAVRenderCanvas@@PAVWorld@@@Z)
1>wxraytracer.obj : error LNK2001: unresolved external symbol "public: virtual bool __thiscall wxThread::TestDestroy(void)" (?TestDestroy@wxThread@@UAE_NXZ)
1>wxraytracer.obj : error LNK2019: unresolved external symbol "public: void __thiscall wxEvtHandler::AddPendingEvent(class wxEvent &)" (?AddPendingEvent@wxEvtHandler@@QAEXAAVwxEvent@@@Z) referenced in function "private: void __thiscall RenderThread::NotifyCanvas(void)" (?NotifyCanvas@RenderThread@@AAEXXZ)
1>wxraytracer.obj : error LNK2019: unresolved external symbol "public: __thiscall wxCommandEvent::wxCommandEvent(int,int)" (??0wxCommandEvent@@QAE@HH@Z) referenced in function "private: void __thiscall RenderThread::NotifyCanvas(void)" (?NotifyCanvas@RenderThread@@AAEXXZ)
1>wxraytracer.obj : error LNK2019: unresolved external symbol "public: __thiscall wxEventHashTable::wxEventHashTable(struct wxEventTable const &)" (??0wxEventHashTable@@QAE@ABUwxEventTable@@@Z) referenced in function "void __cdecl `dynamic initializer for 'protected: static class wxEventHashTable wxraytracerapp::sm_eventHashTable'(void)" (??__E?sm_eventHashTable@wxraytracerapp@@1VwxEventHashTable@@A@@YAXXZ)
1>wxraytracer.obj : error LNK2001: unresolved external symbol "int const wxEVT_NULL" (?wxEVT_NULL@@3HB)
1>wxraytracer.obj : error LNK2001: unresolved external symbol "protected: static class wxAppConsole * (__cdecl* wxAppConsole::ms_appInitFn)(void)" (?ms_appInitFn@wxAppConsole@@1P6APAV1@XZA)
1>wxraytracer.obj : error LNK2001: unresolved external symbol "int const wxEVT_COMMAND_MENU_SELECTED" (?wxEVT_COMMAND_MENU_SELECTED@@3HB)
1>wxraytracer.obj : error LNK2019: unresolved external symbol "int __cdecl wxNewEventType(void)" (?wxNewEventType@@YAHXZ) referenced in function "void __cdecl `dynamic initializer for 'wxEVT_RENDER'(void)" (??__EwxEVT_RENDER@@YAXXZ)
1>wxraytracer.obj : error LNK2001: unresolved external symbol "int const wxEVT_TIMER" (?wxEVT_TIMER@@3HB)
1>wxraytracer.obj : error LNK2019: unresolved external symbol "public: __thiscall wxEventHashTable::~wxEventHashTable(void)" (??1wxEventHashTable@@QAE@XZ) referenced in function "void __cdecl `dynamic atexit destructor for 'protected: static class wxEventHashTable wxraytracerapp::sm_eventHashTable'(void)" (??__F?sm_eventHashTable@wxraytracerapp@@1VwxEventHashTable@@A@@YAXXZ)
1>MSVCRTD.lib(crtexe.obj) : error LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup
1>C:\Users\Spacemonkey49\Documents\Visual Studio 2008\Projects\RayTracev4\Debug\RayTracev4.exe : fatal error LNK1120: 552 unresolved externals


All stuff of that sort, which makes me wonder if it is a result of me not appropriately installing or adding the wxWidget stuff to the library?

 User Rating: 1013   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

How did I know that was what was going to happen next X)

Are you linking to the correct wxWidgets libraries?

Check this, the section under 'Linker'.

Try just adding 'wxmsw28ud_core.lib wxbase28ud.lib' to your 'Additional Dependencies' for your Debug mode build, and 'wxmsw28u_core.lib wxbase28u.lib' for Release mode. Then just try to compile with those ones before you get carried away adding other ones it suggests there.

 User Rating: 1631   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

mattd you beautiful beautiful person, I will name first child (if it's not as retarded as me) after you in honour of the help you've given me :D Just ended up copying the same configuration from the original project found on the site (even though it's obviously far more advanced than mine is right now it still should have similar config) and it worked!

Edit:

Screenshot:

http://img99.imageshack.us/img99/2476/wootu.jpg

 User Rating: 1013   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

Glad to hear you got it working. Have fun!

 User Rating: 1631   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

Alright, sorry to do this again mattd, but in an attempt to make the ray tracer trace more than one object I have run into a problem It now traces nothing! As far as I can tell the code should work as compared to the code on the website (although I can't reference the world.cpp and world.h files since those are not in CodeVersion1) the only difference I've made from the book is that the book says World:hit_bare_bones_objects(const Ray& ray) { //code } should be World:hit_bare_bones_objects(const Ray& ray) const { //code }. Yet this results in an error since you're modifying variables inside this and it doesn't like the *this pass. It still works for a single sphere, but multiple objects produces just a black background. Is there something I am missing I am doing wrong in my variable/object passing?

I've uploaded v5 of the code to:

http://rapidshare.com/files/301493976/RayTracev5.rar.html

(should work without a premium account, let me know if it doesn't and I'll upload it to another filehosting site).

 User Rating: 1013   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

Check out ShadeRec's copy constructor:

ShadeRec::ShadeRec(const ShadeRec& sr)
	: 	hit_an_object(sr.hit_an_object),
		local_hit_point(sr.local_hit_point),
		normal(sr.normal),
		color(black),
		w(sr.w)
{}


It should be:
ShadeRec::ShadeRec(const ShadeRec& sr)
	: 	hit_an_object(sr.hit_an_object),
		local_hit_point(sr.local_hit_point),
		normal(sr.normal),
		color(sr.color),
		w(sr.w)
{}


Why it even has an explicitly defined copy constructor instead of a compiler-defined implicit one, goodness knows...

Anyway, making that change made the two spheres + plane (un-commented in World::build) show up for me.

 User Rating: 1631   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

Wow, I was looking at everything but that statement, kept thinking I wasn't passing something correctly :( Thank you mattd!

 User Rating: 1013   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

Hate to bump this again, but I have run into an issue relating to sampling that I need to ask.

Should Multi-Jittered and/or Hammersley sampling produce a dithering like effect on a sphere with a black background as in the images below?

i.e. These are images I have gotten:

Normal (# of samples = 1):

http://img134.imageshack.us/i/normalw.png/

Hammersley (# of samples = 25):

http://img134.imageshack.us/i/hammersley25.png/

Hammersley (# of samples = 125):

http://img134.imageshack.us/i/hammersley125.png/

Multi-Jittered (# of samples = 25):

http://img694.imageshack.us/i/multijittered25.png/

Multi-Jittered (# of samples = 125):

http://img121.imageshack.us/i/multijittered125.png/

 User Rating: 1013   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

All times are ET (US)

Post Reply
 Last Thread Next Thread 
Forum Rules:
You may not post new threads
You may post replies
You may not edit your posts
You may not use HTML in your posts
Jump To:
Administrative Options: