Jump to content

  • Log In with Google      Sign In   
  • Create Account


Where is my triangle? Issue moving to Directx 11 and Metro


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
28 replies to this topic

#1 AlzPatz   Members   -  Reputation: 132

Like
0Likes
Like

Posted 29 September 2012 - 08:57 AM

Hi. After playing about in directx and metro, I've hit a wall that either I'm being the most useless n00b on the planet or things do not work quite the same as earlier directx. very simply, im trying to render a triangle straight to "normalised / homogenous" or whatever you call it space - using the world's most basic shaders. To make sure that my initialisation code wasn't screwed up, I've transplanted the code into the direct 3D app template and still it does not show. if anyone could help work out why my triangle is not showing, would be appreciated. there must be something easy I've missed. To note this code tries to draw two triangles, filling the screen, one clockwise winding and one anti-clockwise, a test in case my winding was wrong. (Why can't I hit enter on this forum for a new line lol??). Anyway, first I hijack the cuberenders create device resources code
[source lang="cpp"]void CubeRenderer::CreateDeviceResources(){ Direct3DBase::CreateDeviceResources(); VertexPos vertices[] = {  DirectX::XMFLOAT3(0.0f, 0.0f, 0.2f),  DirectX::XMFLOAT3(1.0f, 0.0f, 0.2f),  DirectX::XMFLOAT3(0.0f, 1.0f, 0.2f),  DirectX::XMFLOAT3(0.0f, 1.0f, 0.2f),  DirectX::XMFLOAT3(1.0f, 1.0f, 0.2f),  DirectX::XMFLOAT3(1.0f, 0.0f, 0.2f), }; D3D11_BUFFER_DESC TT_vertexDesc; ZeroMemory(&TT_vertexDesc, sizeof(TT_vertexDesc)); TT_vertexDesc.Usage = D3D11_USAGE_DEFAULT; TT_vertexDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER; TT_vertexDesc.ByteWidth = sizeof(VertexPos) * 6; D3D11_SUBRESOURCE_DATA sResource; ZeroMemory(&sResource, sizeof(sResource)); sResource.pSysMem = vertices; DX::ThrowIfFailed(m_d3dDevice->CreateBuffer(&TT_vertexDesc, &sResource, &TT_vertexBuffer)); //Load the Shaders //Load the vertex shader (the build configuration / properties of the shader file deals with compile to .cso) auto task_LoadTTVS = DX::ReadDataAsync("VS_TriangleTest.cso"); auto task_CreateTTVS = task_LoadTTVS.then([this](DX::ByteArray ba) {  //This async load / helper classes are taken straight from the template. Why not.  auto bc_VS = ba.data;  DX::ThrowIfFailed(m_d3dDevice->CreateVertexShader(bc_VS->Data, bc_VS->Length, nullptr, &VS_TT));  //Create Input Layout Description  D3D11_INPUT_ELEMENT_DESC vertexLayout[] =  {   {"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0}  };  //Create the Input Layout  DX::ThrowIfFailed(m_d3dDevice->CreateInputLayout(vertexLayout, ARRAYSIZE(vertexLayout), bc_VS->Data, bc_VS->Length, &TT_inputLayout)); }); //Load the pixel shader (again, the build and configuration properties of the shader file deal with compilation auto task_LoadTTPS = DX::ReadDataAsync("PS_TriangleTest.cso"); auto task_CreateTTPS = task_LoadTTPS.then([this](DX::ByteArray ba) {  auto bc_PS = ba.data;  DX::ThrowIfFailed(m_d3dDevice->CreatePixelShader(bc_PS->Data, bc_PS->Length, nullptr, &PS_TT));  m_loadingComplete = true; //dont really work properly as earlier shaders might take longer but meh won't be the issue here });}[/source] THen I hijack the rendering bit. FYI I've confirmed that all the context calls are run
const float Red[] = { 1.0f, 0.0f, 0.0f, 1.0f };
m_d3dContext->ClearRenderTargetView(m_renderTargetView.Get(), Red);
//Clear the depth stenicl view
m_d3dContext->ClearDepthStencilView(m_depthStencilView.Get(), D3D11_CLEAR_DEPTH, 1.0f, 0);
if (!m_loadingComplete)
  return;
m_d3dContext->IASetInputLayout(TT_inputLayout.Get());
m_d3dContext->OMSetRenderTargets(1, m_renderTargetView.GetAddressOf(), m_depthStencilView.Get());
//Test triangle following some book code to check that everything is working
UINT str = sizeof(VertexPos);
UINT oset = 0;
m_d3dContext->IASetVertexBuffers(0, 1, &TT_vertexBuffer, &str, &oset);
m_d3dContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
m_d3dContext->VSSetShader(VS_TT.Get(), 0, 0);
m_d3dContext->PSSetShader(PS_TT.Get(), 0, 0);
m_d3dContext->Draw(6, 0);
then the world's simplest shaders (even desperately rewritten to copy ones on the net using a structure, obviously this pass through could just be main function only returning float4...
struct VOut
{
float4 position : SV_POSITION;
};
VOut main( float4 pos : POSITION )
{
VOut output;
output.position = pos;
return output;
}
and the pixel pencil...
float4 main(float4 position : SV_POSITION) : SV_TARGET
{
return float4 (0.0f, 1.0f, 1.0f, 1.0f);
}
and wahay, I always get a red screen. ive tried making the triangles screen sized in case its not -1,-1 to 1,1 but still no joy. any help for a tired n00b? thanks!!

Sponsor:

#2 papulko   Members   -  Reputation: 789

Like
0Likes
Like

Posted 30 September 2012 - 03:19 PM

I'm not sure if this will help but it seems to me your input layout defines vertex position as a 3 element vector (DXGI_FORMAT_R32G32B32_FLOAT), while your vertex shader parameter is expecting a 4 element one (float4 pos). I'd suggest you try and change the vertex shader parameter to float3 and see if that helps!

#3 AlzPatz   Members   -  Reputation: 132

Like
0Likes
Like

Posted 02 October 2012 - 02:05 PM

Hi, thanks so much for your suggestion. My shaders would not compile with a float3 input, but I changed the code to use XMFLOAT4's instead. unfortunately no luck. Im getting really depressed now. Ive tried this in windows 7 dx11 c++, metro c++/cx DX 11 and with sharp DX in c#, always the same. I even followed the code from book "beginning game programming in directx11 that does this, and it didn't work, except their demo compiled and it worked!). seriously cannot for the life of me work this out. it's infuriating, this was supposed to be small step just to check things are working... :(

#4 papulko   Members   -  Reputation: 789

Like
0Likes
Like

Posted 02 October 2012 - 11:48 PM

Hey again, Don't forget to change your input layout to DXGI_FORMAT_R32G32B32A32_FLOAT (and your vertex struct position element if you haven't already) in order for it to work with XMFLOAT4,

