void Panel()
{
float PanelWidth = 200.0f;
float PanelHeight = 200.0f;
g_pD3DDevice->CreateVertexBuffer(4 * sizeof(PANELVERTEX), D3DUSAGE_WRITEONLY,D3DFVF_PANELVERTEX,
D3DPOOL_MANAGED,&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();
D3DXCreateTextureFromFileEx(g_pD3DDevice, "Texture.jpg", 0, 0, 0, 0,
D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, D3DX_DEFAULT,
D3DX_DEFAULT, 0, NULL,NULL,&m_pD3DTexture);
}
How to make a class
can some help me change this to a class?
I''ll give it a shot, but I''ll put everything in the .h file, to be evil
I''m not sure what this will accomplish tho. Usually, a class needs more than a single function to be truely useful.
~~~~~
"Go on then" - benjamin bunny.
Download and play Slime King I.
class CPanel
{
public:
CPanel() {;};
~CPanel() {;};
void Panel(){ /* insert panel Code Here*/};
private:
//insert any global variables that will only be used by your class here
};
I''m not sure what this will accomplish tho. Usually, a class needs more than a single function to be truely useful.
~~~~~
"Go on then" - benjamin bunny.
Download and play Slime King I.
*sigh*
here... in a .h:
class cMyClass
{
public:
void Panel();
};
in a .cpp:
#include "insert_your_h_file_name_here.h"
void cMyClass:anel()
{
float PanelWidth = 200.0f;float PanelHeight = 200.0f;g_pD3DDevice->CreateVertexBuffer(4 * sizeof(PANELVERTEX), D3DUSAGE_WRITEONLY,D3DFVF_PANELVERTEX, D3DPOOL_MANAGED,&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();D3DXCreateTextureFromFileEx(g_pD3DDevice, "Texture.jpg", 0, 0, 0, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL,NULL,&m_pD3DTexture);
}
and in your main c++ file:
#include "insert_your_h_file_name_here.h"
cMyClass myclass;
somewhere in a function to call panel:
myclass.panel();
here... in a .h:
class cMyClass
{
public:
void Panel();
};
in a .cpp:
#include "insert_your_h_file_name_here.h"
void cMyClass:anel()
{
float PanelWidth = 200.0f;float PanelHeight = 200.0f;g_pD3DDevice->CreateVertexBuffer(4 * sizeof(PANELVERTEX), D3DUSAGE_WRITEONLY,D3DFVF_PANELVERTEX, D3DPOOL_MANAGED,&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();D3DXCreateTextureFromFileEx(g_pD3DDevice, "Texture.jpg", 0, 0, 0, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL,NULL,&m_pD3DTexture);
}
and in your main c++ file:
#include "insert_your_h_file_name_here.h"
cMyClass myclass;
somewhere in a function to call panel:
myclass.panel();
I see. Thank you for your help.It took me a while to figure out that it needed to be in a class and not a function.
[edited by - kingpinzs on October 6, 2003 2:10:24 AM]
[edited by - kingpinzs on October 6, 2003 2:10:24 AM]
quote:Original post by kingpinzsMay I ask why this function needs a class?
I see. Thank you for your help.It took me a while to figure out that it needed to be in a class and not a function.
~~~~~
" I...went from hopeless to sucky in a relatively short time." - entivore.
Download and play Slime King I.
Becuase I have to make a lot of panels and instead of making alot of the same thing i am going to try to just make a class nad call it everytime I make a new panel. That is the only way I can figure out how to make a lot of 2d objects.
quote:Original post by kingpinzs
Becuase I have to make a lot of panels and instead of making alot of the same thing i am going to try to just make a class nad call it everytime I make a new panel. That is the only way I can figure out how to make a lot of 2d objects.
Ahh! You don''t need a class, you need a structure.
do this...
struct sPanal{float PanelWidth;float PanelHeight;//other variables you might need.};
Then, in your code, just put this line:
sPanal Panaldata[100];
there! you have an array of 100 panels, you can then pass your panal data into your Panal function. No need to make 100 classes. You can also store data relevant to your panel.
I use this structure with my tile engine.
struct tileAtt{//can you move this way? bool bSolid;//solid? (for collisions) bool bContainsTile;//true, contains tile, false otherwise int iTextureInd;//Tile Number bool bTexture;//is there a texture for this tile? float fRot;//amount of rotation needed float color3f[3];};
Then in my engine class, I use the data to produce all the tiles I need.
~~~~~
" I...went from hopeless to sucky in a relatively short time." - entivore.
Download and play Slime King I.
alright now I undersatnd I need to make a structure.
But how do I turn all this to a structure.
This is what I have so far.
struct panel
{
float panelwidth;
float panelhight;
float screenwidth;
float screenhight;
}
But now exactly what I want
I want soem thing that will do this
Panel->D3DXCreateTextureFromFileEx(g_pD3DDevice, "Texture.jpg", 0, 0, 0, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, D3DX_DEFAULT,
D3DX_DEFAULT, 0, NULL,NULL,&m_pD3DTexture);
Panel2->D3DXCreateTextureFromFileEx(g_pD3DDevice, "Texture2.jpg", 0, 0, 0, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, D3DX_DEFAULT,
D3DX_DEFAULT, 0, NULL,NULL,&m_pD3DTexture);
[edited by - kingpinzs on October 6, 2003 6:58:01 PM]
[edited by - kingpinzs on October 6, 2003 6:58:47 PM]
But how do I turn all this to a structure.
void camera2d(float WindowWidth, float WindowHeight){ D3DXMATRIX Ortho2D; D3DXMATRIX Identity; //Setup the orthogonal projection matrix and the default world/view matrix D3DXMatrixOrthoLH(&Ortho2D, WindowWidth, WindowHeight, 0.0f, 1.0f); D3DXMatrixIdentity(&Identity); g_pD3DDevice->SetTransform(D3DTS_PROJECTION, &Ortho2D); g_pD3DDevice->SetTransform(D3DTS_WORLD, &Identity); g_pD3DDevice->SetTransform(D3DTS_VIEW, &Identity); //Make sure that the z-buffer and lighting are disabled g_pD3DDevice->SetRenderState(D3DRS_ZENABLE, D3DZB_FALSE); g_pD3DDevice->SetRenderState(D3DRS_LIGHTING, FALSE);g_pD3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);g_pD3DDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);g_pD3DDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);g_pD3DDevice->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_MODULATE); }
void Panel(){float PanelWidth = 200.0f;float PanelHeight = 200.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();D3DXCreateTextureFromFileEx(g_pD3DDevice, "Texture.jpg", 0, 0, 0, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL,NULL,&m_pD3DTexture);}
void render2D(){D3DXMATRIX Position;D3DXMatrixTranslation(&Position, 50.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);}
This is what I have so far.
struct panel
{
float panelwidth;
float panelhight;
float screenwidth;
float screenhight;
}
But now exactly what I want
I want soem thing that will do this
Panel->D3DXCreateTextureFromFileEx(g_pD3DDevice, "Texture.jpg", 0, 0, 0, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, D3DX_DEFAULT,
D3DX_DEFAULT, 0, NULL,NULL,&m_pD3DTexture);
Panel2->D3DXCreateTextureFromFileEx(g_pD3DDevice, "Texture2.jpg", 0, 0, 0, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, D3DX_DEFAULT,
D3DX_DEFAULT, 0, NULL,NULL,&m_pD3DTexture);
[edited by - kingpinzs on October 6, 2003 6:58:01 PM]
[edited by - kingpinzs on October 6, 2003 6:58:47 PM]
You mean to tell us the book/tutorial you copied that code from didn''t tell you how to use it? Pshaw.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement