# 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 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 on other sites
why are you using immediate mode? use vertex arrays
-Dan

##### 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.

## Create an account

Register a new account

• ### Forum Statistics

• Total Topics
627704
• Total Posts
2978716
• ### Similar Content

• A friend of mine and I are making a 2D game engine as a learning experience and to hopefully build upon the experience in the long run.

-What I'm using:
C++;. Since im learning this language while in college and its one of the popular language to make games with why not.     Visual Studios; Im using a windows so yea.     SDL or GLFW; was thinking about SDL since i do some research on it where it is catching my interest but i hear SDL is a huge package compared to GLFW, so i may do GLFW to start with as learning since i may get overwhelmed with SDL.
-Questions
Knowing what we want in the engine what should our main focus be in terms of learning. File managements, with headers, functions ect. How can i properly manage files with out confusing myself and my friend when sharing code. Alternative to Visual studios: My friend has a mac and cant properly use Vis studios, is there another alternative to it?

• Both functions are available since 3.0, and I'm currently using glMapBuffer(), which works fine.
But, I was wondering if anyone has experienced advantage in using glMapBufferRange(), which allows to specify the range of the mapped buffer. Could this be only a safety measure or does it improve performance?
Note: I'm not asking about glBufferSubData()/glBufferData. Those two are irrelevant in this case.
• By xhcao
Before using void glBindImageTexture(    GLuint unit, GLuint texture, GLint level, GLboolean layered, GLint layer, GLenum access, GLenum format), does need to make sure that texture is completeness.
• By cebugdev
hi guys,
are there any books, link online or any other resources that discusses on how to build special effects such as magic, lightning, etc. in OpenGL? i mean, yeah most of them are using particles but im looking for resources specifically on how to manipulate the particles to look like an effect that can be use for games,. i did fire particle before, and I want to learn how to do the other 'magic' as well.
Like are there one book or link(cant find in google) that atleast featured how to make different particle effects in OpenGL (or DirectX)? If there is no one stop shop for it, maybe ill just look for some tips on how to make a particle engine that is flexible enough to enable me to design different effects/magic
let me know if you guys have recommendations.
• By dud3
How do we rotate the camera around x axis 360 degrees, without having the strange effect as in my video below?
Mine behaves exactly the same way spherical coordinates would, I'm using euler angles.
Tried googling, but couldn't find a proper answer, guessing I don't know what exactly to google for, googled 'rotate 360 around x axis', got no proper answers.

References:
Code: https://pastebin.com/Hcshj3FQ
The video shows the difference between blender and my rotation:

• 21
• 14
• 12
• 10
• 12