diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/material_editor_window.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/material_editor_window.cpp index afc0b3db0..6e70f02f3 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/material_editor_window.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/material_editor_window.cpp @@ -259,6 +259,13 @@ namespace MaterialEditor materialSplitter->onSceneCleared(); viewPort->stopTimedUpdates(); } + + void MaterialEditorWindow::onTriangleClicked() + { + nl3dIface->clearScene(); + materialSplitter->onSceneCleared(); + nl3dIface->drawTriangle(); + } void MaterialEditorWindow::createMenus() { @@ -305,6 +312,13 @@ namespace MaterialEditor a = new QAction( tr( "Clear scene" ), NULL ); connect( a, SIGNAL( triggered( bool ) ), this, SLOT( onClearSceneClicked() ) ); mm->addAction( a ); + + QMenu *mmmm = mm->addMenu( tr( "Debug" ) ); + { + a = new QAction( tr( "Triangle" ), NULL ); + connect( a, SIGNAL( triggered( bool ) ), this, SLOT( onTriangleClicked() ) ); + mmmm->addAction( a ); + } } a = new QAction( tr( "Shaders" ), NULL ); diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/material_editor_window.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/material_editor_window.h index 27a231388..7e68f4813 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/material_editor_window.h +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/material_editor_window.h @@ -51,6 +51,7 @@ private Q_SLOTS: void onAddTeaPotClicked(); void onClearSceneClicked(); + void onTriangleClicked(); private: void createMenus(); diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/nel3d_interface.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/nel3d_interface.cpp index 03f15b528..da19e2408 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/nel3d_interface.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/nel3d_interface.cpp @@ -445,6 +445,53 @@ namespace MaterialEditor return loadShape( "primitives/teapot.shape" ); } + void CNel3DInterface::drawTriangle() + { + driver->clearBuffers( NLMISC::CRGBA::Black ); + + NLMISC::CMatrix f; + f.identity(); + driver->setFrustumMatrix( f ); + + NL3D::CDriverUser *d = dynamic_cast< NL3D::CDriverUser* >( driver ); + if( d != NULL ) + { + NL3D::IDriver *id = d->getDriver(); + + NL3D::CVertexBuffer vb; + vb.setVertexFormat( NL3D::CVertexBuffer::PositionFlag ); + vb.setNumVertices( 3 ); + vb.setPreferredMemory( NL3D::CVertexBuffer::StaticPreferred, false ); + + NL3D::CVertexBufferReadWrite rw; + vb.lock( rw ); + rw.setVertexCoord( 0, -1.0f, -1.0f, 0.0f ); + rw.setVertexCoord( 1, 1.0f, -1.0f, 0.0f ); + rw.setVertexCoord( 2, 0.0f, 1.0f, 0.0f ); + rw.unlock(); + + NL3D::CIndexBuffer ib; + ib.setNumIndexes( 3 ); + ib.setFormat( NL3D::CIndexBuffer::Indices32 ); + ib.setPreferredMemory( NL3D::CIndexBuffer::StaticPreferred, false ); + + NL3D::CIndexBufferReadWrite iw; + ib.lock( iw ); + iw.setTri( 0, 0, 1, 2 ); + iw.unlock(); + + id->activeVertexBuffer( vb ); + id->activeIndexBuffer( ib ); + + NL3D::CMaterial mat; + mat.setColor( NLMISC::CRGBA::White ); + id->renderRawTriangles( mat, 0, 1 ); + } + + driver->swapBuffers(); + } + + bool CNel3DInterface::loadShape( const std::string &fileName ) { NLMISC::CPath::addSearchPath( NLMISC::CFile::getPath( fileName ), false, false ); diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/nel3d_interface.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/nel3d_interface.h index 0c45cf0fd..80c2eb132 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/nel3d_interface.h +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/nel3d_interface.h @@ -161,6 +161,7 @@ namespace MaterialEditor bool addSphere(); bool addCylinder(); bool addTeaPot(); + void drawTriangle(); bool loadShape( const std::string &fileName ); void clearScene();