i want to draw simple triangle so i read the manual and wrote this code:
PT(GeomTriangles) prim;
PT(GeomVertexData) vdata;
vdata = new GeomVertexData("trinagles", GeomVertexFormat::get_v3t2() , Geom::UH_static);
GeomVertexWriter vertex, texcoord;
vertex = GeomVertexWriter(vdata, "vertex");
texcoord = GeomVertexWriter(vdata, "texcoord");
vertex.add_data3f(1, 0, 0);
texcoord.add_data2f(1, 0);
vertex.add_data3f(1, 1, 0);
texcoord.add_data2f(1, 1);
vertex.add_data3f(0, 1, 0);
texcoord.add_data2f(0, 1);
vertex.add_data3f(0, 0, 0);
texcoord.add_data2f(0, 0);
prim = new GeomTriangles(Geom::UH_static);
prim->add_vertex(0);
prim->add_vertex(1);
prim->add_vertex(2);
prim->close_primitive();
PT(Geom) geom(new Geom(vdata));
geom->add_primitive(prim);
PT(GeomNode) gNode(new GeomNode("gNode"));
cout<<"is_null: " <<gNode.is_null()<<endl;
cout<<"gNode's name: " <<gNode->get_name()<<endl;
/***********************
gNode->add_geom(geom);
NodePath nodePath = window->get_render().attach_new_node(gNode);
/***********************
the program flew (exited) with the following information:
Unhandled exception at 0x011ebe98 in panda test 3.exe: 0xC0000005: Access violation writing location 0x00b135b0.
when i’m removing the part inside the asterisks
the program run properly, but , of course, without the triangle.
thank you all.