画四个点在窗体。

#pragma once

#pragma comment(lib,"d3d9.lib")
#pragma comment(lib,"d3dx9.lib") #include<d3d9.h>
#include<d3dx9.h> //TODO: -1 custom vertex
struct CUSTOMVERTEX
{
float x;
float y;
float z;
float rhw;
}; #define D3DFVF_CUSTOMVERTEX D3DFVF_XYZRHW HRESULT InitD3D(HWND hWnd);
void CleanUp();
void Render();
LRESULT CALLBACK MsgProc(HWND hWnd,UINT msg,WPARAM wParam,LPARAM lParam);
HRESULT InitD3DVertexBuffer(); //TODO: 0 declare d3d variables.
LPDIRECT3D9 g_pd3d = NULL;
LPDIRECT3DDEVICE9 g_pd3dDevice9 = NULL;
LPDIRECT3DVERTEXBUFFER9 g_pd3dVB = NULL; //application entry point.
INT WINAPI wWinMain(
HINSTANCE,
HINSTANCE,
LPWSTR,
INT)
{
//initialize wnd class.
WNDCLASSEX wcex;
ZeroMemory(&wcex,sizeof(wcex));
wcex.cbSize=sizeof(wcex);
wcex.hInstance=GetModuleHandle(NULL);
wcex.lpfnWndProc=MsgProc;
wcex.lpszClassName=L"Self001";
wcex.style=CS_CLASSDC; //register wnd class.
RegisterClassEx(&wcex); //create window.
HWND hWnd=CreateWindowEx(
WS_EX_OVERLAPPEDWINDOW,
L"Self001",
L"Self001 Window",
WS_OVERLAPPEDWINDOW,
100,
100,
300,
300,
NULL,
NULL,
wcex.hInstance,
NULL); //init d3d
if(SUCCEEDED(InitD3D(hWnd)))
{
//show window.
ShowWindow(hWnd,SW_SHOWDEFAULT);
UpdateWindow(hWnd); //message loop.
MSG msg;
ZeroMemory(&msg,sizeof(msg));
while(msg.message != WM_QUIT)
{
if(PeekMessage(&msg,hWnd,0,0,PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
else
{
Render();
}
}
} //unregister wnd class.
UnregisterClass(L"Self001",wcex.hInstance); return 0;
} //init d3d.
HRESULT InitD3D(HWND hWnd)
{
//create d3d.
g_pd3d=Direct3DCreate9(D3D_SDK_VERSION);
if(g_pd3d == NULL)
{
return E_FAIL;
} //initialize d3d present parameters.
D3DPRESENT_PARAMETERS d3dpp;
ZeroMemory(&d3dpp,sizeof(d3dpp));
d3dpp.Windowed=TRUE;
d3dpp.SwapEffect=D3DSWAPEFFECT_DISCARD;
d3dpp.BackBufferFormat=D3DFMT_UNKNOWN; //create d3d device.
if(FAILED(g_pd3d->CreateDevice(
D3DADAPTER_DEFAULT,
D3DDEVTYPE_HAL,
hWnd,
D3DCREATE_SOFTWARE_VERTEXPROCESSING,
&d3dpp,
&g_pd3dDevice9)))
{
return E_FAIL;
} //init vertex buffer.
if(FAILED(InitD3DVertexBuffer()))
{
return E_FAIL;
} return S_OK;
} //clean up d3d.
void CleanUp()
{
//TODO: 3 clean up d3d.
if(g_pd3dVB != NULL)
{
g_pd3dVB->Release();
} //release device.
if(g_pd3dDevice9 != NULL)
{
g_pd3dDevice9->Release();
} //release d3d.
if(g_pd3d != NULL)
{
g_pd3d->Release();
}
} //render the scene.
void Render()
{
//clear target.
g_pd3dDevice9->Clear(
0,
NULL,
D3DCLEAR_TARGET,
D3DCOLOR_XRGB(0,0,0),
1.0f,
0); //draw primitive.
if(SUCCEEDED(g_pd3dDevice9->BeginScene()))
{
//TODO: 2 render d3d.
g_pd3dDevice9->SetStreamSource(0,g_pd3dVB,0,sizeof(CUSTOMVERTEX));
g_pd3dDevice9->SetFVF(D3DFVF_CUSTOMVERTEX);
g_pd3dDevice9->DrawPrimitive(D3DPT_POINTLIST,0,4); g_pd3dDevice9->EndScene();
} //present sence.
g_pd3dDevice9->Present(NULL,NULL,NULL,NULL);
} //window message handler.
LRESULT CALLBACK MsgProc(HWND hWnd,UINT msg,WPARAM wParam,LPARAM lParam)
{
switch(msg)
{
case WM_DESTROY:
CleanUp();
return 0L;
} return DefWindowProc(hWnd,msg,wParam,lParam);
} //init d3d vertex buffer.
HRESULT InitD3DVertexBuffer()
{
//TODO: 1 init vertex buffer data.
//create vertex data.
CUSTOMVERTEX vertices[4]=
{
{50.0f,50.0f,1.0f,1.0f},
{250.0f,50.0f,1.0f,1.0f},
{250.0f,250.0f,1.0f,1.0f},
{50.0f,250.0f,1.0f,1.0f}
}; //create vertex buffer.
if(FAILED(g_pd3dDevice9->CreateVertexBuffer(
sizeof(vertices),
0,
D3DFVF_CUSTOMVERTEX,
D3DPOOL_DEFAULT,
&g_pd3dVB,
NULL)))
{
return E_FAIL;
} //fill vertex buffer.
void* pVertices=NULL;
if(FAILED(g_pd3dVB->Lock(0,sizeof(vertices),&pVertices,0)))
{
return E_FAIL;
} memcpy(pVertices,vertices,sizeof(vertices)); g_pd3dVB->Unlock(); return S_OK;
}

1. 编程的路上练习还是偏多的,这里练习D3D 点列,六中图元中的第一个。

2.我知道不是非常明显,只是四点像素点又能怎么明显呢。

D3D 点列练习的更多相关文章

  1. D3D HOOK实现透视讲解

    实现目的: 目前大部分游戏通过Direct3D实现3D效果,通过挂钩相应函数,可以实现3D透视,屏幕挂字效果.而透视,屏蔽特定效果,设置透明在很多游戏(特别是FPS)中发挥着巨大的作用! 实现思路: ...

  2. FFmpeg滤镜实现区域视频增强 及 D3D实现视频播放区的拉大缩小

    1.区域视频增强 FFmpeg滤镜功能十分强大,用滤镜可以实现视频的区域增强功能. 用eq滤镜就可以实现亮度.对比度.饱和度等的常用视频增强功能. 推荐两篇写得不错的博文: (1)ffmpeg综合应用 ...

  3. D3D三层Texture纹理经像素着色器实现渲染YUV420P

    简单记录一下这两天用Texture实现渲染YUV420P的一些要点. 在视频播放的过程中,有的时候解码出来的数据是YUV420P的.表面(surface)通过设置参数是可以渲染YUV420P的,但Te ...

  4. D3D的绘制

    一.D3D中的绘制 顶点缓存和索引缓存:IDirect3DVertexBuffer9 IDirect3DIndexBuffer 使用这两缓存而不是用数组来存储数据的原因是,缓存可以被放置在显存中,进行 ...

  5. [ZZ] D3D中的模板缓存(3)

    http://www.cppblog.com/lovedday/archive/2008/03/25/45334.html http://www.cppblog.com/lovedday/ D3D中的 ...

  6. D3D的内存类型

    一.对D3D中AGP显存.内存.显存三种内存的解释 三种内存AGP内存(非本地显存),显存(本地内存),系统内存,其中我们都知道系统内存就是咱那内存条,那这AGP内存是个啥玩意啊?其实是因为在以前显卡 ...

  7. D3D depth buffer的预览

    在使用D3D开发游戏的过程中,很多情况下都会用到depth buffer来完成特定的效果,比如DOF,Shadows,SSAO等等.在这些情况下我们就可能需要预览depth buffer来确定它是正确 ...

  8. D3D中深度测试和Alpha混合的关系

    我在学习D3D的深度测试和Alpha混合的时候,有一些遗憾.书上提供的例子里说一定要先渲染不透明物体,再渲染透明物体,对渲染状态的设置也有特殊要求.我看的很晕.自己查图形学的书,上网找资料,结果还是糊 ...

  9. D3D渲染流程--转载

    http://www.cnblogs.com/ixnehc/articles/1282350.html 先从最基础的写起吧,关于Device的渲染流程. D3D9的Device就是D3D给我们提供的一 ...

随机推荐

  1. var和ES6的let

    来源自:http://www.jstips.co/zh_cn/javascript/keyword-var-vs-let/ 特此做个笔记 概述 通过 var 定义的变量,它的作用域是在 functio ...

  2. 洛谷 P3669 [USACO17OPEN]Paired Up 牛牛配对

    P3669 [USACO17OPEN]Paired Up 牛牛配对 题目描述 Farmer John finds that his cows are each easier to milk when ...

  3. HDU 3131 One…Two…Five! (暴力搜索)

    题目链接:pid=3131">HDU 3131 One-Two-Five! (暴力搜索) 题意:给出一串数字,要求用加,减,乘,除(5/2=2)连接(计算无优先级:5+3*6=8*6= ...

  4. 7. Spring Boot 启动加载数据 CommandLineRunner

    转自:https://blog.csdn.net/catoop/article/details/50501710

  5. sql server备份与还原 sql语句

    USE master DECLARE tb CURSOR LOCAL FOR SELECT 'Kill '+ CAST(Spid AS VARCHAR) FROM master.dbo.sysproc ...

  6. apache+nginx 实现动静分离

    apache+nginx 实现动静分离 http://blog.csdn.net/xysoul/article/details/50347971

  7. UVA 294 294 - Divisors (数论)

    UVA 294 - Divisors 题目链接 题意:求一个区间内,因子最多的数字. 思路:因为区间保证最多1W个数字,因子能够遍历区间.然后利用事先筛出的素数求出质因子,之后因子个数为全部(质因子的 ...

  8. EXT gridPanel 添加图片

    var workAreaGrid = new Ext.grid.GridPanel({ region: 'west', title: '工作面预警结果', store: wkSto, width: , ...

  9. python3 用递归方法列出所有目录与文件

    python3 用递归方法列出所有目录与文件 # !/usr/bin/env python # -*- coding:utf-8 -*- # Author:Hiuhung Wan import os ...

  10. AUC(Area Under roc Curve )计算及其与ROC的关系

    转载: http://blog.csdn.net/chjjunking/article/details/5933105 让我们从头说起,首先AUC是一种用来度量分类模型好坏的一个标准.这样的标准其实有 ...