Why the bitmap can still be drawn when the width and height of glViewPort(0,0,width,height) are equal to 0?

  • When the width and height of glViewPort(0,0,width,height) is equal to 0, the bitmap can still be drawn

  • When the width and height of glViewPort(0,0,width,height) is equal to (50,50), the bitmap beyond the viewport will still be drawn,.
    ps: my windows width and height is (300,100)

  • my code is as follows:

void makeRasterFont(void)
{
    GLuint i, j;
    glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

    fontOffset = glGenLists(128);
    for (i = 0, j = 'A'; i < 26; i++, j++)
    {
        glNewList(fontOffset + j, GL_COMPILE);
        glBitmap(8, 13, 0.0, 2.0, 10.0, 0.0, letters[i]);
        glEndList();
    }
    glNewList(fontOffset + ' ', GL_COMPILE);
    glBitmap(8, 13, 0.0, 2.0, 10.0, 0.0, space);
    glEndList();
}
void printString(char* s)
{
    glPushAttrib(GL_LIST_BIT);
    glListBase(fontOffset);
    glCallLists(strlen(s), GL_UNSIGNED_BYTE, (GLubyte*)s);
    glPopAttrib();
}
void display(void)
{
    GLfloat white[3] = {1.0, 1.0, 1.0};

    glViewport(50, 50, 0, 0);
    glClear(GL_COLOR_BUFFER_BIT);
    glColor3fv(white);
    glRasterPos2i(0, 0);
    printString("ABCDEFGHIJK");
    glutSwapBuffers();
    glutPostRedisplay();
}

The viewport determines the mapping from normalised device coordinates (NDC) to window coordinates. All geometry is clipped to the range [-1,1] in all axes in NDC, so it’s clipped to the viewport rectangle in window coordinates.

However, rasterisation of primitives which aren’t bound by their geometry (i.e. anything other than polygons) can result in rendering to pixels outside the viewport. Specifically, points, lines and bitmaps aren’t bound by geometry.

For a bitmap, if the raster position is inside the viewpoint then the raster position is valid and the bitmap will be rendered with its origin at the raster position; if the raster position is outside the viewport then the raster position is invalid and nothing will be rendered. Large points and thick lines can also result in rendering to pixels outside the viewport (triangles are bound by their geometry, so they will never result in rendering to pixels outside the viewport).

If you want to limit rasterisation to a specific rectangle, that’s what the scissor rectangle is for. See glScissor and glEnable(GL_SCISSOR_TEST).

Sorry, I still don’t understand how a bitmap can be drawn on the screen when it is out of the viewport or when the width and height of the viewport are equal to 0.

Doesn’t the phrase "For a bitmap, if the raster position is inside the viewpoint then the raster position is valid and the bitmap will be rendered with its origin at the raster position; if the raster position is outside the viewport then the raster position is invalid and nothing will be rendered. " mean that a bitmap that is outside the viewport will not be drawn?

A bitmap is either drawn or not, depending upon whether the raster position is valid. Note that changing the viewport doesn’t affect the validity of the raster position, so if you change the viewport after calling glRasterPos or glWindowPos the raster position may still be valid in spite of it being outside the (new) viewport.

So how do I tell if the rasterpos is valid?Obviously, when the width and height of the viewport is equal to 0, the rasterpos is not inside the viewport (in my case, glRasterPos is called after glViewPort(x,y,0,0))

So long as the point is within the clip volume, the raster position is valid. The clip volume is the intersection of the 6 half-spaces

-wclip ≤ xclip ≤ wclip
-wclip ≤ yclip ≤ wclip
-wclip ≤ zclip ≤ wclip

In normalised device coordinates, this corresponds to

-1 ≤ xNDC ≤ 1
-1 ≤ zNDC ≤ 1
-1 ≤ zNDC ≤ 1

If a vertex shader is present, the position in clip coordinates is exactly the value of gl_Position. Otherwise, it’s obtained by transforming the specified object coordinates by the current model-view and projection matrices.

This doesn’t matter. Clipping is performed prior to the viewport transformation. Every point which survives clipping will be transformed to (x,y) in window coordinates.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.