OpenGL: how to use integers in glVertex3i

glBegin (GL_TRIANGLES); glVertex3i (100,100,0); glVertex3i (100.80.0); glVertex3i (80.80.0); glEnd ();

These calls do not work. Only glVertex3f works, I just don’t know why. But in glVertex3f I can only put a float less than 1. Because if I put some float greater than 1, the vertex will be off-screen.

So my question is, why don't the above calls work? I think the primitives came out of the mud, but I don’t know why.

+3
source share
2 answers

if you haven’t done anything to move the projection or view setting (e.g. gluPerspective/glTranslate etc), then by default your viewport will span from x (-1, + 1) to y (-1, + 1), which means your screen as follows:

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

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

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

glScalef(0.01, 0.01, 0.01);

This means that "make everything 1/100smaller once, so your triangle will be placed in the viewport (-1.1)."

You should read information about transformations / projections, etc. You can search on Google or use one of the following links:

+6

, , , openGL "".

( gluLookAt - ) . .

, , , glVertex3f 0 1, . :

glVertex3f (100,0, 100,0, 0,0);

, , .

+5

Source: https://habr.com/ru/post/1787244/


All Articles