directx-d3d平面阴影不显示,求大神

问题描述

d3d平面阴影不显示,求大神

#include
#include
#pragma comment(lib,"d3d9.lib")
#pragma comment(lib,"d3dx9.lib")
#pragma comment(lib,"winmm.lib")

#define WindowWidth 1024
#define WindowHeight 768

LPDIRECT3DDEVICE9 d3dDevice = NULL;
LPD3DXMESH d3dMeshTeapot = NULL;
LPD3DXMESH d3dMeshBox = NULL;

bool Installing3D(HWND hWnd)
{
LPDIRECT3D9 d3d = Direct3DCreate9(D3D_SDK_VERSION);
D3DPRESENT_PARAMETERS d3dpp;
::ZeroMemory(&d3dpp,sizeof(d3dpp));
d3dpp.AutoDepthStencilFormat = D3DFMT_D24S8;
d3dpp.BackBufferCount = 1;
d3dpp.BackBufferFormat = D3DFMT_A8R8G8B8;
d3dpp.BackBufferHeight = WindowHeight;
d3dpp.BackBufferWidth = WindowWidth;
d3dpp.EnableAutoDepthStencil = true;
d3dpp.Flags = 0;
d3dpp.FullScreen_RefreshRateInHz = D3DPRESENT_RATE_DEFAULT;
d3dpp.hDeviceWindow = hWnd;
d3dpp.MultiSampleQuality = 0;
d3dpp.MultiSampleType = D3DMULTISAMPLE_NONE;
d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dpp.Windowed = true;
d3d->CreateDevice(D3DADAPTER_DEFAULT,D3DDEVTYPE_HAL,hWnd,D3DCREATE_HARDWARE_VERTEXPROCESSING,&d3dpp,&d3dDevice);
d3d->Release();

D3DXCreateTeapot(d3dDevice,&d3dMeshTeapot,NULL);
D3DXCreateBox(d3dDevice,8.0f,0,8.0f,&d3dMeshBox,NULL);

D3DXMATRIX mView;
D3DXVECTOR3 vEye(0,0,-10),vAt(0,0,0),vUp(0,1,0);
D3DXMatrixLookAtLH(&mView,&vEye,&vAt,&vUp);
d3dDevice->SetTransform(D3DTS_VIEW,&mView);

D3DXMATRIX mProj;
D3DXMatrixPerspectiveFovLH(&mProj,D3DX_PI/4.0,WindowWidth/WindowHeight,1.0f,100.0f);
d3dDevice->SetTransform(D3DTS_PROJECTION,&mProj);

//d3dDevice->SetRenderState(D3DRS_LIGHTING,false);

D3DLIGHT9 light;
::ZeroMemory(&light,sizeof(light));
light.Type = D3DLIGHT_DIRECTIONAL;
light.Ambient = D3DXCOLOR(0.3f,0.3f,0.3f,1.0f);
light.Diffuse = D3DXCOLOR(1.0f,1.0f,1.0f,1.0f);
light.Specular = D3DXCOLOR(0.3f,0.3f,0.3f,1.0f);
light.Direction = D3DXVECTOR3(-1.0f,-1.0f,0);
d3dDevice->SetLight(0,&light);
d3dDevice->LightEnable(0,true);
d3dDevice->SetRenderState(D3DRS_AMBIENT,D3DCOLOR_XRGB(92,92,92));
//d3dDevice->SetRenderState(D3DRS_AMBIENT,D3DCOLOR_XRGB(255,255,255));
d3dDevice->SetRenderState(D3DRS_NORMALIZENORMALS, true);
//d3dDevice->SetRenderState(D3DRS_SPECULARENABLE, true);

return true;

}

