Пример #1
0
TRenderEntity *RenderEntityCreate2D(const uint32 pWidth, const uint32 pHeight, const char *pFileName)
{
    TTexture *lTexture = TextureCreate(pFileName, false);
    if(lTexture==NULL)
        return NULL;
        
    TMaterial *lMaterial = MaterialCreate();
    MaterialAddTexture(lMaterial, lTexture);
        
    TGeom *lQuad = GeomCreateQuad(pWidth, pHeight);
    GeomSetMaterial(lQuad, lMaterial);
        
    TRenderEntity *this = RenderEntityCreate();
    RenderEntitySetGeometry(this, lQuad);
    RenderEntityMove2D(this, pWidth/2.0f, pHeight/2.0f);
    
    this->mWidth = pWidth;
    this->mHeight= pHeight;
        
    TextureDestroy(lTexture);
    MaterialDestroy(lMaterial);
    GeomDestroy(lQuad);
    
    CLASS_INSTANCE();
}
Пример #2
0
void Particles::createGeometry()
{
	gb = AllocateThis(GeometryBuffer);
	gb->setBufferAccess(BufferAccess::Write);
	gb->setBufferUsage(BufferUsage::Dynamic);
	
	material = MaterialCreate(AllocatorGetHeap(), "ParticlesMaterial");

	Material* pMaterial = material.Resolve();
	pMaterial->setDepthWrite(false);
	pMaterial->setBlending(BlendSource::SourceAlpha, BlendDestination::One);
	pMaterial->setShader("Tex");

	RenderBatchPtr renderable = AllocateHeap(RenderBatch);
	renderable->setPrimitiveType(PrimitiveType::Points);
	renderable->setGeometryBuffer(gb);
	renderable->setMaterial(material);
	renderable->setRenderLayer(RenderLayer::Transparency);

	renderable->onPreRender.Bind( this, &Particles::onPreRender );
	renderable->onPostRender.Bind( this, &Particles::onPostRender );
	
	addRenderable(renderable);

	particles.resize(MAX_PARTICLES);
}
Пример #3
0
TRenderEntity *RenderEntityCreateQuadTextured(const uint32 pSizeX, const uint32 pSizeY, const char *pFileName)
{
    TTexture *lTexture = TextureCreate(pFileName, false);
    if(lTexture==NULL)
        return NULL;
        
    TMaterial *lMaterial = MaterialCreate();
    MaterialAddTexture(lMaterial, lTexture);
        
    TGeom *lQuad = GeomCreateQuad(pSizeX, pSizeY);
    GeomSetMaterial(lQuad, lMaterial);
    
    GeomSetTexCoord(lQuad, 0, 0.0f, 0.0f);
	GeomSetTexCoord(lQuad, 1, 1.0f, 0.0f);
	GeomSetTexCoord(lQuad, 2, 1.0f, 1.0f);
	GeomSetTexCoord(lQuad, 3, 0.0f, 1.0f);
        
    TRenderEntity *this = RenderEntityCreate();
    RenderEntitySetGeometry(this, lQuad);
    
    TextureDestroy(lTexture);
    MaterialDestroy(lMaterial);
    GeomDestroy(lQuad);
    
    CLASS_INSTANCE();
}
Пример #4
0
int main (int argc, char *argv[])
{
	Vector3f colour_yellow = {{0.8f, 0.8f, 0.1f}};
	Material* mat_yellow = MaterialCreate("yellow", colour_yellow);
	
	Vector3f plane1_dir = {{0.0f, 0.0f, 1.0f}};
	Primative* plane1 = PrimativeCreatePlane(&plane1_dir, 0.0f, mat_yellow);
	
	Vector3f ray_dir = {{0.0f,2.0f,-1.0f}};
	ray_dir = Vector3fNormalize(&ray_dir);
	Vector3f ray_or = {{0.0f, 0.0f, 2.0f}};
	Ray* r = RayCreate(ray_or, ray_dir);
	
	IntersectPoint* ip = PrimativeIntersect(plane1, r);
	int ip_type = IntersectPointGetType(ip);
	float ip_dist = IntersectPointGetDistance(ip);
	Vector3f* ip_pos = IntersectPointGetPos(ip);
	
	printf("iptype = %d\n", ip_type);
	printf("ipdistance = %f\n", ip_dist);
	printf("ip position: \n");
	Vector3fPrint(ip_pos);
	
	return 0;
}
Пример #5
0
DebugDrawer::DebugDrawer()
	: lines(nullptr)
	, triangles(nullptr)
{
	Allocator* alloc = AllocatorGetThis();
	
	MaterialHandle debug = MaterialCreate(alloc, "Debug");
	
	Material* mat = debug.Resolve();
	mat->setBackfaceCulling(false);
	mat->setBlending(BlendSource::SourceAlpha, BlendDestination::InverseSourceAlpha);
	mat->setDepthCompare( DepthCompare::LessOrEqual );
	mat->setDepthOffset(Vector2(-1.0f, 1.0f));

	//mat->setDepthRange( Vector2(0.1f, 0.9f) );
	//mat->setDepthWrite(false);

	// Lines
	GeometryBuffer* linesVB = AllocateThis(GeometryBuffer);
	linesVB->setBufferAccess(BufferAccess::Write);
	linesVB->setBufferUsage(BufferUsage::Dynamic);
	SetupDebugVertexFormat(linesVB);

	lines = RenderBatchCreate(alloc);
	lines->setGeometryBuffer(linesVB);
	lines->setPrimitiveType(PrimitiveType::Lines);
	lines->setMaterial(debug);
	lines->setRenderLayer(RenderLayer::PostTransparency);
	renderables.push_back(lines.get());

	// Triangles
	GeometryBufferPtr trianglesVB = AllocateThis(GeometryBuffer);
	trianglesVB->setBufferAccess(BufferAccess::Write);
	trianglesVB->setBufferUsage(BufferUsage::Dynamic);
	SetupDebugVertexFormat(trianglesVB.get());

	triangles = RenderBatchCreate(alloc);
	triangles->setGeometryBuffer(trianglesVB);
	triangles->setPrimitiveType(PrimitiveType::Triangles);
	triangles->setMaterial(debug);
	triangles->setRenderLayer(RenderLayer::PostTransparency);
	renderables.push_back(triangles.get());

	// Quads
	GeometryBufferPtr quadsVB = AllocateThis(GeometryBuffer);
	quadsVB->setBufferAccess(BufferAccess::Write);
	quadsVB->setBufferUsage(BufferUsage::Dynamic);
	SetupDebugVertexFormat(quadsVB.get());

	quads = RenderBatchCreate(alloc);
	quads->setGeometryBuffer(quadsVB);
	quads->setPrimitiveType(PrimitiveType::Quads);
	quads->setMaterial(debug);
	quads->setRenderLayer(RenderLayer::PostTransparency);
	renderables.push_back(quads.get());

	reset();
}
Пример #6
0
Gizmo::Gizmo( const EntityPtr& node, const CameraWeakPtr& camera )
	: nodeObject( node )
	, weakCamera( camera )
	, selectedAxis( GizmoAxis::None )
{	
	assert( node != nullptr );

	// Disable the depth testing so the gizmo can be seen behind objects.
	material = MaterialCreate(AllocatorGetHeap(), "GizmoMaterial");
	material.Resolve()->setDepthRange(Vector2(0.0f, 0.1f));
}
Пример #7
0
void Overlay::createGeometry()
{
    material = MaterialCreate(AllocatorGetThis(), "OverlayMaterial");

    renderable = AllocateThis(Renderable);
    renderable->setPrimitiveType(PrimitiveType::Quads);
    renderable->setGeometryBuffer( AllocateThis(GeometryBuffer) );
    renderable->setMaterial(material);
    renderable->setRenderLayer(RenderLayer::Overlays);
    renderable->onPreRender.Bind(this, &Overlay::onPreRender);

    addRenderable( renderable );
}
Пример #8
0
TRenderEntity *RenderEntityCreateCube(const uint32 pSizeX, const uint32 pSizeY, const uint32 pSizeZ)
{        
    TGeom *lCube = GeomCreateCube(pSizeX, pSizeY, pSizeZ);
    
    TMaterial *lMaterial = MaterialCreate(); 
    GeomSetMaterial(lCube, lMaterial);
    MaterialDestroy(lMaterial);
    
    TRenderEntity *this = RenderEntityCreate();
    RenderEntitySetGeometry(this, lCube);
    
    GeomDestroy(lCube);
    
    CLASS_INSTANCE();
}
Пример #9
0
RenderBatchPtr Model::createDebugRenderable() const
{
	MaterialHandle handleMaterial = MaterialCreate(AllocatorGetHeap(), "SkeletonDebug");

	Material* material = handleMaterial.Resolve();
	material->setDepthTest(false);

	GeometryBuffer* gb = AllocateHeap(GeometryBuffer);
	
	RenderBatch* renderable = AllocateHeap(Renderable);
	renderable->setPrimitiveType(PrimitiveType::Lines);
	renderable->setGeometryBuffer(gb);
	renderable->setMaterial(handleMaterial);

	return renderable;
}
Пример #10
0
RenderablePtr DebugBuildFrustum( const Frustum& box )
{
	GeometryBuffer* gb = AllocateHeap(GeometryBuffer);

	MaterialHandle materialHandle = MaterialCreate(AllocatorGetHeap(), "FrustumDebug");
	Material* material = materialHandle.Resolve();
	material->setBackfaceCulling( false );

	Renderable* renderable = AllocateHeap(Renderable);
	renderable->setPrimitiveType(PrimitiveType::Quads);
	renderable->setGeometryBuffer(gb);
	renderable->setMaterial(materialHandle);
	renderable->setPrimitiveRasterMode( PrimitiveRasterMode::Wireframe );

	DebugUpdateFrustum(renderable, box);
	return renderable;
}
Пример #11
0
NAMESPACE_ENGINE_BEGIN

