Archived

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

kingpinzs

Help with steps of making multiple quade textures

Recommended Posts

I am tring to load multiple quade textures in directx 8 but I can only get one to show. Can some one give me the steps in loading multiple quade textures.

Share this post


Link to post
Share on other sites
Generally, if I want to associate multiple textures to a single QUAD; or for that matter a Mesh; I would load each of the textures into memory and cycle through them to create the animation. You can load a texture into memory using either of the following:

D3DXCreateTextureFromFileEx
D3DXCreateTextureFromFile

Then use the SetTexture command to modify to alter the texture being displayed. Keep in mind that in order for this to work; your Flexible Vertex Format (FVF) must be include the D3DFVF_NORMAL flag and each of the vertices must define their own normal.

Hope this helps.


Understanding is a three edged sword...

[edited by - Sean Doherty on October 10, 2003 12:19:20 AM]

Share this post


Link to post
Share on other sites
Thnaks for Your help but that is not really what I needed to know. I know I needed to use D3DXCreateTextureFromFileEx
D3DXCreateTextureFromFile but My question is how to make 50 of these with out copying the code 50 times.

Share this post


Link to post
Share on other sites
quote:

Thnaks for Your help but that is not really what I needed to know. I know I needed to use D3DXCreateTextureFromFileEx
D3DXCreateTextureFromFile but My question is how to make 50 of these with out copying the code 50 times.



You can do this with a for loop and an array.

Understanding is a three edged sword...

Share this post


Link to post
Share on other sites
SO this is what I understand to do

1)Include my files
2)declare my varibles
3)create my vertex
4)Initialisetion of d3d
5)Make my 2d camera
6)make a panel
7)create my texture
8)render the 2d
9)render all the sences
10)make my window
11)make my loop
"BUT NOT IN THAT ORDER"
so my questions it how to get more then one of #6 #7 #8?

If you need I can psot my code it is only about 300 lines not very long at all.

[edited by - kingpinzs on October 11, 2003 2:36:11 PM]

Share this post


Link to post
Share on other sites
What do you mean by "make a panel" ? Kinda hard to give help when the problem is under-specified.

Anyway, I think you need to learn how to program, which is different from learning a programming language (I think you know the language already). I think you need to learn about factoring code, and writing re-usable functions/modules. Maybe even a little bit about data driven design. Try reading the "Game Programming Gems" series of books, perhaps?

Also, download, read, and understand code for other programs from the web. Quake I and II are available, as are utilities like The Gimp or engines like Crystal Space and games like Planeshift. Reading and understanding code takes a lot of time (weeks) but is really a very good way of learning how to program.

That being said, here''s a cheat-sheet, assuming a "panel" is some internal data structure in your source, and you want to be able to render one at a time.


// class Panel, to re-use (in header)
class Panel {
public:
Panel();
// these will need more arguments, I''m sure (like LPD3D and stuff)
void ReadFromTexture( char const * name );
void Render();
};
enum {
MaxPanelCount = 100
};
int MakePanel( char const * fromFile );
void SetPanel( int panel );
void RenderPanel();

// in your panel code

Panel * allPanels[ MaxPanelCount ];
unsigned int numPanels = 0;
Panel * activePanel;

int MakePanel( char const * fromFile )
{
if( numPanels == MaxPanelCount ) return -1;
allPanels[ numPanels ] = new Panel;
allPanels[ numPanels ]->ReadFromTexture( fromFile );
numPanels += 1;
return numPanels-1;
}

void SetActivePanel( int panel )
{
assert( panel >= 0 && panel < numPanels );
activePanel = allPanels[ panel ];
}

void RenderPanel()
{
allPanels[ activePanel ]->Render();
}


// in your game code

// to load -- the names really should come from a
// data file...
int mainPanel = MakePanel( "main.tga" );
int subPanel = MakePanel( "sub.tga" );
int otherPanel = MakePanel( "other.tga" );

SetActivePanel( mainPanel );


// in main loop

while( true ) {
// process events here ...
// render other stuff here ...
RenderPanel();
}


Lots of short-cuts and omissions; I''m demonstrating a simple approach to do what I think you want to do; I''m not developing your app for you :-)

Share this post


Link to post
Share on other sites
The panel is a basic directx 3d square to put your texture in. They are called 2d panel's.


#6