void Render()
{
d3dDevice->Clear(0,0,D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER | D3DCLEAR_STENCIL,D3DCOLOR_XRGB(0,0,0),1.0f,0);
d3dDevice->BeginScene();

D3DXMATRIX mWorld;
D3DXMatrixIdentity(&mWorld);
D3DXMatrixTranslation(&mWorld,0,-2,0);
d3dDevice->SetTransform(D3DTS_WORLD,&mWorld);

//d3dDevice->SetRenderState(D3DRS_FILLMODE,D3DFILL_WIREFRAME);

D3DMATERIAL9 mtrlBox;
mtrlBox.Diffuse = D3DXCOLOR(1,1,1,1);
mtrlBox.Ambient = D3DXCOLOR(0.6f,0.6f,0.6f,1.0f);
mtrlBox.Specular = D3DXCOLOR(0.1f,0.1f,0.1f,1.0f);
mtrlBox.Emissive = D3DXCOLOR(0,0,0,1.0f);
d3dDevice->SetMaterial(&mtrlBox);

d3dMeshBox->DrawSubset(0);

//d3dDevice->SetRenderState(D3DRS_FILLMODE,D3DFILL_SOLID);

D3DMATERIAL9 mtrl;
mtrl.Diffuse = D3DXCOLOR(1,1,1,1);
mtrl.Ambient = D3DXCOLOR(1,1,1,1);
mtrl.Specular = D3DXCOLOR(0.3f,0.3f,0.3f,1.0f);
mtrl.Emissive = D3DXCOLOR(0,0,0,1.0f);
d3dDevice->SetMaterial(&mtrl);

D3DXMATRIX mX,mY,mZ;
D3DXMatrixIdentity(&mWorld);
D3DXMatrixRotationX(&mX,::timeGetTime()/1000.0f);
D3DXMatrixRotationY(&mY,::timeGetTime()/1000.0f);
D3DXMatrixRotationZ(&mZ,::timeGetTime()/1000.0f);
mWorld = mWorld * mX * mY * mZ;
d3dDevice->SetTransform(D3DTS_WORLD,&mWorld);
d3dMeshTeapot->DrawSubset(0);

//shadow
D3DXVECTOR4 vLight(-1.0f,-1.0f,0.0f,0.0f);
D3DXPLANE plane(0.0f,-2.0f,0.0f,0.0f);
D3DXMATRIX mShadow;
D3DXMatrixShadow(&mShadow,&vLight,&plane);

d3dDevice->SetRenderState(D3DRS_STENCILENABLE,    true);
d3dDevice->SetRenderState(D3DRS_STENCILFUNC,      D3DCMP_EQUAL);
d3dDevice->SetRenderState(D3DRS_STENCILREF,       0x0);
d3dDevice->SetRenderState(D3DRS_STENCILMASK,      0xffffffff);
d3dDevice->SetRenderState(D3DRS_STENCILWRITEMASK, 0xffffffff);
d3dDevice->SetRenderState(D3DRS_STENCILZFAIL,     D3DSTENCILOP_KEEP);
d3dDevice->SetRenderState(D3DRS_STENCILFAIL,      D3DSTENCILOP_KEEP);
d3dDevice->SetRenderState(D3DRS_STENCILPASS,      D3DSTENCILOP_INCR);

d3dDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, true);
d3dDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
d3dDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
d3dDevice->SetRenderState(D3DRS_ZENABLE, false);

D3DMATERIAL9 mtrlShadow;
::ZeroMemory(&mtrlShadow, sizeof(mtrlShadow));
mtrlShadow.Ambient = D3DXCOLOR(0.2f, 0.2f, 0.2f, 0.5f);
mtrlShadow.Diffuse = D3DXCOLOR(0.2f, 0.2f, 0.2f, 0.5f);
d3dDevice->SetMaterial(&mtrlShadow);

mWorld = mWorld * mShadow;
d3dDevice->SetTransform(D3DTS_WORLD, &mWorld);
d3dMeshTeapot->DrawSubset(0);

d3dDevice->SetRenderState(D3DRS_ZENABLE, true);
d3dDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, false);
d3dDevice->SetRenderState(D3DRS_STENCILENABLE,    false);

d3dDevice->EndScene();
d3dDevice->Present(NULL,NULL,NULL,NULL);

}

LRESULT CALLBACK MsgPro(HWND hWnd,UINT message,WPARAM wParam,LPARAM lParam)
{
switch(message)
{
case WM_PAINT:
Render();
ValidateRect(hWnd,NULL);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
}
return DefWindowProc(hWnd,message,wParam,lParam);
}

void ShutDown()
{
if(d3dDevice!=NULL) d3dDevice->Release();
if(d3dMeshTeapot!=NULL) d3dMeshTeapot->Release();
}

int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nShowCmd)
{
#define ClassName L"ClassName"
#define WindowName L"WindowName"

WNDCLASSEX wc;
wc.cbClsExtra = 0;
wc.cbSize = sizeof(WNDCLASSEX);
wc.cbWndExtra = 0;
wc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
wc.hCursor = NULL;
wc.hIcon = NULL;
wc.hIconSm = NULL;
wc.hInstance = hInstance;
wc.lpfnWndProc = MsgPro;
wc.lpszClassName = ClassName;
wc.lpszMenuName = NULL;
wc.style = CS_VREDRAW | CS_HREDRAW;
RegisterClassEx(&wc);

HWND hWnd = CreateWindow(ClassName,WindowName,WS_OVERLAPPEDWINDOW,100,5,WindowWidth,WindowHeight,NULL,NULL,hInstance,NULL);

if(Installing3D(hWnd))
{
    ShowWindow(hWnd,nShowCmd);
    UpdateWindow(hWnd);

    MSG msg;
    ::ZeroMemory(&msg,sizeof(msg));
    while(msg.message!=WM_QUIT)
    {
        if(PeekMessage(&msg,NULL,NULL,NULL,PM_REMOVE))
        {
            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }
        else
        {
            Render();
        }
    }
}
ShutDown();
UnregisterClass(ClassName,hInstance);
return 0;

}

时间: 2016-03-14

directx-d3d平面阴影不显示,求大神的相关文章