If you wish to stick with XMFLOAT3, I'm guessing your shader won't compile because the 2nd row in the main method of your vertex shader has to be changed from ("output.position = pos") to "output.position = float4(pos, 1.0f)".

#5 AlzPatz   Members   -  Reputation: 132

Like
0Likes
Like

Posted 03 October 2012 - 09:09 AM

Sorry I wasn't very clear. I did change the Input Layout format to the 4 component format. and I also changed the vertex shader to output a float4 from a float3 (pos, 1.0f). Ill double check again tonight anyhow.

#6 hupsilardee   Members   -  Reputation: 486

Like
0Likes
Like

Posted 04 October 2012 - 04:54 AM

You didnt set a viewport anywhere I could see. It could be this

#7 AlzPatz   Members   -  Reputation: 132

Like
0Likes
Like

Posted 04 October 2012 - 11:29 AM

Viewport is set at the end of another part of the code. Thanks for the suggestion though!

#8 papulko   Members   -  Reputation: 789

Like
0Likes
Like

Posted 05 October 2012 - 02:37 AM

I'm missing a set rasterizer call ( "m_d3dContext->RSSetState()" ), could be it.

#9 AlzPatz   Members   -  Reputation: 132

Like
0Likes
Like

Posted 08 October 2012 - 07:41 AM

Thanks Papulko - you are right, I do not set one. However, Im pretty certain that DX11 sets up a default rasteriser that CULLS back and FILLS_SOLID. Ill add it later, but I dont hold too much hope this will work. :(

#10 L. Spiro   Crossbones+   -  Reputation: 12269

Like
1Likes
Like

Posted 08 October 2012 - 08:30 AM

Change it to disable culling or reverse the winding of your triangles.

Use PIX to confirm the positions of your vertices in screen space after the vertex shader is run.
Use PIX to perform general debugging of the scene and verification of the state at the time of rendering.
Use DirectX Debug Mode and watch the console for important messages on errors and warnings.


L. Spiro
It is amazing how often people try to be unique, and yet they are always trying to make others be like them. - L. Spiro 2011
I spent most of my life learning the courage it takes to go out and get what I want. Now that I have it, I am not sure exactly what it is that I want. - L. Spiro 2013
I went to my local Subway once to find some guy yelling at the staff. When someone finally came to take my order and asked, “May I help you?”, I replied, “Yeah, I’ll have one asshole to go.”
L. Spiro Engine: http://lspiroengine.com
L. Spiro Engine Forums: http://lspiroengine.com/forums

#11 AlzPatz   Members   -  Reputation: 132

Like
0Likes
Like

Posted 08 October 2012 - 09:05 AM

Thanks Spiro. have tried reverse winding. Will try out PIX when I get home. DX DebugMode is turned on, no funny messages.

#12 kauna   Crossbones+   -  Reputation: 2158

Like
0Likes
Like

Posted 08 October 2012 - 11:19 AM

I'm not sure if this will help but it seems to me your input layout defines vertex position as a 3 element vector (DXGI_FORMAT_R32G32B32_FLOAT), while your vertex shader parameter is expecting a 4 element one (float4 pos). I'd suggest you try and change the vertex shader parameter to float3 and see if that helps!


Using DXGI_FORMAT_R32G32B32_FLOAT is perfectly valid. The vertex shader will receive the value as [x,y,z,1.0f] automatically.

Cheers!

Edited by kauna, 08 October 2012 - 11:47 AM.


#13 AlzPatz   Members   -  Reputation: 132

Like
0Likes
Like

Posted 09 October 2012 - 01:40 PM

so..turns out PIX has been replaced by Graphics Diagnostics integrated into Visual Studio 2012. Hurray I thought, until it turns out that it's only available on versions higher than 'express', so that's a £500+ purchase to use graphics debugging on Visual Studio 2012. soul destroying. Not sure anyway around this. I cant download any trial versions etc as I am running RC and some version of windows 8, it's all gone to sh1t until the real version of windows 8 is released.

#14 AlzPatz   Members   -  Reputation: 132

Like
0Likes
Like

Posted 09 October 2012 - 02:11 PM

i would also add that I have no problems doing this simple drawing in DirectX 11 and C++ in windows 7 / win 32. Im at a loss, completely.

#15 col_anderson   Members   -  Reputation: 109

Like
0Likes
Like

Posted 10 October 2012 - 06:32 AM

The problem you are describing sound like the exact same problem when I try to render a cube.

Inspecting the problem with the Graphics Diagnosis Tool tells me that the Pixel Shader has not participate in the graphics pipeline process, in my case, without any obvious reason.

I have double checked it, but it was loaded properly and set correctly in the device context.
This leaves me clueless.

Perhaps the additional diag info helps in your case as well, AlzPatz. (see attachment)

And this is the corresponding source code

Cube.cpp:
#include "Cube.h"
#include "GlobalDefines.h"
#include "Direct3dUtils.h"
struct SChangesEveryFrame{
XMMATRIX mWorld;
};
Cube::Cube(void)
:isInitialized(false),
vertexBuffer(NULL),
indexBuffer(NULL),
cbChangesEveryFrame(NULL),
vertexShaderFile(L"SimpleVertexShader"),
pixelShaderFile(L"SimplePixelShader"),
vertexShader(NULL),
pixelShader(NULL),
inputLayout(NULL)
{
}

Cube::~Cube(void)
{
SAFE_RELEASE(inputLayout);
SAFE_RELEASE(pixelShader);
SAFE_RELEASE(vertexShader);
SAFE_RELEASE(cbChangesEveryFrame);
SAFE_RELEASE(vertexBuffer);
SAFE_RELEASE(indexBuffer);
}
void Cube::Render()
{
if(isInitialized){
  SChangesEveryFrame sChangesEveryFrame;
  //using XMMATRIX causes runtime error - better use XMFloat4x4
  //http://www.gamedev.net/topic/627033-xmmatrixtranspose-crashes/
  //http://xboxforums.create.msdn.com/forums/t/84299.aspx
  sChangesEveryFrame.mWorld = XMMatrixTranspose(XMLoadFloat4x4(&worldMatrix));
  
  UINT stride =sizeof(SimpleColorVertex) ;
  UINT offset = 0;

  immediateContext->IASetInputLayout(inputLayout);
  immediateContext->IASetVertexBuffers(0,1,&vertexBuffer,&stride,&offset);
  immediateContext->IASetIndexBuffer(indexBuffer,DXGI_FORMAT_R16_UINT,0);
  immediateContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);

  immediateContext->UpdateSubresource(cbChangesEveryFrame,0,NULL,&sChangesEveryFrame,0,0);
  immediateContext->VSSetConstantBuffers(2,1,&cbChangesEveryFrame);
  //immediateContext->PSSetConstantBuffers(2,1,&cbChangesEveryFrame);
  immediateContext->VSSetShader(vertexShader, NULL,0);
  immediateContext->PSSetShader(pixelShader, NULL,0);
  immediateContext->DrawIndexed( 36, 0, 0 );
}
}
void Cube::Initialize(ID3D11Device* device, ID3D11DeviceContext* immediateContext)
{
this->device = device;
this->immediateContext = immediateContext;

SimpleColorVertex vertices[] =
{
  { XMFLOAT3( -1.0f, 1.0f, -1.0f ), XMFLOAT4( 0.0f, 0.0f, 1.0f, 1.0f ) },
  { XMFLOAT3( 1.0f, 1.0f, -1.0f ), XMFLOAT4( 0.0f, 1.0f, 0.0f, 1.0f ) },
  { XMFLOAT3( 1.0f, 1.0f, 1.0f ), XMFLOAT4( 0.0f, 1.0f, 1.0f, 1.0f ) },
  { XMFLOAT3( -1.0f, 1.0f, 1.0f ), XMFLOAT4( 1.0f, 0.0f, 0.0f, 1.0f ) },
  { XMFLOAT3( -1.0f, -1.0f, -1.0f ), XMFLOAT4( 1.0f, 0.0f, 1.0f, 1.0f ) },
  { XMFLOAT3( 1.0f, -1.0f, -1.0f ), XMFLOAT4( 1.0f, 1.0f, 0.0f, 1.0f ) },
  { XMFLOAT3( 1.0f, -1.0f, 1.0f ), XMFLOAT4( 1.0f, 1.0f, 1.0f, 1.0f ) },
  { XMFLOAT3( -1.0f, -1.0f, 1.0f ), XMFLOAT4( 0.0f, 0.0f, 0.0f, 1.0f ) }
};
WORD indices[] =
{
  3,1,0,
  2,1,3,

  0,5,4,
  1,5,0,

  3,4,7,
  0,4,3,

  1,6,5,
  2,6,1,

  2,7,6,
  3,7,2,

  6,4,5,
  7,4,6,
};
HRESULT hr;
vertexBuffer = Direct3dUtils::CreateBuffer(device,D3D11_BIND_VERTEX_BUFFER,sizeof(SimpleColorVertex) * ARRAYSIZE(vertices),vertices,hr);
if (FAILED(hr)){
  Direct3dUtils::ShowMessageBoxOnBadResult(hr,L"create vertexbuffer");
  return;
}
indexBuffer = Direct3dUtils::CreateBuffer(device,D3D11_BIND_INDEX_BUFFER,sizeof(WORD) * ARRAYSIZE(indices),indices,hr);
if (FAILED(hr)){
  Direct3dUtils::ShowMessageBoxOnBadResult(hr,L"create indexbuffer");
  return;
}
cbChangesEveryFrame = Direct3dUtils::CreateBuffer(device,D3D11_BIND_CONSTANT_BUFFER,sizeof(SChangesEveryFrame),NULL,hr);
if (FAILED(hr)){
  Direct3dUtils::ShowMessageBoxOnBadResult(hr,L"create cbChangesEveryFrame");
  return;
}
D3D11_INPUT_ELEMENT_DESC layoutDesciption[] =
{
  { "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT,0 ,0, D3D11_INPUT_PER_VERTEX_DATA, 0 },
  { "COLOR" , 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 }
};
Direct3dUtils::LoadVertexShader(device, vertexShaderFile, layoutDesciption,ARRAYSIZE(layoutDesciption), &vertexShader, &inputLayout, hr);
if (FAILED(hr)){
  Direct3dUtils::ShowMessageBoxOnBadResult(hr,L"LoadVertexShader");
  return;
}
Direct3dUtils::LoadPixelShader(device, pixelShaderFile,&pixelShader, hr);
if (FAILED(hr)){
  Direct3dUtils::ShowMessageBoxOnBadResult(hr,L"LoadPixelShader");
  return;
}
XMStoreFloat4x4(&worldMatrix,XMMatrixIdentity());
isInitialized = true;
}

Direct3d.cpp
#include "Direct3d.h"
struct SNeverChanges{
XMMATRIX mView;
};
struct SChangesOnResize{
XMMATRIX mProjection;
};
Direct3d::Direct3d(HWND hwnd)
{
  // TODO set up configuration class to determine proper system configuration, for now we go with the dev system requirments

IDXGIAdapter* adapter = NULL;
D3D_DRIVER_TYPE driverType = D3D_DRIVER_TYPE_HARDWARE;
// TODO allow multiple display modes, including full-screen resolutions -  for now we go with windowed 1024x768x60hz

int resolutionWidth = WINDOWWITDH;
int resolutionHeight = WINDOWHEIGHT;
int refreshrate = 60;
bool windowed = true;
int multisamplingCount = 1;
int mulitsamplingQuality = 0;
UINT createDeviceFlags = 0;
#ifdef _DEBUG
  createDeviceFlags |= D3D11_CREATE_DEVICE_DEBUG;
#endif

DXGI_SWAP_CHAIN_DESC sd;
ZeroMemory( &sd, sizeof(sd) );
sd.BufferCount = 1;
sd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
sd.BufferDesc.RefreshRate.Numerator = refreshrate;
sd.BufferDesc.RefreshRate.Denominator = 1;
sd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
sd.BufferDesc.Width = resolutionWidth;
sd.BufferDesc.Height = resolutionHeight;
sd.Windowed = windowed;
sd.SampleDesc.Count = multisamplingCount;
sd.SampleDesc.Quality = mulitsamplingQuality;
sd.OutputWindow = hwnd;
D3D_FEATURE_LEVEL featureLevels[] =
{
  D3D_FEATURE_LEVEL_11_0,
  D3D_FEATURE_LEVEL_10_1,
  D3D_FEATURE_LEVEL_10_0
};
int numberOfFeatureLevels = ARRAYSIZE(featureLevels);
HRESULT hr;
hr = D3D11CreateDeviceAndSwapChain(adapter, driverType, NULL, createDeviceFlags, featureLevels, numberOfFeatureLevels, D3D11_SDK_VERSION, &sd, &swapChain, &device, NULL, &immediateContext );
if (FAILED(hr)){
  Direct3dUtils::ShowMessageBoxOnBadResult( hr, L"CreateDevice&SwapChain" );
  return;
}
hr = swapChain->GetBuffer( 0, __uuidof( ID3D11Texture2D ), (void**) &backBuffer );
if (FAILED(hr)){
  Direct3dUtils::ShowMessageBoxOnBadResult( hr, L"SwapChain-GetBuffer" );
  return;
}

hr = device->CreateRenderTargetView(backBuffer, NULL, &renderTargetView);
backBuffer->Release();
if (FAILED(hr)){
  Direct3dUtils::ShowMessageBoxOnBadResult( hr, L"CreateRenderTargetView" );
  return;
}

D3D11_TEXTURE2D_DESC stencilDescription;
ZeroMemory(&stencilDescription,sizeof(stencilDescription));
stencilDescription.Usage = D3D11_USAGE_DEFAULT;
stencilDescription.Width = resolutionWidth;
stencilDescription.Height = resolutionHeight;
stencilDescription.MipLevels = 1;
stencilDescription.ArraySize = 1;
stencilDescription.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
stencilDescription.SampleDesc.Count = 1;
stencilDescription.SampleDesc.Quality = 0;
stencilDescription.BindFlags = D3D11_BIND_DEPTH_STENCIL;
stencilDescription.CPUAccessFlags = 0;
stencilDescription.MiscFlags = 0;
hr = device->CreateTexture2D(&stencilDescription,NULL, &depthStencilBuffer);
if (FAILED(hr)){
  Direct3dUtils::ShowMessageBoxOnBadResult( hr, L"CreateDepthStencilBuffer" );
  return;
}  

D3D11_DEPTH_STENCIL_VIEW_DESC viewDescription;
ZeroMemory(&viewDescription,sizeof(viewDescription));
viewDescription.Format = stencilDescription.Format;
viewDescription.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D;
hr = device->CreateDepthStencilView(depthStencilBuffer,&viewDescription,&depthStencilView);
if (FAILED(hr)){
  Direct3dUtils::ShowMessageBoxOnBadResult( hr, L"CreateDepthStencilView" );
  return;
}  

immediateContext->OMSetRenderTargets( 1, &renderTargetView, depthStencilView);
D3D11_VIEWPORT vp;
vp.Width = float(resolutionWidth);
vp.Height = float(resolutionHeight);
vp.MinDepth = 0.0f;
vp.MaxDepth = 1.0f;
vp.TopLeftX = 0;
vp.TopLeftY = 0;
immediateContext->RSSetViewports( 1, &vp );
XMVECTOR eye = XMVectorSet(0.0f, 3.0f, -2.0f, 0.0f);
XMVECTOR at = XMVectorSet(0.0f,1.0f,1.0f,0.0f);
XMVECTOR up = XMVectorSet(0.0f,1.0f,1.0f,0.0f);
XMStoreFloat4x4(&ViewMatrix,XMMatrixLookAtLH(eye,at,up));
SNeverChanges sNeverChanges;
sNeverChanges.mView = XMLoadFloat4x4(&ViewMatrix);
cbNeverChanges = Direct3dUtils::CreateBuffer(device,D3D11_BIND_CONSTANT_BUFFER,sizeof(SNeverChanges),NULL,hr);
if (FAILED(hr)){
  Direct3dUtils::ShowMessageBoxOnBadResult(hr,L"create cbNeverChanges");
  return;
}
immediateContext->UpdateSubresource( cbNeverChanges, 0, NULL, &sNeverChanges, 0, 0 );
XMStoreFloat4x4(&ProjectionMatrix,XMMatrixPerspectiveFovLH(XM_PIDIV2,resolutionWidth/(float)resolutionHeight,0.01f,1.0f));
SChangesOnResize sChangesOnResize;
sChangesOnResize.mProjection = XMLoadFloat4x4(&ProjectionMatrix);
cbChangesOnResize = Direct3dUtils::CreateBuffer(device,D3D11_BIND_CONSTANT_BUFFER,sizeof(SChangesOnResize),NULL,hr);
if (FAILED(hr)){
  Direct3dUtils::ShowMessageBoxOnBadResult(hr,L"create cbNeverChanges");
  return;
}
immediateContext->UpdateSubresource( cbChangesOnResize, 0, NULL, &sChangesOnResize, 0, 0 );
}
Direct3d::~Direct3d(void)
{
if (immediateContext) immediateContext->ClearState();
SAFE_RELEASE(cbNeverChanges);
SAFE_RELEASE(cbChangesOnResize);
SAFE_RELEASE(depthStencilView);
SAFE_RELEASE(renderTargetView);
SAFE_RELEASE(backBuffer);
SAFE_RELEASE(immediateContext);
SAFE_RELEASE(swapChain);
SAFE_RELEASE(device);
}
void Direct3d::Render()
{
float color[] = { 0.0f, 0.2f, 0.0f, 1.0f };
immediateContext->ClearRenderTargetView(renderTargetView, color);
immediateContext->ClearDepthStencilView(depthStencilView, D3D11_CLEAR_DEPTH, 1.0f, 0);
immediateContext->VSSetConstantBuffers(1,1,&cbChangesOnResize);
immediateContext->VSSetConstantBuffers(0,1,&cbNeverChanges);
renderObjects();
swapChain->Present( 0, 0 );
}
void Direct3d::Add(Renderable* object)
{
object->Initialize(device,immediateContext);
objects.insert(objects.end(),object);
}

void Direct3d::renderObjects()
{
for (std::vector<Renderable*>::iterator iter = objects.begin(); iter != objects.end(); iter++)
  (*iter)->Render();
}

My shaders are pretty basic as well:

definitions.fx:
cbuffer cbNeverChanges : register(b0) {
matrix View;
};
cbuffer cbChangesOnResize: register(b1) {
matrix Projection;
};
cbuffer cbChangesEveryFrame : register (b2) {
matrix World;
};
struct VS_INPUT{
float4 Pos : POSITION;
float4 Color : COLOR0;
};
struct PS_INPUT{
float4 Pos : SV_POSITION;
float4 Color : COLOR0;
};

SimplePixelShader.hlsl:
#include "definitions.fx"
float4 main(PS_INPUT input) : SV_Target
{
return input.Color;
}
SimpleVertexShader.hlsl:
#include "definitions.fx"

PS_INPUT main( VS_INPUT input )
{
PS_INPUT output = (PS_INPUT)0;
output.Pos = mul(input.Pos,World);
output.Pos = mul(output.Pos, View);
output.Pos = mul(output.Pos, Projection);
output.Color = input.Color;
return output;
}

Attached Thumbnails

  • GD.jpg

Edited by col_anderson, 10 October 2012 - 06:37 AM.


#16 AlzPatz   Members   -  Reputation: 132

Like
0Likes
Like

Posted 11 October 2012 - 06:46 AM

Hi col_andersen.
Same as me, I do not see anything obvious in the code. You are using the Jun2010 SDK? So no targeting metro?
I could be getting the same effect. Any chance I could send you a simple solution zip file for you to run through the diagnostics to check if the same?

#17 col_anderson   Members   -  Reputation: 109

Like
0Likes
Like

Posted 11 October 2012 - 07:24 AM

I solved the issue for me, but you seem to use untransformed screen coordinates.

The root cause with my code were the Projection and View matrices.

While I stored the world matrix correctly:
sChangesEveryFrame.mWorld = XMMatrixTranspose(XMLoadFloat4x4(&worldMatrix));

I did not do it with the other two:
sNeverChanges.mView = XMLoadFloat4x4(&ViewMatrix);
and
sChangesOnResize.mProjection = XMLoadFloat4x4(&ProjectionMatrix);

The shader has to use a transposed version of the matrices.

AlzPatz - I will get in touch with you via PM.

Edited by col_anderson, 11 October 2012 - 07:39 AM.


#18 AlzPatz   Members   -  Reputation: 132

Like
0Likes
Like

Posted 11 October 2012 - 08:44 AM

thanks - yes, i'm just trying to put a triangle on screen as a simple test lol.

#19 papulko   Members   -  Reputation: 789

Like
0Likes
Like

Posted 11 October 2012 - 09:22 AM

AlzPatz did you setup a view and projection matrix?

#20 AlzPatz   Members   -  Reputation: 132

Like
0Likes
Like

Posted 11 October 2012 - 10:23 AM

Hi - no i do not. I didn't think I needed to if my vertices were already in "Screen Space", or Homogenous clip space, or whatever (-1,-1, z to 1, 1,z). maybe i got wrong end of the stick.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS