Thread: How can i change or make my own terrain

  1. #1
    Registered User
    Join Date
    Aug 2003
    Posts
    2

    How can i change or make my own terrain

    I dont know how i can change or make my own terrain in this game (it's the game of OpenGL Game Programming)

    OS: Win XP
    Compiler: Microsoft Visual C++ 6.0
    Libraries: DirectX & OpenGL

    the source code:
    http://home.ripway.com/2004-1/59981/...timetokill.zip
    (note: i only have 5MB bandwith a day)

    Any help is welcome

  2. #2
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    Here is a sample terrain map that I used in my engine.

    Load this as a raw file - but you will have to smooth it in a paint program or something. The JPG format causes a lot of loss and the BMP was too large to attach.

    Load as a RAW file with no header. The size is 480x480 - to get along with this board's limit of 640x480.


    Code:
    bool Terrain::readRawFile(std::string fileName)
    {
    
      // A height for each vertex
      std::vector<BYTE> in( _numVertices );
    
      std::ifstream inFile(fileName.c_str(), std::ios_base::binary);
    
      if( inFile == 0 )
        return false;
    
      inFile.read((char*)&in[0], 
                      in.size());
    
      inFile.close();
    
      // copy BYTE vector to int vector
      _heightmap.resize( _numVertices );
      for(int i = 0; i < in.size(); i++)
      _heightmap[i] = in[i];
    
    return true;
    }
    That will load the raw file. NumVertices is the number of vertices in your terrain (hence if you use a 256x256 heightmap it will be 256*256)

    The first jpg is height data - convert it to raw format and save.
    The second jpg is the color or texture data. Simply compute the necessary u and v coords per vertex and set this as the texture.

    The u and v increments will be 1/(sizex) and 1/(sizey).

    Several terrain generation programs:

    http://www.ridgecrest.ca.us/~jslayton/terrain.html


    or simply use a paint program and convert image to greyscale. White is highest, black is lowest - paint your terrain...smooth a couple of times and wallah...terrain.
    Last edited by VirtualAce; 05-02-2004 at 04:03 PM.

  3. #3
    Registered User
    Join Date
    Aug 2003
    Posts
    2
    Thanks

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. how to make a windows application
    By crvenkapa in forum C++ Programming
    Replies: 3
    Last Post: 03-26-2007, 09:59 AM
  2. Win32 Common Controls in C++, how do i make and use them?
    By C+noob in forum Windows Programming
    Replies: 6
    Last Post: 01-09-2006, 11:53 AM
  3. Need help with C program
    By ChrisH in forum C Programming
    Replies: 38
    Last Post: 11-13-2004, 01:11 AM
  4. help with calculating change from a dollar
    By z.tron in forum C++ Programming
    Replies: 3
    Last Post: 09-13-2002, 03:58 PM
  5. Replies: 2
    Last Post: 09-04-2001, 02:12 PM