Hi guys,
I’m trying to get a couple of triangles on the screen, but all I’m getting is a blank gray window.
I think I followed the docs pretty closely. I tried scaling the node (I thought it might be too small to notice) and explicitly making the camera look at it, but with no results.
Here is my C++ code:
#include "pandaFramework.h"
#include "pandaSystem.h"
#include "geomTriangles.h"
void createAndAddGeometry(WindowFramework* w)
{
// Create GeomVertexData
PT(GeomVertexData) vdata;
vdata = new GeomVertexData("name", GeomVertexFormat::get_v3n3c4(), Geom::UH_static);
GeomVertexWriter vw(vdata, "vertex"), cw(vdata, "color"), nw(vdata, "normal");
vw.add_data3f(0, 0, 0);
vw.add_data3f(1, 0, 0);
vw.add_data3f(1, 1, 0);
vw.add_data3f(0, 1, 0);
cw.add_data4f(1, 0, 0, 1);
cw.add_data4f(0, 1, 0, 1);
cw.add_data4f(0, 0, 1, 1);
cw.add_data4f(1, 1, 0, 1);
nw.add_data3f(0, 0, 1);
nw.add_data3f(0, 0, 1);
nw.add_data3f(0, 0, 1);
nw.add_data3f(0, 0, 1);
// Create GeomTriangles
PT(GeomTriangles) primitive;
primitive = new GeomTriangles(Geom::UH_static);
primitive -> add_vertices(0, 1, 2);
primitive -> close_primitive();
primitive -> add_vertices(0, 2, 3);
primitive -> close_primitive();
// Create Geom
PT(Geom) g;
g = new Geom(vdata);
g->add_primitive(primitive);
// Create GeomNode and add it to scene
PT(GeomNode) gn;
gn = new GeomNode("gnode");
gn->add_geom(g);
/// Add geom node to scene graph
NodePath gnp = w->get_render().attach_new_node(gn);
gnp.set_pos(0,0,0);
gnp.set_hpr(0.5,.5,.5);
gnp.set_scale(8.0);
w->get_camera_group().look_at(gnp.get_pos());
}
int main(int argc, char* argv[])
{
PandaFramework f;
f.open_framework(argc, argv);
f.set_window_title("procedural_geom");
WindowFramework* w = f.open_window();
createAndAddGeometry(w);
f.main_loop();
return 0;
}
What am I doing wrong here?