关于Direct 9 绘制立方体的问题

只负责写Bug 2017-05-11 08:47:00

#include "d3dUtility.h"

#define WIDTH 800 //屏幕宽
#define HEIGHT 600 //屏幕高

IDirect3DDevice9*device = 0;
D3DPRESENT_PARAMETERS d3dpp;

IDirect3DVertexBuffer9 *VB; //定义顶点缓存
IDirect3DIndexBuffer9 *IB; //定义索引缓存

struct Vertex
{
float _x, _y, _z;
Vertex(float x, float y, float z)
{
_x = x;
_y = y;
_z = z;
}
static const DWORD FVF;
};
const DWORD Vertex::FVF = D3DFVF_XYZ;

bool D3D::Setup()
{
device->CreateVertexBuffer(8 * sizeof(Vertex), D3DUSAGE_WRITEONLY, Vertex::FVF, D3DPOOL_MANAGED, &VB, 0);
device->CreateIndexBuffer(36 * sizeof(WORD), D3DUSAGE_WRITEONLY, D3DFMT_INDEX16, D3DPOOL_MANAGED, &IB, 0);

Vertex *vertices;
VB->Lock(0, 0, (void **)&vertices, 0);
vertices[0] = Vertex(-1.0f, -1.0f, -1.0f);
vertices[1] = Vertex(-1.0f, 1.0f, -1.0f);
vertices[2] = Vertex(1.0f, 1.0f, -1.0f);
vertices[3] = Vertex(1.0f, -1.0f, -1.0f);
vertices[4] = Vertex(-1.0f, -1.0f, 1.0f);
vertices[5] = Vertex(-1.0f, 1.0f, 1.0f);
vertices[6] = Vertex(1.0f, 1.0f, 1.0f);
vertices[7] = Vertex(1.0f, -1.0f, 1.0f);
VB->Unlock();

WORD *indices;
IB->Lock(0, 0, (void **)&indices, 0);
indices[0] = 0; indices[1] = 1; indices[2] = 2;
indices[3] = 0; indices[4] = 2; indices[5] = 3;
// 背面
indices[6] = 4; indices[7] = 6; indices[8] = 5;
indices[9] = 4; indices[10] = 7; indices[11] = 6;
// 左面
indices[12] = 4; indices[13] = 5; indices[14] = 1;
indices[15] = 4; indices[16] = 1; indices[17] = 0;
// 右面
indices[18] = 3; indices[19] = 2; indices[20] = 6;
indices[21] = 3; indices[22] = 6; indices[23] = 7;
// 顶部
indices[24] = 1; indices[25] = 5; indices[26] = 6;
indices[27] = 1; indices[28] = 6; indices[29] = 2;
// 底部
indices[30] = 4; indices[31] = 0; indices[32] = 3;
indices[33] = 4; indices[34] = 3; indices[35] = 7;
IB->Unlock();

D3DXVECTOR3 position(0.0f, 0.0f, -5.0f);
D3DXVECTOR3 target(0.0f, 0.0f, 0.0f);
D3DXVECTOR3 up(0.0f, 1.0f, 0.0f);
D3DXMATRIX V;
D3DXMatrixLookAtLH(&V, &position, &target, &up);
device->SetTransform(D3DTS_VIEW, &V);
// 投影矩阵
D3DXMATRIX proj;
D3DXMatrixPerspectiveFovLH(
&proj,
D3DX_PI * 0.5f, // 90 - degree
(float)WIDTH / (float)HEIGHT,
1.0f,
1000.0f);
device->SetTransform(D3DTS_PROJECTION, &proj);
device->SetRenderState(D3DRS_FILLMODE, D3DFILL_WIREFRAME);

device->BeginScene();// 开始绘制场景
device->SetStreamSource(0, VB, 0, sizeof(Vertex));// 设置资源流
device->SetIndices(IB); // 设置索引缓存
device->SetFVF(Vertex::FVF); // 设置顶点格式
// 利用索引缓存绘制
device->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, 8, 0, 12);
device->EndScene();// 结束绘制场景

