Beispiel #1
0
void rxScreenTriangle::Initialize()
{
    if( ! vertexLayout )
    {
        vertexLayout = RX_GET_INPUT_LAYOUT( ScreenVertex );
    }
    if( ! vertexBuffer )
    {
        // NOTE: z = 1 (the farthest possible distance) -> optimization for deferred lighting/shading engines:
        // skybox outputs z = w = 1 -> if we set depth test to less than the sky won't be shaded
        //
        const ScreenVertex vertices[VERTEX_COUNT] =
        {
            ScreenVertex( Vec4D( -1.0f, -3.0f, 1.0f, 1.0f ), Vec2D( 0.0f, 2.0f ) ),	// lower-left
            ScreenVertex( Vec4D( -1.0f,  1.0f, 1.0f, 1.0f ), Vec2D( 0.0f, 0.0f ) ),	// upper-left
            ScreenVertex( Vec4D(  3.0f,  1.0f, 1.0f, 1.0f ), Vec2D( 2.0f, 0.0f ) ),	// upper-right
        };

        vertexBuffer = rxResourceServer::Get().NewVertexBuffer(
                           sizeof( vertices ),
                           sizeof(vertices[0]),
                           vertices
                       );
    }
}
Beispiel #2
0
void Renderer::render(Model &model, int *shadow_buffer) {
	std::vector<Vec3i> verts(model.nverts());
	for (int i=0; i<model.nverts(); i++) {
		verts[i] = vertex_shader(model, i);
	}
	clear();
	_zbuffer = std::vector<int>(get_width()*get_height(), -1);
	for (int i=0; i<model.nfaces(); i++) {
		std::vector<Vec3i> f = model.face(i);
		ScreenVertex triangle[3];
		for (int t=0; t<3; t++) {
			triangle[t] = ScreenVertex(verts[f[t].ivert], model.uv(f[t].iuv));
		}
		rasterize(triangle, model, shadow_buffer);
	}
}
Beispiel #3
0
void Screen3D::DrawRectangle( int x, int y, int w, int h, D3DCOLOR color )
{
	ScreenVertex v[6];
	v[0] = ScreenVertex( x,    y,   1, color, 0, 0 );
	v[2] = ScreenVertex( x+w,  y+h, 1, color, 1, 1 );
	v[1] = ScreenVertex( x,    y+h, 1, color, 0, 1 );
	v[3] = ScreenVertex( x,    y,   1, color, 0, 0 );
	v[5] = ScreenVertex( x+w,  y,   1, color, 1, 0 );
	v[4] = ScreenVertex( x+w,  y+h, 1, color, 1, 1 );

	SetTexture(NULL, 0);
	SetFVF(D3DFVF_SCREENVERTEX);
	SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);
	D3DDevice->DrawPrimitiveUP( D3DPT_TRIANGLELIST, 2, v,  sizeof(ScreenVertex));
	ResetWireframeState();

}
Beispiel #4
0
void Screen3D::DrawSprite( int x, int y, Texture* Image, int alpha)
{
	SetRenderState(D3DRS_FILLMODE, D3DFILL_SOLID );

	Texture* T = Image;
	Real texturewidth=1, textureheight=1;
	if(T)
	{
		texturewidth  = T->GetWidth();
		textureheight = T->GetHeight();
	}

	//float jiggle= (rand() % 10000) - 5000;
	//jiggle /= 5000.0f;
	float jiggle = 0.5f;

	if( alpha != 255 )
		jiggle = 0;
	x--;
	y--;
	

	ScreenVertex v[6];
	D3DCOLOR color = D3DCOLOR_ARGB( alpha, 255, 255, 255 );
	v[0] = ScreenVertex( x+jiggle,   y+jiggle,   1,					color, 0, 0 );
	v[2] = ScreenVertex( x+jiggle+texturewidth, y+textureheight, 1, color, 1, 1 );
	v[1] = ScreenVertex( x+jiggle,   y+jiggle+textureheight, 1,		color, 0, 1 );
	v[3] = ScreenVertex( x+jiggle,   y+jiggle, 1,					color, 0, 0 );
	v[5] = ScreenVertex( x+jiggle+texturewidth, y+jiggle,   1,		color, 1, 0 );
	v[4] = ScreenVertex( x+jiggle+texturewidth, y+textureheight+jiggle, 1, color, 1, 1 );

	SetTexture(Image, 0);
	SetFVF(D3DFVF_SCREENVERTEX);
	SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);

	
//	D3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE,   TRUE);
//	D3DDevice->SetRenderState(D3DRS_SRCBLEND,           D3DBLEND_SRCALPHA);
	//D3DDevice->SetRenderState(D3DRS_DESTBLEND,          D3DBLEND_INVSRCALPHA);
	
	D3DDevice->DrawPrimitiveUP( D3DPT_TRIANGLELIST, 2, v,  sizeof(ScreenVertex));

	ResetWireframeState();

		// Figure out the vertices for the main window
	/*ScreenVertex WindowVertices[4];

	WindowVertices[0].z   = 0;WindowVertices[1].z   = 0;WindowVertices[2].z   = 0;WindowVertices[3].z   = 0;
	WindowVertices[0].RHW = 1;	WindowVertices[1].RHW = 1; WindowVertices[2].RHW = 1; WindowVertices[3].RHW = 1;
	WindowVertices[0].color = D3DCOLOR_RGBA(255, 255, 255, alpha);WindowVertices[1].color = D3DCOLOR_RGBA(255, 255, 255, alpha);
	WindowVertices[2].color = D3DCOLOR_RGBA(255, 255, 255, alpha);WindowVertices[3].color = D3DCOLOR_RGBA(255, 255, 255, alpha);

	WindowVertices[0].x   = x;
	WindowVertices[0].y   = y;
	WindowVertices[1].x   = x+texturewidth;
	WindowVertices[1].y   = y;
	WindowVertices[2].x   = x;
	WindowVertices[2].y   = y+textureheight;
	WindowVertices[3].x   = x+texturewidth;
	WindowVertices[3].y   = y+textureheight;



	WindowVertices[0].tu  = 0;
	WindowVertices[0].tv  = 0;
	WindowVertices[1].tu  = 1;
	WindowVertices[1].tv  = 0;
	WindowVertices[2].tu  = 0;
	WindowVertices[2].tv  = 1;
	WindowVertices[3].tu  = 1;
	WindowVertices[3].tv  = 1;


	SetTexture(Image, 0);
	D3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE,   TRUE);
	D3DDevice->SetRenderState(D3DRS_SRCBLEND,           D3DBLEND_SRCALPHA);
	D3DDevice->SetRenderState(D3DRS_DESTBLEND,          D3DBLEND_INVSRCALPHA);
	SetFVF(D3DFVF_SCREENVERTEX);
	D3DDevice->DrawPrimitiveUP( D3DPT_TRIANGLESTRIP, 2, WindowVertices,  sizeof(ScreenVertex));*/
}