0
votes

I have a bitmap map that created from a dted file. I want to use that bitmap and create a 3d terrain render. I am trying to do it with vertex vectors but I couldn't reach my goal at all. Here is my paintGL code:

void render::paintGL(){
glLoadIdentity();
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glTranslatef(0,0,-100);
for(int z=0;z<dted.width()-1;z++){
    glBegin(GL_TRIANGLE_STRIP);
    for(int x = 0; x<dted.height()-1; x++){
        glColor3f(matrix[x][z], matrix[x][z], matrix[x][z]);
        glVertex3f(x, matrix[x][z], -z);
        //vertex0 ends here

        glColor3f(matrix[x+1][z], matrix[x+1][z], matrix[x+1][z]);
        glVertex3f(x+1, matrix[x+1][z], -z);
        //vertex1 ends here

        glColor3f(matrix[x][z+1], matrix[x][z+1], matrix[x][z+1]);
        glVertex3f(x, matrix[x][z+1], -z-1);
        //vertex2 ends here

        glColor3f(matrix[x+1][z+1], matrix[x+1][z+1], matrix[x+1][z+1]);
        glVertex3f(x+1, matrix[x+1][z+1], -z-1);
        //vertex3 ends here


    }
    glEnd();
}}

I had to write the code instead of copy-paste because of internet issues. So there may be things that I forgot but I did my best. Let me explain the variables and other things above:

dted is the dted image I created and I set boundaries from that images width and height values. matrix is a 2d matrix that holds the elevation values I get from the pre-created dted image pixels.

After all the code above I couldn't manage to render the terrain. I don't know if it renders the terrain but it just doesn't show me or it's not rendering at all. If you explain where is my mistake and suggest a solution for it, it would be great.

Sorry for the grammar mistakes if I did any, and I hope I did explain my problem well. If the code I provided is not sufficient, feel free to mention that and I can write the other parts down too.

Have a nice day.

Edit: Ok I got a fresh news over here. I have managed to draw a plain after getting over some control with mouse issues. However, when I try to get amplitude, it shows nothing. That because of the too much amplitude I guess, but when I divide it by a constant like 15 the same plain shows up again. Is this because of I used GL_TRIANGLE_STRIP ?

2
First, make sure you are capable of drawing: start with one triangle at a hardcoded location. Second: matrix values are between 0 and 1? They should if you input them to glColor3f. Can you please check that? - Sga
I checked it and saw that it wasn't. However, I divided it to 255 (pixels values were from 0 to 255) and it is still showing nothing. By the way I already draw a cube and it showed well. - user3483948
Now you must check your camera: is it too far? Is the plane perpendicular to it (so that becomes just a thin line)? Try exaggerating Y values with a multiplier - Sga
I have set up a mouse event for that, that zoom outs when right click and zooms in when left click, that changes the translatef function's z value. I did multiplied the amplitude of Y by 15 (matrix[x][z]*15) and unsuprisingly I couldn't see it. Do you think the problem is the camera? - user3483948
Yes, it could be pointed elsewhere - Sga

2 Answers

0
votes

Your rendering code seems strange: You build your tri strip with degenerated triangles and might access data which isn't there. I guessed the rest of your approach and tried to fix your method. Try this:

void render::paintGL(){
  glLoadIdentity();
  glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
  glMatrixMode(GL_MODELVIEW);
  glTranslatef(0,0,-100);
  for(int z = 0; z < dted.width() - 2; z++) {
    glBegin(GL_TRIANGLE_STRIP);
    for(int x = 0; x < dted.height() - 1; x++){
        glColor3f(matrix[x][z], matrix[x][z], matrix[x][z]);
        glVertex3f(x, matrix[x][z], -z);
        //vertex0 ends here

        glColor3f(matrix[x][z + 1], matrix[x][z + 1], matrix[x][z + 1]);
        glVertex3f(x, matrix[x][z + 1], -z - 1);
        //vertex1 ends here

    }
    glEnd();
}}

Other than this, triangle strips are fine. If you still don't see anything, follow the suggestion by Sga and use GL_POINTS. Then fix you camera/other rendering code until you see them.

0
votes

For the other guys who are looking for solution at this: Make sure that your glFrustum's zNear parameter is far enough to see things. Mine were to close and when I increased it, the problem was solved.