fx文件:

 float4x4 matWorld;
float Time=1.0f; struct VS_OUTPUT
{
float4 Pos :POSITION;
float4 Color :COLOR;
}; VS_OUTPUT VS(float4 Pos:POSITION,float4 Color:COLOR)
{
VS_OUTPUT Out=(VS_OUTPUT);
float4 pos1=Pos;
pos1.y+= cos( Time*2.0f)+;
Out.Pos=mul(pos1,matWorld);
Out.Color=Color;
return Out;
} float4 PS(VS_OUTPUT vsout): COLOR
{
return vsout.Color;
} technique RenderScene
{
pass P0
{
CullMode=None;
vertexShader=compile vs_1_1 VS();
pixelShader=compile ps_2_0 PS();
}
}

C#编写的托管代码,基于WW的渲染框架用托管D3D9 调用:

 using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WorldWind.Renderable;
using Utility;
using Microsoft.DirectX.Direct3D;
using System.IO;
using Microsoft.DirectX;
using System.Drawing;
using System.Windows.Forms; namespace AppScene
{
public class Tri : RenderableObject
{
static Effect m_effect = null;
VertexBuffer vertexBuffer = null;
public Tri(string name)
: base(name)
{
}
public override void Initialize(DrawArgs drawArgs)
{
if (m_effect == null)
{
string outerrors = "";
System.Reflection.Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly();
Stream effectStream = assembly.GetManifestResourceStream("AppScene.Tri.fx");
string pathfx = "Tris.fx";
// string pathfx = " Default_DirectX_Effect.fx";
//string pathfx = "CreateParamModel.fx"; //string pathfx = "flag.fx";
//m_effect = Effect.FromStream(
// drawArgs.device,
// effectStream,
// null,
// null,
// ShaderFlags.None,
// null,
// out outerrors);
m_effect = Effect.FromFile(
drawArgs.device,
pathfx,
null,
null,
ShaderFlags.None,
null,
out outerrors);
if (outerrors != null && outerrors.Length > )
Log.Write(Log.Levels.Error, outerrors);
}
vertexBuffer = new VertexBuffer(typeof(CustomVertex.PositionColored), , drawArgs.device, , CustomVertex.PositionColored.Format, Pool.Default);
vertexBuffer.Created += new EventHandler(vertexBuffer_Created);
vertexBuffer_Created(vertexBuffer, null);
Matrix WorldMatrix = Matrix.Identity;
Matrix viewMatrix = Matrix.LookAtLH(new Vector3(0.0f, 3.0f, -9.0f), new Vector3(0.0f, 0.0f, 0.0f), new Vector3(0.0f, 1.0f, 0.0f));
Matrix projMatrix = Matrix.PerspectiveFovLH((float)Math.PI / , 1.0f, 1.0f, 100.0f);
WorldMatrix = drawArgs.device.GetTransform(TransformType.World);
viewMatrix = drawArgs.device.GetTransform(TransformType.View);
projMatrix = drawArgs.device.GetTransform(TransformType.Projection); m_effect.SetValue("matWorld", WorldMatrix * viewMatrix * projMatrix);
// m_effect.SetValue("matViewProjection", viewMatrix * projMatrix);
isInitialized = true;
} public override void Update(DrawArgs drawArgs)
{
try
{
if (!isInitialized)
Initialize(drawArgs); }
catch (Exception ex)
{
Log.Write(ex);
}
}
public override void Render(DrawArgs drawArgs)
{
if (!isInitialized)
return; drawArgs.device.SetStreamSource(, vertexBuffer, );
drawArgs.device.VertexFormat = CustomVertex.PositionColored.Format;
int iTime = Environment.TickCount % ;
float Angle = iTime * (2.0f * (float)Math.PI) / 1000.0f;
m_effect.SetValue("Time", Angle);
m_effect.Technique = "RenderScene";
// m_effect.Technique = "Default_DirectX_Effect";
int numPasses = m_effect.Begin(); for (int i = ; i < numPasses; i++)
{
m_effect.BeginPass(i);
drawArgs.device.DrawPrimitives( PrimitiveType.TriangleList, , );
m_effect.EndPass();
}
m_effect.End(); } void vertexBuffer_Created(object sender, EventArgs e)
{
CustomVertex.PositionColored[] verts = (CustomVertex.PositionColored[])vertexBuffer.Lock(, );
verts[].Position = new Vector3(12.0f,11.0f,10.0f);
verts[].Color = Color.Red.ToArgb();
verts[].Position = new Vector3(30.0f, 32.0f, 10.0f);
verts[].Color = Color.Red.ToArgb();
verts[].Position = new Vector3(10.0f, 60.0f, 10.0f);
verts[].Color = Color.Yellow.ToArgb();
vertexBuffer.Unlock();
} public override void Dispose()
{
if (vertexBuffer!=null)
{
vertexBuffer.Dispose();
}
} public override bool PerformSelectionAction(DrawArgs drawArgs)
{
return false;
}
}
}

这里出现一个问题:

鼠标在窗体上移动才能够显示上下移动的三角形。

有时候启动了程序,三角形干脆不显示。开始还没有这个问题,后来出现这个问题!

原来我以为是视域体的问题,但是这个三角形肯定在视域体内部啊。

是帧率控制的问题?需要控制帧率吗,控制帧率是为了减少屏幕刷新次数。不至于刷新太频繁画面干脆不显示吧!