void Panel()
{
float PanelWidth = 600.0f;
float PanelHeight = 600.0f;

g_pD3DDevice->CreateVertexBuffer(4 * sizeof(PANELVERTEX), 0,D3DFVF_PANELVERTEX,
D3DPOOL_DEFAULT,&p_VertexBuffer );

PANELVERTEX* pVertices = NULL;

p_VertexBuffer->Lock(0, 4 * sizeof(PANELVERTEX), (BYTE**)&pVertices,0);
pVertices[0].color = pVertices[1].color = pVertices[2].color = pVertices[3].color = 0xffffffff;

pVertices[0].x = pVertices[3].x = - PanelWidth / 2.0f;
pVertices[1].x = pVertices[2].x = PanelWidth /2.0f;
pVertices[0].y = pVertices[1].y = PanelHeight / 2.0f;
pVertices[2].y = pVertices[3].y = - PanelHeight / 2.0f;
pVertices[0].z = pVertices[1].z = pVertices[2].z = pVertices[3].z = 1.0f;
pVertices[1].u = pVertices[2].u = 0.625f;
pVertices[0].u = pVertices[3].u = 0.0f;
pVertices[0].v = pVertices[1].v = 0.0f;
pVertices[2].v = pVertices[3].v = 0.9375f;

p_VertexBuffer->Unlock();


#7)

D3DXCreateTextureFromFileEx(g_pD3DDevice, "Texture.jpg", 0, 0, 0, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL,NULL,&m_pD3DTexture);
}





[edited by - kingpinzs on October 11, 2003 9:32:00 PM]

Share this post


Link to post
Share on other sites
quote:

The panel is a basic directx 3d square to put your texture in. They are called 2d panel''s.



I don''t know why you refer to them as a Panel; they are called a QUAD. As for your problem you need to load a set of texture into an array as follows:


D3DXCreateTextureFromFileEx(g_pD3DDevice, "Texture.jpg", 0, 0, 0, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL,NULL,&m_pD3DTexture[0]);

D3DXCreateTextureFromFileEx(g_pD3DDevice, "BlueTexture.jpg", 0, 0, 0, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL,NULL,&m_pD3DTexture[1]);

D3DXCreateTextureFromFileEx(g_pD3DDevice, "GreenTexture.jpg", 0, 0, 0, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL,NULL,&m_pD3DTexture[2]);


Then you can change the texture on your QUAD by calling pD3DDevice->SetTexture(0, ,&m_pD3DTexture) (where i is the value of the texture you want to display). Try this; it will at least give you a better understanding of textures.



Understanding is a three edged sword...

Share this post


Link to post
Share on other sites
now t just makes a white screen. I think I am missing something on put multiple textures in.

How do you put the textures were you want them?


void render2D()
{

D3DXMATRIX Position;
D3DXMatrixTranslation(&Position, 0.0f, 0.0f, 0.0f);
g_pD3DDevice->SetTransform(D3DTS_WORLD, &Position);
g_pD3DDevice->SetVertexShader (D3DFVF_PANELVERTEX);
g_pD3DDevice->SetStreamSource (0, p_VertexBuffer, sizeof(PANELVERTEX));
g_pD3DDevice->DrawPrimitive (D3DPT_TRIANGLEFAN, 0, 2);
g_pD3DDevice->SetTexture(0,m_pD3DTexture[1]);
g_pD3DDevice->SetTexture(0,m_pD3DTexture[2]);
}


I bet this is wrong but I dont know how else to do it.

[edited by - kingpinzs on October 12, 2003 2:05:11 PM]

Share this post


Link to post
Share on other sites
quote:

I bet this is wrong but I dont know how else to do it.



I reordered your source; give it a try:


void render2D()
{
g_pD3DDevice->SetVertexShader (D3DFVF_PANELVERTEX);
g_pD3DDevice->SetStreamSource (0, p_VertexBuffer, sizeof(PANELVERTEX));

D3DXMATRIX Position;
D3DXMatrixTranslation(&Position, 0.0f, 0.0f, 0.0f);
g_pD3DDevice->SetTransform(D3DTS_WORLD, &Position);
g_pD3DDevice->SetTexture(0,m_pD3DTexture[0]);
g_pD3DDevice->DrawPrimitive (D3DPT_TRIANGLEFAN, 0, 2);

D3DXMatrixTranslation(&Position, -500.0f, -500.0f, 0.0f);
g_pD3DDevice->SetTransform(D3DTS_WORLD, &Position);
g_pD3DDevice->SetTexture(0,m_pD3DTexture[1]);
g_pD3DDevice->DrawPrimitive (D3DPT_TRIANGLEFAN, 0, 2);

D3DXMatrixTranslation(&Position, 500.0f, 500.0f, 0.0f);
g_pD3DDevice->SetTransform(D3DTS_WORLD, &Position);
g_pD3DDevice->SetTexture(0,m_pD3DTexture[1]);
g_pD3DDevice->DrawPrimitive (D3DPT_TRIANGLEFAN, 0, 2);
}



Understanding is a three edged sword...

Share this post


Link to post
Share on other sites