示例#1
0
static void displayD3D9()
{
    int i;

    update();

    IDirect3DDevice9_SetRenderState(gDevicePtr, D3DRS_LIGHTING, FALSE);
    IDirect3DDevice9_SetRenderState(gDevicePtr, D3DRS_CLIPPING, FALSE);
    IDirect3DDevice9_SetRenderTarget(gDevicePtr, 0, gDeviceBackBufferPtr);
    utilReshapeOrtho(DEFAULT_WINDOW_WIDTH, DEFAULT_WINDOW_HEIGHT);
    IDirect3DDevice9_Clear(gDevicePtr, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xFF000000, 1.0f, 0);
    IDirect3DDevice9_SetVertexShader(gDevicePtr, gVShaderPtr);
    IDirect3DDevice9_SetPixelShader(gDevicePtr, gPShaderPtr);
    IDirect3DDevice9_SetVertexDeclaration(gDevicePtr, gVertexDeclPtr);
    IDirect3DDevice9_SetStreamSource(gDevicePtr, 0, gVertexBufferPtr, 0, sizeof(FLOAT) * 3);
    IDirect3DDevice9_SetIndices(gDevicePtr, gIndexBufferPtr);

    /* Send projection matrix constants */
    IDirect3DDevice9_SetVertexShaderConstantF(gDevicePtr, 0, gProjectionMatrixf, 4);

    IDirect3DDevice9_BeginScene(gDevicePtr);

    for (i = 0; i < gNumDrawCalls; i++) {
        if (gResetVertexPointers)
            IDirect3DDevice9_SetStreamSource(gDevicePtr, 0, gVertexBufferPtr, 0, sizeof(FLOAT) * 3);

        if (gResetConstants || i == 0)
            update_modelview_constants_d3d9(gModelViewMatrixf);

        IDirect3DDevice9_DrawIndexedPrimitive(gDevicePtr, D3DPT_TRIANGLELIST, 0, 0, NUM_VERTICES, 0, NUM_INDICES);

        if (gResetVertexPointers)
            IDirect3DDevice9_SetStreamSource(gDevicePtr, 0, gVertexBufferPtr, 36, sizeof(FLOAT) * 3);

        if (gResetConstants || i == 0)
            update_modelview_constants_d3d9(gModelViewMatrixf2);

        IDirect3DDevice9_DrawIndexedPrimitive(gDevicePtr, D3DPT_TRIANGLELIST, 0, 0, NUM_VERTICES, 0, NUM_INDICES);
    }

    IDirect3DDevice9_EndScene(gDevicePtr);

    IDirect3DDevice9_Present(gDevicePtr, NULL, NULL, 0, NULL);

    /* Reset state to default */
    IDirect3DDevice9_SetVertexShader(gDevicePtr, NULL);
    IDirect3DDevice9_SetPixelShader(gDevicePtr, NULL);
    IDirect3DDevice9_SetVertexDeclaration(gDevicePtr, NULL);
    IDirect3DDevice9_SetStreamSource(gDevicePtr, 0, NULL, 0, 0);
    IDirect3DDevice9_SetIndices(gDevicePtr, NULL);
}
示例#2
0
void draw_object_ex(IDirect3DDevice9 *device, object *obj, BOOL trans){
	unsigned int mesh;
	if(!device) return;
	if(!obj) return;

	if(obj->update){
		vertex *dest;
		generate_normals(obj);
		IDirect3DVertexBuffer9_Lock(obj->vertexbuffer, 0, 0, (BYTE**)&dest, 0 );
		memcpy(dest,obj->vertices,sizeof(vertex)*obj->vertex_count);
		IDirect3DVertexBuffer9_Unlock(obj->vertexbuffer);
		obj->update = FALSE;
	}

	IDirect3DDevice9_SetTransform( device, D3DTS_WORLD, (D3DMATRIX*)&obj->mat );
	IDirect3DDevice9_SetStreamSource(device, 0, obj->vertexbuffer, 0, sizeof(vertex));
	IDirect3DDevice9_SetFVF(device, OBJECT_VERTEX_TYPE);

	for(mesh=0;mesh<obj->submesh_count;mesh++){
		if(obj->submeshes[mesh].mat){
			if(obj->submeshes[mesh].mat->additive==trans){
				set_material(device,obj->submeshes[mesh].mat);
				IDirect3DDevice9_SetIndices(device,obj->submeshes[mesh].indexbuffer);
				IDirect3DDevice9_DrawIndexedPrimitive(device, D3DPT_TRIANGLELIST, 0,0,obj->vertex_count, 0,obj->submeshes[mesh].triangle_count);
			}
		}else{
			if(!trans){
				IDirect3DDevice9_SetIndices(device,obj->submeshes[mesh].indexbuffer);
				IDirect3DDevice9_DrawIndexedPrimitive(device, D3DPT_TRIANGLELIST, 0,0,obj->vertex_count, 0,obj->submeshes[mesh].triangle_count);
			}
		}
	}
}
示例#3
0
文件: direct3d.c 项目: BtbN/vlc
static int Direct3DRenderRegion(vout_display_t *vd,
                                d3d_region_t *region)
{
    vout_display_sys_t *sys = vd->sys;

    LPDIRECT3DDEVICE9 d3ddev = vd->sys->d3ddev;

    LPDIRECT3DVERTEXBUFFER9 d3dvtc = sys->d3dvtc;
    LPDIRECT3DTEXTURE9      d3dtex = region->texture;

    HRESULT hr;

    /* Import vertices */
    void *vertex;
    hr = IDirect3DVertexBuffer9_Lock(d3dvtc, 0, 0, &vertex, D3DLOCK_DISCARD);
    if (FAILED(hr)) {
        msg_Dbg(vd, "%s:%d (hr=0x%0lX)", __FUNCTION__, __LINE__, hr);
        return -1;
    }
    memcpy(vertex, region->vertex, sizeof(region->vertex));
    hr = IDirect3DVertexBuffer9_Unlock(d3dvtc);
    if (FAILED(hr)) {
        msg_Dbg(vd, "%s:%d (hr=0x%0lX)", __FUNCTION__, __LINE__, hr);
        return -1;
    }

    // Setup our texture. Using textures introduces the texture stage states,
    // which govern how textures get blended together (in the case of multiple
    // textures) and lighting information. In this case, we are modulating
    // (blending) our texture with the diffuse color of the vertices.
    hr = IDirect3DDevice9_SetTexture(d3ddev, 0, (LPDIRECT3DBASETEXTURE9)d3dtex);
    if (FAILED(hr)) {
        msg_Dbg(vd, "%s:%d (hr=0x%0lX)", __FUNCTION__, __LINE__, hr);
        return -1;
    }

    // Render the vertex buffer contents
    hr = IDirect3DDevice9_SetStreamSource(d3ddev, 0, d3dvtc, 0, sizeof(CUSTOMVERTEX));
    if (FAILED(hr)) {
        msg_Dbg(vd, "%s:%d (hr=0x%0lX)", __FUNCTION__, __LINE__, hr);
        return -1;
    }

    // we use FVF instead of vertex shader
    hr = IDirect3DDevice9_SetFVF(d3ddev, D3DFVF_CUSTOMVERTEX);
    if (FAILED(hr)) {
        msg_Dbg(vd, "%s:%d (hr=0x%0lX)", __FUNCTION__, __LINE__, hr);
        return -1;
    }

    // draw rectangle
    hr = IDirect3DDevice9_DrawPrimitive(d3ddev, D3DPT_TRIANGLEFAN, 0, 2);
    if (FAILED(hr)) {
        msg_Dbg(vd, "%s:%d (hr=0x%0lX)", __FUNCTION__, __LINE__, hr);
        return -1;
    }
    return 0;
}
示例#4
0
文件: ctx_wm.c 项目: AgentD/sgui
static void d3d9_draw( sgui_context* context )
{
    sgui_d3d9_context* ctx = (sgui_d3d9_context*)context;
    D3DVIEWPORT9 vp;
    float m[16];

    m[3]=m[7]=m[11]=m[12]=m[13]=0.0f; m[14]=-5.0f; m[15]=1.0f;
    vp.X=0; vp.Y=0; vp.Width=WIDTH; vp.Height=HEIGHT;
    vp.MinZ = 0.0f; vp.MaxZ = 1.0f;

    IDirect3DDevice9_SetViewport( ctx->device, &vp );
    IDirect3DDevice9_Clear( ctx->device, 0, NULL,
                            D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER, 0, 1.0f, 0 );
    vp.Width=WIDTH/2; vp.Height=HEIGHT/2;

    IDirect3DDevice9_BeginScene( ctx->device );

    IDirect3DDevice9_SetRenderState(ctx->device,D3DRS_ZENABLE,TRUE);
    IDirect3DDevice9_SetFVF( ctx->device, CUSTOMFVF );
    IDirect3DDevice9_SetStreamSource( ctx->device, 0, v_buffer, 0,
                                      sizeof(CUSTOMVERTEX) );
    IDirect3DDevice9_SetRenderState(ctx->device,D3DRS_FILLMODE,
                                    D3DFILL_WIREFRAME);

    m[0]=m[10]=cos(t); m[2]=sin(t); m[8]=-m[2]; m[1]=m[4]=m[6]=m[9]=0; m[5]=1;
    vp.X = 0; vp.Y = HEIGHT/2;
    IDirect3DDevice9_SetTransform( ctx->device, D3DTS_VIEW, (D3DMATRIX*)m );
    IDirect3DDevice9_SetViewport( ctx->device, &vp );
    IDirect3DDevice9_DrawPrimitive( ctx->device, D3DPT_TRIANGLELIST, 0, 12 );

    m[1]=m[8]=-sin(t); m[0]=cos(t); m[9]=-m[0]; m[2]=m[4]=m[5]=m[10]=0;m[6]=1;
    vp.X = WIDTH/2; vp.Y = 0;
    IDirect3DDevice9_SetTransform( ctx->device, D3DTS_VIEW, (D3DMATRIX*)m );
    IDirect3DDevice9_SetViewport( ctx->device, &vp );
    IDirect3DDevice9_DrawPrimitive( ctx->device, D3DPT_TRIANGLELIST, 0, 12 );

    m[0]=m[10]=-sin(t); m[2]=cos(t); m[8]=-m[2]; m[1]=m[4]=m[6]=m[9]=0;m[5]=1;
    vp.X = 0; vp.Y = 0;
    IDirect3DDevice9_SetTransform( ctx->device, D3DTS_VIEW, (D3DMATRIX*)m );
    IDirect3DDevice9_SetViewport( ctx->device, &vp );
    IDirect3DDevice9_SetRenderState(ctx->device,D3DRS_FILLMODE,D3DFILL_SOLID);
    IDirect3DDevice9_DrawPrimitive( ctx->device, D3DPT_TRIANGLELIST, 0, 12 );

    /* draw GUI in begin/end block */
    sgui_ctx_wm_draw_gui( wm );

    IDirect3DDevice9_EndScene( ctx->device );
    t += 0.01f;
}
示例#5
0
void d3d_set_stream_source(LPDIRECT3DDEVICE dev, unsigned stream_no,
      void *stream_vertbuf_ptr, unsigned offset_bytes,
      unsigned stride)
{
	LPDIRECT3DVERTEXBUFFER stream_vertbuf = (LPDIRECT3DVERTEXBUFFER)stream_vertbuf_ptr;
#if defined(HAVE_D3D8)
   IDirect3DDevice8_SetStreamSource(dev, stream_no, stream_vertbuf, stride);
#elif defined(_XBOX360)
   D3DDevice_SetStreamSource_Inline(dev, stream_no, stream_vertbuf,
         offset_bytes, stride);
#elif defined(HAVE_D3D9) && !defined(__cplusplus)
   IDirect3DDevice9_SetStreamSource(dev, stream_no, stream_vertbuf, offset_bytes,
         stride);
#else
   dev->SetStreamSource(stream_no, stream_vertbuf, offset_bytes, stride);
#endif
}
示例#6
0
/**
 * It copies picture surface into a texture and renders into a scene.
 *
 * This function is intented for higher end 3D cards, with pixel shader support
 * and at least 64 MiB of video RAM.
 */
