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)
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))
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.