2

I am using GL_TRIANGLE_STRIP to draw my terrain to the screen, however when I compile and run the program I get nothing. When I change GL_TRIANGLE_STRIP to GL_LINES it shows up and works. What can I do to get it working with GL_TRIANGLE_STRIP?

void drawScene() {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0.0f, 0.0f, -10.0f);
glRotatef(30.0f, 1.0f, 0.0f, 0.0f);
glRotatef(-_angle, 0.0f, 1.0f, 0.0f);

GLfloat ambientColor[] = {.5, .5, .5, 1.0f};
glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambientColor);
float scale = 5.0f / max(63.0,63.0);
glScalef(scale, scale*10, scale);
glTranslatef(-(float)(63.0) / 2, 0.0f, -(float)(63.0) / 2);
     /*GLfloat lightColor0[] = {0.6f, 0.6f, 0.6f, 1.0f};
     GLfloat lightPos0[] = {-0.5f, 4, 32, 0.0f};
     glLightfv(GL_LIGHT0, GL_DIFFUSE, lightColor0);
     glLightfv(GL_LIGHT0, GL_POSITION, lightPos0);*/



glColor3f(0.3f, 0.9f, 0.0f);
for(int x = 0;x<64;x++){
    glBegin(GL_LINES);
    for(int z = 0;z<63;z++){
        glNormal3f(0,1,0);
        Vertex(x,map[x][z],z);
        Vertex(x,map[x][z+1],z+1);
    }
    glEnd();
}
for(int z = 0;z<64;z++){
    glBegin(GL_LINES);
    for(int x = 0;x<63;x++){
        Vertex(x,map[x][z],z);
        Vertex(x+1,map[x+1][z],z);
    }
    glEnd();
}

I'm not sure this is important but for my terrain I have code that makes it a 3d Gaussian distribution.

user1133383
  • 103
  • 1
  • 7
  • 2
    Don't bother using fixed-function, it's so old even phones don't use it. – Puppy Jan 06 '12 at 01:30
  • @DeadMG It's fine if all you want to do is get some stuff on screen. The great thing about fixed functionality deprecation is that it's made OpenGL lean and agile (as it should be to compete with another API), however it did do a lot to increase the learning curve. Unless you buy the Super Bible, of course :). – Liam M Jan 06 '12 at 01:43
  • @user1021915: Immediate mode has nothing to do with fixed functionality. It's been deprecated for even longer than shaders exist. Vertex Arrays have been introduced with OpenGL-1.1 (1996), and ever since then immediate mode was just legacy – the only valid reason to use IM was, if you wanted to use display lists, i.e. server side geometry. Since the introduction of vertex buffer objects (ca. 2003) display lists got deprecated. Note that the first fully programmable hardware became available about that time and was very limited, compared to today's GPUs. – datenwolf Jan 06 '12 at 01:58
  • @datenwolf All functionality corresponding to the fixed-pipeline was deprecated but not removed in OpenGL 3.0, which was 2008. GLSL was introduced in 2004. Just because you or others consider something deprecated, doesn't make it deprecated until the ARB says it is. Bad form? perhaps. Furthermore, fixed functionality has everything to do with immediate mode because it's the method through which OpenGL supports it. In this way, by deprecating fixed functionality, the ARB also deprecated immediate mode, which you would no doubt agree was long overdue. – Liam M Jan 06 '12 at 04:29
  • @user1021915: Shaders work with immediate mode just fine. There's absolutely no relation between immediate mode and fixed function pipeline. Also the ARB tried to kill off immediate mode for a very long time. Just look up the discussions for OpenGL-2, where they already tried to remove display lists and immediate mode, but then did not so, because it would have rendered broken too much legacy software. To this date immediate mode and display lists remained in – datenwolf Jan 06 '12 at 10:27
  • @user1021915: Also I suggest you take some dictionary and look up the difference between deprecated and depreciated. Yes, the ARB deprecated the functionality very early, but it was not depreciated until OpenGL-3 – datenwolf Jan 06 '12 at 10:32

2 Answers2

2

An explanation of TRIANGLE_STRIP is found by a Google search. There is an illustration on Wikipedia.

My advice is to print out the first five vertices of your vertex data, and draw it by hand on paper. The fact that GL_LINES work suggest that the right vertices are there, you might just drawing them in the wrong order.

Another piece of advice is to disable backface culling.

glDisable(GL_CULL_FACE);
Christian Neverdal
  • 5,655
  • 6
  • 38
  • 93
  • Culling is always the first thing I turn off in these scenarios. Definitely sounds like you're winding your verts the wrong way. – Matt Lacey Jan 06 '12 at 01:31
1

As a random stab in the dark, do you have culling turned on? It may be that it's not drawing any triangles because the back of the triangles are invisible. Try adding:

glDisable(GL_CULL_FACE);

To you init code, or simply removing:

glEnable(GL_CULL_FACE);

From your init code.

Liam M
  • 5,306
  • 4
  • 39
  • 55