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


Textures per face ?

Recommended Posts

Hi I am implementing a skybox into my game using the cube method. I''ve wrote some code to load the relevant bitmaps as shown below. Bitmaps I want to load for my textures... char* filenames[] = { {"c:\\Clouds\\SnowCliffLeft.bmp"}, {"c:\\Clouds\\SnowCliffRight.bmp"}, {"c:\\Clouds\\SnowCliffFront.bmp"}, {"c:\\Clouds\\SnowCliffBack.bmp"}, {"c:\\Clouds\\SnowCliffTop.bmp"}, {"c:\\Clouds\\SnowCliffBottom.bmp"}, }; in game initialisation..... r = d3dManager.LoadSkyBoxTextures(&filenames[0]); if(FAILED(r)) { d3dManager.SetError("Failed to load textures"); return E_FAIL; } // Set pointer to skybox textures pSkyBoxTextures = d3dManager.GetSkyBoxTexture(); Method to load the textures and store them... HRESULT CD3DManager::LoadSkyBoxTextures(char **pFilenames) { HRESULT r = 0; for (int i=0; i<6; i++) { if(m_pSkyBoxTexture) m_pSkyBoxTexture[i]->Release(); ShowInfo("Loading Textures..."); ShowInfo(pFilenames[i]); r = D3DXCreateTextureFromFile(m_pDevice, pFilenames[i], &m_pSkyBoxTexture[i]); if(FAILED(r)) return E_FAIL; } return r; } Returns a pointer of pointers for textures... inline IDirect3DTexture8** CD3DManager::GetSkyBoxTexture() { return m_pSkyBoxTexture; } In my rendering method... g_pDevice->SetStreamSource(0,g_pVB, sizeof(MYVERTEX)); g_pDevice->SetTexture(0, pSkyBoxTextures[i]); g_pDevice->SetTextureStageState(0,D3DTSS_COLORARG1, D3DTA_TEXTURE); g_pDevice->SetTextureStageState(0,D3DTSS_MINFILTER,D3DTEXF_LINEAR); g_pDevice->SetTextureStageState(0,D3DTSS_COLOROP, D3DTOP_MODULATE); g_pDevice->DrawPrimitive(D3DPT_TRIANGLELIST, 6, 12); This draws the whole cube in one go with the first texture applied to all faces, how do I draw a face at a time with a different texture - do I need a seperate vertex buffer for each face and then set the new texture between calls to DrawPrimitive ? Kind regards, sTeVe

Share this post

Link to post
Share on other sites
Do something like this:

1) Bind your vertexbuffer, set your vertex format.
2) Set all your rending modes, alpha ops, texturing modes and so on.
3) Set your fist texture, then render the one face (two triangles) that corresponds to that texture. Set the next texture and render the next appropriate face. Keep doing this untill you have draw the whole skybox or at least the parts that are visible.

You could also create one big texture that has the six smaller textures in it. Then just set that texture and draw the whole skybox. I would not do this personally since my video card only supports textures up to 256 by 256. Thats like one 85 by 128 texture per face. It doesn't look good at all.

Edited by - Abstraction on January 16, 2002 11:21:49 AM

Share this post

Link to post
Share on other sites

I''ve done the following solution to my asked question:

g_pDevice->SetTexture(0, pSkyBoxTextures[1]);
g_pDevice->SetTexture(0, pSkyBoxTextures[2]);
g_pDevice->SetTexture(0, pSkyBoxTextures[3]);
g_pDevice->SetTexture(0, pSkyBoxTextures[4]);
g_pDevice->SetTexture(0, pSkyBoxTextures[5]);
g_pDevice->SetTexture(0, pSkyBoxTextures[6]);


Share this post

Link to post
Share on other sites