Changing Render Modes in C++

Pardon this extremely basic question. I am just starting out playing with Panda through C++ and was wondering how do I changed the render mode (OGL, DX8, DX9) through the source. I did search around the forum but as I am not sure what I am looking for, did not actually find the way that it is done outside of using Python.

I know it has something to do with the Graphics pipeline, but am trying to translate this to C++.

Thanks in advance for any help.

Exactly the same as you would do in Python.

Something like this:

#include "load_prc_file.h"
load_prc_file_data("", "load-display pandadx9");

Okay, I took the line you gave me and inputted it into the main Cpp I have. I also went ahead and checked the function in the header file. Despite it looking alright to my extremely inexperienced eyes, the inclusion of those two lines yielded this:

Any idea what I’m doing wrong? It compiles alright without that line, and its the code in the Manual.

At this point I’m using VS2008

It might be simpler to change the display mode simply by editing your Config.prc file.

As to the error in question, it looks like you tried to put in a line of executable code outside of any function body. Unlike Python, you can’t simply put a call to a function in the global scope; it has to fall within some function you have already defined, for instance, within main() or some other function that gets executed.

If your C++ experience is not that strong, are you sure you want to be developing an application using C++? Python is a much friendlier language for the beginning as well as the experienced programmer, and probably a better language to use in general, other things being equal. Usually, you would choose C++ over Python only if there were overwhelming factors contributing in C++'s favor, for instance, strong personal experience in C++.

David

Well, I’ve thought about coding with purely Python, but I figured that if I never began, how could I ever learn it? I’m also trying to learn C++ outside of Panda3d, so I figured why not? This is what the main CPP looks right now:

// Filename: pview.cxx
// Created by:  drose (25Feb02)
//
////////////////////////////////////////////////////////////////////
//
// PANDA 3D SOFTWARE
// Copyright (c) Carnegie Mellon University.  All rights reserved.
//
// All use of this software is subject to the terms of the revised BSD
// license.  You should have received a copy of this license along
// with this source code in a file named "LICENSE."
//
////////////////////////////////////////////////////////////////////

#include "pandaFramework.h"
#include "pandaSystem.h"
#include "textNode.h"
#include "configVariableBool.h"
#include "texturePool.h"
#include "multitexReducer.h"
#include "sceneGraphReducer.h"
#include "partGroup.h"
#include "cardMaker.h"
#include "bamCache.h"

XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

// By including checkPandaVersion.h, we guarantee that runtime
// attempts to run pview will fail if it inadvertently links with the
// wrong version of libdtool.so/.dll.

#include "checkPandaVersion.h"

#ifndef HAVE_GETOPT
  #include "gnu_getopt.h"
#else
  #ifdef HAVE_GETOPT_H
    #include <getopt.h>
  #endif
#endif

PandaFramework framework;

int main(int argc, char *argv[]) {

XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    //open a new window framework
  framework.open_framework(argc, argv);
    //set the window title to My Panda3D Window
  framework.set_window_title("My Panda3D Window");
    //open the window
  WindowFramework *window = framework.open_window();

//---------------------------------------------------------------------------------
  //MainCode
  NodePath environ = window->load_model(framework.get_models(),"models/environment");
  environ.reparent_to(window->get_render());
  environ.set_scale(0.25,0.25,0.25);
  environ.set_pos(-8,42,0);
//---------------------------------------------------------------------------------
    //do the main loop, equal to run() in python
  framework.main_loop();
    //close the window framework
  framework.close_framework();
  return (0);
}

I’ve marked the places I’ve attempted to use this with X’s.

With the problems before, I put them where you usually include header files.

If I put them inside the main function, i get:

I also tried to change the display parameters in Config.prc without avail. I tried both changing the one in Panda3d/etc and including one in the VS project folder for this one project. I still want to do this with C++ though.

@drwr: I agree, but e.g. my own game has a settings menu to choose the display mode, and it saves that stuff in my own kind of config format. So in some cases, it would be better to do it programatically, am I wrong?

@radicaldude1234, You cant put it outside the function body, sorry if I was unclear about that. The include line belongs near your other includes, and the place where you have put your second XXXXX sounds correct for the load_prc_file_data() line.

Right, certainly there are cases in which it needs to be done programatically. Nothing wrong with that. In terms of answering the question at hand, though, sometimes the easiest answer is to modify the Config.prc file. That’s why it is there, after all.

David