Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3345076
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T01:08:37+00:00 2026-05-18T01:08:37+00:00

I’m working on a planet generation tool in C++ and currently I’m trying to

  • 0

I’m working on a planet generation tool in C++ and currently I’m trying to generate textures and heightmaps.

I’m using a 3d perlian noise function for this, so every time I generate a texture or heightmap I will calculate the value of the noise function for every vertex on the surface of the sphere.

These co ordinates do not change. Originally I was calculating these by mapping a cube to a sphere using this method.

I then thought well if I know these values are going to be the same each time, why not calculate them once and output them to a headerfile where they can be defined as static arrays.

I want to create textures 512×512 this means 260,000+ co ordinates are generated per face 🙁

The resulting co ordinates were stored in an array:

float textureMapSaved[6][512][512][3] = {etc};

As the cube has 6 faces, 512×512 pixels per face and 3 co ordinates (x,y & z).

This would hopefully then allow me to just loop through the array getting the co ordinate for the value in the perlian noise function that I am interested in.

Thus far I have only managed to transform my computer into a blubbering mess.

My question is:

Is there a viable way of doing this?

Without creating the output file the program takes about 15 minutes to compute the sphere. I couldn’t actually compile with the header, it crashed my computer.

I then tried 256×256 and this worked a little better but my computer was still chugging; I’m guessing this is because it cannot allocate memory for the 4D array efficiently.


Thanks for the quick replies!

At the moment I am doing the following:

std::vector<std::vector<std::vector<std::vector<float>>>> textureFaces = GenerateSphereCoordinates(TEXTURE_MAP);

std::ofstream myfile;
myfile.open ("spheremapping.h");
myfile << "#ifndef _SPHEREMAP \n#define _SPHEREMAP \n\nfloat textureMapSaved[6][" << textureRes << "][" << textureRes << "][3] = {";
for(int i = 0; i < 6; i++)
{
    myfile << "{";
    for(int j = 0; j < textureRes; j++)
    {
        myfile << "{";
        for(int k = 0; k < textureRes; k++)
        {
            if(k != textureRes - 1)
            {
                myfile << "{ " << textureFaces[i][j][k][0] << ", " << textureFaces[i][j][k][1] << ", " << textureFaces[i][j][k][2] << "}, " ;               
            }
            else
            {
                myfile << "{ " << textureFaces[i][j][k][0] << ", " << textureFaces[i][j][k][1] << ", " << textureFaces[i][j][k][2] << "}" ; 
            }
        }
        if(j != textureRes - 1)
        {
            myfile << "}, \n";
        }
        else
        {
            myfile << "} \n";
        }
    }
    if(i != 5)
    {
        myfile << "}, \n\n";
    }
    else
    {
        myfile << "} \n\n";
    }
}
myfile << "};\n\n#endif";
myfile.close();

How do I save it as a binary file and read it directly into memory?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T01:08:37+00:00Added an answer on May 18, 2026 at 1:08 am

    The method you describe is the best combination of efficiency and simplicity. If your compiler can’t handle the entire array definition all at once, break the problem down into pieces. For example:

    typedef float CubeFace[512][512][3];
    CubeFace face1 = {etc};
    ...
    CubeFace * textureMapSaved[6] = {&face1, &face2, &face3, &face4, &face5, &face6};
    

    As an alternative, stop trying to make your definition a compilable text file and make it a binary file. You can read it into memory in one operation, or make it a memory mapped file and let the OS swap it as necessary.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I am trying to loop through a bunch of documents I have to put
I'm making a simple page using Google Maps API 3. My first. One marker
We're building an app, our first using Rails 3, and we're having to build
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have some data like this: 1 2 3 4 5 9 2 6
I have a bunch of posts stored in text files formatted in yaml/textile (from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.