Jump to content

  • Log In with Google      Sign In   
  • Create Account


Ubermeowmix

Member Since 30 Jan 2010
Offline Last Active Jul 17 2014 05:44 PM

Posts I've Made

In Topic: What mesh file format should I be using?

17 February 2014 - 05:06 AM

Nice one, thanks. I had seen the FBX format, I just wanted to make sure that it wasn't another Microsoft initiative like XNA that would be depreciated in 6 months time.


In Topic: Missing the vertex!

06 January 2014 - 05:10 AM

Yay, I've finally managed to get both to draw at once, you legend. Thank you for pointing me in the right direction.

 

All I have to do now is figure out why the text is taking the scaleModifier from my cubes and changing size! I think it needs to be passed through the constant WVP but i'll find it soon enough :P


In Topic: Missing the vertex!

05 January 2014 - 09:03 PM

So after creating this:

 

    //Set the vertex buffer
    UINT stride = sizeof( Vertex );
    UINT offset = 0;
    d3d11DevCon->IASetVertexBuffers( 0, 1, &squareVertBuffer, &stride, &offset );

    //Create the Input Layout
    hr = d3d11Device->CreateInputLayout( layout, numElements, VS_Buffer->GetBufferPointer(),
        VS_Buffer->GetBufferSize(), &vertLayout );

    //Set the Input Layout
    d3d11DevCon->IASetInputLayout( vertLayout );

    //Set Primitive Topology
    d3d11DevCon->IASetPrimitiveTopology( D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST );

 

Where do I then access this information at a later time, as several things need to happen in between.

 

Initialization of further objects, and setting their own unique IA details.

Update of scene, variables need to be adjusted.

 

Then the draw call comes after that, this is where I'm getting 1 triangle of a cube drawn which is weird colours & my text is some how taking on the coordinates of the cubes :S


In Topic: Missing the vertex!

05 January 2014 - 01:49 PM

Right that's what I already had a basic grasp of, as the program I am running is generating 6 cubes & includes clockwise & counter clockwise culling to acheive transparency. Plus each has their own texture, and is affected by the transforms of world space so they all do silly movements.

 

So I understand that the same object can be essentially tweaked and modified within reason.

 

I don't think that this is going to work with the font engine that I have modified to take large text blocks from my Directx 11 game programming book:

bool DrawString( const char* message, float startX, float startY )



