CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    Apr 2010
    Posts
    172

    Post 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

  2. #2
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,637

    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.

  3. #3
    Join Date
    Apr 1999
    Posts
    27,449

    Re: Why is my triangle not displaying??

    Quote Originally Posted by gaar321 View Post
    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
    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

  4. #4
    Join Date
    Apr 2010
    Posts
    172

    Thumbs up Re: Why is my triangle not displaying??

    There is the source code
    Attached Files Attached Files

  5. #5
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,637

    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?

  6. #6
    Join Date
    Apr 2010
    Posts
    172

    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);
        }
    }

  7. #7
    Join Date
    Aug 2000
    Location
    West Virginia
    Posts
    7,725

    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.

  8. #8
    Join Date
    Apr 2010
    Posts
    172

    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
  •  





Click Here to Expand Forum to Full Width

Featured