青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

C++ Programmer's Cookbook

{C++ 基礎(chǔ)} {C++ 高級(jí)} {C#界面,C++核心算法} {設(shè)計(jì)模式} {C#基礎(chǔ)}

Managed Directx --rendering vertices (使用VertexBuffer 進(jìn)行render)

?

// -----------------------------------------------------------------------------
// ?File:?Vertices.cs
//
// ?Desc:?In?this?tutorial,?we?are?rendering?some?vertices.?This?introduces?the
// ???????concept?of?the?vertex?buffer,?a?Direct3D?object?used?to?store
// ???????vertices.?Vertices?can?be?defined?any?way?we?want?by?defining?a
// ???????custom?structure?and?a?custom?FVF?(flexible?vertex?format).?In?this
// ???????tutorial,?we?are?using?vertices?that?are?transformed?(meaning?they
// ???????are?already?in?2D?window?coordinates)?and?lit?(meaning?we?are?not
// ???????using?Direct3D?lighting,?but?are?supplying?our?own?colors).
//
// ?Copyright?(c)?Microsoft?Corporation.?All?rights?reserved.
// -----------------------------------------------------------------------------
using ?System;
using ?System.Drawing;
using ?System.Windows.Forms;
using ?Microsoft.DirectX;
using ?Microsoft.DirectX.Direct3D;

namespace ?VerticesTutorial
{
????
public ? class ?Vertices?:?Form
????
{
????????
// ?Our?global?variables?for?this?project
????????Device?device? = ? null ;? // ?Our?rendering?device
????????VertexBuffer?vertexBuffer? = ? null ;

????????
public ?Vertices()
????????
{
????????????
// ?Set?the?initial?size?of?our?form
???????????? this .ClientSize? = ? new ?System.Drawing.Size( 300 , 300 );
????????????
// ?And?its?caption
???????????? this .Text? = ? " Direct3D?Tutorial?2?-?Vertices " ;
????????}

????????
????????
public ? bool ?InitializeGraphics()
????????
{
????????????
try
????????????
{
????????????????
// ?Now?let's?setup?our?D3D?stuff
????????????????PresentParameters?presentParams? = ? new ?PresentParameters();
????????????????presentParams.Windowed
= true ;
????????????????presentParams.SwapEffect?
= ?SwapEffect.Discard;
????????????????device?
= ? new ?Device( 0 ,?DeviceType.Hardware,? this ,?CreateFlags.SoftwareVertexProcessing,?presentParams);
????????????????
this .OnCreateDevice(device,? null );
????????????????
return ? true ;
????????????}

????????????
catch ?(DirectXException)
????????????
{?
????????????????
return ? false ;?
????????????}

????????}


????????
public ? void ?OnCreateDevice( object ?sender,?EventArgs?e)
????????
{
????????????Device?dev?
= ?(Device)sender;
????????????
// ?Now?Create?the?VB
????????????vertexBuffer? = ? new ?VertexBuffer( typeof (CustomVertex.TransformedColored),? 3 ,?dev,? 0 ,?CustomVertex.TransformedColored.Format,?Pool.Default);
????????????vertexBuffer.Created?
+= ? new ?System.EventHandler( this .OnCreateVertexBuffer);
????????????
this .OnCreateVertexBuffer(vertexBuffer,? null );
????????}

????????
public ? void ?OnCreateVertexBuffer( object ?sender,?EventArgs?e)
????????
{
????????????VertexBuffer?vb?
= ?(VertexBuffer)sender;
????????????GraphicsStream?stm?
= ?vb.Lock( 0 ,? 0 ,? 0 );
????????????CustomVertex.TransformedColored[]?verts?
= ? new ?CustomVertex.TransformedColored[ 3 ];

????????????verts[
0 ].X = 150 ;verts[ 0 ].Y = 50 ;verts[ 0 ].Z = 0.5f ;?verts[ 0 ].Rhw = 1 ;?verts[ 0 ].Color? = ?System.Drawing.Color.Red.ToArgb();
????????????verts[
1 ].X = 250 ;verts[ 1 ].Y = 250 ;verts[ 1 ].Z = 0.5f ;?verts[ 1 ].Rhw = 1 ;?verts[ 1 ].Color? = ?System.Drawing.Color.Yellow.ToArgb();
????????????verts[
2 ].X = 50 ;verts[ 2 ].Y = 250 ;verts[ 2 ].Z = 0.5f ;?verts[ 2 ].Rhw = 1 ;?verts[ 2 ].Color? = ?System.Drawing.Color.SkyBlue.ToArgb();
????????????stm.Write(verts);
????????????vb.Unlock();
????????}

????????
private ? void ?Render()
????????
{
????????????
if ?(device? == ? null )?
????????????????
return ;

????????????
// Clear?the?backbuffer?to?a?blue?color?(ARGB?=?000000ff)
????????????device.Clear(ClearFlags.Target,?System.Drawing.Color.Blue,? 1.0f ,? 0 );
????????????
// Begin?the?scene
????????????device.BeginScene();
????????????
????????????device.SetStreamSource(?
0 ,?vertexBuffer,? 0 );
????????????device.VertexFormat?
= ?CustomVertex.TransformedColored.Format;
????????????device.DrawPrimitives(PrimitiveType.TriangleList,?
0 ,? 1 );
????????????
// End?the?scene
????????????device.EndScene();
????????????device.Present();
????????}

????????
protected ? override ? void ?OnPaint(System.Windows.Forms.PaintEventArgs?e)
????????
{
????????????
this .Render();? // ?Render?on?painting
????????}

????????
protected ? override ? void ?OnKeyPress(System.Windows.Forms.KeyPressEventArgs?e)
????????
{
????????????
if ?(( int )( byte )e.KeyChar? == ?( int )System.Windows.Forms.Keys.Escape)
????????????????
this .Close();? // ?Esc?was?pressed
????????}


????????
/// ? <summary>
????????
/// ?The?main?entry?point?for?the?application.
????????
/// ? </summary>

???????? static ? void ?Main()?
????????
{

????????????
using ?(Vertices?frm? = ? new ?Vertices())
????????????
{
????????????????
if ?( ! frm.InitializeGraphics())? // ?Initialize?Direct3D
???????????????? {
????????????????????MessageBox.Show(
" Could?not?initialize?Direct3D.??This?tutorial?will?exit. " );
????????????????????
return ;
????????????????}

????????????????frm.Show();

????????????????
// ?While?the?form?is?still?valid,?render?and?process?messages
???????????????? while (frm.Created)
????????????????
{
????????????????????frm.Render();
????????????????????Application.DoEvents();
????????????????}

????????????}

????????}


????}

}


1 定義 VertexBuffer vb = null;
2 創(chuàng)建 VertexBuffer?
??? public void OnCreateDevice(object sender, EventArgs e)
??? {
??? Device dev = (Device)sender;
???
??? // Now create the vertex buffer
??? vertexBuffer = new VertexBuffer(
??????? typeof(CustomVertex.TransformedColored), 3, dev, 0,
??????? CustomVertex.TransformedColored.Format, Pool.Default);
??? vertexBuffer.Created +=
??????? new System.EventHandler(this.OnCreateVertexBuffer);
??? this.OnCreateVertexBuffer(vb, null);
??? }

??? public void OnCreateVertexBuffer(object sender, EventArgs e)
??? {
??? VertexBuffer vb = (VertexBuffer)sender;
??? GraphicsStream stm = vb.Lock(0, 0, 0);?? //Lock() 保證cpu能夠直接訪問(wèn) VertexBuffer ,必須和unlock()一起使用
??? CustomVertex.TransformedColored[] verts =
??????? new CustomVertex.TransformedColored[3];
??? .
??? .
??? .
??? vb.Unlock();
??? }
3? GraphicsStream對(duì)象直接訪問(wèn)vertexbuffer, 或者說(shuō)把vertexbuffer的內(nèi)容放到Graphicsstream中以合適的大小.
verts[0].X=150; verts[0].Y=50; verts[0].Z=0.5f; verts[0].Rhw=1;
verts[0].Color = System.Drawing.Color.Aqua.ToArgb();

verts[1].X=250; verts[1].Y=250; verts[1].Z=0.5f; verts[1].Rhw=1;
verts[1].Color = System.Drawing.Color.Brown.ToArgb();

verts[2].X=50; verts[2].Y=250; verts[2].Z=0.5f; verts[2].Rhw=1;
verts[2].Color = System.Drawing.Color.LightPink.ToArgb();

stm.Write(verts);
4 render device
private void Render()
{
??? if (device == null)
??? return;
???
??? // Clear the back buffer to a blue color (ARGB = 000000ff)
??? device.Clear(ClearFlags.Target, System.Drawing.Color.Blue, 1.0f, 0);
??? // Begin the scene
??? device.BeginScene();
???
??? // New for Tutorial 2
??? device.SetStreamSource(0, vertexBuffer, 0);??? //設(shè)置stream源用vertexbuffer.
??? device.VertexFormat = CustomVertex.TransformedColored.Format;? //設(shè)置render格式
??? device.DrawPrimitives(PrimitiveType.TriangleList, 0, 1);?
???
??? // End the scene
??? device.EndScene();
??? device.Present();
}

Read and Write VertexBuffer and IndexBuffer Data With GraphicsStreams


using?System;
using?Microsoft.DirectX;
using?Microsoft.DirectX.Direct3D;

public?struct?PositionNormalTexVertex
{
????
public?Vector3?Position;
????
public?Vector3?Normal;
????
public??float?Tu0,?Tv0;
????
public?static?readonly?VertexFormats?FVF?=?VertexFormats.Position?|?VertexFormats.Texture1;
}

public?class?Example
{
????
public?unsafe?void??GraphicsStreamReadWrite()
????
{
????????
//Create?a?vertex?buffer?in?the?managed?pool
????????VertexBuffer?vb?=?new?VertexBuffer(typeof(PositionNormalTexVertex),?100,?device,?Usage.None,?PositionNormalTexVertex.FVF,?Pool.Managed);

????????
//First,?fill?an?array?of?PositionNormalTexVertex?elements?with?data.
????????PositionNormalTexVertex[]?vertices?=?new?PositionNormalTexVertex[50];
????????
for(int?i=0;?i<50;?i++)
????????
{
????????????
//fill?the?vertices?with?some?data
????????????vertices[i].Position?=?new?Vector3(3f,4f,5f);
????????}


????????
//The?size?of?the?verticies?are?32-bytes?each?(float3?(12)?+?float3?(12)?+?float(4)?+?float(4))
????????
//To?lock?50?verticies,?the?size?of?the?lock?would?be?1600?(32?*?50)
????????GraphicsStream?vbData?=??vb.Lock(0,1600,?LockFlags.None);

????????
//copy?the?vertex?data?into?the?vertex?buffer
????????vbData.Write(vertices);

????????
//Unlock?the?VB
????????vb.Unlock();


????????
//This?time,?lock?the?entire?VertexBuffer
????????vbData?=??vb.Lock(0,?3200,?LockFlags.None);

????????
//Cast?the?InternalDataPointer?(a?void?pointer)?to?an?array?of?verticies
????????PositionNormalTexVertex*?vbArray?=?(PositionNormalTexVertex*)?vbData.InternalDataPointer;

????????
for(int?i=0;?i<100;?i++)
????????
{
????????????
//perform?some?operations?on?the?data
????????????vbArray[i].Tu0?=?i;
????????????vbArray[i].Tv0?
=?vbArray[i].Tu0?*?2;

????????????Console.WriteLine(vbArray[i].Tv0.ToString());
????????}


????????
//Unlock?the?buffer
????????vb.Unlock();
????????vb.Dispose();
????}

}

Read and Write VertexBuffer Data With Arrays

using?System;
using?Microsoft.DirectX;
using?Microsoft.DirectX.Direct3D;

public?struct?PositionNormalTexVertex
{
????
public?Vector3?Position;
????
public?Vector3?Normal;
????
public?float?Tu0,?Tv0;
????
public?static?readonly?VertexFormats?FVF?=?VertexFormats.Position?|?VertexFormats.Texture1;
}


public?class?Example
{
????
public?void?ArrayBasedReadWrite()
????
{
????????
//Create?a?vertex?buffer?in?the?managed?pool
????????VertexBuffer?vb?=?new?VertexBuffer(typeof(PositionNormalTexVertex),?100,?device,?Usage.None,?PositionNormalTex1Vertex.FVF,?Pool.Managed);

????????
//Fill?an?array?of?the?appropriate?type?with?the?VB?data?using?Lock()
????????PositionNormalTexVertex[]?vbData?=?(PositionNormalTexVertex[])?vb.Lock(0,?typeof(PositionNormalTexVertex),?LockFlags.None,?50);
????????
for(int?i=0;?i<50;?i++)
????????
{
????????????
//set?your?vertices?to?something
????????????vbData[i].Position?=?new?Vector3(2f,2f,2f);??
????????????vbData[i].Normal?
=?new?Vector3(1f,0f,0f);
????????????vbData[i].Tu0?
=?i;
????????????vbData[i].Tv0?
=?i;
????????}

????????
//Unlock?the?vb?before?you?can?use?it?elsewhere
????????vb.Unlock();

????????
//This?lock?overload?simply?locks?the?entire?VB?--?setting?ReadOnly?can?improve?perf?when?reading?a?vertexbuffer
????????vbData?=?(PositionNormalTexVertex[])?vb.Lock(0,?LockFlags.ReadOnly);
????????
for(int?i=0;?i<100;?i++)
????????
{
????????????
//read?some?vertex?data
????????????Console.WriteLine("Vertex?"?+?i?+?"Tu:?"?+??vbData[i].Tu0?+?"?,?Tv:?"?+?vbData[i].Tv0);
????????}


????????
//Unlock?the?buffer
????????vb.Unlock();


????????vb.Dispose();
????}

}

posted on 2006-05-12 13:55 夢(mèng)在天涯 閱讀(977) 評(píng)論(0)  編輯 收藏 引用 所屬分類(lèi): DirectX

公告

EMail:itech001#126.com

導(dǎo)航

統(tǒng)計(jì)

  • 隨筆 - 461
  • 文章 - 4
  • 評(píng)論 - 746
  • 引用 - 0

常用鏈接

隨筆分類(lèi)

隨筆檔案

收藏夾

Blogs

c#(csharp)

C++(cpp)

Enlish

Forums(bbs)

My self

Often go

Useful Webs

Xml/Uml/html

搜索

  •  

積分與排名

  • 積分 - 1812199
  • 排名 - 5

最新評(píng)論

閱讀排行榜

青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
      <noscript id="pjuwb"></noscript>
            <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
              <dd id="pjuwb"></dd>
              <abbr id="pjuwb"></abbr>
              亚洲激情成人网| 亚洲第一在线综合网站| 欧美一区二区播放| 亚洲天堂第二页| 亚洲免费中文| 亚洲在线一区二区三区| 欧美一区二区三区四区在线 | 亚洲国产天堂久久综合| 久久精品国产免费看久久精品| 99精品欧美一区| 亚洲女人天堂成人av在线| 欧美中文在线免费| 欧美刺激性大交免费视频| 亚洲精品免费网站| 亚洲综合第一页| 美女国产一区| 国产精品毛片a∨一区二区三区| 国产人成精品一区二区三| 在线观看三级视频欧美| 亚洲视频精选在线| 久久综合中文字幕| 一本久久综合亚洲鲁鲁| 久久精品国产欧美亚洲人人爽| 免费观看在线综合色| 国产精品九色蝌蚪自拍| 有坂深雪在线一区| 亚洲欧美欧美一区二区三区| 久久资源av| 亚洲一区二区三区精品在线观看 | 国一区二区在线观看| 99国产精品| 久久一区欧美| 亚洲男人第一网站| 欧美日本网站| 亚洲精品欧美极品| 毛片av中文字幕一区二区| 亚洲尤物影院| 国产精品高潮在线| 亚洲免费福利视频| 免费观看久久久4p| 午夜在线播放视频欧美| 欧美少妇一区| 99riav久久精品riav| 久久免费视频在线观看| 亚洲欧美一区二区三区在线| 欧美日韩网址| 日韩亚洲欧美一区| 欧美成人有码| 免费看av成人| 亚洲激情av| 亚洲第一页在线| 女同性一区二区三区人了人一| 黄色成人在线观看| 久久一二三区| 久久综合中文字幕| 亚洲精品三级| 亚洲精品久久久久久下一站| 欧美成人资源| 一区二区日本视频| 日韩午夜av电影| 欧美日韩中字| 亚洲网站在线看| 亚洲深夜影院| 国产日韩一区二区三区在线| 欧美精品日韩一本| 欧美日韩国产成人在线观看| 亚洲精品美女在线观看播放| 亚洲激情视频网站| 欧美另类变人与禽xxxxx| 宅男噜噜噜66一区二区66| 亚洲欧洲日韩女同| 欧美日韩美女在线| 亚洲女与黑人做爰| 欧美一区成人| 亚洲国产影院| 亚洲美女视频网| 国产精品麻豆va在线播放| 久久久久.com| 欧美激情一区二区三区全黄| 亚洲视频欧美视频| 亚洲欧美中文另类| 亚洲高清自拍| 艳妇臀荡乳欲伦亚洲一区| 国产精品看片你懂得| 久久久国产亚洲精品| 久久综合狠狠| 亚洲欧美视频一区二区三区| 欧美在线观看日本一区| 亚洲国产精品va在线看黑人| 亚洲美女一区| 狠狠色综合色区| 亚洲日本成人在线观看| 国产欧美一区二区三区沐欲 | 亚洲小说区图片区| 亚洲大胆在线| 亚洲一级黄色片| 亚洲国产成人在线播放| 一区二区三区蜜桃网| 在线观看成人av| 宅男精品导航| 亚洲丰满在线| 亚洲免费一级电影| 亚洲美女性视频| 久久精品国产77777蜜臀| 中文欧美字幕免费| 久久免费精品视频| 欧美一二三视频| 欧美精品v日韩精品v韩国精品v| 久久国产精品久久w女人spa| 欧美人与性禽动交情品| 久久免费国产精品| 国产精品久久一级| 亚洲精品系列| 亚洲久久在线| 玖玖在线精品| 久久一区二区三区四区五区| 国产精品激情av在线播放| 亚洲日本一区二区| 亚洲国产老妈| 另类激情亚洲| 美女91精品| 尤物99国产成人精品视频| 亚洲综合视频1区| 午夜视频在线观看一区二区三区| 欧美日韩另类国产亚洲欧美一级| 欧美国产激情二区三区| 一区二区三区在线免费视频| 午夜精品久久久久久99热软件| 老司机免费视频久久| 影音先锋另类| 欧美综合国产| 久久噜噜亚洲综合| 国产一区二区三区在线观看精品| 亚洲一区bb| 午夜一区不卡| 国产伦理一区| 欧美一区二粉嫩精品国产一线天| 欧美一区二区三区四区夜夜大片| 欧美性淫爽ww久久久久无| 一区二区日韩伦理片| 亚洲一级在线| 国产精品入口尤物| 午夜视黄欧洲亚洲| 久久精品视频免费播放| 精品二区久久| 欧美激情精品| 在线亚洲伦理| 久久久777| 91久久国产综合久久| 欧美激情片在线观看| 日韩午夜剧场| 欧美一区二区免费视频| 韩日欧美一区| 免费成人黄色av| 亚洲美女av网站| 欧美亚洲日本一区| 激情久久影院| 欧美日韩国产黄| 亚洲欧洲99久久| 欧美成人激情视频| 亚洲视频在线观看| 国产一区二区视频在线观看| 免费91麻豆精品国产自产在线观看| 亚洲人永久免费| 久久九九99| 一区二区三区导航| 伊人成人在线视频| 欧美日韩一区二区三区在线看| 亚洲欧美日韩一区二区| 欧美激情第一页xxx| 亚洲欧美电影在线观看| 亚洲国产va精品久久久不卡综合| 欧美日韩国产成人在线| 久久精品成人一区二区三区| 亚洲黄色在线观看| 久久久久国色av免费观看性色| 亚洲人www| 国产在线乱码一区二区三区| 欧美激情性爽国产精品17p| 午夜精品久久久久久久99热浪潮| 亚洲国产精品精华液2区45| 欧美亚洲视频在线观看| 亚洲激情网址| 国产亚洲精品久| 欧美日韩一区精品| 久久综合网络一区二区| 亚洲图片欧洲图片av| 亚洲国产成人久久| 久久久99爱| 先锋影音一区二区三区| 一本高清dvd不卡在线观看| 国语自产精品视频在线看一大j8| 欧美视频成人| 欧美日韩精品高清| 欧美高清视频www夜色资源网| 欧美在线不卡视频| 香蕉久久夜色精品| 亚洲欧美日韩人成在线播放| 日韩一区二区久久| 亚洲美女av在线播放|