Jump to content
  • Advertisement
Sign in to follow this  
langkow

load matrix from a txt file

This topic is 3500 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

Hello! i want to draw objects using openGL (c++) from a matrix, i do this with no problem if i declare the matrix, and call like this:
#define SIZE_L   10
#define SIZE_C   15
char map[SIZE_L][SIZE_C+1] = {
"##$############",
"####$##########",
"######%########",
};

call the matrix map:
void draw()
{
	glPushMatrix();
		glTranslatef(-SIZE_L , 0.01, -SIZE_C);
		for(int i=0; i<SIZE_L; i++)
			for(int j=0; j<SIZE_C+1; j++)
			{
                    if(map[j]=='#')
                    drawObject1();	
                  (...)
	glPopMatrix();
}		
..now i want to draw objects from a matrix but load the matrix from a txt file (for example map.txt). how can i call this file and what do i need (if possible give me a example)? Thank you guys !!

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by langkow
..now i want to draw objects from a matrix but load the matrix from a txt file (for example map.txt). how can i call this file and what do i need (if possible give me a example)?

Thank you guys !!


I just use ifstream (input file stream) to read from a file. It's easy. Here is an example of using ifstream to read a text file.

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!