Clipping the drawing area

Started by
0 comments, last by Sharlin 19 years ago
I draw a 2D texture on screen using OpenGL as follows:

    glBegin(GL_QUADS);
      glTexCoord2d(0.0, 0.0); glVertex3d(x + 0     + skewx, y + 0     + 0    , 1);
      glTexCoord2d(0.0, +u3); glVertex3d(x + sizex + skewx, y + 0     + skewy, 1);
      glTexCoord2d(+v3, +u3); glVertex3d(x + sizex + 0    , y + sizey + skewy, 1);
      glTexCoord2d(+v3, 0.0); glVertex3d(x + 0     + 0    , y + sizey + 0    , 1);
    glEnd();
As you can see it's not just a simple rectangular texture being draw, because there's the possibility to skew it. I'd like to draw this texture in a limited rectangular area of the screen, so when a part of the textures lies outside that area, it should be clipped there. However, I think if I have to do this myself it'll become very complex, especially when the texture is skewed because then it's shape may become a pentagram or something else then instead of a parallellogram. Is there a way to tell OpenGL to draw only in a limited rectangular area of the screen so that it'll automaticly not draw any pixels of the texture outside that area? Thanks. EDIT: to make things more clear, this is for a 2D engine and I used the official "Setting Your Raster Position to a Pixel Location" code from the opengl.org site to set up the camera matrix:

glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, w, h, 0, -1, 1);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
and I want to find the easiest way to let OpenGL automaticly clip things of any shape to an area smaller than the whole screen. I want to give the coordinates of the smaller area in pixel coordinates. [Edited by - Lode on March 26, 2005 3:41:31 PM]
Advertisement
Enable scissor test:
glEnable(GL_SCISSOR_TEST);glScissor(x, y, width, height);

where the coordinates are in window space (that is, "actual" pixel coordinates, similarly to glViewport()).

This topic is closed to new replies.

Advertisement