Sign in to follow this  
mugai

skybox

Recommended Posts

i've done the google thing and haven't found too many.. basically only one from the hazy mind website. does anyone have any other tutorials or could you point me in any other direction for help on this subject? i've created a face object .. which i then create an array of in my skybox class.. each face object contains 4 PositionTextured vertexes etc to make up the wall with the right texture/image. my real problem is rotating the walls into the proper position etc so it's all seamless etc i hope this makes sense.. if not, please let me know and i'll try and give you more information. thank you!

Share this post


Link to post
Share on other sites
Dont let skybox's confused you. They are nothing more that 6 large-textured quads.

I will include my code for my skybox. You can draw a skybox with much left code than how i did it.


#include <d3dx9.h>

#include "c_base_object.h"
#include "c_custom_matrix.h"

class Sky_Box : public Base_Object
{
private:
LPDIRECT3DTEXTURE9 Sky_BoxTexture[6];

LPDIRECT3DVERTEXBUFFER9 Sky_BoxBuffer;

D3D_CUSTOMMATRIX WorldMatrix;

public:
Sky_Box( void );

void LoadSkyBoxData( IDirect3DDevice9 *D3DDevice );
void ShowSkyBox( IDirect3DDevice9 *D3DDevice );

~Sky_Box( void );
};




#include <d3dx9.h>

#include "c_sky_box.h"
#include "c_custom_vertex.h"
#include "c_custom_matrix.h"
#include "c_custom_camera.h"

#include <windows.h>

Sky_Box::Sky_Box( void )
{
Sky_BoxBuffer = NULL;
}

void Sky_Box::LoadSkyBoxData( IDirect3DDevice9 *D3DDevice )
{
CUSTOMVERTEX Sky_BoxVertex[] =
{
{ -400.0f, 400.0f, -400.0f, 0, 0, 1, 1, 0 }, //Front
{ 400.0f, 400.0f, -400.0f, 0, 0, 1, 0, 0 },
{ -400.0f, -400.0f, -400.0f, 0, 0, 1, 1, 1 },
{ 400.0f, -400.0f, -400.0f, 0, 0, 1, 0, 1 },

{ -400.0f, 400.0f, 400.0f, 0, 0, 1, 1, 0 }, //Behind
{ 400.0f, 400.0f, 400.0f, 0, 0, 1, 0, 0 },
{ -400.0f, -400.0f, 400.0f, 0, 0, 1, 1, 1 },
{ 400.0f, -400.0f, 400.0f, 0, 0, 1, 0, 1 },

{ -400.0f, 400.0f, -400.0f, 0, 0, 1, 0, 1 }, //Top
{ 400.0f, 400.0f, -400.0f, 0, 0, 1, 1, 1 },
{ -400.0f, 400.0f, 400.0f, 0, 0, 1, 0, 0 },
{ 400.0f, 400.0f, 400.0f, 0, 0, 1, 1, 0 },

{ -400.0f, -400.0f, -400.0f, 0, 0, 1, 1, 0 }, //Bottom
{ 400.0f, -400.0f, -400.0f, 0, 0, 1, 0, 0 },
{ -400.0f, -400.0f, 400.0f, 0, 0, 1, 1, 1 },
{ 400.0f, -400.0f, 400.0f, 0, 0, 1, 0, 1 },

{ -400.0f, 400.0f, -400.0f, 0, 0, 1, 1, 0 }, //Right
{ -400.0f, 400.0f, 400.0f, 0, 0, 1, 0, 0 },
{ -400.0f, -400.0f, -400.0f, 0, 0, 1, 1, 1 },
{ -400.0f, -400.0f, 400.0f, 0, 0, 1, 0, 1 },

{ 400.0f, 400.0f, -400.0f, 0, 0, 1, 1, 0 }, //Left
{ 400.0f, 400.0f, 400.0f, 0, 0, 1, 0, 0 },
{ 400.0f, -400.0f, -400.0f, 0, 0, 1, 1, 1 },
{ 400.0f, -400.0f, 400.0f, 0, 0, 1, 0, 1 },
};

D3DDevice->CreateVertexBuffer( 24 * sizeof(CUSTOMVERTEX),
0, D3DFVF_CUSTOMVERTEX,
D3DPOOL_MANAGED, &Sky_BoxBuffer, NULL );

void *Buffer;

Sky_BoxBuffer->Lock( 0, sizeof(Sky_BoxVertex), (void**)&Buffer, 0 );

memcpy( Buffer, Sky_BoxVertex, sizeof(Sky_BoxVertex) );

Sky_BoxBuffer->Unlock();

LoadCustomTexture( D3DDevice, L"Textures/Front.bmp", &Sky_BoxTexture[0] );
LoadCustomTexture( D3DDevice, L"Textures/Back.bmp", &Sky_BoxTexture[1] );
LoadCustomTexture( D3DDevice, L"Textures/Top.bmp", &Sky_BoxTexture[2] );
LoadCustomTexture( D3DDevice, L"Textures/Bottom.bmp", &Sky_BoxTexture[3] );
LoadCustomTexture( D3DDevice, L"Textures/Right.bmp", &Sky_BoxTexture[4] );
LoadCustomTexture( D3DDevice, L"Textures/Left.bmp", &Sky_BoxTexture[5] );

return;
}

void Sky_Box::ShowSkyBox( IDirect3DDevice9 *D3DDevice )
{
D3DDevice->SetTransform( D3DTS_WORLD, &WorldMatrix.DoNothing );

D3DDevice->SetStreamSource( 0, Sky_BoxBuffer, 0, sizeof(CUSTOMVERTEX) );

D3DDevice->SetFVF( D3DFVF_CUSTOMVERTEX );

int Sky_BoxCount = 0;

for( int Draw = 0; Draw <= 20; Draw += 4 )
{
D3DDevice->SetTexture( 0, Sky_BoxTexture[Sky_BoxCount] );
D3DDevice->DrawPrimitive( D3DPT_TRIANGLESTRIP, Draw, 2 );

if( Sky_BoxCount != 5 )
Sky_BoxCount += 1;
}

return;
}

Sky_Box::~Sky_Box( void )
{
if( Sky_BoxBuffer )
Sky_BoxBuffer->Release();

for( int I = 0; I < 6; I++ )
{
if( Sky_BoxTexture[I] )
Sky_BoxTexture[I]->Release();
}

return;
}


Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this