Hi,
here is some sample code for creating 2 triangles following the (somewhat inconsistent panda3d manual).
#include "pandaFramework.h"
#include "pandaSystem.h"
#include "geomTriangles.h"
PandaFramework framework;
int main(int argc, char *argv[])
{
//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();
//here is room for your own code
window->setup_trackball();
PT(GeomVertexArrayFormat) array;
array = new GeomVertexArrayFormat();
array->add_column(InternalName::make("vertex"), 3, Geom::NT_float32, Geom::C_point);
array->add_column(InternalName::make("normal"), 3, Geom::NT_float32, Geom::C_vector);
array->add_column(InternalName::make("color"), 1, Geom::NT_packed_dabc, Geom::C_color);
PT(GeomVertexFormat) unregistered_format;
unregistered_format = new GeomVertexFormat();
unregistered_format->add_array(array);
CPT(GeomVertexFormat) format;
format = GeomVertexFormat::register_format(unregistered_format);
PT(GeomVertexData) vdata;
vdata = new GeomVertexData("TestTriangle", format, Geom::UH_static);
GeomVertexWriter vertex, normal, color;
vertex = GeomVertexWriter(vdata, "vertex");
normal = GeomVertexWriter(vdata, "normal");
color = GeomVertexWriter(vdata, "color");
vertex.add_data3f(1, 0, 0);
normal.add_data3f(0, 0, 1);
color.add_data4f(0, 0, 1, 1);
vertex.add_data3f(1, 1, 0);
normal.add_data3f(0, 0, 1);
color.add_data4f(0, 0, 1, 1);
vertex.add_data3f(0, 1, 0);
normal.add_data3f(0, 0, 1);
color.add_data4f(0, 0, 1, 1);
vertex.add_data3f(0, 0, 0);
normal.add_data3f(0, 0, 1);
color.add_data4f(0, 0, 1, 1);
PT(GeomTriangles) prim;
prim = new GeomTriangles(Geom::UH_static);
prim->add_vertex(0);
prim->add_vertex(1);
prim->add_vertex(2);
prim->close_primitive();
prim->add_vertex(2);
prim->add_vertex(1);
prim->add_vertex(3);
prim->close_primitive();
PT(Geom) geom;
geom = new Geom(vdata);
geom->add_primitive(prim);
PT(GeomNode) node;
node = new GeomNode("gnode");
node->add_geom(geom);
NodePath nodePath = window->get_render().attach_new_node(node);
//do the main loop, equal to run() in python
framework.main_loop();
//close the window framework
framework.close_framework();
return (0);
}
In a Release Build this code does crash while in a debug build it doesn’t but it also does not display any triangles. Any ideas what is wrong with it ?
here the crash and callstack
Chrys