3
votes

glBegin(GL_TRIANGLES); glVertex3i(100,100,0); glVertex3i(100,80,0); glVertex3i(80,80,0); glEnd();

These calls does not work. Only glVertex3f works, just do not know why. But in glVertex3f, I can only put float less than 1. Since if I put some float large than 1, the vertex will be out of the screen.

So my question is that why above calls does not work? I think the primitves are out of the boudary, but do not know why.

2
Wont it depend on your current transformation matrix? Scale, for example? And plus, things can be out of the screen. Zoom out, change the camera to some other coordinate, or anything.UltraInstinct

2 Answers

6
votes

if you didn't do anything to move set up a projection or view (e.g. gluPerspective/glTranslate etc), then by default, your viewport will span from x(-1,+1) to y(-1,+1), which means that your screen looks like:

                  y (+1)
        +------------------------+
        |                        |
        |                        |
x(-1)   |                        |   x(+1)
        |                        |
        |                        |
        |                        |
        +------------------------+
                 y (-1)

And the center of the screen is (0,0).

If your model has coordinates outside the (-1,+1) range, then you will need to scale it down to this range. So your triangle should appear if you call this before glBegin:

glScalef(0.01, 0.01, 0.01);

This means "make everything 1/100 times smaller, so your triangle will fit within the (-1,1) viewport".

You should read up on transformations/projections etc. You can search on google, or try one of these links:

5
votes

The fact that you don't see them on your screen doesn't mean they don't actually exist in the openGL "universe".

Try to move the camera away (with the gluLookAt method - or with translates and rotates) and place the points again. You should see them without any trouble.

Moreover, I would like to correct you on the assumption that glVertex3f only takes numbers between 0 to 1, which it doesn't. Your code could be:

glVertex3f(100.0, 100.0, 0.0);

And it would work as well, if the position of the camera allows you to see the elements you're drawing.