return true;
}



我直接调用这个函数窗口没东西,老哥们帮我看看缺少了什么步骤,谢谢
...全文
170 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
wallesyoyo 2017-05-11
  • 打赏
  • 举报
回复
你把main函数贴出来看看吧,是不是没加消息循环额?
只负责写Bug 2017-05-11
  • 打赏
  • 举报
回复
引用 13 楼 wanggui2015 的回复:
[quote=引用 12 楼 qq_15173325 的回复:] [quote=引用 11 楼 wanggui2015 的回复:] 啥都没有吗?你这是线框模式,好歹有几条线出来的呀。。

#include "d3dUtility.h"

#define WIDTH 800  //屏幕宽
#define HEIGHT 600  //屏幕高

IDirect3DDevice9*device = 0;
D3DPRESENT_PARAMETERS d3dpp;

IDirect3DVertexBuffer9 *VB;  //定义顶点缓存
IDirect3DIndexBuffer9 *IB;  //定义索引缓存

struct Vertex
{
	float _x, _y, _z;
	Vertex(float x, float y, float z)
	{
		_x = x;
		_y = y;
		_z = z;
	}
	static const DWORD FVF;
};
const DWORD Vertex::FVF = D3DFVF_XYZ;

bool D3D::Setup()
{
	device->CreateVertexBuffer(
		3 * sizeof(Vertex), // size in bytes
		D3DUSAGE_WRITEONLY, // flags
		Vertex::FVF,        // vertex format
		D3DPOOL_MANAGED,    // managed memory pool
		&VB,          // return create vertex buffer
		0);                 // not used - set to 0

	Vertex *vertices;
	VB->Lock(0, 0, (void **)&vertices, 0);
	vertices[0] = Vertex(-1.0f, 0.0f, 2.0f);
	vertices[1] = Vertex(0.0f, 1.0f, 2.0f);
	vertices[2] = Vertex(1.0f, 0.0f, 2.0f);
	VB->Unlock();

	

	
	D3DXMATRIX proj;
	D3DXMatrixPerspectiveFovLH(
		&proj,
		D3DX_PI * 0.5f, // 90 - degree
		(float)WIDTH / (float)HEIGHT,
		1.0f,
		1000.0f);
	device->SetTransform(D3DTS_PROJECTION, &proj);

	device->Clear(0, 0, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xffffffff, 1.0f, 0);
	device->BeginScene();

	device->SetStreamSource(0, VB, 0, sizeof(Vertex));
	device->SetFVF(Vertex::FVF);

	// Draw one triangle.
	device->DrawPrimitive(D3DPT_TRIANGLELIST, 0, 1);

	device->EndScene();
	device->Present(0, 0, 0, 0);

	return true;
}




