Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 10 Apr 2005
Offline Last Active May 11 2016 11:47 PM

#5287901 Object reference not set to an instance of an object

Posted by kloffy on 20 April 2016 - 11:40 PM

Just curious: My C# is rusty, but isn't there anything like this?
private static IEnumerable<T> Generate(Func<T> f) {
    while (true) yield return f();

Used like so:
var Planets = Generate(() => new PlanetDetails()).Take(10).ToArray();

Feels a bit more straightforward than WozNZ's suggestions.

#5277236 vertex shader useless when using geometry shader?

Posted by kloffy on 21 February 2016 - 12:32 AM

It depends, but in general I would say the more computation you can offload to the vertex shader the better. For example, if you're just transforming vertices, depending on your primitive topology, the geometry shader may end up doing more operations. But as always in optimisation, benchmarking is key...

#5144098 [C++] Is there an easy way to mimic printf()'s behavior?

Posted by kloffy on 03 April 2014 - 08:15 AM

Nice one Aardvajk. But ouch, all those template arguments. My shot at a C++11 version:
#include <iostream>
#include <iomanip>
#include <sstream>
#include <string>

namespace detail {

template<typename TOStream, typename... TArgs>
void print(TOStream& os, TArgs&&... args) {}

template<typename TOStream, typename TArg, typename... TArgs>
void print(TOStream& os, TArg&& arg, TArgs&&... args)
	print(os << std::forward<TArg>(arg), std::forward<TArgs>(args)...);


template<typename... TArgs>
std::string print(TArgs&&... args)
	std::ostringstream os;
	detail::print(os, std::forward<TArgs>(args)...);
	return os.str();

int main()
	std::cout << print("Hello", std::boolalpha, std::fixed, std::setprecision(2), ' ', 1, ' ', 2.0, ' ', true) << std::endl;
	return 0;

#5064288 Reflection on Uneven Planes

Posted by kloffy on 23 May 2013 - 04:18 PM

It is fairly hard to do these accurately. Basically, you would need ray-tracing. However, there are techniques that can provide a good visual approximation. In particular, you should have a look at environment mapping (or cube mapping).

#5058669 Little help with code, requiring knowledge.

Posted by kloffy on 02 May 2013 - 11:26 AM

However they work completely opposite from each other. As C# constructs the derived class first and then the base, in C++ however the base gets constructed before the derived class.

This is almost true, but there's one important detail to be aware of. Although objects do indeed start out as the most derived type, with the method table being for the most derived type, the constructors are still run in order from the base class to the most derived class. This is the most sensible order, since a constructor in a base class must be run before the constructor of any derived class in order for the object to be in a consistent state. Therefore, in C# one has to be extra careful when making virtual method calls in a constructor. If the type is not the most derived type in its inheritance hierarchy, the method will be called on a class whose constructor has not yet been run. (See Stack Overflow)

#5058415 GLSL lingo comparison/evolution chart

Posted by kloffy on 01 May 2013 - 02:53 PM

Nice find, this is going into my bookmarks!


The OpenGL wiki actually has some pretty great content. Google has led me there before...

#5055905 A C++ code to smooth (and fix cracks in) meshes generated by the standard, or...

Posted by kloffy on 22 April 2013 - 08:12 PM

Nice work! This could surely come in handy at some point.

#5012312 Does making a game like fruit ninja/angry brids require a large team

Posted by kloffy on 18 December 2012 - 09:27 PM

No, but it helps ... seriously, I would love to love Gimp and InkScape and I check up on them every few years to see if I can reasonably make the switch from Adobe products but it still seems like it would be hard.

In general, I agree with your point. However, you should also consider that switching from a complex piece of software to another is always frustrating. Of course, this is exacerbated if the new tool is missing some particular feature that you like. Yet, I find that the transition is the most difficult part.

I did the switch from Photoshop to Gimp a long time ago. It took quite some time for me to adjust. Now that I am used to it, Gimp allows me to do anything I need. Most of my image processing needs are fairly basic. But, if you are not a professional graphics artist and you are not already using Photoshop, you will probably be quite content with Gimp.

#4999348 How efficient is glm when it returns the result

Posted by kloffy on 09 November 2012 - 11:10 AM

I believe the relevant optimization technique here is Return value optimization.

#4991753 Good C++11 resources for advanced programmer

Posted by kloffy on 19 October 2012 - 05:40 AM

As mentioned by mrbastard and MikeBMcL, channel9 is pretty great.

Since you asked about C++11: This is the best explanation of rvalue references that I have heard so far:


#4979768 Abbreviations for programming related words-

Posted by kloffy on 13 September 2012 - 10:46 AM

Abbrev. 4 prgm rl8d wrdz-

There I fixed it.

#4938433 Why use scripting languages? And which one to use?

Posted by kloffy on 08 May 2012 - 11:26 AM

Let me just add that if you cannot think of a good reason to add scripting to your game, chances are you don't need it (yet). Don't add features just because you see them somewhere else. If you keep adding features that don't directly benefit your game, you will lose track and likely never finish.

#4927062 Starting in Python: best graphics module?

Posted by kloffy on 31 March 2012 - 06:47 PM

If you're saying that getting an image up on the screen with PyOgre is as easy as this:

from PySFML import sf

def main():
    window = sf.RenderWindow(sf.VideoMode(800, 600), "SFML Sprite")

    image = sf.Image()
    if not image.LoadFromFile("image.png"):

    sprite = sf.Sprite(image)

    while window.IsOpened():
        event = sf.Event()
        while window.GetEvent(event):
            if event.Type == sf.Event.Closed:


if __name__ == '__main__':

I'm going to have to take your word for it. Like I said, not much experience with Ogre3D on my side...

#4926841 Starting in Python: best graphics module?

Posted by kloffy on 30 March 2012 - 07:51 PM

I haven't used Ogre, but it looks a bit heavy for a basic 2D project. Maybe also have a look at PySFML.

#4926803 Alternative to singleton

Posted by kloffy on 30 March 2012 - 04:26 PM

I have enjoyed reading this thread, but it seems that it is more and more heading in the direction like most singleton threads: everybody is throwing in their reasons for why singletons are bad. That was never really an issue to begin with. The thread starter asked for an alternative.

The reason that these threads always end up this way is probably because there is no simple answer. To make things worse, it is difficult to reduce it to a simple problem. Whenever I try to think of a example, it either does not capture the entire problem or it becomes too complex. I kind of liked the example of the Entity class, which needs to load various types of Resources. Do you pass every ResourceManager to the Entity constructor? Do you group several ResourceManagers together into a LoadingContext and pass that? Is that really an improvement?

Ultimately, I think we all agree that there are better solutions than singletons. The problem is that unfortunately there isn't one solution. Some people would like to hear: "instead of singletons always pass parameters". If you were to naively follow such advice, your code quality would most likely not improve. I myself would love to find such a simple do-it-all solution, which is why I still read these threads. Unfortunately, I will probably never find it...