I want to know how to use C++to add texture images to a newly created EGG file and save them
The following is my code
I tried to ask ChatGPT, but there was no solution
#include <pandaFramework.h>
#include <pandaSystem.h>
#include <TexturePool.h>
#include <eggTexture.h>
#include <eggData.h>
int main(int argc, char* argv[]) {
PandaFramework framework;
framework.open_framework(argc, argv);
WindowFramework* window = framework.open_window();
PT(EggData) data = new EggData();
PT(Texture) texture = TexturePool::load_texture("111.png");
PT(EggTexture) egg_texture = new EggTexture(texture->get_filename());
egg_texture->set_filename(texture->get_filename());
egg_texture->set_format(texture->get_format());
egg_texture->set_wrap_mode(EggTexture::WM_repeat);
data->add_texture(egg_texture);
PT(EggTextureCollection) textures = new EggTextureCollection();
textures->add_texture(egg_texture);
PT(EggGroupNode) root = data->get_root();
for (int i = 0; i < root->get_num_children(); i++) {
PT(EggNode) child = root->get_child(i);
if (child->is_of_type(EggPolygon::get_class_type())) {
PT(EggPolygon) poly = DCAST(EggPolygon, child);
poly->set_texture_type(EggPolygon::TT_normal);
poly->set_texture(ts, egg_texture);
}
}
data->write_egg("cylinder.egg")
NodePath cylinder = window->load_model(framework.get_models(), "cylinder.egg");
cylinder.reparent_to(window->get_render());
cylinder.set_pos(0, 0, 0);
window->setup_trackball();
framework.main_loop();
framework.close_framework();
return 0;
}