Trouble rendering a basic map from Multidimensional array [Solved]

This topic is 3784 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

Basically, I have a multi-dimensional array which loads data from a file. The file may look something like: 4 4 1 2 2 1 2 3 3 2 2 3 3 2 1 2 2 1 The first two are the width & length then the rest are the height, the higher the number the higher it goes. I've got all the data to the array fine but I'm having trouble turning it into a rendered map. I can different layers but I can't get the layers to slope from one to another. Here's what I have so far:
void Terrain::Draw(void){
int Square = 0, DeltaSquare = 0, Translate;
for(int i = 0; i < Width; i++){
for(int j = 0; j < Length; j++){
DeltaSquare = Square;
Square = Heights[j];

glVertex3f(j, Square-1, i);
glVertex3f(j, Square-1, -i);
glVertex3f(-j, Square-1, -i);
glVertex3f(-j, Square-1, i);
glEnd();
}
}
}


[Edited by - MrPickle on May 11, 2008 4:48:14 AM]

Share on other sites
Are you trying to render terrain? If so that code will basically just render quads and look like a staircase...

You need to make sure all 4 vertices per quad grab the heights correctly.

void Terrain::Draw(void){	int vertex0 = 0, vertex1 = 0, vertex2 = 0, vertex3 = 0, DeltaSquare = 0, Translate;	for(int i = 0; i < Width-1; i++){		for(int j = 0; j < Length-1; j++){			vertex0 = Heights[j];                        vertex1 = Heights[j+1];                        vertex2 = Heights[i+1][j+1];                        vertex3 = Heights[i+1][j];						glBegin(GL_QUADS);			glVertex3f(j, vertex0, i);			glVertex3f(j, vertex1, i+1);			glVertex3f(j+1, vertex2, i+1);			glVertex3f(j+1, vertex3, i);			glEnd();		}	}}

Or something like that. It's been awhile since I have done immediate mode terrain rendering... :)

Share on other sites
Yey, thank you!

	glBegin(GL_QUADS);	glVertex3f(j, vertex0, i);	glVertex3f(j, vertex1, i+1);	glVertex3f(j+1, vertex2, i+1);	glVertex3f(j+1, vertex3, i);	glEnd();

to this though:
	glVertex3f(j, vertex0, i);	glVertex3f(j+1, vertex1, i);	glVertex3f(j+1, vertex2, i+1);	glVertex3f(j, vertex3, i+1);otherwise the squares where at funny angles.

1. 1
2. 2
Rutin
23
3. 3
4. 4
frob
16
5. 5

• 9
• 33
• 13
• 12
• 10
• Forum Statistics

• Total Topics
632578
• Total Posts
3007172

×