bool D3D::initD3D(D3DDEVTYPE DeviceType, HWND hwnd)
{
	IDirect3D9 * d3d9 = Direct3DCreate9(D3D_SDK_VERSION);

	// 填充主显示设备的能力( D3DCAPS9结构)
	D3DCAPS9 caps;
	d3d9->GetDeviceCaps(
		D3DADAPTER_DEFAULT, // 主显示设备
		DeviceType, // 设备类型,一般是D3DDEVTYPE_HAL.
		&caps); // 返回填充后的D3DCAPS9 结构,包含主显示设备的能力
				// 是否可以使用硬件顶点处理?
	int vp = 0;
	if (caps.DevCaps& D3DDEVCAPS_HWTRANSFORMANDLIGHT)
	{
		// 是,支持硬件顶点处理
		vp = D3DCREATE_HARDWARE_VERTEXPROCESSING;
	}
	else
	{
		// 不,只能用软件顶点处理
		vp = D3DCREATE_SOFTWARE_VERTEXPROCESSING;
	}

	d3dpp.BackBufferWidth = 800;
	d3dpp.BackBufferHeight = 600;
	d3dpp.BackBufferFormat = D3DFMT_A8R8G8B8; //像素格式
	d3dpp.BackBufferCount = 1;
	d3dpp.MultiSampleType = D3DMULTISAMPLE_NONE;
	d3dpp.MultiSampleQuality = 0;
	d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
	d3dpp.hDeviceWindow = hwnd;
	d3dpp.Windowed = true; // fullscreen
	d3dpp.EnableAutoDepthStencil = true;
	d3dpp.AutoDepthStencilFormat = D3DFMT_D24S8; // depth format
	d3dpp.Flags = 0;
	d3dpp.FullScreen_RefreshRateInHz = D3DPRESENT_RATE_DEFAULT;
	d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;

	int hr = d3d9->CreateDevice(
		D3DADAPTER_DEFAULT, //primary adapter
		D3DDEVTYPE_HAL,//devicetype
		hwnd,//window associated withdevice
		D3DCREATE_HARDWARE_VERTEXPROCESSING, //vertexprocessing type
		&d3dpp,//presentparameters
		&device);//returned created device
	if (FAILED(hr))
	{
		::MessageBox(0, "CreateDevice() -FAILED", 0, 0);
		return 0;
	}
	else
	{
		return 1;
	}


}
大哥 你看看 我把立方体改成三角形了 什么东西都没有出来。。 我窗口背景颜色是白色[/quote] 你贴出来的代码是没问题的额,你程序能出来窗口吗?还是有窗口没内容?[/quote] 大哥 谢谢你的耐心 群里面的朋友说要循环调用 我就把函数放到WM_PAINI里面调用就有东西出来了。
wallesyoyo 2017-05-11
  • 打赏
  • 举报
回复
引用 12 楼 qq_15173325 的回复:
[quote=引用 11 楼 wanggui2015 的回复:] 啥都没有吗?你这是线框模式,好歹有几条线出来的呀。。

#include "d3dUtility.h"

#define WIDTH 800  //屏幕宽
#define HEIGHT 600  //屏幕高

IDirect3DDevice9*device = 0;
D3DPRESENT_PARAMETERS d3dpp;

IDirect3DVertexBuffer9 *VB;  //定义顶点缓存
IDirect3DIndexBuffer9 *IB;  //定义索引缓存

struct Vertex
{
	float _x, _y, _z;
	Vertex(float x, float y, float z)
	{
		_x = x;
		_y = y;
		_z = z;
	}
	static const DWORD FVF;
};
const DWORD Vertex::FVF = D3DFVF_XYZ;

bool D3D::Setup()
{
	device->CreateVertexBuffer(
		3 * sizeof(Vertex), // size in bytes
		D3DUSAGE_WRITEONLY, // flags
		Vertex::FVF,        // vertex format
		D3DPOOL_MANAGED,    // managed memory pool
		&VB,          // return create vertex buffer
		0);                 // not used - set to 0

	Vertex *vertices;
	VB->Lock(0, 0, (void **)&vertices, 0);
	vertices[0] = Vertex(-1.0f, 0.0f, 2.0f);
	vertices[1] = Vertex(0.0f, 1.0f, 2.0f);
	vertices[2] = Vertex(1.0f, 0.0f, 2.0f);
	VB->Unlock();

	

	
	D3DXMATRIX proj;
	D3DXMatrixPerspectiveFovLH(
		&proj,
		D3DX_PI * 0.5f, // 90 - degree
		(float)WIDTH / (float)HEIGHT,
		1.0f,
		1000.0f);
	device->SetTransform(D3DTS_PROJECTION, &proj);

	device->Clear(0, 0, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xffffffff, 1.0f, 0);
	device->BeginScene();

	device->SetStreamSource(0, VB, 0, sizeof(Vertex));
	device->SetFVF(Vertex::FVF);

	// Draw one triangle.
	device->DrawPrimitive(D3DPT_TRIANGLELIST, 0, 1);

	device->EndScene();
	device->Present(0, 0, 0, 0);

	return true;
}




bool D3D::initD3D(D3DDEVTYPE DeviceType, HWND hwnd)
{
	IDirect3D9 * d3d9 = Direct3DCreate9(D3D_SDK_VERSION);

	// 填充主显示设备的能力( D3DCAPS9结构)
	D3DCAPS9 caps;
	d3d9->GetDeviceCaps(
		D3DADAPTER_DEFAULT, // 主显示设备
		DeviceType, // 设备类型,一般是D3DDEVTYPE_HAL.
		&caps); // 返回填充后的D3DCAPS9 结构,包含主显示设备的能力
				// 是否可以使用硬件顶点处理?
	int vp = 0;
	if (caps.DevCaps& D3DDEVCAPS_HWTRANSFORMANDLIGHT)
	{
		// 是,支持硬件顶点处理
		vp = D3DCREATE_HARDWARE_VERTEXPROCESSING;
	}
	else
	{
		// 不,只能用软件顶点处理
		vp = D3DCREATE_SOFTWARE_VERTEXPROCESSING;
	}

	d3dpp.BackBufferWidth = 800;
	d3dpp.BackBufferHeight = 600;
	d3dpp.BackBufferFormat = D3DFMT_A8R8G8B8; //像素格式
	d3dpp.BackBufferCount = 1;
	d3dpp.MultiSampleType = D3DMULTISAMPLE_NONE;
	d3dpp.MultiSampleQuality = 0;
	d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
	d3dpp.hDeviceWindow = hwnd;
	d3dpp.Windowed = true; // fullscreen
	d3dpp.EnableAutoDepthStencil = true;
	d3dpp.AutoDepthStencilFormat = D3DFMT_D24S8; // depth format
	d3dpp.Flags = 0;
	d3dpp.FullScreen_RefreshRateInHz = D3DPRESENT_RATE_DEFAULT;
	d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;

	int hr = d3d9->CreateDevice(
		D3DADAPTER_DEFAULT, //primary adapter
		D3DDEVTYPE_HAL,//devicetype
		hwnd,//window associated withdevice
		D3DCREATE_HARDWARE_VERTEXPROCESSING, //vertexprocessing type
		&d3dpp,//presentparameters
		&device);//returned created device
	if (FAILED(hr))
	{
		::MessageBox(0, "CreateDevice() -FAILED", 0, 0);
		return 0;
	}
	else
	{
		return 1;
	}


}
大哥 你看看 我把立方体改成三角形了 什么东西都没有出来。。 我窗口背景颜色是白色[/quote] 你贴出来的代码是没问题的额,你程序能出来窗口吗?还是有窗口没内容?
只负责写Bug 2017-05-11
  • 打赏
  • 举报
回复
引用 11 楼 wanggui2015 的回复:
啥都没有吗?你这是线框模式,好歹有几条线出来的呀。。

#include "d3dUtility.h"

#define WIDTH 800  //屏幕宽
#define HEIGHT 600  //屏幕高

IDirect3DDevice9*device = 0;
D3DPRESENT_PARAMETERS d3dpp;

IDirect3DVertexBuffer9 *VB;  //定义顶点缓存
IDirect3DIndexBuffer9 *IB;  //定义索引缓存

struct Vertex
{
	float _x, _y, _z;
	Vertex(float x, float y, float z)
	{
		_x = x;
		_y = y;
		_z = z;
	}
	static const DWORD FVF;
};
const DWORD Vertex::FVF = D3DFVF_XYZ;

