Jump to content
  • Advertisement
Sign in to follow this  
majak

Reading from extern file

This topic is 5021 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi I've just started learning directx, drawing triangles.. I want to get my array from another file (.txt or something) is that possible? and how? CUSTOMVERTEX Vertices[] = { { 150.0f, 150.0f, 0.5f, 1.0f, 0xffff0000, }, // x, y, z, rhw, color { 119.0f, 160.0f, 0.5f, 1.0f, 0xff00ff00, }, { 111.0f, 150.0f, 0.5f, 1.0f, 0xff00ffff, }, }; Thanks =)

Share this post


Link to post
Share on other sites
Advertisement
One way is to use the standard ways for reading files, like fread, fgetc etc. The file reading is not part of directx in this case.

Dragoncar

Share this post


Link to post
Share on other sites
no I know, but how can I use IOstream in the middle of the dirext programming?

g_pd3dDevice->CreateVertexBuffer( 5*sizeof(Vertex), 0, D3DFVF_MY_VERTEX,
D3DPOOL_DEFAULT, &g_pPointList_VB, NULL );

pVertices = NULL;
g_pPointList_VB->Lock( 0, sizeof(g_pointList), (void**)&pVertices, 0 );
memcpy( pVertices, g_pointList, sizeof(g_pointList) );
g_pPointList_VB->Unlock();

////////////////////////////
case D3DPT_POINTLIST:
g_pd3dDevice->SetStreamSource( 0, g_pPointList_VB, 0, sizeof(Vertex) );
g_pd3dDevice->SetFVF( D3DFVF_MY_VERTEX );
g_pd3dDevice->DrawPrimitive( D3DPT_POINTLIST, 0, 5 );
break;
///////////////////////////////

Vertex g_pointList[] =
{
{ 0.0f, 0.0f, 0.0f, D3DCOLOR_COLORVALUE( 1.0, 0.0, 0.0, 1.0 ) },
{ 0.5f, 0.0f, 0.0f, D3DCOLOR_COLORVALUE( 0.0, 1.0, 0.0, 1.0 ) },
{-0.5f, 0.0f, 0.0f, D3DCOLOR_COLORVALUE( 0.0, 0.0, 1.0, 1.0 ) },
{ 0.0f,-0.5f, 0.0f, D3DCOLOR_COLORVALUE( 1.0, 1.0, 0.0, 1.0 ) },
{ 0.0f, 0.5f, 0.0f, D3DCOLOR_COLORVALUE( 0.0, 1.0, 1.0, 1.0 ) },
};

this last piece of code (the array) I want to get that from an .txt file.

Share this post


Link to post
Share on other sites
In the middle of your Directx program you can use the standard io. If you what to read

Vertex g_pointList[] = 
{
{ 0.0f, 0.0f, 0.0f, D3DCOLOR_COLORVALUE( 1.0, 0.0, 0.0, 1.0 ) },
{ 0.5f, 0.0f, 0.0f, D3DCOLOR_COLORVALUE( 0.0, 1.0, 0.0, 1.0 ) },
{-0.5f, 0.0f, 0.0f, D3DCOLOR_COLORVALUE( 0.0, 0.0, 1.0, 1.0 ) },
{ 0.0f,-0.5f, 0.0f, D3DCOLOR_COLORVALUE( 1.0, 1.0, 0.0, 1.0 ) },
{ 0.0f, 0.5f, 0.0f, D3DCOLOR_COLORVALUE( 0.0, 1.0, 1.0, 1.0 ) },
};



dynamically during the execution you can't you need to read the the values in from the file and load them into the array.

Dragoncar

Share this post


Link to post
Share on other sites
the .txt file is updatet realtime all the time with new data, and I want to show this picture realtime. Aren't there a way to recieve data externally realtime?

Share this post


Link to post
Share on other sites
So if I create the array Vertex g_pointList[] in my .ccp file, I can get the data
{ 0.0f, 0.0f, 0.0f, D3DCOLOR_COLORVALUE( 1.0, 0.0, 0.0, 1.0 )
{ 0.5f, 0.0f, 0.0f, D3DCOLOR_COLORVALUE( 0.0, 1.0, 0.0, 1.0 )
{-0.5f, 0.0f, 0.0f, D3DCOLOR_COLORVALUE( 0.0, 0.0, 1.0, 1.0 )
{ 0.0f,-0.5f, 0.0f, D3DCOLOR_COLORVALUE( 1.0, 1.0, 0.0, 1.0 )
{ 0.0f, 0.5f, 0.0f, D3DCOLOR_COLORVALUE( 0.0, 1.0, 1.0, 1.0 )
from the .txt file?

how do i put these data into the array?

Share this post


Link to post
Share on other sites
So in that case just re read the file into the array when you want the updated data, but why are you updating a file and not just storing the data in memory?

Share this post


Link to post
Share on other sites
To get the data from the text file you read the data from the text file (which is in a know format) and then you break each line apart at the know points and put each part into the structure that you use.

example in english: (assuming one struct stored per line, and each piece of data seperated by a :)

Open File.
While not end of file
Read line
While not the end of the line
Read the characters until the : and place it in its part of the data structure
End While
End While

Hope this helps.

Apoligises if I haven't understood your question.

Dragoncar

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!