Sign in to follow this  
OpenGL_Guru

OpenGL GL_TRIANGLE_STRIP --problems rendering 3D terrain

Recommended Posts

maybe i am just openGL'd out for the day and i know i am close just not sure what i am doing wrong. below is how i was doing it before and after that how i am trying to do it now. i am using this method to draw 3D terrain. this first way of drawing the strip was to take already defined arrays. for my program it is terrain[1441][721][3]. basically i took the approach of searching through the data file , set up a few counters then assigned my 3d array that way. of course i knew this isnt the best way to do it but i will continue. after loading all the x, y, z(depth) into the array, my loop to draw it goes as such:
 for(int j = 0; j < numy - 1; j++)
   {
    glBegin(GL_TRIANGLE_STRIP);
	for(int i = 0; i < numx; i++)
      {
	  glVertex3dv(terrain_gS[i][j]);
	   glVertex3dv(terrain_gS[i][j+1]);
      }

	glEnd();
   }  

my updated program now has my array defined after checking for and loading the data. since i am using a class obviously doing it the way before will give me an error. so i crunch through the data and come up with the same numbers but assign the x and y counts to local private variable to the class, then declare my terrain array as such: terrain = new float[x_size * y_size * 3]; this equals to 3,116,883 points. anyway i am trying to change the 2 for loops above to do that same thing but i my program keeps crashing or i play with it and it runs but my strips dont connect(a bunch of points in space) or something else weird happens. what would need to be corrected from below? on a final note, i have loaded my data in correctly as a function that i do not show you is written for that purpose so i not its not any numbers in the wrong place , its in this drawing part itself as below.
 int count = 0;

 for(int j = 0; j < y_size-1; j++)
   {
    glBegin(GL_TRIANGLE_STRIP);
	for(int i = 0; i < x_size; i++)
      {
	glVertex3f(terrain[count], terrain[count+1], terrain[count+2]);
        count += 3;
	glVertex3f(terrain[count], terrain[count+1], terrain[count+2]);
	   count += 3;
	   //cout << count << endl; 
      }

	glEnd();

 } 

im sorry for not formatting this to make it more readable -- how do i do that?? then i will go back and change it.. thanks so much in advance! [Edited by - OpenGL_Guru on December 3, 2004 8:28:19 AM]

Share this post


Link to post
Share on other sites
[ source ] and [ /source ] format the code

Your loop indices are not correct - you're adding 1 each loop but consuming 6 vertices (e.g. i=+6 or maybe it should be j+=6 hard to visualize).

Are the arrays terrain points or are they pre-formatted triangle strips or is the array is full of terrain points (e.g. height-map)? You have to go in a zig-zag pattern to make the strip work with a height-map.

Share this post


Link to post
Share on other sites
this is how i load the data: code below, its all a 1-D array now(terrain[0 ... total_size] instead of a 3d array terrain[x_size][y_size][3]. they are just stored terrain points. here is how i load the new 1D array:

  
for(lati = start_lat; lati <= end_lat; lati += cell_size)
{
for(float loni = start_lon; loni <= end_lon; loni += cell_size)
{
lat = lati; lon = loni;
terrain[count] = lon; terrain[count+1] = lat; terrain [count+2] = 0.0;
count += 3;
}
}





start_lat = -90.0, end_lat = 90.0
start_lon = 0.0, end_lat = 360.0
cell_size = 0.25 which equals the resolution of the terrain.

as you might can guess from these numbers this is the world in lat, lon coordinates with a height of zero but i have a file with some height values. i was using 0 to test this one out.

before i had the same looop as above except i had a local i, j to assign to my terrain 3D array with [i][j][height] values coming from whatever lat, lon, and height happened to be. the difference now is is that i have this big 1D array but somehow i am messing it all up. because i add 6 to count through each loop i have tried dividing y_size - 1 by 6 but that didnt work either. thanks for your time and i hope i answered you questions.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this