{



    // size in bytes for a single sprite



    const int sizeOfSprite = sizeof( VertexSquare ) * 6;







    int length = strlen( message );







    //clamp for strings too long



    if( length > ciMaxLetters )



        length = ciMaxLetters;







    //chars width on screen



    // this could be pulled in for the height of the loaded font if it's a single line, or even divided by itself if it can be squared.



    //float charWidth = 32.0f / Width;



    //float charHeight = 32.0f / Height;



    float charWidth = 256.0f / Width;



    float charHeight = 256.0f / Height;







    //chars texel width



    // this could be pulled in for the width of the loaded font



    float texelWidth = 32.0f / 1024.0f;



    float texelHeight = 32.0f / 96.0f;







    //verts per-triangle (3) * total triangles (2) = 6



    const int verticesPerLetter = 6;







    D3D11_MAPPED_SUBRESOURCE mapResource;



    HRESULT hr = d3d11DevCon->Map( pVertexBuffers,



                                          0,



                                          D3D11_MAP_WRITE_DISCARD,



                                          0,



                                          &mapResource );







    if( FAILED( hr ) ) { DXTRACE_MSG( L"Failed to map resource." ); return false; }







    //point to our vertex buffer's internal data.



    VertexSquare *spritePtr = ( VertexSquare* )mapResource.pData;







    const int indexStart = static_cast<char>( ' ' );



    const int indexEnd = static_cast<char>( '~' );







    int iCurrLetterInc = 0;



    int iLineCount = 0;



    int iLineReset = 0;



    int iCurrCrop = 45;



    



    std::stringstream wss;



    for( int i = 0; i < length; ++i )                                        //FOR LOOP to check each character in message



    {



        //if current char count is over #



            //then increment the line number to X



            //reset the current startX to zero



                //increment the values of startY to incorporate an extra multiple of height



        //set the code going again







        if(iCurrLetterInc >= iCurrCrop)                                    //if i is greater than iCurrCrop, increment the line



        {



            iLineCount++;



            iCurrLetterInc = 0;



        }







        int newX = iLineCount * iCurrCrop;



        



        float thisStartX = startX + ( charWidth * static_cast<float>( i - newX ) );



        float thisEndX = thisStartX + charWidth;







        float thisStartY = startY - ( iLineCount * charHeight );                    //because of multiple lines the thisStartY will be lower everytime we start a new line



        float thisEndY = ( startY + charHeight ) - ( iLineCount * charHeight );        //VERY IMPORTANT... the second brackets mean that they are doubling up the x value in the down direction, otherwise it will turn the polygon away from the camera.







        spritePtr[0].pos = XMFLOAT3( thisEndX,        thisEndY,        1.0f );



        spritePtr[1].pos = XMFLOAT3( thisEndX,        thisStartY,        1.0f );



        spritePtr[2].pos = XMFLOAT3( thisStartX,    thisStartY,        1.0f );



        spritePtr[3].pos = XMFLOAT3( thisStartX,    thisStartY,        1.0f );



        spritePtr[4].pos = XMFLOAT3( thisStartX,    thisEndY,        1.0f );



        spritePtr[5].pos = XMFLOAT3( thisEndX,        thisEndY,        1.0f );







        int texLookup = 0;



        int letter = static_cast<char>( message[i] );







        if( letter < indexStart || letter > indexEnd )



        {



            texLookup = indexStart;                                    //if it's out of bounds use a space



        } else {



            texLookup = ( letter - indexStart ) ;



        }







        float tuStart    = 0.0f;



        float tuEnd        = 0.0f;



        float tuTop        = 0.0f;



        float tuBottom    = 0.0f;







        if( letter > 63 )                                            //if letter is > ?(1024 pixel width 1st line ends) but less than ~ (third row's start)



        {



            if ( letter > 95 )



            {



                tuStart = 0.0f + ( texelWidth * static_cast<float>( texLookup ) );



                tuEnd = tuStart + texelWidth;







                tuTop = 0.0f + ( texelHeight * 2 );



                tuBottom = tuTop + texelHeight;                        //OutputDebugString( "THIRD LINE LOADED!\n" );



            } else {



                tuStart = 0.0f + ( texelWidth * static_cast<float>( texLookup ) );



                tuEnd = tuStart + texelWidth;







                tuTop = 0.0f + ( texelHeight * 1 );



                tuBottom = tuTop + texelHeight;                        //OutputDebugString( "SECOND LINE LOADED!\n" );



            }



        } else {



            tuStart = 0.0f + ( texelWidth * static_cast<float>( texLookup ) );



            tuEnd = tuStart + texelWidth;







            tuTop = 0.0f;



            tuBottom = tuTop + texelHeight;                            //OutputDebugString( "FIRST LINE LOADED!\n" );



        }







        spritePtr[0].texCoord = XMFLOAT2( tuEnd, tuTop );



        spritePtr[1].texCoord = XMFLOAT2( tuEnd, tuBottom );



        spritePtr[2].texCoord = XMFLOAT2( tuStart, tuBottom );



        spritePtr[3].texCoord = XMFLOAT2( tuStart, tuBottom );



        spritePtr[4].texCoord = XMFLOAT2( tuStart, tuTop );



        spritePtr[5].texCoord = XMFLOAT2( tuEnd, tuTop );







        spritePtr += 6;



        iCurrLetterInc++;



    }



    //OutputDebugString( wss.str().c_str()  );



    



    d3d11DevCon->Unmap( pVertexBuffers, 0 );



    d3d11DevCon->Draw( 6 * length, 0 );  // 6 vertices * the length of the font







    return true;



}

Where do I start adding models and other geometric primitives?
 
Is that what the offset is about?
 
Is it basically, rough sudo code example follows:


Buffer* cubeObject;
Buffer* treeModelObject;
Buffer* carModelObject;
(and an index buffer for each)
 
//Then each one gets loaded
UINT stride = sizeof( VertexCube );

UINT offset = 0;


d3d11DevCon->IASetVertexBuffers( 0, 1, &cubeObject, &stride, &offset );
 
UINT stride = sizeof( VertexTree );

UINT offset = ???;
 
d3d11DevCon->IASetVertexBuffers( 0, 1, &treeModelObject, &stride, &offset );
 
UINT stride = sizeof( VertexCar );

UINT offset = ???;
 
d3d11DevCon->IASetVertexBuffers( 0, 1, &carModelObject, &stride, &offset );
 
//and then the draw calls follow

There's nowhere that explains what to do when offsetting to outline what to put where and why!?

 

I don't understand where different models are saved in memory to be presented after their draw calls have been actioned. If I make multiple calls to IASetVertexBuffers then everything goes south.

 


In Topic: Missing the vertex!

05 January 2014 - 01:41 PM

This post duplicated, see below


PARTNERS