Sign in to follow this  

Changing texture during run time

This topic is 4660 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

hey - i am developing a game editor in C++/DX and have encountered a problem. when i create map sturcture array (like below) to represent tile textures: o,1,o, 1,1,o, 1,1,1, 1,1,o, o,1,o, it then replaces the numbers with textures in another struct array and goes to perform animation etc. I need it to change the texture in the appropriate tile when the LMB is clicked (left mouse button) BUT when i run CreateQuad again on the tile in question it flags an error (VC++ 6.0) - does anyone know of a solution to this? Xpy

Share this post


Link to post
Share on other sites
As Ace said - you need to provide more details. Especially the error code, the debug trace and the line of code that causes it.

I'll be guessing that you're not destroying the previous data, or invalidating the data in some way. But thats all we can do - guess [smile]

hth
Jack

Share this post


Link to post
Share on other sites
ok, well the code is as follows:



#include "Includes.h"

// custom vertex structure for our quads
struct CCustomVertex
{
float x, y, z, rhw; // The transformed position for the vertex.
DWORD dwColor; // The vertex colour.
float tu, tv; // Texture co-ordinates.

static const DWORD FVF;
};
const DWORD CCustomVertex::FVF = D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_TEX1;

///////////change later to quad
struct CRectangularObject
{
IDirect3DTexture9 *pTexture;
CCustomVertex vertices[4];
};


HWND main_window_handle = NULL; // globally track main window
HINSTANCE main_instance = NULL; // globally track hinstance
int MouseX,MouseY,MouseButtons;

CRectangularObject *g_pObjects;
UINT g_nObjectBufferSize, g_nNewObjectPointer;

#include "BungEngine.h"

int GameInit()
{

InitD3d(1024,768);
InitDi();

g_pObjects = new CRectangularObject[800];
g_nObjectBufferSize = 800;

tTexture = LoadTexture(_T("Grass.png"));
tAnimTexture = LoadTexture (_T("Water Files2.png"));
tGrassTextures = LoadTexture(_T("GRASS_TRANSITION.png"));
tSand = LoadTexture(_T("Sand.png"));


for (k=0;k<2;k++, z=0)
{
for (i=0; i<19; i++)
{
for (j=0; j<10; j++)
{
switch (MAP_STRUCTURE[k][i][j])
{
case 0:
{
qTile[k][i][j].itsX = (j*size_x) + (z*32) + (200);
qTile[k][i][j].itsY = (i*size_y)-(i*16) + (200);
qTile[k][i][j].quad[0] = 0;
qTile[k][i][j].isAnimated = 0;
}break;

case 10:
{
qTile[k][i][j].itsX = (j*size_x) + (z*32) + (200);
qTile[k][i][j].itsY = (i*size_y)-(i*16) + (200);
qTile[k][i][j].quad[0] = CreateQuad(qTile[k][i][j].itsX, qTile[k][i][j].itsY, 64, 32, tTexture, 0, 0);
qTile[k][i][j].isAnimated = 0;
}break;

case 20:
{
qTile[k][i][j].itsX = (j*size_x) + (z*32) + (200);
qTile[k][i][j].itsY = (i*size_y)-(i*16) + (200);
qTile[k][i][j].quad[0] = CreateQuad(qTile[k][i][j].itsX, qTile[k][i][j].itsY, 64, 32, tSand, 0, 0);
qTile[k][i][j].isAnimated = 0;
}break;

case 40:
{
qTile[k][i][j].itsX = (j*size_x) + (z*32) + (200);
qTile[k][i][j].itsY = (i*size_y)-(i*16) + (200);
qTile[k][i][j].quad[0] = CreateQuad(qTile[k][i][j].itsX, qTile[k][i][j].itsY, 64, 32, tAnimTexture, 0, 0);
qTile[k][i][j].quad[1] = CreateQuad(qTile[k][i][j].itsX, qTile[k][i][j].itsY, 64, 32, tAnimTexture, 64, 0);
qTile[k][i][j].quad[2] = CreateQuad(qTile[k][i][j].itsX, qTile[k][i][j].itsY, 64, 32, tAnimTexture, 128, 0);
qTile[k][i][j].isAnimated = 1;
}break;

}
}


if (z==1)
z=0;
else z=1;
}
}


g_pd3dDevice->CreateVertexBuffer(g_nNewObjectPointer * 4 * sizeof(CCustomVertex),
D3DUSAGE_WRITEONLY, ///look into this---------------
CCustomVertex::FVF,
D3DPOOL_MANAGED, &g_pVB, NULL);
return(1);
}


int GameMain()
{
CurrentTexture = 10;
tCurrentTexture = LoadTexture(_T("Grass.png"));
BeginRender();
// Clear the backbuffer to black
g_pd3dDevice->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_ARGB(0,000,000,000)/*D3DCOLOR_XRGB(0,0,255)*/, 1.0f, 0);

/*if(FAILED(lpdimouse->GetDeviceState(sizeof(DIMOUSESTATE),
(LPVOID)mousestate)))*/

//{/*err*/}

lpdimouse->GetDeviceState(sizeof(DIMOUSESTATE), (LPVOID)&mousestate);

object_x = mousestate.lX;
object_y = mousestate.lY;

if (mousestate.rgbButtons[1])
MAP_STRUCTURE[CurrentLayer][MouseToTilePos_Y][MouseToTilePos_X] = CurrentTexture;


