May 31st, 2012, 08:07 AM
#1
Why is my triangle not displaying??
Can anyone figure out why my triangle is not displaying please? Thanks in advance
Here is the link as the code is to large to paste
http://www.mediafire.com/download.php?ospidnejfbt7b9i
May 31st, 2012, 08:12 AM
#2
Re: Why is my triangle not displaying??
Dude, that's a 56MB rar file. Nobody's going to download that. Just paste the appropriate source code in here.
May 31st, 2012, 09:36 AM
#3
Re: Why is my triangle not displaying??
Originally Posted by
gaar321
Zip the source code and then attach it to your post.
Posting a link to a different site is not the way to get others see your code, as persons would be reluctant to visit such a "download" site -- who knows what crap that site puts on your machine if you visit it.
Regards,
Paul McKenzie
May 31st, 2012, 11:35 AM
#4
Re: Why is my triangle not displaying??
Attached Files
May 31st, 2012, 11:48 AM
#5
Re: Why is my triangle not displaying??
You don't want to make this easy do you. Which file, and which function are you having problems with? A project file would have been nice so we could build it.
Is there some reason you just don't want to past in your triangle displaying code?
May 31st, 2012, 12:26 PM
#6
Re: Why is my triangle not displaying??
I will try and make this as clear as possible then
When I run the project the background colour appears vertices are loaded into the buffers without a problem, the shaders load correctly as well as the matrix from the camera class yet when I run it the triangle will not appear :S
Graphic Render
Code:
bool GraphicsClass::Render()
{
D3DXMATRIX worldMatrix, viewMatrix, projectionMatrix;
D3D->BeginScene(1.0f,0.0f,0.0f,1.0f);
CameraS->Render();
CameraS->GetViewMatrix(viewMatrix);
D3D->GetWorldMatrix(worldMatrix);
D3D->GetProjectionMatrix(projectionMatrix);
Models->Render(D3D->GetDevice());
Shaders->RenderShaders(D3D->GetDevice(),Models->GetVertexCount(),worldMatrix,viewMatrix,projectionMatrix);
D3D->EndScene();
return true;
}
CameraClass
Code:
CameraClass::CameraClass()
{
m_positionX = 0.0f;
m_positionY = 0.0f;
m_positionZ = 0.0f;
m_rotationX = 0.0f;
m_rotationY = 0.0f;
m_rotationZ = 0.0f;
}
CameraClass::CameraClass(const CameraClass& other)
{
}
CameraClass::~CameraClass()
{
}
void CameraClass::SetPosition(float x, float y, float z)
{
m_positionX = x;
m_positionY = y;
m_positionZ = z;
return;
}
void CameraClass::SetRotation(float x, float y, float z)
{
m_rotationX = x;
m_rotationY = y;
m_rotationZ = z;
return;
}
D3DXVECTOR3 CameraClass::GetPosition()
{
return D3DXVECTOR3(m_positionX, m_positionY, m_positionZ);
}
D3DXVECTOR3 CameraClass::GetRotation()
{
return D3DXVECTOR3(m_rotationX, m_rotationY, m_rotationZ);
}
void CameraClass::Render()
{
D3DXVECTOR3 up, position, lookAt;
float yaw, pitch, roll;
D3DXMATRIX rotationMatrix;
// Setup the vector that points upwards.
up.x = 0.0f;
up.y = 1.0f;
up.z = 0.0f;
// Setup the position of the camera in the world.
position.x = m_positionX;
position.y = m_positionY;
position.z = m_positionZ;
// Setup where the camera is looking by default.
lookAt.x = 0.0f;
lookAt.y = 0.0f;
lookAt.z = 1.0f;
// Set the yaw (Y axis), pitch (X axis), and roll (Z axis) rotations in radians.
pitch = m_rotationX * 0.0174532925f;
yaw = m_rotationY * 0.0174532925f;
roll = m_rotationZ * 0.0174532925f;
// Create the rotation matrix from the yaw, pitch, and roll values.
D3DXMatrixRotationYawPitchRoll(&rotationMatrix, yaw, pitch, roll);
// Transform the lookAt and up vector by the rotation matrix so the view is correctly rotated at the origin.
D3DXVec3TransformCoord(&lookAt, &lookAt, &rotationMatrix);
D3DXVec3TransformCoord(&up, &up, &rotationMatrix);
// Translate the rotated camera position to the location of the viewer.
lookAt = position + lookAt;
// Finally create the view matrix from the three updated vectors.
D3DXMatrixLookAtLH(&m_viewMatrix, &position, &lookAt, &up);
return;
}
void CameraClass::GetViewMatrix(D3DXMATRIX& viewMatrix)
{
viewMatrix = m_viewMatrix;
return;
}
Render actual triangle
Code:
void ShaderClass::RenderShaders(ID3D10Device* Device,int vertexCount,D3DXMATRIX worldMatrix, D3DXMATRIX viewMatrix, D3DXMATRIX projectionMatrix)
{
m_worldMatrixPtr->SetMatrix((float*)&worldMatrix);
m_viewMatrixPtr->SetMatrix((float*)&viewMatrix);
m_projectionMatrixPtr->SetMatrix((float*)&projectionMatrix);
D3D10_TECHNIQUE_DESC techniqueDesc;
unsigned int i;
Device->IASetInputLayout(m_layout);
m_technique->GetDesc(&techniqueDesc);
for(i=0; i<techniqueDesc.Passes; ++i)
{
m_technique->GetPassByIndex(i)->Apply(0);
Device->Draw(vertexCount,0);
}
return;
}
Model load
Code:
bool result = true;
VertexStruct* vertices;
unsigned long* indices;
m_vertexCount = 8;
D3D10_BUFFER_DESC vertexBufferDesc;
D3D10_SUBRESOURCE_DATA vertexData;
ObjLoad->LoadMeshResource("File1.obj");
vertices = new VertexStruct[ObjLoad->VertexCoordinates.size()];
if(!vertices)
{
return false;
}
int countNum = 0;
for(countNum = 0; countNum < ObjLoad->VertexCoordinates.size();countNum++)
{
vertices[countNum].Position = ObjLoad->VertexCoordinates.data()[countNum];
vertices[countNum].color = D3DXVECTOR4(0.0f, 1.0f, 0.0f, 1.0f);
}
vertexBufferDesc.Usage = D3D10_USAGE_DEFAULT;
vertexBufferDesc.ByteWidth = sizeof(VertexStruct) * m_vertexCount;
vertexBufferDesc.BindFlags = D3D10_BIND_VERTEX_BUFFER;
vertexBufferDesc.CPUAccessFlags = 0;
vertexBufferDesc.MiscFlags = 0;
vertexData.pSysMem = vertices;
result = Device->CreateBuffer(&vertexBufferDesc, &vertexData, &m_vertexBuffer);
if(FAILED(result))
{
return false;
}
// Set up the description of the index buffer.
delete [] vertices;
vertices = 0;
return true;
HLSL code
Code:
////////////////////////////////////////////////////////////////////////////////
// Filename: TriangleShader.fx
////////////////////////////////////////////////////////////////////////////////
/////////////
// GLOBALS //
/////////////
matrix worldMatrix;
matrix viewMatrix;
matrix projectionMatrix;
//////////////
// TYPEDEFS //
//////////////
struct VertexInputType
{
float4 position : POSITION;
float4 color : COLOR;
};
struct PixelInputType
{
float4 position : SV_POSITION;
float4 color : COLOR;
};
////////////////////////////////////////////////////////////////////////////////
// Vertex Shader
////////////////////////////////////////////////////////////////////////////////
PixelInputType ColorVertexShader(VertexInputType input)
{
PixelInputType output;
// Change the position vector to be 4 units for proper matrix calculations.
input.position.w = 1.0f;
// Calculate the position of the vertex against the world, view, and projection matrices.
output.position = mul(input.position, worldMatrix);
output.position = mul(output.position, viewMatrix);
output.position = mul(output.position, projectionMatrix);
// Store the input color for the pixel shader to use.
output.color = input.color;
return output;
}
////////////////////////////////////////////////////////////////////////////////
// Pixel Shader
////////////////////////////////////////////////////////////////////////////////
float4 ColorPixelShader(PixelInputType input) : SV_Target
{
return input.color;
}
////////////////////////////////////////////////////////////////////////////////
// Technique
////////////////////////////////////////////////////////////////////////////////
technique10 ColorTechnique
{
pass pass0
{
SetVertexShader(CompileShader(vs_4_0, ColorVertexShader()));
SetPixelShader(CompileShader(ps_4_0, ColorPixelShader()));
SetGeometryShader(NULL);
}
}
May 31st, 2012, 12:38 PM
#7
Re: Why is my triangle not displaying??
Have you verified that your input file is being read ? It looks
line you are missing a return in it ... but from what I can see it
should read OK anyway.
May 31st, 2012, 12:59 PM
#8
Re: Why is my triangle not displaying??
Yeah i have (N)
Code:
bool ShaderClass::ShaderInit(ID3D10Device* Device,HWND hWnd)
{
bool result = true;
result = InitializeShader(Device,hWnd,"TriangleShader.fx");
if(!result)
{
MessageBox(0,0,0,0);
return false;
}
return true;
}
bool ShaderClass::InitializeShader(ID3D10Device* Device, HWND hwnd, char* filename)
{
HRESULT result;
ID3D10Blob* errorMessage;
unsigned int numElements;
D3D10_PASS_DESC passDesc;
errorMessage = 0;
result = D3DX10CreateEffectFromFile(filename,0,0,"fx_4_0",D3D10_SHADER_ENABLE_STRICTNESS,0,Device,0,0,&m_effect,&errorMessage,0);
if(FAILED(result))
{
// If the shader failed to compile it should have writen something to the error message.
if(errorMessage)
{
OutputShaderErrorMessage(errorMessage, hwnd, filename);
}
// If there was nothing in the error message then it simply could not find the shader file itself.
else
{
MessageBox(hwnd, filename, "Missing Shader File", MB_OK);
}
return false;
}
m_technique = m_effect->GetTechniqueByName("ColorTechnique");
if(!m_technique)
{
return false;
}
D3D10_INPUT_ELEMENT_DESC InputLayout[] = {
{"POSITION",0,DXGI_FORMAT_R32G32B32_FLOAT,0,0,D3D10_INPUT_PER_VERTEX_DATA,0},
{"COLOR",0,DXGI_FORMAT_R32G32B32_FLOAT,0,D3D10_APPEND_ALIGNED_ELEMENT,D3D10_INPUT_PER_VERTEX_DATA,0},};
numElements = sizeof(InputLayout) / sizeof(InputLayout[0]);
m_technique->GetPassByIndex(0)->GetDesc(&passDesc);
result = Device->CreateInputLayout(InputLayout,numElements,passDesc.pIAInputSignature,passDesc.IAInputSignatureSize,&m_layout);
if(FAILED(result))
{
return false;
}
m_worldMatrixPtr = m_effect->GetVariableByName("worldMatrix")->AsMatrix();
m_viewMatrixPtr = m_effect->GetVariableByName("viewMatrix")->AsMatrix();
m_projectionMatrixPtr = m_effect->GetVariableByName("projectionMatrix")->AsMatrix();
return true;
}
Posting Permissions
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
Forum Rules
Click Here to Expand Forum to Full Width