static int D3D_Reset(SDL_Renderer * renderer) { D3D_RenderData *data = (D3D_RenderData *) renderer->driverdata; HRESULT result; /* Release the default render target before reset */ if (data->defaultRenderTarget) { IDirect3DSurface9_Release(data->defaultRenderTarget); data->defaultRenderTarget = NULL; } result = IDirect3DDevice9_Reset(data->device, &data->pparams); if (FAILED(result)) { if (result == D3DERR_DEVICELOST) { /* Don't worry about it, we'll reset later... */ return 0; } else { return D3D_SetError("Reset()", result); } } IDirect3DDevice9_SetVertexShader(data->device, NULL); IDirect3DDevice9_SetFVF(data->device, D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_TEX1); IDirect3DDevice9_SetRenderState(data->device, D3DRS_CULLMODE, D3DCULL_NONE); IDirect3DDevice9_SetRenderState(data->device, D3DRS_LIGHTING, FALSE); IDirect3DDevice9_GetRenderTarget(data->device, 0, &data->defaultRenderTarget); return 0; }
static int D3D_UpdateClipRect(SDL_Renderer * renderer) { const SDL_Rect *rect = &renderer->clip_rect; D3D_RenderData *data = (D3D_RenderData *) renderer->driverdata; RECT r; HRESULT result; if (!SDL_RectEmpty(rect)) { IDirect3DDevice9_SetRenderState(data->device, D3DRS_SCISSORTESTENABLE, TRUE); r.left = rect->x; r.top = rect->y; r.right = rect->w + rect->w; r.bottom = rect->y + rect->h; result = IDirect3DDevice9_SetScissorRect(data->device, &r); if (result != D3D_OK) { D3D_SetError("SetScissor()", result); return -1; } } else { IDirect3DDevice9_SetRenderState(data->device, D3DRS_SCISSORTESTENABLE, FALSE); } return 0; }
static void D3D_SetBlendMode(D3D_RenderData * data, int blendMode) { switch (blendMode) { case SDL_BLENDMODE_NONE: IDirect3DDevice9_SetRenderState(data->device, D3DRS_ALPHABLENDENABLE, FALSE); break; case SDL_BLENDMODE_BLEND: IDirect3DDevice9_SetRenderState(data->device, D3DRS_ALPHABLENDENABLE, TRUE); IDirect3DDevice9_SetRenderState(data->device, D3DRS_SRCBLEND, D3DBLEND_SRCALPHA); IDirect3DDevice9_SetRenderState(data->device, D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA); break; case SDL_BLENDMODE_ADD: IDirect3DDevice9_SetRenderState(data->device, D3DRS_ALPHABLENDENABLE, TRUE); IDirect3DDevice9_SetRenderState(data->device, D3DRS_SRCBLEND, D3DBLEND_SRCALPHA); IDirect3DDevice9_SetRenderState(data->device, D3DRS_DESTBLEND, D3DBLEND_ONE); break; case SDL_BLENDMODE_MOD: IDirect3DDevice9_SetRenderState(data->device, D3DRS_ALPHABLENDENABLE, TRUE); IDirect3DDevice9_SetRenderState(data->device, D3DRS_SRCBLEND, D3DBLEND_ZERO); IDirect3DDevice9_SetRenderState(data->device, D3DRS_DESTBLEND, D3DBLEND_SRCCOLOR); break; } }
void init_defaultstate(IDirect3DDevice9 *device){ int i; matrix projection_matrix, view_matrix; IDirect3DDevice9_SetVertexShader(device, NULL); IDirect3DDevice9_SetRenderState(device, D3DRS_CULLMODE, D3DCULL_CCW); IDirect3DDevice9_SetRenderState(device, D3DRS_LIGHTING, TRUE); IDirect3DDevice9_SetRenderState(device, D3DRS_ZENABLE, D3DZB_TRUE); IDirect3DDevice9_SetRenderState(device, D3DRS_SPECULARENABLE, TRUE); IDirect3DDevice9_SetRenderState(device, D3DRS_NORMALIZENORMALS, TRUE); for(i=0;i<8;i++){ IDirect3DDevice9_SetTextureStageState(device, i, D3DTSS_COLOROP, D3DTOP_DISABLE); IDirect3DDevice9_SetTextureStageState(device, i, D3DTSS_COLORARG1, D3DTA_TEXTURE); IDirect3DDevice9_SetTextureStageState(device, i, D3DTSS_COLORARG2, D3DTA_CURRENT); IDirect3DDevice9_SetTextureStageState(device, i, D3DTSS_ALPHAOP, D3DTOP_DISABLE); IDirect3DDevice9_SetTextureStageState(device, i, D3DTSS_ALPHAARG1, D3DTA_CURRENT); IDirect3DDevice9_SetSamplerState(device, i, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR); IDirect3DDevice9_SetSamplerState(device, i, D3DSAMP_MINFILTER, D3DTEXF_LINEAR); IDirect3DDevice9_SetSamplerState(device, i, D3DSAMP_MIPFILTER, D3DTEXF_POINT); // IDirect3DDevice9_SetSamplerState(device, i, D3DSAMP_MIPFILTER, D3DTEXF_LINEAR); } matrix_project( projection_matrix, 45.f, 4.f/3.f, 1.f, 1000.f ); IDirect3DDevice9_SetTransform( device, D3DTS_PROJECTION, (D3DMATRIX*)&projection_matrix ); matrix_identity( view_matrix ); IDirect3DDevice9_SetTransform( device, D3DTS_VIEW, (D3DMATRIX*)&view_matrix ); }
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); }
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; }
static void d3d9_init( sgui_context* context ) { float m[16], f, iNF, fov_deg = 60.0f, Near = 0.1f, Far = 100.0f; CUSTOMVERTEX vdat[ sizeof(indices)/sizeof(indices[0]) ]; sgui_d3d9_context* ctx = (sgui_d3d9_context*)context; float aspectratio = (float)WIDTH / (float)HEIGHT; unsigned int i, idx, r, g, b; for( i=0; i<sizeof(indices)/sizeof(indices[0]); ++i ) { idx = indices[ i ]; r = vertices[ idx*6+3 ] * 255.0f; g = vertices[ idx*6+4 ] * 255.0f; b = vertices[ idx*6+5 ] * 255.0f; vdat[ i ].x = vertices[ idx*6 ]; vdat[ i ].y = vertices[ idx*6+1 ]; vdat[ i ].z = vertices[ idx*6+2 ]; vdat[ i ].color = D3DCOLOR_ARGB(0xFF,r,g,b); } IDirect3DDevice9_Reset( ctx->device, &ctx->present ); IDirect3DDevice9_CreateVertexBuffer( ctx->device, sizeof(vdat), 0, CUSTOMFVF, D3DPOOL_MANAGED, &v_buffer, NULL ); /* load vertex data */ IDirect3DVertexBuffer9_Lock( v_buffer, 0, 0, (void**)&pVoid, 0 ); memcpy( pVoid, vdat, sizeof(vdat) ); IDirect3DVertexBuffer9_Unlock( v_buffer ); /* setup renderer state */ IDirect3DDevice9_SetRenderState(ctx->device,D3DRS_CULLMODE,D3DCULL_NONE); IDirect3DDevice9_SetRenderState(ctx->device,D3DRS_LIGHTING,FALSE ); IDirect3DDevice9_SetRenderState(ctx->device,D3DRS_ZENABLE, TRUE ); /* set up perspective projection matrix */ f = 1.0 / tan( fov_deg * DEGTORAD * 0.5 ); iNF = 1.0 / ( Near - Far ); m[0]=f/aspectratio; m[4]=0; m[ 8]=0; m[12]=0; m[1]=0; m[5]=f; m[ 9]=0; m[13]=0; m[2]=0; m[6]=0; m[10]=(Far+Near)*iNF; m[14]=2*Far*Near*iNF; m[3]=0; m[7]=0; m[11]=-1; m[15]=0; IDirect3DDevice9_SetTransform(ctx->device,D3DTS_PROJECTION,(D3DMATRIX*)m); drawgui = 0; }
/** * It renders the 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, d3d_region_t *picture, int subpicture_count, d3d_region_t *subpicture) { vout_display_sys_t *sys = vd->sys; LPDIRECT3DDEVICE9 d3ddev = sys->d3ddev; HRESULT hr; if (sys->clear_scene) { /* 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; } sys->clear_scene = false; } // Begin the scene hr = IDirect3DDevice9_BeginScene(d3ddev); if (FAILED(hr)) { msg_Dbg(vd, "%s:%d (hr=0x%0lX)", __FUNCTION__, __LINE__, hr); return; } Direct3DRenderRegion(vd, picture); if (subpicture_count > 0) IDirect3DDevice9_SetRenderState(d3ddev, D3DRS_ALPHABLENDENABLE, TRUE); for (int i = 0; i < subpicture_count; i++) { d3d_region_t *r = &subpicture[i]; if (r->texture) Direct3DRenderRegion(vd, r); } if (subpicture_count > 0) IDirect3DDevice9_SetRenderState(d3ddev, D3DRS_ALPHABLENDENABLE, FALSE); // End the scene hr = IDirect3DDevice9_EndScene(d3ddev); if (FAILED(hr)) { msg_Dbg(vd, "%s:%d (hr=0x%0lX)", __FUNCTION__, __LINE__, hr); return; } }
//=================================================================== // RENDER_API IMPLEMENTATION //=================================================================== JBKRenderResult JBKRender_Create(int64_t hWindow) { // acquire D3D interface gD3D = Direct3DCreate9(D3D_SDK_VERSION); ASSERT(gD3D != NULL, "Failed to load DirectX9!"); memset(&gPresentParams, 0, sizeof(D3DPRESENT_PARAMETERS)); gPresentParams.Windowed = TRUE; gPresentParams.SwapEffect = D3DSWAPEFFECT_DISCARD; gPresentParams.BackBufferFormat = D3DFMT_X8R8G8B8; gPresentParams.BackBufferWidth = 1024; gPresentParams.BackBufferHeight = 768; gPresentParams.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE; // create D3D device DXCall( IDirect3D9_CreateDevice( gD3D, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, (HWND)hWindow, D3DCREATE_HARDWARE_VERTEXPROCESSING, &gPresentParams, &gDevice) ); // set lighting off DXCall( IDirect3DDevice9_SetRenderState(gDevice, D3DRS_LIGHTING, FALSE) ); DXCall( IDirect3DDevice9_SetRenderState(gDevice, D3DRS_ZENABLE, FALSE) ); // create a debug font DXCall( D3DXCreateFont( gDevice, 18, 0, FW_REGULAR, 0, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, ANTIALIASED_QUALITY, DEFAULT_PITCH | FF_DONTCARE, "Arial", &gDebugFont) ); return JBK_RENDER_OK; }
void d3d_set_render_state(void *data, D3DRENDERSTATETYPE state, DWORD value) { LPDIRECT3DDEVICE dev = (LPDIRECT3DDEVICE)data; if (!dev) return; #if defined(HAVE_D3D9) && !defined(__cplusplus) IDirect3DDevice9_SetRenderState(dev, state, value); #else dev->SetRenderState(state, value); #endif }
static void set_blender(ALLEGRO_DISPLAY *display) { int op, src, dst, alpha_op, alpha_src, alpha_dst; ALLEGRO_COLOR color; LPDIRECT3DDEVICE9 device = al_d3d_get_device(display); al_get_separate_blender(&op, &src, &dst, &alpha_op, &alpha_src, &alpha_dst, &color); src = al_blender_to_d3d(src); dst = al_blender_to_d3d(dst); alpha_src = al_blender_to_d3d(alpha_src); alpha_dst = al_blender_to_d3d(alpha_dst); IDirect3DDevice9_SetRenderState(device, D3DRS_SRCBLEND, src); IDirect3DDevice9_SetRenderState(device, D3DRS_DESTBLEND, dst); IDirect3DDevice9_SetRenderState(device, D3DRS_SEPARATEALPHABLENDENABLE, true); IDirect3DDevice9_SetRenderState(device, D3DRS_SRCBLENDALPHA, alpha_src); IDirect3DDevice9_SetRenderState(device, D3DRS_DESTBLENDALPHA, alpha_dst); IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_ALPHAOP, D3DTOP_MODULATE); }
static int D3D_Reset(SDL_Renderer * renderer) { D3D_RenderData *data = (D3D_RenderData *) renderer->driverdata; HRESULT result; result = IDirect3DDevice9_Reset(data->device, &data->pparams); if (FAILED(result)) { if (result == D3DERR_DEVICELOST) { /* Don't worry about it, we'll reset later... */ return 0; } else { D3D_SetError("Reset()", result); return -1; } } IDirect3DDevice9_SetVertexShader(data->device, NULL); IDirect3DDevice9_SetFVF(data->device, D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_TEX1); IDirect3DDevice9_SetRenderState(data->device, D3DRS_CULLMODE, D3DCULL_NONE); IDirect3DDevice9_SetRenderState(data->device, D3DRS_LIGHTING, FALSE); return 0; }
/** \fn setup \brief Allocate stuff for a given display with/height. It is called again each time the zoom is changed */ bool dxvaRender::setup() { D3DVIEWPORT9 viewPort = {0, 0, displayWidth, displayHeight, 0, 1}; ADM_info("D3D (re)Setting up \n"); D3DPRESENT_PARAMETERS presentationParameters; memset(&presentationParameters, 0, sizeof(presentationParameters)); presentationParameters.Windowed = TRUE; presentationParameters.SwapEffect = D3DSWAPEFFECT_DISCARD; // We could use copy, but discard seems faster according to ms presentationParameters.Flags = D3DPRESENTFLAG_VIDEO; presentationParameters.hDeviceWindow = windowId; presentationParameters.BackBufferWidth = displayWidth; presentationParameters.BackBufferHeight = displayHeight; presentationParameters.MultiSampleType = D3DMULTISAMPLE_NONE; presentationParameters.PresentationInterval = D3DPRESENT_INTERVAL_ONE; presentationParameters.BackBufferFormat = displayMode.Format; presentationParameters.BackBufferCount = 1; presentationParameters.EnableAutoDepthStencil = FALSE; #ifndef REUSE_DEVICE if(ADM_FAILED(IDirect3D9_CreateDevice( d3dHandle, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, presentationParameters.hDeviceWindow, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &presentationParameters, &d3dDevice))) { ADM_warning("Failed to create D3D device\n"); return false; } #else d3dDevice=admD3D::getDevice(); #endif // D3DFORMAT yv12=(D3DFORMAT)MAKEFOURCC('Y','V','1','2'); // if( ADM_FAILED(IDirect3DDevice9_CreateOffscreenPlainSurface( d3dDevice, displayWidth,displayHeight, displayMode.Format, D3DPOOL_DEFAULT, &mySurface, NULL))) { ADM_warning("D3D Cannot create surface\n"); return false; } if( ADM_FAILED(IDirect3DDevice9_CreateOffscreenPlainSurface( d3dDevice, imageWidth,imageHeight, yv12, D3DPOOL_DEFAULT, &myYV12Surface, NULL))) { ADM_warning("D3D Cannot create surface\n"); return false; } // put some defaults IDirect3DDevice9_SetRenderState(d3dDevice, D3DRS_SRCBLEND, D3DBLEND_ONE); IDirect3DDevice9_SetRenderState(d3dDevice, D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA); IDirect3DDevice9_SetRenderState(d3dDevice, D3DRS_ALPHAFUNC, D3DCMP_GREATER); IDirect3DDevice9_SetRenderState(d3dDevice, D3DRS_ALPHAREF, (DWORD)0x0); IDirect3DDevice9_SetRenderState(d3dDevice, D3DRS_LIGHTING, FALSE); IDirect3DDevice9_SetSamplerState(d3dDevice, 0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR); IDirect3DDevice9_SetSamplerState(d3dDevice, 0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR); // if(ADM_FAILED(IDirect3DDevice9_SetViewport(d3dDevice, &viewPort))) { ADM_warning("D3D Cannot set D3D viewport\n"); return false; } scaler=new ADMColorScalerFull(ADM_CS_BICUBIC,imageWidth,imageHeight,displayWidth,displayHeight, ADM_COLOR_YV12, ADM_COLOR_RGB32A ); videoBuffer=new uint8_t[displayWidth*displayHeight*4]; panScan.left =0; panScan.right =imageWidth-1; panScan.top =0; panScan.bottom=imageHeight-1; targetRect.left =0; targetRect.right =displayWidth-1; targetRect.top =0; targetRect.bottom=displayHeight-1; ADM_info("Setup done\n"); return true; }
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; }
int main(){ BOOL done = FALSE; MSG msg; IDirect3DDevice9 *device = NULL; IDirect3DSurface9 *main_rendertarget = NULL; D3DFORMAT format; float old_time = 0; /* render-to-texture-stuff */ IDirect3DTexture9 *rtt_texture; IDirect3DSurface9 *rtt_surface; IDirect3DTexture9 *rtt_32_texture; IDirect3DSurface9 *rtt_32_surface; /* textures used from mainloop */ int white, black; int odd_is_back_again[4]; int at_the_gathering_2003[4]; int o_d_d_in_your_face[4]; int world_domination[4]; int back_once_again[3]; int were_back; int cred[4]; int mad_props[4]; int not_eph[4]; int piss_the_fuck_off[11]; int hardcore; int refmap, refmap2; int eatyrcode; int code_0, code_1; int overlaytest; int circle_particle; /* special-textures */ int rtt_texture_id; int rtt_32_texture_id; int video_texture_id; int dilldall,dilldall2; int metaball_text; /* videos */ video *vid; /* 3d-scenes */ scene *fysikkfjall; scene *startblob; scene *inni_abstrakt; scene *korridor; scene *skjerm_rom; scene *bare_paa_lissom; format = D3DFMT_X8R8G8B8; device = d3dwin_open(TITLE, WIDTH, HEIGHT, format, FULLSCREEN); if(!device){ format = D3DFMT_A8R8G8B8; device = d3dwin_open(TITLE, WIDTH, HEIGHT, format, FULLSCREEN); if(!device){ format = D3DFMT_X1R5G5B5; device = d3dwin_open(TITLE, WIDTH, HEIGHT, format, FULLSCREEN); if(!device){ format = D3DFMT_R5G6B5; device = d3dwin_open(TITLE, WIDTH, HEIGHT, format, FULLSCREEN); if(!device) error("failed to initialize Direct3D9"); } } } #ifdef BIGSCREEN set_gamma(device,1.05f); #endif if (!BASS_Init(1, 44100, BASS_DEVICE_LATENCY, win, NULL)) error("failed to initialize BASS"); fp = file_open("worlddomination.ogg"); if (!fp) error("music-file not found"); music_file = BASS_StreamCreateFile(1, fp->data, 0, fp->size, 0); /*** music ***/ // if(!pest_open(win)) error("failed to initialize DirectSond"); // if(!pest_load("worlddomination.ogg",0)) error("failed to load music-file"); /*** subsystems ***/ init_tunnel(); video_init(); if(!init_particles(device)) error("failed to initialize"); if(!init_overlays(device)) error("f**k a duck"); if(!init_marching_cubes(device)) error("screw a kangaroo"); make_random_particles(particles, PARTICLES, vector_make(0,-180,0), 500); make_random_particles(particles2, PARTICLES2, vector_make(0,-180,0), 500); make_random_particles(particles3, PARTICLES3, vector_make(0,0,0), 800); /*** rendertextures ***/ if (IDirect3DDevice9_CreateTexture(device, 512, 256, 0,D3DUSAGE_RENDERTARGET, D3DFMT_X8R8G8B8, D3DPOOL_DEFAULT, &rtt_texture, NULL)!=D3D_OK) error("failed to create rendertarget-texture"); if (IDirect3DTexture9_GetSurfaceLevel(rtt_texture,0,&rtt_surface)!=D3D_OK) error("could not get kvasi-backbuffer-surface"); if ((rtt_texture_id=texture_insert(device, "rendertexture.jpg", rtt_texture))==-1) error("fakk off!"); if(IDirect3DDevice9_CreateTexture(device,16,16,0,D3DUSAGE_RENDERTARGET|D3DUSAGE_AUTOGENMIPMAP,D3DFMT_X8R8G8B8,D3DPOOL_DEFAULT, &rtt_32_texture, NULL)!=D3D_OK) error("failed to create rendertarget-texture"); if(IDirect3DTexture9_GetSurfaceLevel(rtt_32_texture,0,&rtt_32_surface)!=D3D_OK) error("could not get kvasi-backbuffer-surface"); if((rtt_32_texture_id=texture_insert(device, "rendertexture2.jpg", rtt_32_texture))==-1) error("fakk off!"); /*** textures ***/ /* solid colors for fades etc */ if((white=texture_load(device,"white.png",FALSE))==-1) error("shjit!"); if((black=texture_load(device,"black.png",FALSE))==-1) error("shjit!"); /* textoverlays */ if((odd_is_back_again[0]=texture_load(device,"odd_is_back_again_0.png",FALSE))==-1) error("failed to load image"); if((odd_is_back_again[1]=texture_load(device,"odd_is_back_again_1.png",FALSE))==-1) error("failed to load image"); if((odd_is_back_again[2]=texture_load(device,"odd_is_back_again_2.png",FALSE))==-1) error("failed to load image"); if((odd_is_back_again[3]=texture_load(device,"odd_is_back_again_3.png",FALSE))==-1) error("failed to load image"); if((at_the_gathering_2003[0]=texture_load(device,"at_the_gathering_2003_0.png",FALSE))==-1) error("failed to load image"); if((at_the_gathering_2003[1]=texture_load(device,"at_the_gathering_2003_1.png",FALSE))==-1) error("failed to load image"); if((at_the_gathering_2003[2]=texture_load(device,"at_the_gathering_2003_2.png",FALSE))==-1) error("failed to load image"); if((at_the_gathering_2003[3]=texture_load(device,"at_the_gathering_2003_3.png",FALSE))==-1) error("failed to load image"); if((back_once_again[0]=texture_load(device,"back_once_again_0.png",TRUE))==-1) error("failed to load image"); if((back_once_again[1]=texture_load(device,"back_once_again_1.png",TRUE))==-1) error("failed to load image"); if((back_once_again[2]=texture_load(device,"back_once_again_2.png",TRUE))==-1) error("failed to load image"); if((o_d_d_in_your_face[0]=texture_load(device,"o_d_d_in_your_face_0.png",TRUE))==-1) error("failed to load image"); if((o_d_d_in_your_face[1]=texture_load(device,"o_d_d_in_your_face_1.png",TRUE))==-1) error("failed to load image"); if((o_d_d_in_your_face[2]=texture_load(device,"o_d_d_in_your_face_2.png",TRUE))==-1) error("failed to load image"); if((o_d_d_in_your_face[3]=texture_load(device,"o_d_d_in_your_face_3.png",TRUE))==-1) error("failed to load image"); if((world_domination[0]=texture_load(device,"world_domination_0.png",TRUE))==-1) error("failed to load image"); if((world_domination[1]=texture_load(device,"world_domination_1.png",TRUE))==-1) error("failed to load image"); if((world_domination[2]=texture_load(device,"world_domination_2.png",TRUE))==-1) error("failed to load image"); if((world_domination[3]=texture_load(device,"world_domination_3.png",TRUE))==-1) error("failed to load image"); if((were_back=texture_load(device,"were_back.png",TRUE))==-1) error("failed to load image"); if((cred[0]=texture_load(device,"cred_0.png",TRUE))==-1) error("failed to load image"); if((cred[1]=texture_load(device,"cred_1.png",TRUE))==-1) error("failed to load image"); if((cred[2]=texture_load(device,"cred_2.png",TRUE))==-1) error("failed to load image"); if((cred[3]=texture_load(device,"cred_3.png",TRUE))==-1) error("failed to load image"); if((mad_props[0]=texture_load(device,"mad_props_0.png",TRUE))==-1) error("failed to load image"); if((mad_props[1]=texture_load(device,"mad_props_1.png",TRUE))==-1) error("failed to load image"); if((mad_props[2]=texture_load(device,"mad_props_2.png",TRUE))==-1) error("failed to load image"); if((mad_props[3]=texture_load(device,"mad_props_3.png",TRUE))==-1) error("failed to load image"); if((not_eph[0]=texture_load(device,"not_eph_0.png",TRUE))==-1) error("failed to load image"); if((not_eph[1]=texture_load(device,"not_eph_1.png",TRUE))==-1) error("failed to load image"); if((not_eph[2]=texture_load(device,"not_eph_2.png",TRUE))==-1) error("failed to load image"); if((not_eph[3]=texture_load(device,"not_eph_3.png",TRUE))==-1) error("failed to load image"); if((piss_the_fuck_off[0]=texture_load(device,"piss_the_fuck_off_0.png",TRUE))==-1) error("failed to load image"); if((piss_the_fuck_off[1]=texture_load(device,"piss_the_fuck_off_1.png",TRUE))==-1) error("failed to load image"); if((piss_the_fuck_off[2]=texture_load(device,"piss_the_fuck_off_2.png",TRUE))==-1) error("failed to load image"); if((piss_the_fuck_off[3]=texture_load(device,"piss_the_fuck_off_3.png",TRUE))==-1) error("failed to load image"); if((piss_the_fuck_off[4]=texture_load(device,"piss_the_fuck_off_4.png",TRUE))==-1) error("failed to load image"); if((piss_the_fuck_off[5]=texture_load(device,"piss_the_fuck_off_5.png",TRUE))==-1) error("failed to load image"); if((piss_the_fuck_off[6]=texture_load(device,"piss_the_fuck_off_6.png",TRUE))==-1) error("failed to load image"); if((piss_the_fuck_off[7]=texture_load(device,"piss_the_fuck_off_7.png",TRUE))==-1) error("failed to load image"); if((piss_the_fuck_off[8]=texture_load(device,"piss_the_fuck_off_8.png",TRUE))==-1) error("failed to load image"); if((piss_the_fuck_off[9]=texture_load(device,"piss_the_fuck_off_9.png",TRUE))==-1) error("failed to load image"); if((piss_the_fuck_off[10]=texture_load(device,"piss_the_fuck_off_10.png",TRUE))==-1) error("failed to load image"); if((hardcore=texture_load(device,"hardcore.png",TRUE))==-1) error("failed to load image"); /* other textures */ if((circle_particle=texture_load(device,"circle_particle.jpg",FALSE))==-1) error("shjit!"); if((refmap=texture_load(device,"fysikkfjall/refmap.jpg",FALSE))==-1) error("shjit!"); if((refmap2=texture_load(device,"refmap2.jpg",FALSE))==-1) error("shjit!"); if((eatyrcode=texture_load(device,"eatyrcode.jpg",FULLSCREEN_HACK))==-1) error("shjit!"); if((code_0=texture_load(device,"code-0.jpg",FALSE))==-1) error("shjit!"); if((code_1=texture_load(device,"code-1.jpg",FALSE))==-1) error("shjit!"); if((overlaytest=texture_load(device,"overlaytest.jpg",FALSE))==-1) error("shjit!"); if((dilldall=texture_load(device,"dilldall.png",FALSE))==-1) error("shjit!"); if((dilldall2=texture_load(device,"dilldall2.png",FALSE))==-1) error("shjit!"); if((metaball_text=texture_load(device,"metaballs.png",TRUE))==-1) error("shjit!"); /*** video ***/ if(!(vid=video_load(device,"test.kpg"))) error("fæck!"); video_texture_id = texture_insert(device, "skjerm_rom/skjerm_tom.tga", vid->texture); /*** misc stuff ***/ /* main rendertarget */ IDirect3DDevice9_GetRenderTarget(device,0,&main_rendertarget); /* default state */ IDirect3DDevice9_CreateStateBlock(device, D3DSBT_ALL, &default_state); init_defaultstate(device); IDirect3DStateBlock9_Capture(default_state); /*** 3d scenes ***/ if(!(fysikkfjall=load_scene(device,"fysikkfjall/fysikkfjall.krs"))) error("failed to load 3d scene"); if(!(startblob=load_scene(device,"startblob/startblob.krs"))) error("failed to load 3d scene"); if(!(inni_abstrakt=load_scene(device,"inni_abstrakt/inni_abstrakt.krs"))) error("failed to load 3d scene"); if(!(korridor=load_scene(device,"korridor/korridor.krs"))) error("failed to load 3d scene"); if(!(skjerm_rom=load_scene(device,"skjerm_rom/skjerm_rom.krs"))) error("failed to load 3d scene"); if(!(bare_paa_lissom=load_scene(device,"bare_paa_lissom/bare_paa_lissom.krs"))) error("failed to load 3d scene"); // pest_play(); BASS_Start(); BASS_StreamPlay(music_file, 1, 0); do{ grid g; int i; matrix m, temp, temp_matrix; matrix marching_cubes_matrix; long long bytes_played = BASS_ChannelGetPosition(music_file); float time = bytes_played * (1.0 / (44100 * 2 * 2)); // float time = pest_get_pos()+0.05f; float delta_time = time-old_time; int beat = (int)(time*((float)BPM/60.f)); if(time_index<(sizeof(timetable)/4)){ while(timetable[time_index]<time) time_index++; } #ifdef _DEBUG printf("time: %2.2f, delta_time: %2.2f, time_index: %i, beat: %i \r",time,delta_time,time_index,beat); #endif IDirect3DDevice9_SetRenderTarget(device,0,main_rendertarget); IDirect3DStateBlock9_Apply(default_state); IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER|D3DCLEAR_STENCIL, 0, 1.0f, 0); // IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_ZBUFFER, 0, 1.0f, 0); IDirect3DDevice9_BeginScene(device); #if 1 if(time_index<40){ if(time_index>0&&time_index<5){ draw_overlay(device,odd_is_back_again[time_index-1],0,0,1,FALSE); }else if(time_index>4&&time_index<19){ float itime = time*10; grid_flat(g,0,0); for(i=0;i<7;i++){ int scale = (time_index&1); grid_wave(g,(float)sin(itime-i+sin(i-itime))*0.3f*scale,(float)cos(itime*0.69f+i*0.733f)*0.3f*scale,7,(float)sin(itime+i*0.1f)*0.5f*scale); } draw_grid(device, g, odd_is_back_again[3], FALSE); }else if(time_index>=19){ float itime = (time-timetable[18])*0.5f; grid_flat(g,0,0); for(i=0;i<7;i++){ grid_wave(g,(float)sin(time-i+sin(i-time))*0.3f,(float)cos(time*0.69f+i*0.733f)*0.3f,7, itime*itime); } draw_grid(device, g, odd_is_back_again[3], FALSE); } if(time_index>20&&time_index<25){ draw_overlay(device,at_the_gathering_2003[(time_index-21)%4],0,0,1,TRUE); }else if(time_index>=25&&time_index<38){ float itime = time*10; grid_flat(g,0,0); for(i=0;i<10;i++){ int scale = (time_index&1); grid_wave(g,(float)sin(itime-i+sin(i-itime))*0.3f*scale,(float)cos(itime*0.69f+i*0.733f)*0.3f*scale,7,(float)sin(itime+i*0.1f)*0.5f*scale); } draw_grid(device,g,at_the_gathering_2003[3],TRUE); }else if(time_index>=38){ float itime = (time-timetable[37])*0.5f; grid_flat(g,0,0); for(i=0;i<10;i++){ grid_wave(g,(float)sin(time-i+sin(i-time))*0.3f,(float)cos(time*0.69f+i*0.733f)*0.3f,7, itime*itime); } draw_grid(device,g,at_the_gathering_2003[3],TRUE); } }else if(time_index<52){ animate_scene(inni_abstrakt,(time-timetable[39])); draw_scene(device,inni_abstrakt,0,TRUE); flash(device,white,time,timetable[39],1); if(time_index<43){ draw_overlay(device, back_once_again[(time_index-40)%3],0,0,1,FALSE); }else if(time_index<47){ draw_overlay(device, o_d_d_in_your_face[(time_index-43)%4],0,0,1,FALSE); }else if(time_index<51){ draw_overlay(device, world_domination[(time_index-47)%4],0,0,1,FALSE); }else{ draw_overlay(device, were_back,0,0,(time-timetable[51]),FALSE); } draw_overlay(device,dilldall,sin(sin(time)*0.07f+(((beat+1)/2)*0.8f)),sin(time*0.03337f+(((beat+1)/2)*0.14f)),0.5f,TRUE); draw_overlay(device,dilldall2,sin(sin(time*0.1f)*0.07f+time*0.1f+(((beat+1)/2)*0.8f)),sin(time*0.01337f+(((beat+1)/2)*0.14f)),0.5f,TRUE); }else if(time_index<69){ animate_scene(startblob,(time-timetable[39]-0.27f+((beat+1)&2))*0.74948f); startblob->cameras[0].fog = TRUE; startblob->cameras[0].fog_start = 100.f; startblob->cameras[0].fog_end = 700.f; if(time_index>=53 && time_index<66 && time_index&1 ){ float f = fade(timetable[time_index-1],1.7f,time,0.5f,0); f *= f; f *= 2; if(f>0.f) IDirect3DDevice9_SetRenderTarget(device,0,rtt_surface); draw_scene(device,startblob,0,TRUE); draw_particles(device, particles3, PARTICLES3, code_0); if(f>0.f){ IDirect3DDevice9_SetRenderTarget(device,0,main_rendertarget); draw_radialblur(device,0,0,f,0,rtt_texture_id, FALSE); } if(time_index<61) draw_overlay(device,cred[((time_index/2)-2)%4],0,0,f*3,FALSE); }else{ draw_scene(device,startblob,0,TRUE); draw_particles(device, particles3, PARTICLES3, circle_particle); } if(time_index>=54&& !(time_index&1)){ float f = fade(timetable[time_index-1],1.8f,time,1.f,0)*0.8f; IDirect3DDevice9_SetRenderTarget(device,0,rtt_32_surface); draw_scene(device,startblob,0,TRUE); draw_particles(device, particles3, PARTICLES3, code_0); IDirect3DDevice9_SetRenderTarget(device,0,main_rendertarget); IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_MAGFILTER, D3DTEXF_POINT); draw_overlay(device,rtt_32_texture_id,0,0,f,TRUE); draw_overlay(device,rtt_32_texture_id,0,0,f,TRUE); IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR); } flash(device,were_back,time,timetable[51],2); flash(device,white,time,timetable[51],1); }else if(time_index<79){ for(i=0;i<BALLS;i++){ balls[i].pos.x = (float)sin(time+i-sin((float)i*0.1212111f))*0.35f; balls[i].pos.y = (float)cos(time-(float)i*0.29342111f)*0.35f; balls[i].pos.z = (float)sin(time*0.31121f+sin(i-time))*0.35f; balls[i].r = 0.15f + (float)sin(time+i)*0.01f; balls[i].pos = vector_normalize(balls[i].pos); balls[i].pos = vector_scale(balls[i].pos, (float)(cos(i*0.11131f-time*0.55311f)+sin(time+(float)sin(time-i+time*0.3f)))*0.2f ); } animate_scene(korridor,(time-timetable[68])*0.65f ); draw_scene(device,korridor,(beat/4)&1,TRUE); memcpy(temp,korridor->objects[korridor->object_count-1]->mat,sizeof(matrix)); matrix_scale(marching_cubes_matrix,vector_make(120,120,120)); matrix_multiply(marching_cubes_matrix,temp,marching_cubes_matrix); matrix_rotate(temp,vector_make(time,-time,time*0.5f+sin(time))); matrix_multiply(marching_cubes_matrix,marching_cubes_matrix,temp); IDirect3DDevice9_SetTransform( device, D3DTS_WORLD, (D3DMATRIX*)&marching_cubes_matrix ); fill_metafield_blur(balls, BALLS,0.98f); march_my_cubes_opt(balls, BALLS, 0.9f); IDirect3DDevice9_SetRenderState(device, D3DRS_CULLMODE, D3DCULL_NONE); set_texture(device,0,refmap2); IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_TEXCOORDINDEX, D3DTSS_TCI_CAMERASPACEREFLECTIONVECTOR ); IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLOROP, D3DTOP_ADD); IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLORARG1, D3DTA_TEXTURE); IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLORARG2, D3DTA_CURRENT); draw_marched_cubes(device); flash(device,white,time,timetable[68],1); if(time_index>69&&time_index<74){ draw_overlay(device,mad_props[(time_index+2)%4],0,0,1,FALSE); }else if(time_index>73&&time_index<77){ draw_overlay(device,not_eph[(time_index+2)%4],0,0,1,FALSE); }else if(time_index==77){ float f = fade(timetable[76],2.5f,time,1,0); draw_overlay(device,not_eph[3],0,0,f,FALSE); } } if(time_index>77&&time_index<92){ float f = fade(timetable[77],timetable[78]-timetable[77],time,0,1); draw_overlay(device,eatyrcode,0,0,f,FALSE); if(time>109.5f){ IDirect3DStateBlock9_Apply(default_state); animate_particles(particles, PARTICLES, delta_time*30); animate_particles(particles2, PARTICLES2, delta_time*28); draw_particles(device, particles, PARTICLES, code_0); draw_particles(device, particles2, PARTICLES2, code_1); } if(time_index>79&&time_index<90){ draw_overlay(device,piss_the_fuck_off[(time_index-80)%11],0,0,1,FALSE); }else if(time_index==90){ float f = fade(timetable[89],2,time,1,0); draw_overlay(device,piss_the_fuck_off[10],0,0,f,FALSE); } if(time_index==91){ float f = fade(timetable[90],2,time,1,0); draw_overlay(device,hardcore,0,0,f,FALSE); } }else if(time_index>91 && time_index<97){ animate_scene(skjerm_rom,time); video_update(vid, time); draw_scene(device,skjerm_rom,((beat/4)&1),TRUE); draw_overlay(device,dilldall,sin(sin(time)*0.07f+(((beat+1)/2)*0.8f)),sin(time*0.03337f+(((beat+1)/2)*0.14f)),0.5f,TRUE); draw_overlay(device,dilldall2,sin(sin(time*0.1f)*0.07f+time*0.1f+(((beat+1)/2)*0.8f)),sin(time*0.01337f+(((beat+1)/2)*0.14f)),0.5f,TRUE); if(time_index>92) draw_overlay(device, world_domination[(time_index-93)%4],0,0,1,FALSE); }else if(time_index>96&&time_index<104){ grid_zero(g); matrix_translate(m, vector_make(cos(time)*1.5f, sin(time)*1.5f,time*10)); matrix_rotate(temp_matrix, vector_make(sin(time*0.8111f)*0.2f,sin(time*1.2f)*0.2f,time)); matrix_multiply(m,m,temp_matrix); render_tunnel(g,m); matrix_rotate(temp_matrix, vector_make(0,M_PI,0)); matrix_multiply(m,m,temp_matrix); render_tunnel(g,m); matrix_rotate(temp_matrix, vector_make(M_PI,0,0)); matrix_multiply(m,m,temp_matrix); render_tunnel(g,m); grid_add_noice(g,sin(time)*0.1f); draw_grid(device, g, circle_particle, FALSE); if(time_index>97&&time_index<102){ float f = 1; if(time_index==101) f = fade(timetable[100],3,time,1,0); draw_overlay(device, o_d_d_in_your_face[(time_index-42)%4],0,0,f,FALSE); } } if(time_index>101 && time_index<104){ float f = fade(timetable[101],8,time,0,1); float f2 = fade(timetable[101],4,time,0,1); draw_overlay(device,black,0,0,f2,FALSE); IDirect3DDevice9_SetRenderTarget(device,0,rtt_surface); IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER, 0, 1.0f, 0); IDirect3DStateBlock9_Apply(default_state); animate_scene(bare_paa_lissom,time-timetable[101]); draw_scene(device,bare_paa_lissom,0,TRUE); time *=0.5f; for(i=0;i<BALLS2;i++){ balls2[i].pos.x = (float)sin(time+i-sin((float)i*0.1212111f))*0.35f; balls2[i].pos.y = (float)cos(time-(float)i*0.29342111f)*0.35f; balls2[i].pos.z = (float)sin(time*0.31121f+sin(i-time))*0.35f; balls2[i].r = 0.15f + (float)sin(time+i)*0.01f; balls2[i].pos = vector_normalize(balls2[i].pos); balls2[i].pos = vector_scale(balls2[i].pos, (float)(cos(i*0.11131f-time*0.55311f)+sin(time+(float)sin(time-i+time*0.3f)))*0.2f ); } memcpy(temp,bare_paa_lissom->objects[bare_paa_lissom->object_count-1]->mat,sizeof(matrix)); matrix_scale(marching_cubes_matrix,vector_make(120,120,120)); matrix_multiply(marching_cubes_matrix,temp,marching_cubes_matrix); IDirect3DDevice9_SetTransform( device, D3DTS_WORLD, (D3DMATRIX*)&marching_cubes_matrix ); fill_metafield(balls2, BALLS2); march_my_cubes_opt(balls2, BALLS2, 0.9f); IDirect3DDevice9_SetRenderState(device, D3DRS_CULLMODE, D3DCULL_NONE); set_texture(device,0,refmap); IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_TEXCOORDINDEX, D3DTSS_TCI_CAMERASPACEREFLECTIONVECTOR ); IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLOROP, D3DTOP_ADD); IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLORARG1, D3DTA_TEXTURE); IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLORARG2, D3DTA_CURRENT); draw_marched_cubes(device); IDirect3DDevice9_SetRenderTarget(device,0,main_rendertarget); draw_overlay(device,rtt_texture_id,0,0,f,TRUE); if(time_index==103){ float f; time *= 2; f = fade(timetable[time_index-1],3,time,1,0); draw_overlay(device,metaball_text,0,0,f,FALSE); flash(device,white,time,timetable[time_index-1],1); } } if(time_index==104){ float f = fade(timetable[103],timetable[104]-timetable[103],time,0,1); animate_scene(korridor,180-(time-timetable[time_index-1])*0.8f ); draw_scene(device,korridor,(beat/4)&1,TRUE); draw_overlay(device,black,0,0,f,FALSE); } if(time_index==105){ float f = fade(timetable[104],timetable[105]-timetable[104],time,0,1); float t = (time-timetable[time_index-1])*0.6f+2.2f; animate_scene(fysikkfjall,t); draw_scene(device,fysikkfjall,0,TRUE); draw_overlay(device,black,0,0,f,FALSE); } #endif /* */ /* draw_overlay(device, were_back, (1+sin(time))*0.5f, TRUE); */ // animate_scene(risterom,time); // draw_scene(device,risterom,0,TRUE); #if 0 //helvete_har_frosset draw_overlay(device, eatyrcode, 1,FALSE); IDirect3DStateBlock9_Apply(default_state); animate_particles(particles, PARTICLES, delta_time*30); animate_particles(particles2, PARTICLES2, delta_time*28); draw_particles(device, particles, PARTICLES, code_0); draw_particles(device, particles2, PARTICLES2, code_1); #endif #ifdef pikk // IDirect3DDevice9_SetRenderTarget(device,0,rtt_surface); IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER, 0, 1.0f, 0); draw_overlay(device, eatyrcode, TRUE); animate_scene(startblob,(time-timetable[39]-0.27f)*0.7453f); draw_scene(device,startblob,0,FALSE); draw_particles(device, particles, PARTICLES, code_0); draw_particles(device, particles2, PARTICLES2, code_1); // IDirect3DDevice9_SetRenderTarget(device,0,main_rendertarget); /* draw_radialblur(device, (float)sin(time)*0.2f, (float)sin(-time*0.331f)*0.13f, (float)(2+(float)sin(time*0.5f))*0.2f, 0,//sin(time)*0.25f, rtt_texture_id, TRUE); animate_scene(fysikkfjall,time); draw_scene(device,fysikkfjall,0,FALSE); */ // draw_overlay(device, rtt_texture_id, TRUE); #endif // draw_overlay(device, eatyrcode, FALSE); // video_update(vid, time); #if 0 // IDirect3DDevice9_SetRenderTarget(device,0,rtt_surface); animate_scene(testscene,time); // morph_object(testscene->objects[0], time ); draw_scene(device,testscene,0,TRUE); // draw_particles(device, particles, PARTICLES, particle); // IDirect3DDevice9_SetRenderTarget(device,0,main_rendertarget); #endif #if 0 time *=0.5f; for(i=0;i<BALLS2;i++){ balls2[i].pos.x = (float)sin(time+i-sin((float)i*0.1212111f))*0.35f; balls2[i].pos.y = (float)cos(time-(float)i*0.29342111f)*0.35f; balls2[i].pos.z = (float)sin(time*0.31121f+sin(i-time))*0.35f; balls2[i].r = 0.15f + (float)sin(time+i)*0.01f; balls2[i].pos = vector_normalize(balls2[i].pos); balls2[i].pos = vector_scale(balls2[i].pos, (float)(cos(i*0.11131f-time*0.55311f)+sin(time+(float)sin(time-i+time*0.3f)))*0.2f ); // balls2[i].pos.x *= 2.8f; } matrix_translate(temp,vector_make(0,0,87)); matrix_scale(marching_cubes_matrix,vector_make(50,50,50)); matrix_multiply(marching_cubes_matrix,temp,marching_cubes_matrix); IDirect3DDevice9_SetTransform( device, D3DTS_WORLD, (D3DMATRIX*)&marching_cubes_matrix ); fill_metafield(balls2, BALLS2); // fill_metafield_blur(balls, BALLS,0.98f); march_my_cubes_opt(balls2, BALLS2, 0.9f); // march_my_cubes(0.9f); IDirect3DDevice9_SetRenderState(device, D3DRS_CULLMODE, D3DCULL_CW); set_texture(device,0,refmap); IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_TEXCOORDINDEX, D3DTSS_TCI_CAMERASPACEREFLECTIONVECTOR ); IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLOROP, D3DTOP_ADD); IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLORARG1, D3DTA_TEXTURE); IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLORARG2, D3DTA_CURRENT); draw_marched_cubes(device); #endif #if 0 // time *= 0.5f; grid_zero(g); // for(i=0;i<10;i++) // grid_wave(g,sin(time-i+sin(i-time))*0.3f,cos(time*0.69f+i*0.733f)*0.3f,7,sin(time+i*0.1f)*0.5f); matrix_translate(m, vector_make(cos(time)*1.5f, sin(time)*1.5f,time*10)); matrix_rotate(temp_matrix, vector_make(sin(time*0.8111f)*0.2f,sin(time*1.2f)*0.2f,time)); matrix_multiply(m,m,temp_matrix); // empty_grid( grid ); render_tunnel(g,m); matrix_rotate(temp_matrix, vector_make(0,M_PI,0)); matrix_multiply(m,m,temp_matrix); render_tunnel(g,m); matrix_rotate(temp_matrix, vector_make(M_PI,0,0)); matrix_multiply(m,m,temp_matrix); render_tunnel(g,m); // tyfuus_expand_grid( screen, grid, texture ); grid_add_noice(g,sin(time)*0.1f); draw_grid(device, g, circle_particle, FALSE); #endif // IDirect3DDevice9_SetRenderTarget(device,0,main_rendertarget); // video_update(vid,time); /* draw_radialblur(device, (float)sin(time)*0.2f, (float)sin(-time*0.331f)*0.13f, (float)(1+(float)sin(time*0.5f))*0.2f, 0,//sin(time)*0.25f, rtt_texture_id, FALSE); */ // IDirect3DStateBlock9_Apply(default_state); // draw_overlay(device,rtt_texture_id,FALSE); // draw_overlay(device,fullscreen,FALSE); // draw_radialblur(device,0,sin(time*0.2f)*2.f, rtt_texture_id); // IDirect3DDevice9_StretchRect(device,main_rendertarget,NULL,rtt_surface,NULL,D3DTEXF_NONE); // IDirect3DBaseTexture9_GenerateMipSubLevels(rtt_texture); IDirect3DDevice9_EndScene(device); if(IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL)==D3DERR_DEVICELOST) error("fakkin lost device. keep your hands off alt-tab, looser."); old_time = time; while (PeekMessage(&msg,NULL,0,0,PM_REMOVE)){ TranslateMessage(&msg); DispatchMessage(&msg); if (msg.message == WM_QUIT || msg.message == WM_KEYDOWN && LOWORD(msg.wParam) == VK_ESCAPE) done = TRUE; } }while(!done); deinit_marching_cubes(); deinit_overlays(); deinit_particles(); free_scene(fysikkfjall); free_scene(startblob); free_scene(inni_abstrakt); free_scene(korridor); free_scene(skjerm_rom); free_scene(bare_paa_lissom); free_materials(); free_textures(); free_video(vid); rtt_surface->lpVtbl->Release(rtt_surface); rtt_32_surface->lpVtbl->Release(rtt_32_surface); main_rendertarget->lpVtbl->Release(main_rendertarget); IDirect3DStateBlock9_Release(default_state); d3dwin_close(); if (music_file) BASS_StreamFree( music_file ); if (fp) file_close( fp ); BASS_Free(); // pest_close(); return 0; }
SDL_Renderer * D3D_CreateRenderer(SDL_Window * window, Uint32 flags) { SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window); SDL_VideoData *videodata = (SDL_VideoData *) display->device->driverdata; SDL_WindowData *windowdata = (SDL_WindowData *) window->driverdata; SDL_Renderer *renderer; D3D_RenderData *data; HRESULT result; D3DPRESENT_PARAMETERS pparams; IDirect3DSwapChain9 *chain; D3DCAPS9 caps; renderer = (SDL_Renderer *) SDL_calloc(1, sizeof(*renderer)); if (!renderer) { SDL_OutOfMemory(); return NULL; } data = (D3D_RenderData *) SDL_calloc(1, sizeof(*data)); if (!data) { D3D_DestroyRenderer(renderer); SDL_OutOfMemory(); return NULL; } data->d3d = videodata->d3d; renderer->DisplayModeChanged = D3D_DisplayModeChanged; renderer->CreateTexture = D3D_CreateTexture; renderer->QueryTexturePixels = D3D_QueryTexturePixels; renderer->SetTexturePalette = D3D_SetTexturePalette; renderer->GetTexturePalette = D3D_GetTexturePalette; renderer->SetTextureColorMod = D3D_SetTextureColorMod; renderer->SetTextureAlphaMod = D3D_SetTextureAlphaMod; renderer->SetTextureBlendMode = D3D_SetTextureBlendMode; renderer->SetTextureScaleMode = D3D_SetTextureScaleMode; renderer->UpdateTexture = D3D_UpdateTexture; renderer->LockTexture = D3D_LockTexture; renderer->UnlockTexture = D3D_UnlockTexture; renderer->DirtyTexture = D3D_DirtyTexture; renderer->RenderPoint = D3D_RenderPoint; renderer->RenderLine = D3D_RenderLine; renderer->RenderFill = D3D_RenderFill; renderer->RenderCopy = D3D_RenderCopy; renderer->RenderPresent = D3D_RenderPresent; renderer->DestroyTexture = D3D_DestroyTexture; renderer->DestroyRenderer = D3D_DestroyRenderer; renderer->info = D3D_RenderDriver.info; renderer->window = window->id; renderer->driverdata = data; renderer->info.flags = SDL_RENDERER_ACCELERATED; SDL_zero(pparams); pparams.BackBufferWidth = window->w; pparams.BackBufferHeight = window->h; if (window->flags & SDL_WINDOW_FULLSCREEN) { pparams.BackBufferFormat = PixelFormatToD3DFMT(display->fullscreen_mode.format); } else { pparams.BackBufferFormat = D3DFMT_UNKNOWN; } if (flags & SDL_RENDERER_PRESENTFLIP2) { pparams.BackBufferCount = 2; pparams.SwapEffect = D3DSWAPEFFECT_FLIP; } else if (flags & SDL_RENDERER_PRESENTFLIP3) { pparams.BackBufferCount = 3; pparams.SwapEffect = D3DSWAPEFFECT_FLIP; } else if (flags & SDL_RENDERER_PRESENTCOPY) { pparams.BackBufferCount = 1; pparams.SwapEffect = D3DSWAPEFFECT_COPY; } else { pparams.BackBufferCount = 1; pparams.SwapEffect = D3DSWAPEFFECT_DISCARD; } if (window->flags & SDL_WINDOW_FULLSCREEN) { pparams.Windowed = FALSE; pparams.FullScreen_RefreshRateInHz = display->fullscreen_mode.refresh_rate; } else { pparams.Windowed = TRUE; pparams.FullScreen_RefreshRateInHz = 0; } if (flags & SDL_RENDERER_PRESENTVSYNC) { pparams.PresentationInterval = D3DPRESENT_INTERVAL_ONE; } else { pparams.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE; } IDirect3D9_GetDeviceCaps(videodata->d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, &caps); result = IDirect3D9_CreateDevice(videodata->d3d, D3DADAPTER_DEFAULT, /* FIXME */ D3DDEVTYPE_HAL, windowdata->hwnd, (caps. DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT) ? D3DCREATE_HARDWARE_VERTEXPROCESSING : D3DCREATE_SOFTWARE_VERTEXPROCESSING, &pparams, &data->device); if (FAILED(result)) { D3D_DestroyRenderer(renderer); D3D_SetError("CreateDevice()", result); return NULL; } data->beginScene = SDL_TRUE; /* Get presentation parameters to fill info */ result = IDirect3DDevice9_GetSwapChain(data->device, 0, &chain); if (FAILED(result)) { D3D_DestroyRenderer(renderer); D3D_SetError("GetSwapChain()", result); return NULL; } result = IDirect3DSwapChain9_GetPresentParameters(chain, &pparams); if (FAILED(result)) { IDirect3DSwapChain9_Release(chain); D3D_DestroyRenderer(renderer); D3D_SetError("GetPresentParameters()", result); return NULL; } IDirect3DSwapChain9_Release(chain); switch (pparams.SwapEffect) { case D3DSWAPEFFECT_COPY: renderer->info.flags |= SDL_RENDERER_PRESENTCOPY; break; case D3DSWAPEFFECT_FLIP: switch (pparams.BackBufferCount) { case 2: renderer->info.flags |= SDL_RENDERER_PRESENTFLIP2; break; case 3: renderer->info.flags |= SDL_RENDERER_PRESENTFLIP3; break; } break; case D3DSWAPEFFECT_DISCARD: renderer->info.flags |= SDL_RENDERER_PRESENTDISCARD; break; } if (pparams.PresentationInterval == D3DPRESENT_INTERVAL_ONE) { renderer->info.flags |= SDL_RENDERER_PRESENTVSYNC; } data->pparams = pparams; IDirect3DDevice9_GetDeviceCaps(data->device, &caps); renderer->info.max_texture_width = caps.MaxTextureWidth; renderer->info.max_texture_height = caps.MaxTextureHeight; /* Set up parameters for rendering */ IDirect3DDevice9_SetVertexShader(data->device, NULL); IDirect3DDevice9_SetFVF(data->device, D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_TEX1); IDirect3DDevice9_SetRenderState(data->device, D3DRS_ZENABLE, D3DZB_FALSE); IDirect3DDevice9_SetRenderState(data->device, D3DRS_CULLMODE, D3DCULL_NONE); IDirect3DDevice9_SetRenderState(data->device, D3DRS_LIGHTING, FALSE); /* Enable color modulation by diffuse color */ IDirect3DDevice9_SetTextureStageState(data->device, 0, D3DTSS_COLOROP, D3DTOP_MODULATE); IDirect3DDevice9_SetTextureStageState(data->device, 0, D3DTSS_COLORARG1, D3DTA_TEXTURE); IDirect3DDevice9_SetTextureStageState(data->device, 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE); /* Enable alpha modulation by diffuse alpha */ IDirect3DDevice9_SetTextureStageState(data->device, 0, D3DTSS_ALPHAOP, D3DTOP_MODULATE); IDirect3DDevice9_SetTextureStageState(data->device, 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE); IDirect3DDevice9_SetTextureStageState(data->device, 0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE); /* Disable second texture stage, since we're done */ IDirect3DDevice9_SetTextureStageState(data->device, 1, D3DTSS_COLOROP, D3DTOP_DISABLE); IDirect3DDevice9_SetTextureStageState(data->device, 1, D3DTSS_ALPHAOP, D3DTOP_DISABLE); return renderer; }
SDL_Renderer * D3D_CreateRenderer(SDL_Window * window, Uint32 flags) { SDL_Renderer *renderer; D3D_RenderData *data; SDL_SysWMinfo windowinfo; HRESULT result; D3DPRESENT_PARAMETERS pparams; IDirect3DSwapChain9 *chain; D3DCAPS9 caps; Uint32 window_flags; int w, h; SDL_DisplayMode fullscreen_mode; D3DMATRIX matrix; renderer = (SDL_Renderer *) SDL_calloc(1, sizeof(*renderer)); if (!renderer) { SDL_OutOfMemory(); return NULL; } data = (D3D_RenderData *) SDL_calloc(1, sizeof(*data)); if (!data) { SDL_free(renderer); SDL_OutOfMemory(); return NULL; } data->d3dDLL = SDL_LoadObject("D3D9.DLL"); if (data->d3dDLL) { IDirect3D9 *(WINAPI * D3DCreate) (UINT SDKVersion); D3DCreate = (IDirect3D9 * (WINAPI *) (UINT)) SDL_LoadFunction(data->d3dDLL, "Direct3DCreate9"); if (D3DCreate) { data->d3d = D3DCreate(D3D_SDK_VERSION); } if (!data->d3d) { SDL_UnloadObject(data->d3dDLL); data->d3dDLL = NULL; } } if (!data->d3d) { SDL_free(renderer); SDL_free(data); SDL_SetError("Unable to create Direct3D interface"); return NULL; } renderer->WindowEvent = D3D_WindowEvent; renderer->CreateTexture = D3D_CreateTexture; renderer->UpdateTexture = D3D_UpdateTexture; renderer->LockTexture = D3D_LockTexture; renderer->UnlockTexture = D3D_UnlockTexture; renderer->SetRenderTarget = D3D_SetRenderTarget; renderer->UpdateViewport = D3D_UpdateViewport; renderer->RenderClear = D3D_RenderClear; renderer->RenderDrawPoints = D3D_RenderDrawPoints; renderer->RenderDrawLines = D3D_RenderDrawLines; renderer->RenderFillRects = D3D_RenderFillRects; renderer->RenderCopy = D3D_RenderCopy; renderer->RenderReadPixels = D3D_RenderReadPixels; renderer->RenderPresent = D3D_RenderPresent; renderer->DestroyTexture = D3D_DestroyTexture; renderer->DestroyRenderer = D3D_DestroyRenderer; renderer->info = D3D_RenderDriver.info; renderer->driverdata = data; renderer->info.flags = SDL_RENDERER_ACCELERATED; SDL_VERSION(&windowinfo.version); SDL_GetWindowWMInfo(window, &windowinfo); window_flags = SDL_GetWindowFlags(window); SDL_GetWindowSize(window, &w, &h); SDL_GetWindowDisplayMode(window, &fullscreen_mode); SDL_zero(pparams); pparams.hDeviceWindow = windowinfo.info.win.window; pparams.BackBufferWidth = w; pparams.BackBufferHeight = h; if (window_flags & SDL_WINDOW_FULLSCREEN) { pparams.BackBufferFormat = PixelFormatToD3DFMT(fullscreen_mode.format); } else { pparams.BackBufferFormat = D3DFMT_UNKNOWN; } pparams.BackBufferCount = 1; pparams.SwapEffect = D3DSWAPEFFECT_DISCARD; if (window_flags & SDL_WINDOW_FULLSCREEN) { pparams.Windowed = FALSE; pparams.FullScreen_RefreshRateInHz = fullscreen_mode.refresh_rate; } else { pparams.Windowed = TRUE; pparams.FullScreen_RefreshRateInHz = 0; } if (flags & SDL_RENDERER_PRESENTVSYNC) { pparams.PresentationInterval = D3DPRESENT_INTERVAL_ONE; } else { pparams.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE; } /* FIXME: Which adapter? */ data->adapter = D3DADAPTER_DEFAULT; IDirect3D9_GetDeviceCaps(data->d3d, data->adapter, D3DDEVTYPE_HAL, &caps); result = IDirect3D9_CreateDevice(data->d3d, data->adapter, D3DDEVTYPE_HAL, pparams.hDeviceWindow, D3DCREATE_FPU_PRESERVE | ((caps. DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT) ? D3DCREATE_HARDWARE_VERTEXPROCESSING : D3DCREATE_SOFTWARE_VERTEXPROCESSING), &pparams, &data->device); if (FAILED(result)) { D3D_DestroyRenderer(renderer); D3D_SetError("CreateDevice()", result); return NULL; } data->beginScene = SDL_TRUE; data->scaleMode = D3DTEXF_FORCE_DWORD; /* Get presentation parameters to fill info */ result = IDirect3DDevice9_GetSwapChain(data->device, 0, &chain); if (FAILED(result)) { D3D_DestroyRenderer(renderer); D3D_SetError("GetSwapChain()", result); return NULL; } result = IDirect3DSwapChain9_GetPresentParameters(chain, &pparams); if (FAILED(result)) { IDirect3DSwapChain9_Release(chain); D3D_DestroyRenderer(renderer); D3D_SetError("GetPresentParameters()", result); return NULL; } IDirect3DSwapChain9_Release(chain); if (pparams.PresentationInterval == D3DPRESENT_INTERVAL_ONE) { renderer->info.flags |= SDL_RENDERER_PRESENTVSYNC; } data->pparams = pparams; IDirect3DDevice9_GetDeviceCaps(data->device, &caps); renderer->info.max_texture_width = caps.MaxTextureWidth; renderer->info.max_texture_height = caps.MaxTextureHeight; if (caps.NumSimultaneousRTs >= 2) { renderer->info.flags |= SDL_RENDERER_TARGETTEXTURE; } /* Set up parameters for rendering */ IDirect3DDevice9_SetVertexShader(data->device, NULL); IDirect3DDevice9_SetFVF(data->device, D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_TEX1); IDirect3DDevice9_SetRenderState(data->device, D3DRS_ZENABLE, D3DZB_FALSE); IDirect3DDevice9_SetRenderState(data->device, D3DRS_CULLMODE, D3DCULL_NONE); IDirect3DDevice9_SetRenderState(data->device, D3DRS_LIGHTING, FALSE); /* Enable color modulation by diffuse color */ IDirect3DDevice9_SetTextureStageState(data->device, 0, D3DTSS_COLOROP, D3DTOP_MODULATE); IDirect3DDevice9_SetTextureStageState(data->device, 0, D3DTSS_COLORARG1, D3DTA_TEXTURE); IDirect3DDevice9_SetTextureStageState(data->device, 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE); /* Enable alpha modulation by diffuse alpha */ IDirect3DDevice9_SetTextureStageState(data->device, 0, D3DTSS_ALPHAOP, D3DTOP_MODULATE); IDirect3DDevice9_SetTextureStageState(data->device, 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE); IDirect3DDevice9_SetTextureStageState(data->device, 0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE); /* Disable second texture stage, since we're done */ IDirect3DDevice9_SetTextureStageState(data->device, 1, D3DTSS_COLOROP, D3DTOP_DISABLE); IDirect3DDevice9_SetTextureStageState(data->device, 1, D3DTSS_ALPHAOP, D3DTOP_DISABLE); /* Store the default render target */ IDirect3DDevice9_GetRenderTarget(data->device, 0, &data->defaultRenderTarget ); data->currentRenderTarget = NULL; /* Set an identity world and view matrix */ matrix.m[0][0] = 1.0f; matrix.m[0][1] = 0.0f; matrix.m[0][2] = 0.0f; matrix.m[0][3] = 0.0f; matrix.m[1][0] = 0.0f; matrix.m[1][1] = 1.0f; matrix.m[1][2] = 0.0f; matrix.m[1][3] = 0.0f; matrix.m[2][0] = 0.0f; matrix.m[2][1] = 0.0f; matrix.m[2][2] = 1.0f; matrix.m[2][3] = 0.0f; matrix.m[3][0] = 0.0f; matrix.m[3][1] = 0.0f; matrix.m[3][2] = 0.0f; matrix.m[3][3] = 1.0f; IDirect3DDevice9_SetTransform(data->device, D3DTS_WORLD, &matrix); IDirect3DDevice9_SetTransform(data->device, D3DTS_VIEW, &matrix); return renderer; }
/** * It allocates and initializes the resources needed to render the scene. */ static int Direct3DCreateScene(vout_display_t *vd) { vout_display_sys_t *sys = vd->sys; LPDIRECT3DDEVICE9 d3ddev = sys->d3ddev; HRESULT hr; /* * Create a texture for use when rendering a scene * for performance reason, texture format is identical to backbuffer * which would usually be a RGB format */ LPDIRECT3DTEXTURE9 d3dtex; hr = IDirect3DDevice9_CreateTexture(d3ddev, sys->d3dpp.BackBufferWidth, sys->d3dpp.BackBufferHeight, 1, D3DUSAGE_RENDERTARGET, sys->d3dpp.BackBufferFormat, D3DPOOL_DEFAULT, &d3dtex, NULL); if (FAILED(hr)) { msg_Err(vd, "Failed to create texture. (hr=0x%lx)", hr); return VLC_EGENERIC; } /* ** Create a vertex buffer for use when rendering scene */ LPDIRECT3DVERTEXBUFFER9 d3dvtc; hr = IDirect3DDevice9_CreateVertexBuffer(d3ddev, sizeof(CUSTOMVERTEX)*4, D3DUSAGE_DYNAMIC|D3DUSAGE_WRITEONLY, D3DFVF_CUSTOMVERTEX, D3DPOOL_DEFAULT, &d3dvtc, NULL); if (FAILED(hr)) { msg_Err(vd, "Failed to create vertex buffer. (hr=0x%lx)", hr); IDirect3DTexture9_Release(d3dtex); return VLC_EGENERIC; } /* */ sys->d3dtex = d3dtex; sys->d3dvtc = d3dvtc; // Texture coordinates outside the range [0.0, 1.0] are set // to the texture color at 0.0 or 1.0, respectively. IDirect3DDevice9_SetSamplerState(d3ddev, 0, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP); IDirect3DDevice9_SetSamplerState(d3ddev, 0, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP); // Set linear filtering quality IDirect3DDevice9_SetSamplerState(d3ddev, 0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR); IDirect3DDevice9_SetSamplerState(d3ddev, 0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR); // set maximum ambient light IDirect3DDevice9_SetRenderState(d3ddev, D3DRS_AMBIENT, D3DCOLOR_XRGB(255,255,255)); // Turn off culling IDirect3DDevice9_SetRenderState(d3ddev, D3DRS_CULLMODE, D3DCULL_NONE); // Turn off the zbuffer IDirect3DDevice9_SetRenderState(d3ddev, D3DRS_ZENABLE, D3DZB_FALSE); // Turn off lights IDirect3DDevice9_SetRenderState(d3ddev, D3DRS_LIGHTING, FALSE); // Enable dithering IDirect3DDevice9_SetRenderState(d3ddev, D3DRS_DITHERENABLE, TRUE); // disable stencil IDirect3DDevice9_SetRenderState(d3ddev, D3DRS_STENCILENABLE, FALSE); // manage blending IDirect3DDevice9_SetRenderState(d3ddev, D3DRS_ALPHABLENDENABLE, TRUE); IDirect3DDevice9_SetRenderState(d3ddev, D3DRS_SRCBLEND,D3DBLEND_SRCALPHA); IDirect3DDevice9_SetRenderState(d3ddev, D3DRS_DESTBLEND,D3DBLEND_INVSRCALPHA); IDirect3DDevice9_SetRenderState(d3ddev, D3DRS_ALPHATESTENABLE,TRUE); IDirect3DDevice9_SetRenderState(d3ddev, D3DRS_ALPHAREF, 0x10); IDirect3DDevice9_SetRenderState(d3ddev, D3DRS_ALPHAFUNC,D3DCMP_GREATER); // Set texture states IDirect3DDevice9_SetTextureStageState(d3ddev, 0, D3DTSS_COLOROP,D3DTOP_MODULATE); IDirect3DDevice9_SetTextureStageState(d3ddev, 0, D3DTSS_COLORARG1,D3DTA_TEXTURE); IDirect3DDevice9_SetTextureStageState(d3ddev, 0, D3DTSS_COLORARG2,D3DTA_DIFFUSE); // turn off alpha operation IDirect3DDevice9_SetTextureStageState(d3ddev, 0, D3DTSS_ALPHAOP, D3DTOP_DISABLE); msg_Dbg(vd, "Direct3D scene created successfully"); return VLC_SUCCESS; }
static HRESULT WINAPI ID3DXLineImpl_Begin(ID3DXLine* iface) { ID3DXLineImpl *This = impl_from_ID3DXLine(iface); HRESULT hr; D3DXMATRIX identity, projection; D3DVIEWPORT9 vp; TRACE ("(%p)->()\n", This); if (This->state != NULL) /* We already began. Return error. */ return D3DERR_INVALIDCALL; hr = IDirect3DDevice9_CreateStateBlock(This->device, D3DSBT_ALL, &This->state); if (FAILED(hr)) return D3DXERR_INVALIDDATA; hr = IDirect3DDevice9_GetViewport(This->device, &vp); if (FAILED(hr)) goto failed; D3DXMatrixIdentity(&identity); D3DXMatrixOrthoOffCenterLH(&projection, 0.0, vp.Width, /* Min and max x */ vp.Height, 0.0, /* Min and max y. Screen y is on top so this is inverted */ 0.0, 1.0); /* Min and max z */ hr = IDirect3DDevice9_SetTransform(This->device, D3DTS_WORLD, &identity); if (FAILED(hr)) goto failed; hr = IDirect3DDevice9_SetTransform(This->device, D3DTS_VIEW, &identity); if (FAILED(hr)) goto failed; hr = IDirect3DDevice9_SetTransform(This->device, D3DTS_PROJECTION, &projection); if (FAILED(hr)) goto failed; /* Windows sets similar states so we do the same */ hr = IDirect3DDevice9_SetRenderState(This->device, D3DRS_LIGHTING, FALSE); if (FAILED(hr)) goto failed; hr = IDirect3DDevice9_SetRenderState(This->device, D3DRS_FOGENABLE, FALSE); if (FAILED(hr)) goto failed; hr = IDirect3DDevice9_SetRenderState(This->device, D3DRS_SHADEMODE, D3DSHADE_FLAT); if (FAILED(hr)) goto failed; hr = IDirect3DDevice9_SetRenderState(This->device, D3DRS_ALPHABLENDENABLE, TRUE); if (FAILED(hr)) goto failed; hr = IDirect3DDevice9_SetRenderState(This->device, D3DRS_SRCBLEND, D3DBLEND_SRCALPHA); if (FAILED(hr)) goto failed; hr = IDirect3DDevice9_SetRenderState(This->device, D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA); if (FAILED(hr)) goto failed; return D3D_OK; failed: IDirect3DStateBlock9_Apply(This->state); IDirect3DStateBlock9_Release(This->state); This->state = NULL; return D3DXERR_INVALIDDATA; }
SDL_Renderer * D3D_CreateRenderer(SDL_Window * window, Uint32 flags) { SDL_VideoDisplay *display = window->display; SDL_VideoData *videodata = (SDL_VideoData *) display->device->driverdata; SDL_WindowData *windowdata = (SDL_WindowData *) window->driverdata; SDL_Renderer *renderer; D3D_RenderData *data; HRESULT result; D3DPRESENT_PARAMETERS pparams; IDirect3DSwapChain9 *chain; D3DCAPS9 caps; renderer = (SDL_Renderer *) SDL_calloc(1, sizeof(*renderer)); if (!renderer) { SDL_OutOfMemory(); return NULL; } data = (D3D_RenderData *) SDL_calloc(1, sizeof(*data)); if (!data) { D3D_DestroyRenderer(renderer); SDL_OutOfMemory(); return NULL; } data->d3d = videodata->d3d; videodata->render = RENDER_D3D; renderer->DisplayModeChanged = D3D_DisplayModeChanged; renderer->CreateTexture = D3D_CreateTexture; renderer->QueryTexturePixels = D3D_QueryTexturePixels; renderer->SetTexturePalette = D3D_SetTexturePalette; renderer->GetTexturePalette = D3D_GetTexturePalette; renderer->SetTextureColorMod = D3D_SetTextureColorMod; renderer->SetTextureAlphaMod = D3D_SetTextureAlphaMod; renderer->SetTextureBlendMode = D3D_SetTextureBlendMode; renderer->SetTextureScaleMode = D3D_SetTextureScaleMode; renderer->UpdateTexture = D3D_UpdateTexture; renderer->LockTexture = D3D_LockTexture; renderer->UnlockTexture = D3D_UnlockTexture; renderer->DirtyTexture = D3D_DirtyTexture; renderer->RenderDrawPoints = D3D_RenderDrawPoints; renderer->RenderDrawLines = D3D_RenderDrawLines; renderer->RenderDrawRects = D3D_RenderDrawRects; renderer->RenderFillRects = D3D_RenderFillRects; renderer->RenderCopy = D3D_RenderCopy; renderer->RenderReadPixels = D3D_RenderReadPixels; renderer->RenderWritePixels = D3D_RenderWritePixels; renderer->RenderPresent = D3D_RenderPresent; renderer->DestroyTexture = D3D_DestroyTexture; renderer->DestroyRenderer = D3D_DestroyRenderer; renderer->info = D3D_RenderDriver.info; renderer->window = window; renderer->driverdata = data; renderer->info.flags = SDL_RENDERER_ACCELERATED; SDL_zero(pparams); pparams.BackBufferWidth = window->w; pparams.BackBufferHeight = window->h; if (window->flags & SDL_WINDOW_FULLSCREEN) { pparams.BackBufferFormat = PixelFormatToD3DFMT(window->fullscreen_mode.format); } else { pparams.BackBufferFormat = D3DFMT_UNKNOWN; } if (flags & SDL_RENDERER_PRESENTFLIP2) { pparams.BackBufferCount = 2; pparams.SwapEffect = D3DSWAPEFFECT_FLIP; } else if (flags & SDL_RENDERER_PRESENTFLIP3) { pparams.BackBufferCount = 3; pparams.SwapEffect = D3DSWAPEFFECT_FLIP; } else if (flags & SDL_RENDERER_PRESENTCOPY) { pparams.BackBufferCount = 1; pparams.SwapEffect = D3DSWAPEFFECT_COPY; } else { pparams.BackBufferCount = 1; pparams.SwapEffect = D3DSWAPEFFECT_DISCARD; } if (window->flags & SDL_WINDOW_FULLSCREEN) { pparams.Windowed = FALSE; pparams.FullScreen_RefreshRateInHz = window->fullscreen_mode.refresh_rate; } else { pparams.Windowed = TRUE; pparams.FullScreen_RefreshRateInHz = 0; } if (flags & SDL_RENDERER_PRESENTVSYNC) { pparams.PresentationInterval = D3DPRESENT_INTERVAL_ONE; } else { pparams.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE; } data->adapter = D3D_FindAdapter(videodata->d3d, display); IDirect3D9_GetDeviceCaps(videodata->d3d, data->adapter, D3DDEVTYPE_HAL, &caps); result = IDirect3D9_CreateDevice(videodata->d3d, data->adapter, D3DDEVTYPE_HAL, windowdata->hwnd, (caps. DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT) ? D3DCREATE_HARDWARE_VERTEXPROCESSING : D3DCREATE_SOFTWARE_VERTEXPROCESSING, &pparams, &data->device); if (FAILED(result)) { D3D_DestroyRenderer(renderer); D3D_SetError("CreateDevice()", result); return NULL; } data->beginScene = SDL_TRUE; /* Get presentation parameters to fill info */ result = IDirect3DDevice9_GetSwapChain(data->device, 0, &chain); if (FAILED(result)) { D3D_DestroyRenderer(renderer); D3D_SetError("GetSwapChain()", result); return NULL; } result = IDirect3DSwapChain9_GetPresentParameters(chain, &pparams); if (FAILED(result)) { IDirect3DSwapChain9_Release(chain); D3D_DestroyRenderer(renderer); D3D_SetError("GetPresentParameters()", result); return NULL; } IDirect3DSwapChain9_Release(chain); switch (pparams.SwapEffect) { case D3DSWAPEFFECT_COPY: renderer->info.flags |= SDL_RENDERER_PRESENTCOPY; break; case D3DSWAPEFFECT_FLIP: switch (pparams.BackBufferCount) { case 2: renderer->info.flags |= SDL_RENDERER_PRESENTFLIP2; break; case 3: renderer->info.flags |= SDL_RENDERER_PRESENTFLIP3; break; } break; case D3DSWAPEFFECT_DISCARD: renderer->info.flags |= SDL_RENDERER_PRESENTDISCARD; break; } if (pparams.PresentationInterval == D3DPRESENT_INTERVAL_ONE) { renderer->info.flags |= SDL_RENDERER_PRESENTVSYNC; } data->pparams = pparams; IDirect3DDevice9_GetDeviceCaps(data->device, &caps); renderer->info.max_texture_width = caps.MaxTextureWidth; renderer->info.max_texture_height = caps.MaxTextureHeight; /* Set up parameters for rendering */ IDirect3DDevice9_SetVertexShader(data->device, NULL); IDirect3DDevice9_SetFVF(data->device, D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_TEX1); IDirect3DDevice9_SetRenderState(data->device, D3DRS_ZENABLE, D3DZB_FALSE); IDirect3DDevice9_SetRenderState(data->device, D3DRS_CULLMODE, D3DCULL_NONE); IDirect3DDevice9_SetRenderState(data->device, D3DRS_LIGHTING, FALSE); /* Enable color modulation by diffuse color */ IDirect3DDevice9_SetTextureStageState(data->device, 0, D3DTSS_COLOROP, D3DTOP_MODULATE); IDirect3DDevice9_SetTextureStageState(data->device, 0, D3DTSS_COLORARG1, D3DTA_TEXTURE); IDirect3DDevice9_SetTextureStageState(data->device, 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE); /* Enable alpha modulation by diffuse alpha */ IDirect3DDevice9_SetTextureStageState(data->device, 0, D3DTSS_ALPHAOP, D3DTOP_MODULATE); IDirect3DDevice9_SetTextureStageState(data->device, 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE); IDirect3DDevice9_SetTextureStageState(data->device, 0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE); /* Disable second texture stage, since we're done */ IDirect3DDevice9_SetTextureStageState(data->device, 1, D3DTSS_COLOROP, D3DTOP_DISABLE); IDirect3DDevice9_SetTextureStageState(data->device, 1, D3DTSS_ALPHAOP, D3DTOP_DISABLE); { #ifdef ASSEMBLE_SHADER const char *shader_text = "ps_1_1\n" "def c0, 0, 0, 0, 0.496\n" "def c1, 0, 0, 0, 1\n" "def c2, 0, 0, 0, -1\n" "tex t0\n" "mul r1, t0, v0\n" "add r0, r1, c0\n" "cnd r0, r0.a, c1, c2\n" "add r0, r0, r1\n"; LPD3DXBUFFER pCode; // buffer with the assembled shader code LPD3DXBUFFER pErrorMsgs; // buffer with error messages LPDWORD shader_data; DWORD shader_size; result = D3DXAssembleShader( shader_text, SDL_strlen(shader_text), NULL, NULL, 0, &pCode, &pErrorMsgs ); if (FAILED(result)) { D3D_SetError("D3DXAssembleShader()", result); } shader_data = (DWORD*)pCode->lpVtbl->GetBufferPointer(pCode); shader_size = pCode->lpVtbl->GetBufferSize(pCode); #else const DWORD shader_data[] = { 0xffff0101,0x00000051,0xa00f0000,0x00000000,0x00000000,0x00000000, 0x3efdf3b6,0x00000051,0xa00f0001,0x00000000,0x00000000,0x00000000, 0x3f800000,0x00000051,0xa00f0002,0x00000000,0x00000000,0x00000000, 0xbf800000,0x00000042,0xb00f0000,0x00000005,0x800f0001,0xb0e40000, 0x90e40000,0x00000002,0x800f0000,0x80e40001,0xa0e40000,0x00000050, 0x800f0000,0x80ff0000,0xa0e40001,0xa0e40002,0x00000002,0x800f0000, 0x80e40000,0x80e40001,0x0000ffff }; #endif result = IDirect3DDevice9_CreatePixelShader(data->device, shader_data, &data->ps_mask); if (FAILED(result)) { D3D_SetError("CreatePixelShader()", result); } } return renderer; }
/* Helper function */ static void set_states(ID3DXSpriteImpl *object) { D3DXMATRIX mat; D3DVIEWPORT9 vp; /* Miscellaneous stuff */ IDirect3DDevice9_SetVertexShader(object->device, NULL); IDirect3DDevice9_SetPixelShader(object->device, NULL); IDirect3DDevice9_SetNPatchMode(object->device, 0.0f); /* Render states */ IDirect3DDevice9_SetRenderState(object->device, D3DRS_ALPHABLENDENABLE, TRUE); IDirect3DDevice9_SetRenderState(object->device, D3DRS_ALPHAFUNC, D3DCMP_GREATER); IDirect3DDevice9_SetRenderState(object->device, D3DRS_ALPHAREF, 0x00); IDirect3DDevice9_SetRenderState(object->device, D3DRS_ALPHATESTENABLE, object->alphacmp_caps); IDirect3DDevice9_SetRenderState(object->device, D3DRS_BLENDOP, D3DBLENDOP_ADD); IDirect3DDevice9_SetRenderState(object->device, D3DRS_CLIPPING, TRUE); IDirect3DDevice9_SetRenderState(object->device, D3DRS_CLIPPLANEENABLE, FALSE); IDirect3DDevice9_SetRenderState(object->device, D3DRS_COLORWRITEENABLE, D3DCOLORWRITEENABLE_ALPHA | D3DCOLORWRITEENABLE_BLUE | D3DCOLORWRITEENABLE_GREEN | D3DCOLORWRITEENABLE_RED); IDirect3DDevice9_SetRenderState(object->device, D3DRS_CULLMODE, D3DCULL_NONE); IDirect3DDevice9_SetRenderState(object->device, D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA); IDirect3DDevice9_SetRenderState(object->device, D3DRS_DIFFUSEMATERIALSOURCE, D3DMCS_COLOR1); IDirect3DDevice9_SetRenderState(object->device, D3DRS_ENABLEADAPTIVETESSELLATION, FALSE); IDirect3DDevice9_SetRenderState(object->device, D3DRS_FILLMODE, D3DFILL_SOLID); IDirect3DDevice9_SetRenderState(object->device, D3DRS_FOGENABLE, FALSE); IDirect3DDevice9_SetRenderState(object->device, D3DRS_INDEXEDVERTEXBLENDENABLE, FALSE); IDirect3DDevice9_SetRenderState(object->device, D3DRS_LIGHTING, FALSE); IDirect3DDevice9_SetRenderState(object->device, D3DRS_RANGEFOGENABLE, FALSE); IDirect3DDevice9_SetRenderState(object->device, D3DRS_SEPARATEALPHABLENDENABLE, FALSE); IDirect3DDevice9_SetRenderState(object->device, D3DRS_SHADEMODE, D3DSHADE_GOURAUD); IDirect3DDevice9_SetRenderState(object->device, D3DRS_SPECULARENABLE, FALSE); IDirect3DDevice9_SetRenderState(object->device, D3DRS_SRCBLEND, D3DBLEND_SRCALPHA); IDirect3DDevice9_SetRenderState(object->device, D3DRS_SRGBWRITEENABLE, FALSE); IDirect3DDevice9_SetRenderState(object->device, D3DRS_STENCILENABLE, FALSE); IDirect3DDevice9_SetRenderState(object->device, D3DRS_VERTEXBLEND, FALSE); IDirect3DDevice9_SetRenderState(object->device, D3DRS_WRAP0, 0); /* Texture stage states */ IDirect3DDevice9_SetTextureStageState(object->device, 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE); IDirect3DDevice9_SetTextureStageState(object->device, 0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE); IDirect3DDevice9_SetTextureStageState(object->device, 0, D3DTSS_ALPHAOP, D3DTOP_MODULATE); IDirect3DDevice9_SetTextureStageState(object->device, 0, D3DTSS_COLORARG1, D3DTA_TEXTURE); IDirect3DDevice9_SetTextureStageState(object->device, 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE); IDirect3DDevice9_SetTextureStageState(object->device, 0, D3DTSS_COLOROP, D3DTOP_MODULATE); IDirect3DDevice9_SetTextureStageState(object->device, 0, D3DTSS_TEXCOORDINDEX, 0); IDirect3DDevice9_SetTextureStageState(object->device, 0, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_DISABLE); IDirect3DDevice9_SetTextureStageState(object->device, 1, D3DTSS_ALPHAOP, D3DTOP_DISABLE); IDirect3DDevice9_SetTextureStageState(object->device, 1, D3DTSS_COLOROP, D3DTOP_DISABLE); /* Sampler states */ IDirect3DDevice9_SetSamplerState(object->device, 0, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP); IDirect3DDevice9_SetSamplerState(object->device, 0, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP); if(object->texfilter_caps & D3DPTFILTERCAPS_MAGFANISOTROPIC) IDirect3DDevice9_SetSamplerState(object->device, 0, D3DSAMP_MAGFILTER, D3DTEXF_ANISOTROPIC); else IDirect3DDevice9_SetSamplerState(object->device, 0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR); IDirect3DDevice9_SetSamplerState(object->device, 0, D3DSAMP_MAXMIPLEVEL, 0); IDirect3DDevice9_SetSamplerState(object->device, 0, D3DSAMP_MAXANISOTROPY, object->maxanisotropy); if(object->texfilter_caps & D3DPTFILTERCAPS_MINFANISOTROPIC) IDirect3DDevice9_SetSamplerState(object->device, 0, D3DSAMP_MINFILTER, D3DTEXF_ANISOTROPIC); else IDirect3DDevice9_SetSamplerState(object->device, 0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR); if(object->texfilter_caps & D3DPTFILTERCAPS_MIPFLINEAR) IDirect3DDevice9_SetSamplerState(object->device, 0, D3DSAMP_MIPFILTER, D3DTEXF_LINEAR); else IDirect3DDevice9_SetSamplerState(object->device, 0, D3DSAMP_MIPFILTER, D3DTEXF_POINT); IDirect3DDevice9_SetSamplerState(object->device, 0, D3DSAMP_MIPMAPLODBIAS, 0); IDirect3DDevice9_SetSamplerState(object->device, 0, D3DSAMP_SRGBTEXTURE, 0); /* Matrices */ D3DXMatrixIdentity(&mat); IDirect3DDevice9_SetTransform(object->device, D3DTS_WORLD, &mat); IDirect3DDevice9_SetTransform(object->device, D3DTS_VIEW, &object->view); IDirect3DDevice9_GetViewport(object->device, &vp); D3DXMatrixOrthoOffCenterLH(&mat, vp.X+0.5f, (float)vp.Width+vp.X+0.5f, (float)vp.Height+vp.Y+0.5f, vp.Y+0.5f, vp.MinZ, vp.MaxZ); IDirect3DDevice9_SetTransform(object->device, D3DTS_PROJECTION, &mat); }
void JBKRender_SetBlendAlpha8() { DXCall( IDirect3DDevice9_SetRenderState(gDevice, D3DRS_BLENDOP, D3DBLENDOP_ADD) ); DXCall( IDirect3DDevice9_SetRenderState(gDevice, D3DRS_SRCBLEND, D3DBLEND_SRCALPHA) ); DXCall( IDirect3DDevice9_SetRenderState(gDevice, D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA) ); }
void JBKRender_DisableAlphaBlending() { DXCall( IDirect3DDevice9_SetRenderState(gDevice, D3DRS_ALPHABLENDENABLE, 0) ); }
/** @brief libvo Callback: Draw OSD/Subtitles, */ static void draw_osd(void) { // we can not render OSD if we lost the device e.g. because it was uncooperative if (!priv->d3d_device) return; if (vo_osd_changed(0)) { D3DLOCKED_RECT locked_rect; /**< Offscreen surface we lock in order to copy MPlayer's frame inside it.*/ /* clear the OSD */ if (FAILED(IDirect3DTexture9_LockRect(priv->d3d_texture_system, 0, &locked_rect, NULL, 0))) { mp_msg(MSGT_VO,MSGL_ERR, "<vo_direct3d>OSD texture lock failed.\n"); return; } /* clear the whole texture to avoid issues due to interpolation */ memset(locked_rect.pBits, 0, locked_rect.Pitch * priv->osd_texture_height); /* this unlock is used for both slice_draw path and D3DRenderFrame path */ if (FAILED(IDirect3DTexture9_UnlockRect(priv->d3d_texture_system, 0))) { mp_msg(MSGT_VO,MSGL_ERR, "<vo_direct3d>OSD texture unlock failed.\n"); return; } priv->is_osd_populated = 0; /* required for if subs are in the boarder region */ priv->is_clear_needed = 1; vo_draw_text_ext(priv->osd_width, priv->osd_height, priv->border_x, priv->border_y, priv->border_x, priv->border_y, priv->src_width, priv->src_height, draw_alpha); if (!priv->device_texture_sys) { /* only DMA to the shadow if its required */ if (FAILED(IDirect3DDevice9_UpdateTexture(priv->d3d_device, (IDirect3DBaseTexture9 *)priv->d3d_texture_system, (IDirect3DBaseTexture9 *)priv->d3d_texture_osd))) { mp_msg(MSGT_VO,MSGL_ERR, "<vo_direct3d>OSD texture transfer failed.\n"); return; } } } /* update OSD */ if (priv->is_osd_populated) { struct_vertex osd_quad_vb[] = { {-1.0f, 1.0f, 0.0f, 0, 0 }, { 1.0f, 1.0f, 0.0f, 1, 0 }, {-1.0f,-1.0f, 0.0f, 0, 1 }, { 1.0f,-1.0f, 0.0f, 1, 1 } }; /* calculate the texture coordinates */ osd_quad_vb[1].tu = osd_quad_vb[3].tu = (float)priv->osd_width / priv->osd_texture_width; osd_quad_vb[2].tv = osd_quad_vb[3].tv = (float)priv->osd_height / priv->osd_texture_height; if (FAILED(IDirect3DDevice9_BeginScene(priv->d3d_device))) { mp_msg(MSGT_VO,MSGL_ERR,"<vo_direct3d>BeginScene failed.\n"); return; } /* turn on alpha test */ IDirect3DDevice9_SetRenderState(priv->d3d_device, D3DRS_ALPHABLENDENABLE, TRUE); IDirect3DDevice9_SetRenderState(priv->d3d_device, D3DRS_ALPHATESTENABLE, TRUE); /* need to use a texture here (done here as we may be able to texture from system memory) */ IDirect3DDevice9_SetTexture(priv->d3d_device, 0, (IDirect3DBaseTexture9 *)(priv->device_texture_sys ? priv->d3d_texture_system : priv->d3d_texture_osd)); IDirect3DDevice9_SetFVF(priv->d3d_device, D3DFVF_MY_VERTEX); IDirect3DDevice9_DrawPrimitiveUP(priv->d3d_device, D3DPT_TRIANGLESTRIP, 2, osd_quad_vb, sizeof(struct_vertex)); /* turn off alpha test */ IDirect3DDevice9_SetRenderState(priv->d3d_device, D3DRS_ALPHATESTENABLE, FALSE); IDirect3DDevice9_SetRenderState(priv->d3d_device, D3DRS_ALPHABLENDENABLE, FALSE); if (FAILED(IDirect3DDevice9_EndScene(priv->d3d_device))) { mp_msg(MSGT_VO,MSGL_ERR,"<vo_direct3d>EndScene failed.\n"); return; } } }
/** @brief Create D3D Offscreen and Backbuffer surfaces. Each * surface is created only if it's not already present. * @return 1 on success, 0 on failure */ static int create_d3d_surfaces(void) { int osd_width = vo_dwidth, osd_height = vo_dheight; int tex_width = osd_width, tex_height = osd_height; mp_msg(MSGT_VO, MSGL_V, "<vo_direct3d>create_d3d_surfaces called.\n"); if (!priv->d3d_surface && FAILED(IDirect3DDevice9_CreateOffscreenPlainSurface( priv->d3d_device, priv->src_width, priv->src_height, priv->movie_src_fmt, D3DPOOL_DEFAULT, &priv->d3d_surface, NULL))) { mp_msg(MSGT_VO, MSGL_ERR, "<vo_direct3d>Allocating offscreen surface failed.\n"); return 0; } if (!priv->d3d_backbuf && FAILED(IDirect3DDevice9_GetBackBuffer(priv->d3d_device, 0, 0, D3DBACKBUFFER_TYPE_MONO, &priv->d3d_backbuf))) { mp_msg(MSGT_VO, MSGL_ERR, "<vo_direct3d>Allocating backbuffer failed.\n"); return 0; } /* calculate the best size for the OSD depending on the factors from the device */ if (priv->device_caps_power2_only) { tex_width = 1; tex_height = 1; while (tex_width < osd_width ) tex_width <<= 1; while (tex_height < osd_height) tex_height <<= 1; } if (priv->device_caps_square_only) /* device only supports square textures */ tex_width = tex_height = tex_width > tex_height ? tex_width : tex_height; // better round up to a multiple of 16 tex_width = (tex_width + 15) & ~15; tex_height = (tex_height + 15) & ~15; // make sure we respect the size limits without breaking aspect or pow2-requirements while (tex_width > priv->max_texture_width || tex_height > priv->max_texture_height) { osd_width >>= 1; osd_height >>= 1; tex_width >>= 1; tex_height >>= 1; } priv->osd_width = osd_width; priv->osd_height = osd_height; priv->osd_texture_width = tex_width; priv->osd_texture_height = tex_height; mp_msg(MSGT_VO, MSGL_V, "<vo_direct3d>OSD texture size (%dx%d), requested (%dx%d).\n", vo_dwidth, vo_dheight, priv->osd_texture_width, priv->osd_texture_height); /* create OSD */ if (!priv->d3d_texture_system && FAILED(IDirect3DDevice9_CreateTexture(priv->d3d_device, priv->osd_texture_width, priv->osd_texture_height, 1, D3DUSAGE_DYNAMIC, D3DFMT_A8L8, D3DPOOL_SYSTEMMEM, &priv->d3d_texture_system, NULL))) { mp_msg(MSGT_VO,MSGL_ERR, "<vo_direct3d>Allocating OSD texture in system RAM failed.\n"); return 0; } if (!priv->device_texture_sys) { /* only create if we need a shadow version on the external device */ if (!priv->d3d_texture_osd && FAILED(IDirect3DDevice9_CreateTexture(priv->d3d_device, priv->osd_texture_width, priv->osd_texture_height, 1, D3DUSAGE_DYNAMIC, D3DFMT_A8L8, D3DPOOL_DEFAULT, &priv->d3d_texture_osd, NULL))) { mp_msg(MSGT_VO,MSGL_ERR, "<vo_direct3d>Allocating OSD texture in video RAM failed.\n"); return 0; } } /* setup default renderstate */ IDirect3DDevice9_SetRenderState(priv->d3d_device, D3DRS_SRCBLEND, D3DBLEND_ONE); IDirect3DDevice9_SetRenderState(priv->d3d_device, D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA); IDirect3DDevice9_SetRenderState(priv->d3d_device, D3DRS_ALPHAFUNC, D3DCMP_GREATER); IDirect3DDevice9_SetRenderState(priv->d3d_device, D3DRS_ALPHAREF, (DWORD)0x0); IDirect3DDevice9_SetRenderState(priv->d3d_device, D3DRS_LIGHTING, FALSE); IDirect3DDevice9_SetSamplerState(priv->d3d_device, 0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR); IDirect3DDevice9_SetSamplerState(priv->d3d_device, 0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR); return 1; }
void xprGpuStatePreRender(XprGpuState* self) { IDirect3DDevice9* d3ddev = xprAPI.d3ddev; IDirect3DDevice9_SetRenderState(d3ddev, D3DRS_ZENABLE, (BOOL)self->desc.depthTest); IDirect3DDevice9_SetRenderState(d3ddev, D3DRS_ZWRITEENABLE, (BOOL)self->desc.depthWrite); IDirect3DDevice9_SetRenderState(d3ddev, D3DRS_CULLMODE, self->desc.cull ? D3DCULL_CW : D3DCULL_NONE); if(self->desc.blend) { IDirect3DDevice9_SetRenderState(d3ddev, D3DRS_ALPHABLENDENABLE, TRUE); IDirect3DDevice9_SetRenderState(d3ddev, D3DRS_SEPARATEALPHABLENDENABLE, TRUE); IDirect3DDevice9_SetRenderState(d3ddev, D3DRS_SRCBLEND, XprGpuState_blendFactorMapping[self->desc.blendFactorSrcRGB - XprGpuState_BlendFactor_One]); IDirect3DDevice9_SetRenderState(d3ddev, D3DRS_DESTBLEND, XprGpuState_blendFactorMapping[self->desc.blendFactorDestRGB - XprGpuState_BlendFactor_One]); IDirect3DDevice9_SetRenderState(d3ddev, D3DRS_SRCBLENDALPHA, XprGpuState_blendFactorMapping[self->desc.blendFactorSrcA - XprGpuState_BlendFactor_One]); IDirect3DDevice9_SetRenderState(d3ddev, D3DRS_DESTBLENDALPHA, XprGpuState_blendFactorMapping[self->desc.blendFactorDestA - XprGpuState_BlendFactor_One]); } else { IDirect3DDevice9_SetRenderState(d3ddev, D3DRS_ALPHABLENDENABLE, FALSE); } IDirect3DDevice9_SetRenderState(d3ddev, D3DRS_FILLMODE, XprGpuState_polygonModeMapping[self->desc.polygonMode - XprGpuState_PolygonMode_Line]); }