Triangle doesn't display

I'm trying to learn OpenGL/GLUT, and I'm reading "beginning opengl game programming", and I took some code from it, merged it with GLUT code I found online, and surprise surprise, it didn't work. I know about nothing about OpenGL, so I don't know where I went wrong.
Here's the display function:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
    glLoadIdentity();
    
    gluLookAt(0.0,1.0,0.0,
              0.0,0.0,0.0,
              0.0,1.0,0.0);
    
    glBegin(GL_TRIANGLES);
        glColor4f(1.0f, 0.0f, 0.0f, 1.0f);
        glVertex3f(2.0f, 2.5f, -1.0f);
        glColor4f(0.0f, 1.0f, 0.0f, 1.0f);
        glVertex3f(-3.5f, -2.5f, -1.0f);
        glColor4f(0.0f, 0.0f, 1.0f, 1.0f);
        glVertex3f(2.0f, -4.0f, -1.0);
    glEnd();
    glFlush();

and this is the main function:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
int main(int argc, char** argv) {
    glutInit(&argc, argv);
    
    glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE | GLUT_DEPTH);
    
    glutInitWindowSize(500, 500);
    glutInitWindowPosition(0, 0);
    glutCreateWindow("2 Dimensional Triangle");
    
    glutDisplayFunc(otherDisplay);
    
    
    myinit();
    glutMainLoop();
        
    return 0;
}
> I know about nothing about OpenGL, so I don't know where I went wrong.
I don't like your learning method.

1
2
3
4
5
gluLookAt(
   eye,
   center,
   up
);
The viewer is at the eye point, looking at the center. The `up' vector defines the head rotation (where is your nose).
man wrote:
the direction described by the UP vector projected onto the viewing plane is mapped to the positive y axis so that it points upward in the viewport. The UP vector must not be parallel to the line of sight from the eye point to the reference point.
So you are using the function wrong.
Suppose that you put instead
1
2
3
    gluLookAt(0.0,1.0,0.0,
              0.0,0.0,0.0,
              1.0,0.0,0.0);
that means look at the xz plane, where x is pointing upward.
Now check the coordinates of your triangle, all the `z' are the same, so you are looking at its side
Last edited on
I'm trying to learn OpenGL/GLUT, and I'm reading "beginning opengl game programming",


If that source code is from that book... then that book is old and I would not recommend it.

GLUT is very old (it has since been more or less replaced by FreeGLUT).

glMatrixMode / glLoadIdentity / glVertex / etc are all deprecated functions in modern versions of OpenGL.

If you want something more up to date, I recommend this tutorial:
http://www.arcsynthesis.org/gltut/
It does mention that all of that is deprecated, and ne555, what would my triangle be if I did that?
Last edited on
^ Well, you could be simply facing the wrong way.
Ne555 probably just made sure you're facing the right way.

But as Disch suggested you, you should avoid using deprecated functions and use the suggested ones.
This will result in faster and safer programs.
> what would my triangle be if I did that?
¿do what?
You are looking at its side. From your point of view, the three points are aligned, so there is no triangle.
I guess what would my vertexes be would've been a better way to put it.
Topic archived. No new replies allowed.