More C++ Woes

I need to set the background color, but how do I get a “base” object? Which include? What’s the name? What on earth is base in all this python code? What is self? I know nothing about Python and there is so much Python in the outdated docs it’s giving me a headache :stuck_out_tongue: I have no idea why my supervisor suggested Panda in a C++ project because it’s really not suited to a newcomer.

Your master (supervisor) is certainly a wise man, so FEEL THE SOURCE, young padawan!

This is how ShowBase implements setting the background color:

    def setBackgroundColor(self, r = None, g = None, b = None, a = 0.0, win = None):
        """
        Sets the window background color to the indicated value.
        This assumes the window is set up to clear the color each
        frame (this is the normal setting).

        The color may be either a VBase3 or a VBase4, or a 3-component
        tuple, or the individual r, g, b parameters.
        """
        if g != None:
            color = VBase4(r, g, b, a)
        else:
            arg = r
            if isinstance(arg, VBase4):
                color = arg
            else:
                color = VBase4(arg[0], arg[1], arg[2], a)

        if win == None:
            win = self.win

        if win:
           win.setClearColor(color)

Python code is not that hard to read. So the answer to your question is:

void DrawableRegion::set_clear_color(LVecBase4f const &color);

enn0x

Okay that helped me up to:

window->get_display_region()->set_clear_color(Colorf(0, 0, 0, 1));

Which throws the error

error LNK2019: unresolved external symbol "__declspec(dllimport) public: class DisplayRegion * __thiscall WindowFramework::get_display_region(void)const " (__imp_?get_display_region@WindowFramework@@QBEPAVDisplayRegion@@XZ) referenced in function _main

So what library am I missing for that? :stuck_out_tongue:

Well, god knows why (because clearly he uses Python) that didn’t work, so I just used the other object using DrawableRegion with

window->get_graphics_window()->set_clear_color(Colorf(0, 0, 0, 1));

And it worked fine building, however the background is still the defaulted grey… :confused:. Yes I set the clear color active, really I don’t understand why this is 1- So hard to do and 2- So poorly documented to the point that files in the documents referred to have been renamed, all of the functions in documents are a different naming convention in C++, the Python keeps refering to things like ShowBase, base, self etc all of which simply aren’t used (whatever they are in Python) in C++. Also no explanation as to exactly what they are in Python anyway to give a hint to how you might go about it in C++.

OK, the short answer is:

window->get_graphics_window()->get_active_display_region(0)->set_clear_color(Colorf(0, 0, 0, 1));

But it might be easier just to put the following in your Config.prc instead, which changes the initial default:

background-color 0 0 0

The longer answer is that either windows or display regions can perform a clear. Generally, it doesn’t matter which one does, but by default in PandaFramework, the display region is set up to perform the clear. Since the display region clear happens after the window clear, then it doesn’t matter what clear color you put on the window, since the display region will immediately come along and clear it again.

(This feature of supporting clear on either the window or the display region makes more sense when your window is subdivided into multiple display regions. In this case, it is faster to have the window do the clear all at once; but you might need to have each display region do the clear instead, if they each have a different background color or if they overlap each other.)

As to why window->get_display_region() failed to work, well, I apologize for that bug. This method was removed a long time ago–it’s ambiguous because there might be multiple display regions on a window, and we felt it was better to let the user get the particular display region he wanted directly from the window. But we forgot to remove the interface definition, so the definition remained and looked tempting to call, even though there was no function behind it.

Note that most of the C++ documentation can be found in the source code itself. Most functions are documented in the paragraph introducing the function body. Once you get in the habit of looking for the function body to check its documentation, you’ll be much more comfortable reading the C++ code.

Why are all of the functions renamed between C++ and Python? That’s just one of those things. Panda evolved over a period of several years; and it is and has always been an active project used and developed by a professional game studio. This means that early decisions that affect the structure of later code development are very difficult to change. Before we used Python as our high-level language of choice, we used a language called Squeak, which does not allow underscores in method names. So we had to rename our methods to be compatible with Squeak. Eventually, we abandoned Squeak and embraced Python instead (and we’ve been very happy with Python), but by then we’d already gotten used to the new names we’d been using in Squeak, so we just kept them. Looking back now, it doesn’t seem like the right decision, but it seemed like a fine thing to do at the time.

Still, the renaming is quite predictable and consistent. We remove every underscore and capitalize the next letter. Thus, set_clear_color becomes setClearColor. Once you understand this, it is quite easy to go back and forth.

I’m not sure what you’re referring to about files in the documents being renamed.

ShowBase is the main Python framework that gets the app off the ground. It is functionally equivalent to the PandaFramework / WindowFramework module, but it is very Python-specific, just as PandaFramework is very C+±specific. Neither is core to the heart of Panda, though; it’s just frustrating because getting past this is making it difficult to get to the meat of the engine. I understand that, and I sympathize. But hang in there–once you do get past, you’ll find that Panda is really the same thing in Python and in C++, and the documentation on the website here still applies.

But don’t forget to read the documentation in the source code. :slight_smile:

David