timer-pb倒计时 问题在线等求大神解答 非常感谢

问题描述 pb倒计时 问题在线等求大神解答 非常感谢 想用一个 st_1控件 相识5 4 3 2 1 一秒一次 我知道 timer事件 timer (1)可是 怎么在timer 事件中写 循环输出显示 求大神在线解答 非常急 我小白 解决方案 int i=1count=0;while(1){ print(""%dn""i) timer(1); i++; print(""%d""i) if(i==5) { i=1; }}不知道这

socket-JAVA代理服务器,用浏览器打开的时候显示的网页信息总是不全,有时候显示不出来,求大神帮我看看

问题描述 JAVA代理服务器,用浏览器打开的时候显示的网页信息总是不全,有时候显示不出来,求大神帮我看看 package work; import java.io.*; import java.net.*; public class MMProxy extends Thread { static public int CONNECT_RETRIES = 5; //尝试与目标主机连接次数 static public int CONNECT_PAUSE = 5; //每次建立连接的间隔时间 stat

求大神帮我解决ueditor单图上传按钮显示的问题asp.net

问题描述 求大神帮我解决ueditor单图上传按钮显示的问题asp.net 因为公司项目需要,昨天下载了一个.net版的ueditor富文本编辑器,现在也只是能在页面上显示出来了,还有很多的配置问题没解决,现在的问题是单图上传按钮是灰色的,怎么让它显示?还是多图上传的本地文件上传的配置问题,希望能来个大牛帮我解决一下,最好有个截图解释一下,才刚工作一个月,谢谢了

win7系统-电脑显示“远程计算机或设备将不接受连接”,怎么解决,求大神!

问题描述 电脑显示"远程计算机或设备将不接受连接",怎么解决,求大神! 解决方案 http://jingyan.baidu.com/article/acf728fd20ebe6f8e510a3c7.htmlhttp://zhidao.baidu.com/question/286387967http://bbs.ithome.com/thread-441544-1-1.html 解决方案二: http://zhidao.baidu.com/link?url=QlXT6qQmwj3M20G

java 上传图片到服务器上,在页面上不能显示,急急急,在线等,求大神帮忙!!!!!

问题描述 java 上传图片到服务器上,在页面上不能显示,急急急,在线等,求大神帮忙!!!!! java 上传图片到服务器上,图片上传成功,但是在页面展示时不能加载,路径没问题,手动将上传的图片改个名字后能正常加载 解决方案 最终的上传路径有没有特殊字符或者空格啥的,最好不要带特殊字符包括空格啥的. 解决方案二: 图片在内网服务器上A,部署在服务器B的应用要显示图片,受网络限制外网用户无法访问到图片,为了解决这个问题现将图片下载到服务器B上,现在服务器B上存在图片,但是不能正常加载,通过手动地对

页面显示-为什么页面上 显示不出jsp中label 里的文字 求大神指教

问题描述 为什么页面上 显示不出jsp中label 里的文字 求大神指教 为什么页面上 显示不出jsp中label 里的文字 求大神指教 解决方案 你要显示什么东西?把代码贴出来 解决方案二: 你这是表格还是div的?如果是表格的话应该就没有这问题吧.div的话可能被覆盖了.div的话可以这样试试: 密码 相关文章 java web-.jsp页面中如何把文字写在图片上想要的位置? jsp-在一个JSP页面显示显示两张表的数据,求大神求好心淫 帮帮我~~~~~~ java web-求大神指教关于J

t 遍历文件夹 ile nfo-急求使用Qt遍历打开文件夹,并把所有子文件的路径显示在ListWidget中,求大神帮忙!

问题描述 急求使用Qt遍历打开文件夹,并把所有子文件的路径显示在ListWidget中,求大神帮忙! bool StyleBatch::findFilePath(QString path){ QDir dir(path);if (!dir.exists()) return 0;dir.setFilter(QDir::Dirs|QDir::Files);dir.setSorting(QDir::DirsFirst);QFileInfoList list = dir.entryInfoList();

在布局中的TextView中的字体为什会显示2/3?求大神相助

问题描述 在布局中的TextView中的字体为什会显示2/3?求大神相助 如图 解决方案 高度不够了,他的的父容器的高度不够,或者textview是不是设置了padding啥的 解决方案二: 高度不够,要加高度 解决方案三: 字体太大,导致显示不完全.加大高度或减小字体 解决方案四: 下次再碰到这样的问题你可以打开手机里自带的显示布局容器的功能,看看是因为你控件高度问题还是Padding问题 解决方案五: aaaaaaaaaaa

自定义的cell中,button不显示图片文字 求大神告诉我下

问题描述 自定义的cell中,button不显示图片文字 求大神告诉我下 这是自定义的cell - (UIButton *)categoryBtn{ if (!_categoryBtn) { _categoryBtn = [[UIButton alloc]init]; _categoryBtn.backgroundColor = [UIColor yellowColor]; _categoryBtn.titleLabel.text = @""111111""; [_