• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
GrimmBro

Change texture at runtime?

3 posts in this topic

Hi there,

 

If I have a 2D array consisting of cubes which represents a dungeon; different values in the array being what that cube will render as. The values all render fine when run and the 2D array can be hard coded to make up a level. However when I change the value of a specific location in the array, say

 dungeonArray[6][6] = 1;
 

to

 

 

dungeonArray[6][6] = 2;
 

This is to change the cube from a path to wall say. The physical properties of the new value are applied but not the change of texture appearance. The graphical elements of the array contain these values which do not seem to visually change no matter what I have tried so far. I am using 

 

d3dContext->UpdateSubresource(       
        constantBuffer[0].Get(),
        0,
        NULL,
        &constantBufferDataUpdate,
        0,
        0
        );
 

in the update function of the Game class; should this not update the textures. As when I press a test key the array does update as I said but no change in appearance. Any help or advice on this would be greatly appreciated.

0

Share this post


Link to post
Share on other sites

Where's your code to bind the next texture? I'm not familiar with UpdateSubresource, but you need to bind the new texture to render for that state change, otherwise it'll just use the last one that was bound before you render it.

0

Share this post


Link to post
Share on other sites

This is nothing related to texture input.

 

How do you handle your textures in the shader? in the cpu code?

 

 

How you assign textures in Dx11 is via PS/DS/HS/VS-SetShaderResources.

0

Share this post


Link to post
Share on other sites

Sorry for all the code in advance but am I to update the render call somehow after a graphical element in the array is switched?

 

PixelShader.hlsl

Texture2D Texture;
SamplerState samplerState;

struct PixelShaderInput
{
	float4 pos : SV_POSITION;
	float4 color : COLOR;
	float2 texcoord : TEXCOORD;
};

float4 main(PixelShaderInput input) : SV_TARGET
{
	return input.color * Texture.Sample(samplerState, input.texcoord);
}

 

VertexShader.hlsl

cbuffer PerFrameCB : register(b0)
{
	matrix view;
	matrix projection;

	float4 lightVector;
    float4 lightColor;
    float4 ambientColor;
};

cbuffer PerObjectCB : register(b1)
{
	matrix modeltransform;
}

struct VertexShaderInput
{
	float4 pos : POSITION;
	float4 normal : NORMAL;
	float2 texcoord : TEXCOORD;
};

struct VertexShaderOutput
{
	float4 pos : SV_POSITION;
	float4 color : COLOR;
	float2 texcoord : TEXCOORD;
};

VertexShaderOutput main(VertexShaderInput input)
{
	VertexShaderOutput output;
	float4 pos = input.pos;

	// Transform the vertex position into projected space.
	pos = mul(pos, modeltransform);
	pos = mul(pos, view);
	pos = mul(pos, projection);
	output.pos = pos;

	output.color = ambientColor;

	float diffusebrightness = saturate(dot(input.normal, lightVector));
    output.color += lightColor * diffusebrightness;

	output.texcoord = input.texcoord;

	return output;
}

in Dungeon.cpp

