|
|
|
@ -447,144 +447,6 @@ namespace MaterialEditor
|
|
|
|
|
return loadShape( "primitives/teapot.shape" );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const char *vs =
|
|
|
|
|
"#version 330\n"
|
|
|
|
|
"\n"
|
|
|
|
|
"layout ( location = 0 ) in vec4 vertex;\n"
|
|
|
|
|
"layout ( location = 3 ) in vec4 color;\n"
|
|
|
|
|
"out vec4 vColor;\n"
|
|
|
|
|
"\n"
|
|
|
|
|
"void main( void )\n"
|
|
|
|
|
"{\n"
|
|
|
|
|
"gl_Position = vertex;\n"
|
|
|
|
|
"vColor = color;\n"
|
|
|
|
|
"}\n";
|
|
|
|
|
|
|
|
|
|
const char *ps =
|
|
|
|
|
"#version 330\n"
|
|
|
|
|
"\n"
|
|
|
|
|
"in vec4 vColor;\n"
|
|
|
|
|
"out vec4 color;\n"
|
|
|
|
|
"\n"
|
|
|
|
|
"uniform float redShift;"
|
|
|
|
|
"\n"
|
|
|
|
|
"void main( void )\n"
|
|
|
|
|
"{\n"
|
|
|
|
|
"vec4 finalColor = vColor.rgba;\n"
|
|
|
|
|
"finalColor.r = redShift;\n"
|
|
|
|
|
"color = finalColor;\n"
|
|
|
|
|
"}\n";
|
|
|
|
|
|
|
|
|
|
void CNel3DInterface::drawTriangle()
|
|
|
|
|
{
|
|
|
|
|
NL3D::CDriverUser *d = dynamic_cast< NL3D::CDriverUser* >( driver );
|
|
|
|
|
if( d != NULL )
|
|
|
|
|
{
|
|
|
|
|
NL3D::IDriver *id = d->getDriver();
|
|
|
|
|
|
|
|
|
|
NL3D::CVertexBuffer vb;
|
|
|
|
|
vb.setVertexFormat( NL3D::CVertexBuffer::PositionFlag | NL3D::CVertexBuffer::PrimaryColorFlag );
|
|
|
|
|
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.setColor( 0, NLMISC::CRGBA::Red );
|
|
|
|
|
rw.setVertexCoord( 1, 1.0f, -1.0f, 0.0f );
|
|
|
|
|
rw.setColor( 1, NLMISC::CRGBA::Green );
|
|
|
|
|
rw.setVertexCoord( 2, 0.0f, 1.0f, 0.0f );
|
|
|
|
|
rw.setColor( 2, NLMISC::CRGBA::Blue );
|
|
|
|
|
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();
|
|
|
|
|
|
|
|
|
|
NL3D::CMaterial mat;
|
|
|
|
|
|
|
|
|
|
NL3D::IProgramObject *po = id->createProgramObject();
|
|
|
|
|
NL3D::IProgram *vp = id->createVertexProgram();
|
|
|
|
|
NL3D::IProgram *pp = id->createPixelProgram();
|
|
|
|
|
|
|
|
|
|
vp->shaderSource( vs );
|
|
|
|
|
pp->shaderSource( ps );
|
|
|
|
|
|
|
|
|
|
std::string log;
|
|
|
|
|
bool ok = false;
|
|
|
|
|
|
|
|
|
|
ok = vp->compile( log );
|
|
|
|
|
if( !ok )
|
|
|
|
|
{
|
|
|
|
|
delete po;
|
|
|
|
|
delete vp;
|
|
|
|
|
delete pp;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ok = pp->compile( log );
|
|
|
|
|
if( !ok )
|
|
|
|
|
{
|
|
|
|
|
delete po;
|
|
|
|
|
delete vp;
|
|
|
|
|
delete pp;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ok = po->attachVertexProgram( vp );
|
|
|
|
|
if( !ok )
|
|
|
|
|
{
|
|
|
|
|
delete po;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ok = po->attachPixelProgram( pp );
|
|
|
|
|
if( !ok )
|
|
|
|
|
{
|
|
|
|
|
delete po;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ok = po->link( log );
|
|
|
|
|
if( !ok )
|
|
|
|
|
{
|
|
|
|
|
delete po;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ok = id->activeProgramObject( po );
|
|
|
|
|
if( !ok )
|
|
|
|
|
{
|
|
|
|
|
delete po;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int opacityLocation = id->getUniformLocation( "redShift" );
|
|
|
|
|
if( opacityLocation != -1 )
|
|
|
|
|
id->setUniform1f( opacityLocation, 0.25f );
|
|
|
|
|
|
|
|
|
|
id->activeVertexBuffer( vb );
|
|
|
|
|
id->activeIndexBuffer( ib );
|
|
|
|
|
|
|
|
|
|
driver->clearBuffers( NLMISC::CRGBA::Black );
|
|
|
|
|
NLMISC::CMatrix f;
|
|
|
|
|
f.identity();
|
|
|
|
|
driver->setFrustumMatrix( f );
|
|
|
|
|
|
|
|
|
|
id->renderRawTriangles2( mat, 0, 1 );
|
|
|
|
|
driver->swapBuffers();
|
|
|
|
|
id->activeProgramObject( NULL );
|
|
|
|
|
delete po;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool CNel3DInterface::loadShape( const std::string &fileName )
|
|
|
|
|
{
|
|
|
|
|
NLMISC::CPath::addSearchPath( NLMISC::CFile::getPath( fileName ), false, false );
|
|
|
|
|