//-----------------------------------//

BulletDebugDrawer::BulletDebugDrawer()
{
	gb = AllocateThis(GeometryBuffer, BufferUsage::Dynamic, BufferAccess::Write);
	clearBuffer();

	material = MaterialCreate(AllocatorGetHeap(), "PhysicsDebug");
	material.Resolve()->setDepthCompare(DepthCompare::LessOrEqual);

	renderable = AllocateThis(Renderable);
	renderable->setPrimitiveType(PrimitiveType::Lines);
	renderable->setGeometryBuffer(gb);
	renderable->setMaterial(material);
}
Пример #12
0
RenderablePtr DebugBuildRay( const Ray& pickRay, float length )
{
	std::vector<Vector3> vertex;
	vertex.push_back( pickRay.origin );
	vertex.push_back( pickRay.getPoint(length) );

	std::vector<Vector3> colors( 2, Color::Red );

	GeometryBuffer* gb = AllocateHeap(GeometryBuffer);
	gb->set( VertexAttribute::Position, vertex );
	gb->set( VertexAttribute::Color, colors );

	MaterialHandle material = MaterialCreate(AllocatorGetHeap(), "RayDebug");

	Renderable* renderable = AllocateHeap(Renderable);
	renderable->setPrimitiveType(PrimitiveType::Lines);
	renderable->setGeometryBuffer(gb);
	renderable->setMaterial(material);
	
	return renderable;
}
Пример #13
0
RenderablePtr DebugBuildBoundingBox( const BoundingBox& box )
{
	GeometryBuffer* gb = AllocateHeap(GeometryBuffer);

	MaterialHandle materialHandle = MaterialCreate(AllocatorGetHeap(), "BoundingBoxDebug");
	
	Material* mat = materialHandle.Resolve();
	mat->setDepthCompare( DepthCompare::LessOrEqual );
	mat->setBackfaceCulling( false );
	//mat->setDepthRange( Vector2(0.1f, 0.9f) );

	Renderable* renderable = AllocateHeap(Renderable);
	renderable->setPrimitiveType(PrimitiveType::Quads);
	renderable->setGeometryBuffer(gb);
	renderable->setMaterial(materialHandle);
	renderable->setPrimitiveRasterMode( PrimitiveRasterMode::Wireframe );

	DebugUpdateBoudingBox(gb, box, Color::White);

	return renderable;
}
Пример #14
0
TRenderEntity *RenderEntityCreateCubeTextured(const uint32 pSizeX, const uint32 pSizeY, const uint32 pSizeZ, const char *pFileName)
{
    TTexture *lTexture = TextureCreate(pFileName, false);
    if(lTexture==NULL)
        return NULL;
        
    TMaterial *lMaterial = MaterialCreate();
    MaterialAddTexture(lMaterial, lTexture);
        
    TGeom *lCube = GeomCreateCube(pSizeX, pSizeY, pSizeZ);
    GeomSetMaterial(lCube, lMaterial);
        
    TRenderEntity *this = RenderEntityCreate();
    RenderEntitySetGeometry(this, lCube);
    
    TextureDestroy(lTexture);
    MaterialDestroy(lMaterial);
    GeomDestroy(lCube);
    
    CLASS_INSTANCE();
}
Пример #15
0
    CLASS_CREATE(TMaterial);

    int i;
    for(i=0;i<MATERIAL_MAX_TEXTURES;i++)
        this->mTextures[i] = NULL;

    this->mShader = NULL;
    
    MaterialSetColor(this,gColor[0],gColor[1],gColor[2],gColor[3]);

    CLASS_INSTANCE();
}

TMaterial *MaterialClone(const TMaterial *this)
{
    TMaterial *lClone = MaterialCreate();
    
    int i;
    for(i=0;i<MATERIAL_MAX_TEXTURES;i++)
    {
        if(this->mTextures[i]==NULL)
            break;
            
        MaterialAddTexture(lClone, this->mTextures[i]);
    }

    if(this->mShader!=NULL)
        MaterialAddShader(lClone, this->mShader);
    
    MaterialSetRGB(lClone, this->mColor[0], this->mColor[1], this->mColor[2]);
    MaterialSetAlpha(lClone, this->mColor[3]);