Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* I'm trying to draw a single triangle, yet nothing is showing up.
- I was hoping someone could look this over and let me know where I'm going wrong.
- I can get other scenes to show up like the Cube_d.mesh, but not able to draw a vertex
- buffer with index buffer.
- One possibility I'm thinking is that ... I haven't assigned a material, but not sure
- how to do that with a submesh. If it were an item, I'd use item->setDatablock(block), but
- with a submesh, I do not know.
- */
- // My Point class is like this ...
- class Point
- {
- private:
- long int id;
- float px;
- float py;
- float pz;
- float nx;
- float ny;
- float nz;
- ...
- };
- const Point t_originalVertices[3] =
- {
- Point(1, 1, 1, 1, 4.2261737590000e-001, 0.0000000000000e-000, 9.0630817410000e-001),
- Point(2, 1, 1, 1, 3.8076493140000e-001, 1.8336847420000e-001, 9.0630793570000e-001),
- Point(3, 1, 1, 1, 2.1642477810000e-001, 0.0000000000000e-000, 9.7629928590000e-001)
- };
- Ogre::IndexBufferPacked* MyWindow::createIndexBuffer()
- {
- Ogre::IndexBufferPacked *indexBuffer = 0;
- const Ogre::uint16 t_indexData[3 * 1 * 1] =
- {
- 0, 1, 2
- };
- Ogre::uint16 *triIndices = reinterpret_cast<Ogre::uint16*>
- (OGRE_MALLOC_SIMD(sizeof(Ogre::uint16) * 1 * 1 * 3,
- Ogre::MEMCATEGORY_GEOMETRY));
- memcpy(triIndices, t_indexData, sizeof(t_indexData));
- Ogre::RenderSystem *renderSystem = m_ogreRoot->getRenderSystem();
- Ogre::VaoManager *vaoManager = renderSystem->getVaoManager();
- try {
- indexBuffer = vaoManager->createIndexBuffer(
- Ogre::IndexBufferPacked::IT_16BIT, 1 * 1 * 3,
- Ogre::BT_IMMUTABLE, triIndices, true);
- }
- catch (Ogre::Exception &e) {
- OGRE_FREE_SIMD(indexBuffer, Ogre::MEMCATEGORY_GEOMETRY);
- indexBuffer = 0;
- throw e;
- }
- return indexBuffer;
- }
- void MyWindow::createScene()
- {
- Ogre::RenderSystem *renderSystem = m_ogreRoot->getRenderSystem();
- Ogre::VaoManager *vaoManager = renderSystem->getVaoManager();
- /* Create the mesh. */
- Ogre::MeshPtr omesh =
- Ogre::MeshManager::getSingleton().createManual("My Model",
- Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
- /* Create a submesh. */
- Ogre::SubMesh *subMesh = omesh->createSubMesh();
- /* Vertex declaration. */
- Ogre::VertexElement2Vec vertexElements;
- vertexElements.push_back(Ogre::VertexElement2(Ogre::VET_FLOAT3,
- Ogre::VES_POSITION));
- vertexElements.push_back(Ogre::VertexElement2(Ogre::VET_FLOAT3,
- Ogre::VES_NORMAL));
- Point *triVertices = reinterpret_cast<Point*>(
- OGRE_MALLOC_SIMD(sizeof(Point) * 3,
- Ogre::MEMCATEGORY_GEOMETRY));
- /* Fill the data. */
- memcpy(triVertices, t_originalVertices, sizeof(Point) * 3);
- Ogre::VertexBufferPacked *vertexBuffer = 0; //nullptr;
- try {
- /* Create the actual vertex buffer. */
- vertexBuffer = vaoManager->createVertexBuffer(vertexElements, 3,
- Ogre::BT_IMMUTABLE, triVertices, true);
- }
- catch (Ogre::Exception &e) {
- OGRE_FREE_SIMD(vertexBuffer, Ogre::MEMCATEGORY_GEOMETRY);
- vertexBuffer = 0;
- throw e;
- }
- Ogre::VertexBufferPackedVec vertexBuffers;
- vertexBuffers.push_back(vertexBuffer);
- Ogre::IndexBufferPacked *indexBuffer = createIndexBuffer();
- Ogre::VertexArrayObject *vao = vaoManager->createVertexArrayObject(
- vertexBuffers, indexBuffer, Ogre::OT_TRIANGLE_LIST);
- subMesh->mVao[Ogre::VpNormal].push_back(vao);
- subMesh->mVao[Ogre::VpShadow].push_back(vao);
- omesh->_setBounds(Ogre::Aabb(Ogre::Vector3::ZERO,
- Ogre::Vector3::UNIT_SCALE), false);
- omesh->_setBoundingSphereRadius(1.732f);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement