Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Silex

Anything wrong with this? ( Should display a skybox, but doesn't )

This topic is 5371 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Here''s the implementation of my skybox class:
#include "Skybox.h"

Skybox::Skybox( IDirect3DDevice9* device )
{
	Device = device;

	// Initialize vertices
	if( !InitVB() )
	{
		::MessageBox(0, "Error initializing Skybox vertex buffer.", 0, 0);
		:ostQuitMessage(0);
	}

	// Initialize indices
	if( !InitIB() )
	{
		::MessageBox(0, "Error initializing Skybox index buffer.", 0, 0);
		:ostQuitMessage(0);
	}

}

Skybox::~Skybox()
{
	d3d::Release(VB);
	d3d::Release(IB);
}

bool Skybox::InitVB( )
{
	HRESULT hr = E_FAIL;

	if ( Device )
		hr = Device->CreateVertexBuffer( 8 * sizeof(d3d::XYZVertex),
										D3DUSAGE_WRITEONLY,
										d3d::XYZVertex::FVF,
										D3DPOOL_MANAGED,
										&VB,
										0 );

	if ( FAILED(hr) )
		return false;

	d3d::XYZVertex* v;
	VB->Lock( 0, 0, (void**)&v, 0 );

	//Top vertices
	v[0] = d3d::XYZVertex(  10.0f,  10.0f,  10.0f );
	v[1] = d3d::XYZVertex(  10.0f,  10.0f, -10.0f );
	v[2] = d3d::XYZVertex( -10.0f,  10.0f, -10.0f );
	v[3] = d3d::XYZVertex( -10.0f,  10.0f,  10.0f );

	//Bottom vertices
	v[4] = d3d::XYZVertex(  10.0f, -10.0f,  10.0f );
	v[5] = d3d::XYZVertex(  10.0f, -10.0f, -10.0f );
	v[6] = d3d::XYZVertex( -10.0f, -10.0f, -10.0f );
	v[7] = d3d::XYZVertex( -10.0f, -10.0f,  10.0f );

	VB->Unlock();
	
	return true;
}

bool Skybox::InitIB()
{
	HRESULT hr = E_FAIL;

	if ( Device )
		hr = Device->CreateIndexBuffer(	36 * sizeof(WORD),
										D3DUSAGE_WRITEONLY,
										D3DFMT_INDEX16,
										D3DPOOL_MANAGED,
										&IB,
										0 );

	if ( FAILED(hr) )
		return false;

	WORD* i;
	IB->Lock( 0, 0, (void**)&i, 0 );

	//Top faces
	i[0] = 0; i[1] = 2; i[2] = 1;
	i[3] = 0; i[4] = 3; i[5] = 2;
	//Bottom faces
	i[6] = 4; i[7]  = 5; i[8]  = 6;
	i[9] = 6; i[10] = 7; i[11] = 4;
	//Left faces
	i[12] = 3; i[13] = 7; i[14] = 6;
	i[15] = 6; i[16] = 2; i[17] = 3;
	//Right faces
	i[18] = 0; i[19] = 5; i[20] = 4;
	i[21] = 0; i[22] = 1; i[23] = 5;
	//Front faces
	i[24] = 3; i[25] = 0; i[26] = 4;
	i[27] = 4; i[28] = 7; i[29] = 3;
	//Back faces
	i[30] = 5; i[31] = 1; i[32] = 6;
	i[33] = 6; i[34] = 1; i[35] = 2;
	
	IB->Unlock();
	
	return true;
}

void Skybox::Render( )
{
	pre_render();

	D3DXMATRIX matView, matViewSave;
	Device->GetTransform( D3DTS_VIEW, &matViewSave );
	matView = matViewSave;
	matView._41 = 0.0f; matView._42 = -0.3f; matView._43 = 0.0f;
	
	Device->SetTransform( D3DTS_VIEW, &matView );
	
	Device->DrawIndexedPrimitive( D3DPT_TRIANGLELIST, 0, 0, 8, 0, 12 );
	
	Device->SetTransform( D3DTS_VIEW, &matViewSave );

	post_render();
}

void Skybox:re_render()
{
	//Device->SetRenderState( D3DRS_CULLMODE, D3DCULL_NONE );
	Device->SetRenderState( D3DRS_ZENABLE, false );
	Device->SetRenderState( D3DRS_ZWRITEENABLE, false );
	Device->SetRenderState( D3DRS_LIGHTING, false );
	Device->SetRenderState( D3DRS_FILLMODE, D3DFILL_WIREFRAME );
	Device->SetStreamSource( 0, VB, 0, sizeof(d3d::XYZVertex) );
}

void Skybox:ost_render()
{
	Device->SetRenderState( D3DRS_ZENABLE, true );
	Device->SetRenderState( D3DRS_ZWRITEENABLE, true );
	Device->SetRenderState( D3DRS_FILLMODE, D3DFILL_SOLID);
	Device->SetRenderState( D3DRS_LIGHTING, true );
}
 
Can anyone see any errors in there or is the problem elsewhere?

Share this post


Link to post
Share on other sites
Advertisement
You need to call SetIndices(pIndexBuffer);
Also call SetFVF(FVF);
Other than that, I didn't see anything outright wrong.

Chris

[edited by - Supernat02 on February 6, 2004 11:34:57 PM]

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!