Advertisement
SRD

ogre

SRD
Oct 17th, 2017
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.81 KB | None | 0 0
  1. /* I'm trying to draw a single triangle, yet nothing is showing up.
  2. I was hoping someone could look this over and let me know where I'm going wrong.
  3. I can get other scenes to show up like the Cube_d.mesh, but not able to draw a vertex
  4. buffer with index buffer.
  5. One possibility I'm thinking is that ... I haven't assigned a material, but not sure
  6. how to do that with a submesh. If it were an item, I'd use item->setDatablock(block), but
  7. with a submesh, I do not know.
  8. */
  9.  
  10. // My Point class is like this ...
  11. class Point
  12. {
  13.     private:
  14.         long int id;
  15.         float px;
  16.         float py;
  17.         float pz;
  18.         float nx;
  19.         float ny;
  20.         float nz;
  21.         ...
  22. };
  23.  
  24. const Point t_originalVertices[3] =
  25. {
  26.     Point(1, 1, 1, 1, 4.2261737590000e-001, 0.0000000000000e-000, 9.0630817410000e-001),
  27.     Point(2, 1, 1, 1, 3.8076493140000e-001, 1.8336847420000e-001, 9.0630793570000e-001),
  28.     Point(3, 1, 1, 1, 2.1642477810000e-001, 0.0000000000000e-000, 9.7629928590000e-001)
  29. };
  30.  
  31. Ogre::IndexBufferPacked* MyWindow::createIndexBuffer()
  32. {
  33.     Ogre::IndexBufferPacked *indexBuffer = 0;
  34.  
  35.     const Ogre::uint16 t_indexData[3 * 1 * 1] =
  36.     {  
  37.         0, 1, 2
  38.     };
  39.    
  40.     Ogre::uint16 *triIndices = reinterpret_cast<Ogre::uint16*>
  41.         (OGRE_MALLOC_SIMD(sizeof(Ogre::uint16) * 1 * 1 * 3,
  42.         Ogre::MEMCATEGORY_GEOMETRY));
  43.  
  44.     memcpy(triIndices, t_indexData, sizeof(t_indexData));
  45.  
  46.     Ogre::RenderSystem *renderSystem = m_ogreRoot->getRenderSystem();
  47.     Ogre::VaoManager *vaoManager = renderSystem->getVaoManager();
  48.  
  49.     try {
  50.         indexBuffer = vaoManager->createIndexBuffer(
  51.             Ogre::IndexBufferPacked::IT_16BIT, 1 * 1 * 3,
  52.             Ogre::BT_IMMUTABLE, triIndices, true);
  53.     }
  54.     catch (Ogre::Exception &e) {
  55.         OGRE_FREE_SIMD(indexBuffer, Ogre::MEMCATEGORY_GEOMETRY);
  56.         indexBuffer = 0;
  57.  
  58.         throw e;
  59.     }
  60.    
  61.     return indexBuffer;
  62. }
  63.  
  64. void MyWindow::createScene()
  65. {
  66.     Ogre::RenderSystem *renderSystem = m_ogreRoot->getRenderSystem();
  67.     Ogre::VaoManager *vaoManager = renderSystem->getVaoManager();
  68.    
  69.     /* Create the mesh. */
  70.     Ogre::MeshPtr omesh =
  71.         Ogre::MeshManager::getSingleton().createManual("My Model",
  72.             Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
  73.  
  74.     /* Create a submesh. */
  75.     Ogre::SubMesh *subMesh = omesh->createSubMesh();
  76.  
  77.     /* Vertex declaration. */
  78.     Ogre::VertexElement2Vec vertexElements;
  79.     vertexElements.push_back(Ogre::VertexElement2(Ogre::VET_FLOAT3,
  80.         Ogre::VES_POSITION));
  81.     vertexElements.push_back(Ogre::VertexElement2(Ogre::VET_FLOAT3,
  82.         Ogre::VES_NORMAL));
  83.  
  84.     Point *triVertices = reinterpret_cast<Point*>(
  85.             OGRE_MALLOC_SIMD(sizeof(Point) * 3,
  86.             Ogre::MEMCATEGORY_GEOMETRY));
  87.  
  88.     /* Fill the data. */
  89.     memcpy(triVertices, t_originalVertices, sizeof(Point) * 3);
  90.  
  91.     Ogre::VertexBufferPacked *vertexBuffer = 0; //nullptr;
  92.        
  93.     try {
  94.         /* Create the actual vertex buffer. */
  95.         vertexBuffer = vaoManager->createVertexBuffer(vertexElements, 3,
  96.             Ogre::BT_IMMUTABLE, triVertices, true);
  97.     }
  98.     catch (Ogre::Exception &e) {
  99.         OGRE_FREE_SIMD(vertexBuffer, Ogre::MEMCATEGORY_GEOMETRY);
  100.         vertexBuffer = 0;
  101.  
  102.         throw e;
  103.     }
  104.  
  105.     Ogre::VertexBufferPackedVec vertexBuffers;
  106.     vertexBuffers.push_back(vertexBuffer);
  107.  
  108.     Ogre::IndexBufferPacked *indexBuffer = createIndexBuffer();
  109.  
  110.     Ogre::VertexArrayObject *vao = vaoManager->createVertexArrayObject(
  111.         vertexBuffers, indexBuffer, Ogre::OT_TRIANGLE_LIST);
  112.  
  113.     subMesh->mVao[Ogre::VpNormal].push_back(vao);
  114.     subMesh->mVao[Ogre::VpShadow].push_back(vao);
  115.  
  116.     omesh->_setBounds(Ogre::Aabb(Ogre::Vector3::ZERO,
  117.         Ogre::Vector3::UNIT_SCALE), false);
  118.     omesh->_setBoundingSphereRadius(1.732f);
  119. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement