Creating a triangle strip with sfml error.

When I was crating a trianglestrip, I encountered an error; Not an error, it still works, it just doesn't "Work".
I am trying to create a terrain and it just comes out as pure "crap";
I think that the basic logic of me program isn't working, its just that i cant figure out what the heck isnt working.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
  Vector2f landPos[931];

int main()
{
    double xycounter = 0;
    for(int i = 0; i != 31; i++){
        for(int j = 0; j!= 30; j++){
            landPos[int(xycounter)].y = i * 10;
            landPos[int(xycounter)].x = j * 10;
            xycounter++;
        }
    }

    RenderWindow Mainwindow(VideoMode(400, 400), "Map");

    VertexArray land(TrianglesFan, 1202);
    cout << "Worked to create VA" << endl;
    for(int i = 0; i != 900; i = i + 3){
        land[i].position = landPos[i];
        land[i + 1].position = landPos[i + 20];
        land[i + 2].position = landPos[i + 21];
        land[i].color.a = 10;
        land[i + 1].color.a = 10;
        land[i + 2].color.a = 10;
        cout << "WORKED LOOP: " << i/3 << endl;
    }
cout << "Pos loop worked";
    while(Mainwindow.isOpen()){
        Event e;
        while(Mainwindow.pollEvent(e)){
            if(e.type == Event::Closed){
                Mainwindow.close();
            }
        }
        Mainwindow.clear(Color(0, 0, 0));
        Mainwindow.draw(land);
        Mainwindow.display();

    }
}

Thanks!
*And also, im using Codeblocks(MINGW) and sfml 2.1
Last edited on
I think that the basic logic of me program isn't working, its just that i cant figure out what the heck isnt working.


Maybe if you described the logic and the result you're trying to produce, it would be easier to tell why that isn't happening.
I am trying to produce a terrain, like this one:
http://socoder.net/uploads/186/high.PNG
So...
Here is my logic:
 
Vector2f landPos[931]

This is the array that creates the x, y positions and stores them. //Note how it is single dimension
1
2
3
4
5
6
7
8
double xycounter = 0;
    for(int i = 0; i != 31; i++){
        for(int j = 0; j!= 30; j++){
            landPos[int(xycounter)].y = i * 10;
            landPos[int(xycounter)].x = j * 10;
            xycounter++;
        }
    }

this sets the values to the landPos //I and J act as y and x, and i * that by 10 to get it spread out, i use xycounter to act as a number that will eventually reach 900, the nescesarry amount for the array
1
2
3
4
5
6
7
8
9
for(int i = 0; i != 900; i = i + 3){
        land[i].position = landPos[i];
        land[i + 1].position = landPos[i + 20];
        land[i + 2].position = landPos[i + 21];
        land[i].color.a = 10;
        land[i + 1].color.a = 10;
        land[i + 2].color.a = 10;
        cout << "WORKED LOOP: " << i/3 << endl;
    }

Here i set the x and y for the vertex array, and also the alpha
Thanks for helping me.
I am trying to produce a terrain, like this one:

It is not possible to get that result using a single triangle fan, and very likely you'll need to introduce a z-coordinate. If I were you, I'd dump your current logic and do some research prior to writing another line of code.
Ok. Thank you!
Topic archived. No new replies allowed.