|
楼主 |
发表于 2011-5-10 07:52:32
|
显示全部楼层
本帖最后由 5224204 于 2011-5-10 08:02 编辑
多谢回复!!已经实现了,不熟悉osg底层太麻烦了,憋了一个星期。。。。。。
附上代码,有同样需要的可以参考一下!
class MyDrawable : public osg:rawable
{
public:
MyDrawable() {}
/** Copy constructor using CopyOp to manage deep vs shallow copy.*/
MySmokeDrawable(const MyDrawable& MyDrawable,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY):
osg::Drawable(MyDrawable,copyop) {}
META_Object(MyApp,MyDrawable)
virtual void drawImplementation(osg::RenderInfo& renderInfo) const
{
osg::State* state = renderInfo.getState();
state->disableAllVertexArrays();
const osg::Drawable::Extensions* glExt = osg::Drawable::getExtensions(state->getContextID(), true);
//vbo create.....
glExt->glGenBuffers(1, &vboID);
glExt->glBindBuffer(GL_ARRAY_BUFFER_ARB, vboID);
glExt->glBufferData(GL_ARRAY_BUFFER_ARB, sizeof(Vertex)*24, NULL, GL_DYNAMIC_DRAW );
glExt->glBufferSubData(GL_ARRAY_BUFFER_ARB, 0, sizeof(Vertex)*24, verts);
state->setTexCoordPointer(0, 2, GL_FLOAT, sizeof(Vertex), BUFFER_OFFSET(12));
state->setNormalPointer(GL_FLOAT, sizeof(Vertex), BUFFER_OFFSET(20));
state->setColorPointer(4, GL_FLOAT, sizeof(Vertex), BUFFER_OFFSET(32));
state->setVertexPointer(3, GL_FLOAT, sizeof(Vertex), BUFFER_OFFSET(0));
glExt->glGenBuffers(1, &indexVBOID);
glExt->glBindBuffer(GL_ELEMENT_ARRAY_BUFFER_ARB, indexVBOID);
glExt->glBufferData(GL_ELEMENT_ARRAY_BUFFER_ARB, 36*sizeof(GLubyte), index, GL_STATIC_DRAW);
// glGenBuffers(1, &vboID); // Create the buffer ID, this is basically the same as generating texture ID's
// glBindBuffer(GL_ARRAY_BUFFER, vboID); // Bind the buffer (vertex array data)
//
// glBufferData(GL_ARRAY_BUFFER, sizeof(Vertex) * 24, NULL, GL_DYNAMIC_DRAW);
// glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(Vertex) * 24, verts);
//
//
// glTexCoordPointer(2, GL_FLOAT, sizeof(Vertex), BUFFER_OFFSET(12));
// glNormalPointer(GL_FLOAT, sizeof(Vertex), BUFFER_OFFSET(20));
// glColorPointer(4, GL_FLOAT, sizeof(Vertex), BUFFER_OFFSET(32));
// glVertexPointer(3, GL_FLOAT, sizeof(Vertex), BUFFER_OFFSET(0));
//
//
// glGenBuffers(1, &indexVBOID); // Generate buffer
// glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexVBOID); // Bind the element array buffer
// glBufferData(GL_ELEMENT_ARRAY_BUFFER, 36 * sizeof(GLubyte), index, GL_STATIC_DRAW);
//create done........do anything you want
...
...
}
}
再请教一下array, 这是否是唯一的实现方法? 还有没有别的渠道? 比如创建完Geometry 或者 通过Geometry来指定或者获取vbo ID? |
|