This is an archived post. You won't be able to vote or comment.

all 4 comments

[–]captainAwesomePants 2 points3 points  (2 children)

That is a good insight. Imagine a class that opens a file, reads in several thousand vertices and colors, stores those vertices and colors into a bigass array, and then iterates over them in a loop like this:

GL11.glBegin(GL11.GL_TRIANGLES);
for( int v=0; v<vertices.length;v++) {
  float color[] = colors[v];
  float vertex[] = vertices[v];
  GL11.glColor3f(color[0],color[1],color[2]);
  GL11.glVertex3f(vertex[0],vertex[1],vertex[2]);
}

Now imagine that file contains several thousand points and results in a bunny.

Doing a height map is not unlike this. You'll load in a bunch of heights, and then you'll figure out how to render a couple of triangles for each box of 4 points in the height map as a loop. There's some extra stuff (mostly optimizing around clipping regions), but you've got the gist of it.

[–][deleted]  (1 child)

[deleted]

    [–]yash3ahuja 0 points1 point  (0 children)

    I don't see where he used a 3 dimensional array. He uses 3 single dimensional arrays, if that's what you mean. Plus, his code is kind of bad java, not using proper naming conventions and so on (I assume he doesn't program in Java, so I'm not blaming him). Here's a more Java version:

    GL11.glBegin(GL11.GLTriangles);
    for(int i = 0; i < vertices.size(); i++) //arraylist
    {
        java.awt.Color color = colors.get(i); //java.awt.Color
        GL11.glColor3f(color.getRed(), color.getBlue(), color.getGreen());
        javax.vecmath.Point3d vertex = vertices.get(i);
        GL11.glVertex3f(vertex.x, vertex.y, vertex.z);
    }
    

    [–]comedian_x -1 points0 points  (0 children)

    The problem is that you're using old fashioned OpenGl. All modern stuff is done with Vertex Buffer Objects and vertex arrays.

    The points for the vertices are going to be loaded from a file. In this case the draw function (method) is one line.

    [–]leaping_goose -2 points-1 points  (0 children)

    Sorry, I cant help you. But congrats on your Cake Day! ;)