static void Direct3DRenderScene(vout_display_t *vd, LPDIRECT3DSURFACE9 surface)
{
    vout_display_sys_t *sys = vd->sys;
    LPDIRECT3DDEVICE9 d3ddev = sys->d3ddev;
    HRESULT hr;

    // check if device is still available
    hr = IDirect3DDevice9_TestCooperativeLevel(d3ddev);
    if (FAILED(hr)) {
        if (hr == D3DERR_DEVICENOTRESET && !sys->reset_device) {
            vout_display_SendEventPicturesInvalid(vd);
            sys->reset_device = true;
        }
        return;
    }
    /* */
    LPDIRECT3DTEXTURE9      d3dtex  = sys->d3dtex;
    LPDIRECT3DVERTEXBUFFER9 d3dvtc  = sys->d3dvtc;

    /* Clear the backbuffer and the zbuffer */
    hr = IDirect3DDevice9_Clear(d3ddev, 0, NULL, D3DCLEAR_TARGET,
                              D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0);
    if (FAILED(hr)) {
        msg_Dbg(vd, "%s:%d (hr=0x%0lX)", __FUNCTION__, __LINE__, hr);
        return;
    }
    /*  retrieve picture surface */
    LPDIRECT3DSURFACE9 d3dsrc = surface;
    if (!d3dsrc) {
        msg_Dbg(vd, "no surface to render ?");
        return;
    }

    /* retrieve texture top-level surface */
    LPDIRECT3DSURFACE9 d3ddest;
    hr = IDirect3DTexture9_GetSurfaceLevel(d3dtex, 0, &d3ddest);
    if (FAILED(hr)) {
        msg_Dbg(vd, "%s:%d (hr=0x%0lX)", __FUNCTION__, __LINE__, hr);
        return;
    }

    /* Copy picture surface into texture surface
     * color space conversion and scaling happen here */
    RECT src = vd->sys->rect_src_clipped;
    RECT dst = vd->sys->rect_dest_clipped;

    hr = IDirect3DDevice9_StretchRect(d3ddev, d3dsrc, &src, d3ddest, &dst, D3DTEXF_LINEAR);
    IDirect3DSurface9_Release(d3ddest);
    if (FAILED(hr)) {
        msg_Dbg(vd, "%s:%d (hr=0x%0lX)", __FUNCTION__, __LINE__, hr);
        return;
    }

    /* Update the vertex buffer */
    CUSTOMVERTEX *vertices;
    hr = IDirect3DVertexBuffer9_Lock(d3dvtc, 0, 0, (void **)&vertices, D3DLOCK_DISCARD);
    if (FAILED(hr)) {
        msg_Dbg(vd, "%s:%d (hr=0x%0lX)", __FUNCTION__, __LINE__, hr);
        return;
    }

    /* Setup vertices */
    const float f_width  = vd->sys->d3dpp.BackBufferWidth;
    const float f_height = vd->sys->d3dpp.BackBufferHeight;

    /* -0.5f is a "feature" of DirectX and it seems to apply to Direct3d also */
    /* http://www.sjbrown.co.uk/2003/05/01/fix-directx-rasterisation/ */
    vertices[0].x       = -0.5f;       // left
    vertices[0].y       = -0.5f;       // top
    vertices[0].z       = 0.0f;
    vertices[0].diffuse = D3DCOLOR_ARGB(255, 255, 255, 255);
    vertices[0].rhw     = 1.0f;
    vertices[0].tu      = 0.0f;
    vertices[0].tv      = 0.0f;

    vertices[1].x       = f_width - 0.5f;    // right
    vertices[1].y       = -0.5f;       // top
    vertices[1].z       = 0.0f;
    vertices[1].diffuse = D3DCOLOR_ARGB(255, 255, 255, 255);
    vertices[1].rhw     = 1.0f;
    vertices[1].tu      = 1.0f;
    vertices[1].tv      = 0.0f;

    vertices[2].x       = f_width - 0.5f;    // right
    vertices[2].y       = f_height - 0.5f;   // bottom
    vertices[2].z       = 0.0f;
    vertices[2].diffuse = D3DCOLOR_ARGB(255, 255, 255, 255);
    vertices[2].rhw     = 1.0f;
    vertices[2].tu      = 1.0f;
    vertices[2].tv      = 1.0f;

    vertices[3].x       = -0.5f;       // left
    vertices[3].y       = f_height - 0.5f;   // bottom
    vertices[3].z       = 0.0f;
    vertices[3].diffuse = D3DCOLOR_ARGB(255, 255, 255, 255);
    vertices[3].rhw     = 1.0f;
    vertices[3].tu      = 0.0f;
    vertices[3].tv      = 1.0f;

    hr= IDirect3DVertexBuffer9_Unlock(d3dvtc);
    if (FAILED(hr)) {
        msg_Dbg(vd, "%s:%d (hr=0x%0lX)", __FUNCTION__, __LINE__, hr);
        return;
    }

    // Begin the scene
    hr = IDirect3DDevice9_BeginScene(d3ddev);
    if (FAILED(hr)) {
        msg_Dbg(vd, "%s:%d (hr=0x%0lX)", __FUNCTION__, __LINE__, hr);
        return;
    }

    // Setup our texture. Using textures introduces the texture stage states,
    // which govern how textures get blended together (in the case of multiple
    // textures) and lighting information. In this case, we are modulating
    // (blending) our texture with the diffuse color of the vertices.
    hr = IDirect3DDevice9_SetTexture(d3ddev, 0, (LPDIRECT3DBASETEXTURE9)d3dtex);
    if (FAILED(hr)) {
        msg_Dbg(vd, "%s:%d (hr=0x%0lX)", __FUNCTION__, __LINE__, hr);
        IDirect3DDevice9_EndScene(d3ddev);
        return;
    }

    // Render the vertex buffer contents
    hr = IDirect3DDevice9_SetStreamSource(d3ddev, 0, d3dvtc, 0, sizeof(CUSTOMVERTEX));
    if (FAILED(hr)) {
        msg_Dbg(vd, "%s:%d (hr=0x%0lX)", __FUNCTION__, __LINE__, hr);
        IDirect3DDevice9_EndScene(d3ddev);
        return;
    }

    // we use FVF instead of vertex shader
    hr = IDirect3DDevice9_SetFVF(d3ddev, D3DFVF_CUSTOMVERTEX);
    if (FAILED(hr)) {
        msg_Dbg(vd, "%s:%d (hr=0x%0lX)", __FUNCTION__, __LINE__, hr);
        IDirect3DDevice9_EndScene(d3ddev);
        return;
    }

    // draw rectangle
    hr = IDirect3DDevice9_DrawPrimitive(d3ddev, D3DPT_TRIANGLEFAN, 0, 2);
    if (FAILED(hr)) {
        msg_Dbg(vd, "%s:%d (hr=0x%0lX)", __FUNCTION__, __LINE__, hr);
        IDirect3DDevice9_EndScene(d3ddev);
        return;
    }

    // End the scene
    hr = IDirect3DDevice9_EndScene(d3ddev);
    if (FAILED(hr)) {
        msg_Dbg(vd, "%s:%d (hr=0x%0lX)", __FUNCTION__, __LINE__, hr);
        return;
    }
}
示例#7
0
文件: sprite.c 项目: radhermit/wine
static HRESULT WINAPI ID3DXSpriteImpl_Begin(ID3DXSprite *iface, DWORD flags)
{
    ID3DXSpriteImpl *This = impl_from_ID3DXSprite(iface);
    HRESULT hr;
    TRACE("(%p): relay\n", This);

    if(flags>D3DXSPRITE_FLAGLIMIT || This->ready) return D3DERR_INVALIDCALL;

    /* TODO: Implement flags:
    D3DXSPRITE_BILLBOARD: makes the sprite always face the camera
    D3DXSPRITE_DONOTMODIFY_RENDERSTATE: name says it all
    D3DXSPRITE_OBJECTSPACE: do not change device transforms
    D3DXSPRITE_SORT_DEPTH_BACKTOFRONT: sort by position
    D3DXSPRITE_SORT_DEPTH_FRONTTOBACK: sort by position
    D3DXSPRITE_SORT_TEXTURE: sort by texture (so that it doesn't change too often)
    */
    /* Seems like alpha blending is always enabled, regardless of D3DXSPRITE_ALPHABLEND flag */
    if(flags & (D3DXSPRITE_BILLBOARD |
                D3DXSPRITE_DONOTMODIFY_RENDERSTATE | D3DXSPRITE_OBJECTSPACE |
                D3DXSPRITE_SORT_DEPTH_BACKTOFRONT))
        FIXME("Flags unsupported: %#x\n", flags);
    /* These flags should only matter to performances */
    else if(flags & (D3DXSPRITE_SORT_DEPTH_FRONTTOBACK | D3DXSPRITE_SORT_TEXTURE))
        TRACE("Flags unsupported: %#x\n", flags);

    if(This->vdecl==NULL) {
        static const D3DVERTEXELEMENT9 elements[] =
        {
            { 0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0 },
            { 0, 12, D3DDECLTYPE_D3DCOLOR, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_COLOR, 0 },
            { 0, 16, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0 },
            D3DDECL_END()
        };
        IDirect3DDevice9_CreateVertexDeclaration(This->device, elements, &This->vdecl);
    }

    if(!(flags & D3DXSPRITE_DONOTSAVESTATE)) {
        if(This->stateblock==NULL) {
            /* Tell our state block what it must store */
            hr=IDirect3DDevice9_BeginStateBlock(This->device);
            if(hr!=D3D_OK) return hr;

            set_states(This);

            IDirect3DDevice9_SetVertexDeclaration(This->device, This->vdecl);
            IDirect3DDevice9_SetStreamSource(This->device, 0, NULL, 0, sizeof(SPRITEVERTEX));
            IDirect3DDevice9_SetIndices(This->device, NULL);
            IDirect3DDevice9_SetTexture(This->device, 0, NULL);

            IDirect3DDevice9_EndStateBlock(This->device, &This->stateblock);
        }
        IDirect3DStateBlock9_Capture(This->stateblock); /* Save current state */
    }

    /* Apply device state */
    set_states(This);

    This->flags=flags;
    This->ready=TRUE;

    return D3D_OK;
}
示例#8
0
int main( void )
{
    LPDIRECT3DVERTEXBUFFER9 v_buffer;
    sgui_window_description desc;
    IDirect3DTexture9* texture;
    sgui_d3d9_context* ctx;
    sgui_canvas* texcanvas;
    IDirect3DDevice9* dev;
    sgui_widget* check2;
    sgui_widget* check;
    sgui_widget* butt;
    sgui_window* wnd;
    float a=0.0f;
    VOID* pVoid;
    float m[16];

    sgui_init( );

    /*************************** create a window **************************/
    desc.parent         = NULL;
    desc.share          = NULL;
    desc.width          = 640;
    desc.height         = 480;
    desc.flags          = SGUI_FIXED_SIZE|SGUI_DOUBLEBUFFERED;
    desc.backend        = SGUI_DIRECT3D_9;
    desc.bits_per_pixel = 32;
    desc.depth_bits     = 16;
    desc.stencil_bits   = 0;
    desc.samples        = 0;

    wnd = sgui_window_create_desc( &desc );

    sgui_window_set_title( wnd, "Direct3D 9 Texture Canvas" );
    sgui_window_move_center( wnd );
    sgui_window_set_visible( wnd, SGUI_VISIBLE );
    sgui_window_set_vsync( wnd, 1 );

    /************************ createtexture canvas ************************/
    texcanvas = sgui_tex_canvas_create( wnd, sgui_window_get_context( wnd ),
                                        128, 128 );

    butt = sgui_button_create( 10, 10, 60, 25, "Button", 0 );
    check = sgui_checkbox_create( 10, 40, "Direct3D" );
    check2 = sgui_checkbox_create( 10, 65, "Texture" );

    sgui_button_set_state( check, 1 );
    sgui_button_set_state( check2, 1 );

    sgui_widget_add_child( &texcanvas->root, butt );
    sgui_widget_add_child( &texcanvas->root, check );
    sgui_widget_add_child( &texcanvas->root, check2 );

    /************** connect keyboard input to texture canvas **************/
    sgui_event_connect( wnd, SGUI_KEY_PRESSED_EVENT,
                        sgui_canvas_send_window_event, texcanvas,
                        SGUI_FROM_EVENT, SGUI_EVENT );

    sgui_event_connect( wnd, SGUI_KEY_RELEASED_EVENT,
                        sgui_canvas_send_window_event, texcanvas,
                        SGUI_FROM_EVENT, SGUI_EVENT );

    sgui_event_connect( wnd, SGUI_CHAR_EVENT,
                        sgui_canvas_send_window_event, texcanvas,
                        SGUI_FROM_EVENT, SGUI_EVENT );

    /*************************** Direct3D setup ***************************/
    /* get the device context, set new present parameters */
    ctx = (sgui_d3d9_context*)sgui_window_get_context( wnd );
    dev = ctx->device;

    IDirect3DDevice9_Reset( dev, &ctx->present );

    /* create a vertex buffer */
    IDirect3DDevice9_CreateVertexBuffer( dev, sizeof(vertices), 0,
                                         CUSTOMFVF, D3DPOOL_MANAGED,
                                         &v_buffer, NULL );

    /* load vertex data */
    IDirect3DVertexBuffer9_Lock( v_buffer, 0, 0, (void**)&pVoid, 0 );
    memcpy( pVoid, vertices, sizeof(vertices) );
    IDirect3DVertexBuffer9_Unlock( v_buffer );

    /* setup renderer state */
    IDirect3DDevice9_SetRenderState( dev, D3DRS_CULLMODE, D3DCULL_NONE );
    IDirect3DDevice9_SetRenderState( dev, D3DRS_LIGHTING, FALSE );
    IDirect3DDevice9_SetRenderState( dev, D3DRS_ZENABLE, TRUE );

    /* set up perspective projection matrix */
    perspective( m, 45.0f, (float)desc.width/(float)desc.height,
                 0.1f, 100.0f );
    IDirect3DDevice9_SetTransform( dev, D3DTS_PROJECTION, (D3DMATRIX*)m );

    /* set up texturing, bind canvas texture to stage 0 */
    texture = sgui_tex_canvas_get_texture( texcanvas );

    IDirect3DDevice9_SetTexture( dev, 0, (IDirect3DBaseTexture9*)texture );
    IDirect3DDevice9_SetTextureStageState( dev, 0, D3DTSS_COLOROP,
                                           D3DTOP_BLENDTEXTUREALPHA );
    IDirect3DDevice9_SetTextureStageState( dev, 0, D3DTSS_COLORARG1,
                                           D3DTA_TEXTURE );
    IDirect3DDevice9_SetTextureStageState( dev, 0, D3DTSS_COLORARG2,
                                           D3DTA_DIFFUSE );
    IDirect3DDevice9_SetTextureStageState( dev, 0, D3DTSS_ALPHAOP,
                                           D3DTOP_DISABLE );

    IDirect3DDevice9_SetSamplerState(dev,0,D3DSAMP_MINFILTER,D3DTEXF_LINEAR);
    IDirect3DDevice9_SetSamplerState(dev,0,D3DSAMP_MAGFILTER,D3DTEXF_LINEAR);

    /****************************** main loop *****************************/
    while( sgui_main_loop_step( ) )
    {
        /* redraw widgets in dirty areas */
        sgui_canvas_redraw_widgets( texcanvas, 1 );

        /* draw scene */
        IDirect3DDevice9_Clear( dev, 0, NULL,
                                D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER,
                                0, 1.0f, 0 );

        IDirect3DDevice9_BeginScene( dev );

        transform( m, a );
        IDirect3DDevice9_SetTransform( dev, D3DTS_VIEW, (D3DMATRIX*)m );
        a += 0.01f;

        IDirect3DDevice9_SetFVF( dev, CUSTOMFVF );
        IDirect3DDevice9_SetStreamSource( dev, 0, v_buffer, 0,
                                          sizeof(CUSTOMVERTEX) );

        IDirect3DDevice9_DrawPrimitive( dev, D3DPT_TRIANGLELIST, 0, 8 );

        IDirect3DDevice9_EndScene( dev );

        /* swap front and back buffer */
        sgui_window_swap_buffers( wnd );
    }

    /****************************** clean up ******************************/
    sgui_canvas_destroy( texcanvas );
    sgui_widget_destroy( check2 );
    sgui_widget_destroy( check );
    sgui_widget_destroy( butt );

    IDirect3DVertexBuffer9_Release( v_buffer );

    sgui_window_destroy( wnd );
    sgui_deinit( );
    return 0;
}