qTile[CurrentLayer][MouseToTilePos_Y][MouseToTilePos_X].quad[0] = 0;/*
CreateQuad(qTile[CurrentLayer][MouseToTilePos_Y][MouseToTilePos_X].itsX,
qTile[CurrentLayer][MouseToTilePos_Y][MouseToTilePos_X].itsY,
64, 32, tCurrentTexture, 0, 0);*/




for (k=0;k<3;k++)
for (i=0; i<19; i++)
for (j=0; j<10; j++)
{
if (qTile[k][i][j].isAnimated == 0)
DrawQuad(qTile[k][i][j].quad[0]);

if (qTile[k][i][j].isAnimated == 1)
DrawQuad(qTile[0][i][j].quad[animation_frame]);
}



FinishRender();
return(1);
}

int GameShutdown()
{
tTexture->Release();
tAnimTexture->Release();
tGrassTextures->Release();
tSand->Release();
CloseD3d();
return(1);
}


//-----------------------------------------------------------------------------
// Window Proc Function
// Description: the windows procedure
//-----------------------------------------------------------------------------
LRESULT CALLBACK WindowProc(HWND hwnd,
UINT msg,
WPARAM wparam,
LPARAM lparam)
{
PAINTSTRUCT ps;
HDC hdc;

switch(msg)
{
case WM_CREATE:
{
SetTimer(hwnd, 1, 500, NULL);
return(0);
} break;

case WM_PAINT:
{
hdc = BeginPaint(hwnd,&ps);
EndPaint(hwnd,&ps);
return(0);
} break;

case WM_MOUSEMOVE:
{
MouseX = (int)LOWORD(lparam);
MouseY = (int)HIWORD(lparam);
MouseButtons = (int)wparam;

/* if (MouseButtons & MK_LBUTTON)
{
MAP_STRUCTURE[CurrentLayer][MouseToTilePos_Y][MouseToTilePos_X] = CurrentTexture;
}
*/

case WM_TIMER:
{
animation_frame++;
if (animation_frame == 2)
animation_frame = 0;
} break;

} break;

case WM_LBUTTONDOWN:{ MouseButtons = (int)wparam; } break;
case WM_LBUTTONUP: { MouseButtons = (int)wparam; } break;
case WM_RBUTTONDOWN:{ MouseButtons = (int)wparam; } break;
case WM_RBUTTONUP: { MouseButtons = (int)wparam; } break;

SendMessage(hwnd, WM_NCLBUTTONDOWN, HTCAPTION, NULL);
/*HTCAPTION = the caption/titlebar area
HTBOTTOMRIGHT = the resizing corner
*/





case WM_DESTROY:
{
PostQuitMessage(0);
KillTimer(hwnd, 1);
return(0);
} break;

default:break;
}

return (DefWindowProc(hwnd, msg, wparam, lparam));
}
int WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hprevinstance, LPSTR lpcmdline, int ncmdshow)
{
WNDCLASSEX winclass; // this will hold the class we create
HWND hwnd; // generic window handle
MSG msg; // generic message
// HDC hdc; // graphics device context

winclass.cbSize = sizeof(WNDCLASSEX);
winclass.style = CS_DBLCLKS | CS_OWNDC | CS_HREDRAW | CS_VREDRAW;
winclass.lpfnWndProc = WindowProc;
winclass.cbClsExtra = 0;
winclass.cbWndExtra = 0;
winclass.hInstance = hinstance;
winclass.hIcon = NULL;//LoadIcon(hinstance, MAKEINTRESOURCE(IDI_ICON1));
winclass.hCursor = NULL;//LoadCursor(hinstance, MAKEINTRESOURCE(IDC_CURSOR1));
winclass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
winclass.lpszMenuName = "EditorControlsMenu";
winclass.lpszClassName = "WINCLASS1";
winclass.hIconSm = NULL;//LoadIcon(hinstance, MAKEINTRESOURCE(IDI_ICON1));


// save hinstance in global
main_instance = hinstance;

if (!RegisterClassEx(&winclass))
return(0);

//MessageBox(NULL, "Creating window.", "Manual Debug Operation", MB_OK);
if (!(hwnd = CreateWindowEx(WS_EX_APPWINDOW,
"WINCLASS1",
"ToW: Map Editor Rendered Display",
WS_POPUP | WS_VISIBLE | WS_BORDER | WS_CAPTION | WS_MAXIMIZEBOX | WS_MINIMIZEBOX
| WS_SYSMENU,
(GetSystemMetrics(SM_CXSCREEN)/2)-(520/2),(GetSystemMetrics(SM_CYSCREEN)/2)-(360/2),
520,360,
NULL,
LoadMenu(hinstance, "EditorControlsMenu"),
hinstance,
NULL)))
return(0);

//HMENU hmenuhandle = LoadMenu(hinstance, "EditorControlsMenu");
//
//SetMenu(hwnd, hmenuhandle);

// save main window handle
main_window_handle = hwnd;

ShowCursor(TRUE);

GameInit();

// enter main event loop
while(TRUE)
{
if (PeekMessage(&msg,NULL,0,0,PM_REMOVE))
{
if (msg.message == WM_QUIT)
break;

TranslateMessage(&msg);
DispatchMessage(&msg);
}

GameMain();
}

GameShutdown();

return(0);//msg.wParam);
}




Share this post


Link to post
Share on other sites

This topic is 4660 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.

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