bool D3D::Setup()
{
	device->CreateVertexBuffer(
		3 * sizeof(Vertex), // size in bytes
		D3DUSAGE_WRITEONLY, // flags
		Vertex::FVF,        // vertex format
		D3DPOOL_MANAGED,    // managed memory pool
		&VB,          // return create vertex buffer
		0);                 // not used - set to 0

	Vertex *vertices;
	VB->Lock(0, 0, (void **)&vertices, 0);
	vertices[0] = Vertex(-1.0f, 0.0f, 2.0f);
	vertices[1] = Vertex(0.0f, 1.0f, 2.0f);
	vertices[2] = Vertex(1.0f, 0.0f, 2.0f);
	VB->Unlock();

	

	
	D3DXMATRIX proj;
	D3DXMatrixPerspectiveFovLH(
		&proj,
		D3DX_PI * 0.5f, // 90 - degree
		(float)WIDTH / (float)HEIGHT,
		1.0f,
		1000.0f);
	device->SetTransform(D3DTS_PROJECTION, &proj);

	device->Clear(0, 0, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xffffffff, 1.0f, 0);
	device->BeginScene();

	device->SetStreamSource(0, VB, 0, sizeof(Vertex));
	device->SetFVF(Vertex::FVF);

	// Draw one triangle.
	device->DrawPrimitive(D3DPT_TRIANGLELIST, 0, 1);

	device->EndScene();
	device->Present(0, 0, 0, 0);

	return true;
}




bool D3D::initD3D(D3DDEVTYPE DeviceType, HWND hwnd)
{
	IDirect3D9 * d3d9 = Direct3DCreate9(D3D_SDK_VERSION);

	// 填充主显示设备的能力( D3DCAPS9结构)
	D3DCAPS9 caps;
	d3d9->GetDeviceCaps(
		D3DADAPTER_DEFAULT, // 主显示设备
		DeviceType, // 设备类型,一般是D3DDEVTYPE_HAL.
		&caps); // 返回填充后的D3DCAPS9 结构,包含主显示设备的能力
				// 是否可以使用硬件顶点处理?
	int vp = 0;
	if (caps.DevCaps& D3DDEVCAPS_HWTRANSFORMANDLIGHT)
	{
		// 是,支持硬件顶点处理
		vp = D3DCREATE_HARDWARE_VERTEXPROCESSING;
	}
	else
	{
		// 不,只能用软件顶点处理
		vp = D3DCREATE_SOFTWARE_VERTEXPROCESSING;
	}

	d3dpp.BackBufferWidth = 800;
	d3dpp.BackBufferHeight = 600;
	d3dpp.BackBufferFormat = D3DFMT_A8R8G8B8; //像素格式
	d3dpp.BackBufferCount = 1;
	d3dpp.MultiSampleType = D3DMULTISAMPLE_NONE;
	d3dpp.MultiSampleQuality = 0;
	d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
	d3dpp.hDeviceWindow = hwnd;
	d3dpp.Windowed = true; // fullscreen
	d3dpp.EnableAutoDepthStencil = true;
	d3dpp.AutoDepthStencilFormat = D3DFMT_D24S8; // depth format
	d3dpp.Flags = 0;
	d3dpp.FullScreen_RefreshRateInHz = D3DPRESENT_RATE_DEFAULT;
	d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;

	int hr = d3d9->CreateDevice(
		D3DADAPTER_DEFAULT, //primary adapter
		D3DDEVTYPE_HAL,//devicetype
		hwnd,//window associated withdevice
		D3DCREATE_HARDWARE_VERTEXPROCESSING, //vertexprocessing type
		&d3dpp,//presentparameters
		&device);//returned created device
	if (FAILED(hr))
	{
		::MessageBox(0, "CreateDevice() -FAILED", 0, 0);
		return 0;
	}
	else
	{
		return 1;
	}


}
大哥 你看看 我把立方体改成三角形了 什么东西都没有出来。。 我窗口背景颜色是白色
wallesyoyo 2017-05-11
  • 打赏
  • 举报
回复
啥都没有吗?你这是线框模式,好歹有几条线出来的呀。。
只负责写Bug 2017-05-11
  • 打赏
  • 举报
回复
引用 8 楼 wanggui2015 的回复:
[quote=引用 7 楼 qq_15173325 的回复:] [quote=引用 6 楼 wanggui2015 的回复:] [quote=引用 3 楼 qq_15173325 的回复:] [quote=引用 2 楼 wanggui2015 的回复:] 你这个貌似是龙书里面的官方配套例程吧?你完全按照他的代码来肯定没问题的呀。这个Display函数你看下你的对吗?
bool Display(float timeDelta)
{
	if( Device )
	{
		//
		// spin the cube:
		//
		D3DXMATRIX Rx, Ry;

		// rotate 45 degrees on x-axis
		D3DXMatrixRotationX(&Rx, 3.14f / 4.0f);

		// incremement y-rotation angle each frame
		static float y = 0.0f;
		D3DXMatrixRotationY(&Ry, y);
		y += timeDelta;

		// reset angle to zero when angle reaches 2*PI
		if( y >= 6.28f )
			y = 0.0f;

		// combine x- and y-axis rotation transformations.
		D3DXMATRIX p = Rx * Ry;

		Device->SetTransform(D3DTS_WORLD, &p);

		//
		// draw the scene:
		//
		Device->Clear(0, 0, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xffffffff, 1.0f, 0);
		Device->BeginScene();

		Device->SetStreamSource(0, VB, 0, sizeof(Vertex));
		Device->SetIndices(IB);
		Device->SetFVF(Vertex::FVF);

		// Draw cube.
		Device->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, 8, 0, 12);

		Device->EndScene();
		Device->Present(0, 0, 0, 0);
	}
	return true;
}
大哥 我不想完全照搬他的 我想知道我还漏了什么步骤[/quote] 你的绘制部分的代码就要放到这个Display函数里面的啊,这个函数每帧都会调用,你那个setup只是个初始化过程。[/quote] 他画的是旋转的 我想要不旋转的 这个函数要怎么改 我把这个函数里面的设置资源流的代码拷到setup函数里面了[/quote] 额,明白了,你的绘制部分代码少两个函数额,clear和present,如果你不想旋转,你可能看到的东西只是一个面的样子。[/quote] 好的 少了2个函数 但是加上去也没有画东西出来 听别人说没有循环调用 是怎么回事?
wallesyoyo 2017-05-11
  • 打赏
  • 举报
回复
Clear清除后台缓冲,然后draw绘制到后台缓冲,present是把后台缓冲提交到前台缓冲并显示出来
wallesyoyo 2017-05-11
  • 打赏
  • 举报
回复
引用 7 楼 qq_15173325 的回复:
[quote=引用 6 楼 wanggui2015 的回复:] [quote=引用 3 楼 qq_15173325 的回复:] [quote=引用 2 楼 wanggui2015 的回复:] 你这个貌似是龙书里面的官方配套例程吧?你完全按照他的代码来肯定没问题的呀。这个Display函数你看下你的对吗?
bool Display(float timeDelta)
{
	if( Device )
	{
		//
		// spin the cube:
		//
		D3DXMATRIX Rx, Ry;

		// rotate 45 degrees on x-axis
		D3DXMatrixRotationX(&Rx, 3.14f / 4.0f);

		// incremement y-rotation angle each frame
		static float y = 0.0f;
		D3DXMatrixRotationY(&Ry, y);
		y += timeDelta;

		// reset angle to zero when angle reaches 2*PI
		if( y >= 6.28f )
			y = 0.0f;

		// combine x- and y-axis rotation transformations.
		D3DXMATRIX p = Rx * Ry;

		Device->SetTransform(D3DTS_WORLD, &p);

		//
		// draw the scene:
		//
		Device->Clear(0, 0, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xffffffff, 1.0f, 0);
		Device->BeginScene();

		Device->SetStreamSource(0, VB, 0, sizeof(Vertex));
		Device->SetIndices(IB);
		Device->SetFVF(Vertex::FVF);

		// Draw cube.
		Device->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, 8, 0, 12);

		Device->EndScene();
		Device->Present(0, 0, 0, 0);
	}
	return true;
}
大哥 我不想完全照搬他的 我想知道我还漏了什么步骤[/quote] 你的绘制部分的代码就要放到这个Display函数里面的啊,这个函数每帧都会调用,你那个setup只是个初始化过程。[/quote] 他画的是旋转的 我想要不旋转的 这个函数要怎么改 我把这个函数里面的设置资源流的代码拷到setup函数里面了[/quote] 额,明白了,你的绘制部分代码少两个函数额,clear和present,如果你不想旋转,你可能看到的东西只是一个面的样子。
只负责写Bug 2017-05-11
  • 打赏
  • 举报
