Texturing in C++

Don't mind the mess!

We're currently in the process of migrating the Panda3D Manual to a new service. This is a temporary layout in the meantime.

Texturing in C++

Panda's C++ interface to texturing is basically the same as it's Python interface, That's why it is very recommended to read the entire section including the Python examples.

However, there are two major differences, which are explained in this page.


1. C++ does not have a loader.loadTexture. You need to use the TexturePool to load textures. Please note that the Texture class is reference counted.

#include "texturePool.h"
 
PT(Texture) tex;
tex = TexturePool::load_texture("maps/noise.rgb");
 
NodePath smiley;
smiley = window->load_model(window->get_render(),"smiley.egg");
smiley.set_texture(tex, 1);


2. You don't directly need CardMaker to display your texture in a 2D or 3D scene. You can load it as if it were a model, and treat it like any other model.

NodePath noiseplane;
noiseplane = window->load_model(window->get_render(), "maps/noise.rgb");

This short piece of code will result in a single polygon in the scene with the noise texture applied to it. If you need it in the 2d scene, you can use get_aspect2d() or get_render2d() instead of get_render().

Previous Top Next