机器有没有问题?

这个问题真是困扰人!

WW的渲染框架本身会有问题吗,通过继承构建的渲染列表对状态机产生影响了?书上的示例程序是没有问题的,为啥我写到一个RenderObject中会出现问题?

后记:移植了NativeMethod类后就好了,应该是消息分发的问题。

第一个Shader程序的更多相关文章

  1. 【浅墨Unity3D Shader编程】之一 夏威夷篇:游戏场景的创建 & 第一个Shader的书写

    本系列文章由@浅墨_毛星云 出品,转载请注明出处. 文章链接:http://blog.csdn.net/poem_qianmo/article/details/40723789 作者:毛星云(浅墨)  ...

  2. 【OpenGL】详解第一个OpenGL程序

    写在前面 OpenGL能做的事情太多了!很多程序也看起来很复杂.很多人感觉OpenGL晦涩难懂,原因大多是被OpenGL里面各种语句搞得头大,一会gen一下,一会bind一下,一会又active一下. ...

  3. 【浅墨Unity3D Shader编程】之中的一个 夏威夷篇:游戏场景的创建 &amp; 第一个Shader的书写

    本系列文章由@浅墨_毛星云 出品.转载请注明出处. 文章链接:http://blog.csdn.net/poem_qianmo/article/details/40723789 作者:毛星云(浅墨)  ...

  4. DirectX游戏编程(一):创建一个Direct3D程序

    一.环境 Visual Studio 2012,DirectX SDK (June 2010) 二.准备 1.环境变量(如没有配置请添加) 变量名:DXSDK_DIR 变量值:D:\Software\ ...

  5. 第一个python程序

    一个python程序的两种执行方式: 1.第一种方式是通过python解释器: cmd->python->进入python解释器->编写python代码->回车. 2.第二种方 ...

  6. 编写第一个MapReduce程序—— 统计气温

    摘要:hadoop安装完成后,像学习其他语言一样,要开始写一个“hello world!” ,看了一些学习资料,模仿写了个程序.对于一个C#程序员来说,写个java程序,并调用hadoop的包,并跑在 ...

  7. 1.3 第一个C#程序

    几乎没一门编程语言的第一个程序都叫“你好,世界”,所以先在visual studio 中创建一个Helloworld程序. 各部分的详细内容: Main方法是程序运行的起点,最重要的代码就写在Main ...

  8. 一个.net程序员的安卓之旅-Eclipse设置代码智能提示功能

    一个.net程序员的安卓之旅-代码智能提示功能 过完年回来就决心开始学安卓开发,就网上买了个内存条加在笔记本上(因为笔记本原来2G内存太卡了,装了vs2010.SQL Server 2008.orac ...

  9. MFC-01-Chapter01:Hello,MFC---1.3 第一个MFC程序(02)

    1.3.1 应用程序对象 MFC应用程序的核心就是基于CWinApp类的应用程序对象,CWinApp提供了消息循环来检索消息并将消息调度给应用程序的窗口.当包含头文件<afxwin.h>, ...

随机推荐

  1. Don‘t talk.Just do it.

    对于算法,自己掌握的还是不多.并且我发现对于一个算法的理解非常重要.也许你会发现你貌似会用某总算法但是,他一旦变形,自己就无从下手. 还有就是对于算法.最好每次都自己敲,这样不仅能添加对于算法的熟度. ...

  2. Linux基本监控项目

    1.网卡流量 (统计网卡TX(发送)RX(接受)流量脚本) 使用 Nagios 来监控网卡流量 2013/01/31 Nagios, 网卡 监控统计与日志分析 评论 2,272   下载地址为:che ...

  3. Spring学习笔记--自动装配Bean属性

    Spring提供了四种类型的自动装配策略: byName – 把与Bean的属性具有相同名字(或者ID)的其他Bean自动装配到Bean的对应属性中. byType – 把与Bean的属性具有相同类型 ...

  4. jQueryValidate实现重复性验证

    $(function(){      $("#frm").validateForm({           rules:{                'caResourceSt ...

  5. OpenStack三个节点icehouse

    一.环境准备 1.架构 创建3台虚拟机,分别作为controll节点.network节点和compute1节点. Controller节点:1processor,2G memory,5G storag ...

  6. CentOS7安装Openvswitch 2.3.1 LTS

    CentOS7安装Openvswitch 2.3.0 LTS,centos7openvswitch 一.环境: 宿主机:windows 8.1 update 3 虚拟机:vmware 11 虚拟机操作 ...

  7. 开源的PaaS方案:在OpenStack上部署CloudFoundry (三)部署BOSH

    BOSH是CloudFoundry提供的用来安装部署和升级CloudFoundry的自动化工具,可是说是CloudFoundry的一部分.总体来说,BOSH是Client/Server结构, BOSH ...

  8. SimpleDateFormat使用详解 <转>

    public class SimpleDateFormat extends DateFormat SimpleDateFormat 是一个以国别敏感的方式格式化和分析数据的具体类. 它允许格式化 (d ...

  9. JQuery事件e参数的方法preventDefault()取消默认行为

    <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <m ...

  10. C# 文件夹的常用操作

    C#获取文件夹下的所有文件的文件名 string path = @"E:\微课视频大于200M"; DirectoryInfo folder = new DirectoryInfo ...