2'
class ShaderPass :public Object {
protected:
Texture * texture; // blended texture
Vector4D color; // used color
int srcBlend; // blend modes

Добавляем модели

int dstBlend;
bool envMapped; // whether we use
// environment mapping
Transform2D * textureTransf; // texture coordinates
// transform
public:
ShaderPass ( const char * theName, Texture * theTexture, const Vector4DS theColor, bool env = false ); -ShaderPass () ;
void setBlendingMode ( int s, int d ) {
srcBlend = s; dstBlend = d;
}
void setTransform ( const Transform2DS tr );
virtual void drawPoly ( Views view, const Polygon3D *
poly ) const;
virtual void drawMesh ( Views view, const Cameras
camera, const Vector4DS color, Fog * fog, const Mesh3D * mesh ) const;
static MetaClass classlnstance;
} ;

Ниже мы приводим реализацию метода drawMesh для рендеринга моделей.

void ShaderPass :: drawMesh ( Views view, const Cameras
camera, const Vector4DS theColor, Fog * fog, const Mesh3D * mesh ) const
{
bool transp = srcBlend != View :: bmNone SS dstBlend != View :: bmNone;
glPushAttrib ( GL_COLOR_BUFFER_BIT | GL_ENABLE_BIT |
GL_TRANSFORM_BIT ); if ( textureTransf != NULL ) // setup texture matrix {
float m [16];
textureTransf -> buildHomogeneousMatrix ( m );
glMatrixMode ( GL_TEXTURE ); glPushMatrix (); glMultMatrixf ( m ) ;
}
if ( envMapped ) // setup spherical env. mapping
{
glTexGeni ( GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP ); glTexGeni ( GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP ); glEnable ( GL_TEXTURE_GEN_S ); glEnable ( GL_TEXTURE_GEN_T ) ;
}
if ( transp ) {
glEnable ( GL_BLEND );
view.blendFunc ( srcBlend, dstBlend );
}
// draw mesh
mesh -> draw ( view, camera, color * theColor, fog, texture, transp );
// restore texture matrix if ( textureTransf != NULL ) glPopMatrix ();
glPopAttrib ();
}

Как видно из приведенного кода, сначала устанавливается необходимый режим вывода, после чего вызывается метод Mesh3D :: draw. После этого восстанавливаются изменения в состоянии OpenGL.


⇐ Предыдущая| |Следующая ⇒