回复
引用 6 楼 wanggui2015 的回复:
[quote=引用 3 楼 qq_15173325 的回复:] [quote=引用 2 楼 wanggui2015 的回复:] 你这个貌似是龙书里面的官方配套例程吧?你完全按照他的代码来肯定没问题的呀。这个Display函数你看下你的对吗?
bool Display(float timeDelta)
{
	if( Device )
	{
		//
		// spin the cube:
		//
		D3DXMATRIX Rx, Ry;

		// rotate 45 degrees on x-axis
		D3DXMatrixRotationX(&Rx, 3.14f / 4.0f);

		// incremement y-rotation angle each frame
		static float y = 0.0f;
		D3DXMatrixRotationY(&Ry, y);
		y += timeDelta;

		// reset angle to zero when angle reaches 2*PI
		if( y >= 6.28f )
			y = 0.0f;

		// combine x- and y-axis rotation transformations.
		D3DXMATRIX p = Rx * Ry;

		Device->SetTransform(D3DTS_WORLD, &p);

		//
		// draw the scene:
		//
		Device->Clear(0, 0, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xffffffff, 1.0f, 0);
		Device->BeginScene();

		Device->SetStreamSource(0, VB, 0, sizeof(Vertex));
		Device->SetIndices(IB);
		Device->SetFVF(Vertex::FVF);

		// Draw cube.
		Device->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, 8, 0, 12);

		Device->EndScene();
		Device->Present(0, 0, 0, 0);
	}
	return true;
}
大哥 我不想完全照搬他的 我想知道我还漏了什么步骤[/quote] 你的绘制部分的代码就要放到这个Display函数里面的啊,这个函数每帧都会调用,你那个setup只是个初始化过程。[/quote] 他画的是旋转的 我想要不旋转的 这个函数要怎么改 我把这个函数里面的设置资源流的代码拷到setup函数里面了
wallesyoyo 2017-05-11
  • 打赏
  • 举报
回复
引用 3 楼 qq_15173325 的回复:
[quote=引用 2 楼 wanggui2015 的回复:] 你这个貌似是龙书里面的官方配套例程吧?你完全按照他的代码来肯定没问题的呀。这个Display函数你看下你的对吗?
bool Display(float timeDelta)
{
	if( Device )
	{
		//
		// spin the cube:
		//
		D3DXMATRIX Rx, Ry;

		// rotate 45 degrees on x-axis
		D3DXMatrixRotationX(&Rx, 3.14f / 4.0f);

		// incremement y-rotation angle each frame
		static float y = 0.0f;
		D3DXMatrixRotationY(&Ry, y);
		y += timeDelta;

		// reset angle to zero when angle reaches 2*PI
		if( y >= 6.28f )
			y = 0.0f;

		// combine x- and y-axis rotation transformations.
		D3DXMATRIX p = Rx * Ry;

		Device->SetTransform(D3DTS_WORLD, &p);

		//
		// draw the scene:
		//
		Device->Clear(0, 0, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xffffffff, 1.0f, 0);
		Device->BeginScene();

		Device->SetStreamSource(0, VB, 0, sizeof(Vertex));
		Device->SetIndices(IB);
		Device->SetFVF(Vertex::FVF);

		// Draw cube.
		Device->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, 8, 0, 12);

		Device->EndScene();
		Device->Present(0, 0, 0, 0);
	}
	return true;
}
大哥 我不想完全照搬他的 我想知道我还漏了什么步骤[/quote] 你的绘制部分的代码就要放到这个Display函数里面的啊,这个函数每帧都会调用,你那个setup只是个初始化过程。
只负责写Bug 2017-05-11
  • 打赏
  • 举报
回复
引用 1 楼 wanggui2015 的回复:
你的绘制部分的代码呢?
他画的旋转的立方体 我一下子看不懂那么多 我只想简单的画个立方体 是不是缺少了什么?
只负责写Bug 2017-05-11
  • 打赏
  • 举报
回复
我把设置资源流拷到setup函数里面了
只负责写Bug 2017-05-11
  • 打赏
  • 举报
回复
引用 2 楼 wanggui2015 的回复:
你这个貌似是龙书里面的官方配套例程吧?你完全按照他的代码来肯定没问题的呀。这个Display函数你看下你的对吗?
bool Display(float timeDelta)
{
	if( Device )
	{
		//
		// spin the cube:
		//
		D3DXMATRIX Rx, Ry;

		// rotate 45 degrees on x-axis
		D3DXMatrixRotationX(&Rx, 3.14f / 4.0f);

		// incremement y-rotation angle each frame
		static float y = 0.0f;
		D3DXMatrixRotationY(&Ry, y);
		y += timeDelta;

		// reset angle to zero when angle reaches 2*PI
		if( y >= 6.28f )
			y = 0.0f;

		// combine x- and y-axis rotation transformations.
		D3DXMATRIX p = Rx * Ry;

		Device->SetTransform(D3DTS_WORLD, &p);

		//
		// draw the scene:
		//
		Device->Clear(0, 0, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xffffffff, 1.0f, 0);
		Device->BeginScene();

		Device->SetStreamSource(0, VB, 0, sizeof(Vertex));
		Device->SetIndices(IB);
		Device->SetFVF(Vertex::FVF);

		// Draw cube.
		Device->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, 8, 0, 12);

		Device->EndScene();
		Device->Present(0, 0, 0, 0);
	}
	return true;
}
大哥 我不想完全照搬他的 我想知道我还漏了什么步骤
wallesyoyo 2017-05-11
  • 打赏
  • 举报
回复
你这个貌似是龙书里面的官方配套例程吧?你完全按照他的代码来肯定没问题的呀。这个Display函数你看下你的对吗?
bool Display(float timeDelta)
{
	if( Device )
	{
		//
		// spin the cube:
		//
		D3DXMATRIX Rx, Ry;

		// rotate 45 degrees on x-axis
		D3DXMatrixRotationX(&Rx, 3.14f / 4.0f);

		// incremement y-rotation angle each frame
		static float y = 0.0f;
		D3DXMatrixRotationY(&Ry, y);
		y += timeDelta;

		// reset angle to zero when angle reaches 2*PI
		if( y >= 6.28f )
			y = 0.0f;

		// combine x- and y-axis rotation transformations.
		D3DXMATRIX p = Rx * Ry;

		Device->SetTransform(D3DTS_WORLD, &p);

		//
		// draw the scene:
		//
		Device->Clear(0, 0, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xffffffff, 1.0f, 0);
		Device->BeginScene();

		Device->SetStreamSource(0, VB, 0, sizeof(Vertex));
		Device->SetIndices(IB);
		Device->SetFVF(Vertex::FVF);

		// Draw cube.
		Device->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, 8, 0, 12);

		Device->EndScene();
		Device->Present(0, 0, 0, 0);
	}
	return true;
}
wallesyoyo 2017-05-11
  • 打赏
  • 举报
回复
你的绘制部分的代码呢?

3,881

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 其它技术问题
社区管理员
  • 其它技术问题社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