void Dungeon::CreateGraphicsElements(Microsoft::WRL::ComPtr<ID3D11Device1>& dev, Microsoft::WRL::ComPtr<ID3D11DeviceContext1>& devCon)
{
	//create graphics elements
	m_DungeonElements.resize(m_DungeonArray.size());
	for (unsigned int i = 0; i < m_DungeonArray.size(); ++i)
	{
		m_DungeonElements[i].resize(m_DungeonArray[i].size());
	}

	float dungeonWidth = KElementSize*m_DungeonElements.size();
	float dungeonHeight = KElementSize *m_DungeonElements[0].size();

	for (unsigned int i = 0; i < m_DungeonElements.size(); i++)
		for (unsigned int j = 0; j < m_DungeonElements[i].size(); j++)
		{
			Microsoft::WRL::ComPtr<ID3D11ShaderResourceView> selectedTexture = nullptr;
			int scaleHeight = 1;
			float elementY = -ElementSize;
			switch (m_DungeonArray[i][j])
			{
			case 1://wall
				scaleHeight = 2;
				elementY = 0;
				selectedTexture = m_TextureWall;
				break;
			case 2://cave
				selectedTexture = m_TextureCave;
				break;
			case 3://vegetation
				scaleHeight = 2;
				elementY = 0;
				selectedTexture = m_TextureVegetation;
				break;
			case 4://liquid
				selectedTexture = m_TextureLiquid;
				scaleHeight = 2;
				elementY = 0;
				break;
			case 5://gold
				selectedTexture = m_TextureGold;
				scaleHeight = 2;			
				elementY = 0;
				break;
			}

			m_DungeonElements[i][j] = new CDungeonElement(Vector3D( 0+j*KElementSize-dungeonWidth/2.0f, elementY, 0-i*KElementSize+dungeonHeight/2.0f), Vector3D(KElementSize, KElementSize*scaleHeight, KElementSize),
				selectedTexture, aDev, aDevCon);
			
	                //states to try and change certain blocks on array which are triggered by key presses.
              		if (m_blockState == BlockState::Path)
			{
				m_DungeonArray[3][3]=5;
			}
			if (m_blockState == BlockState::Wall)
			{
				m_DungeonArray[2][3]=5;
			}
			
			
		}
		}

this is called in

void Dungeon::createDungeon(Microsoft::WRL::ComPtr<ID3D11Device1>& dev, Microsoft::WRL::ComPtr<ID3D11DeviceContext1>& devCon)

in Game.cpp

 

void Game::Render()
{
	// bind the render targets
	m_d3dContext->OMSetRenderTargets(
		1,
		m_d3dRenderTargetView.GetAddressOf(),
		m_d3dDepthStencilView.Get()
		);
	
	// clear both the render target and depth stencil to default values
	const float black[] = { 0.0f, 0.0f, 0.0f, 1.000f };		//Clears screen to black.
	m_d3dContext->ClearRenderTargetView(
		m_d3dRenderTargetView.Get(),
		black
		);

	if (!m_deferredResourcesReady)
	{
		// Only render the loading screen for now.
		m_loadScreen->Render();
		return;
	}

	m_d3dContext->ClearDepthStencilView(
		m_d3dDepthStencilView.Get(),
		D3D11_CLEAR_DEPTH,
		1.0f,
		0
		);

	if (!m_loadingComplete)
	{
		return;
	}	

	m_d3dContext->IASetInputLayout(m_inputLayout.Get());

	// set the vertex shader stage state
	m_d3dContext->VSSetShader(
		m_vertexShader.Get(),
		nullptr,
		0
		);

	m_d3dContext->VSSetConstantBuffers(
		0,
		2,
		m_constantBuffer[0].GetAddressOf()
		);

	m_d3dContext->PSSetShader(
		m_pixelShader.Get(),
		nullptr,
		0
		);
	
	mp_Dungeon->Render(m_d3dContext, m_constantBuffer[1]);
	

}

 

void Game::Update(float timeTotal, float timeDelta)
{
	UNREFERENCED_PARAMETER( timeDelta );

#pragma region loading checks

	if (!m_loadingComplete) 
		return;

	if (!m_deferredResourcesReady)
	{		return;
	}
#pragma endregion loading checks

	ProcessInput();
		
	int res = mp_Dungeon->Update(timeDelta);		//update dungeon (only deals with player position for now)
	
		m_d3dContext->UpdateSubresource(
		m_constantBuffer[0].Get(),
		0,
		NULL,
		&m_constantBufferDataPerFrame,
		0,
		0
		);

	        m_d3dContext->UpdateSubresource(
		m_constantBuffer[1].Get(),
		0,
		NULL,
		&m_constantBufferDataPerObject,
		0,
		0
		);

}

Pretty sure I'm going to kick myself when I find out how to do this but I will be so happy when I do. Can anyone let me know how I can switch the graphical element value in the array and have it update in game?

0

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  
Followers 0