From: Brian Paul Date: Wed, 17 Mar 2010 16:17:04 +0000 (-0600) Subject: progs/samples: improve copy.c demo X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=a196a5d3303a49c5f79a283f91f8e0cc8aa87f69;p=mesa.git progs/samples: improve copy.c demo If the test image was larger than the window, nothing was drawn because of invalid raster position. Use glWindowPos instead of glRasterPos. Also, use integer src/dst coordinates to avoid grabbing black pixels outside of the src image region. --- diff --git a/progs/samples/copy.c b/progs/samples/copy.c index 391c637d6fa..353a3a2e1a2 100644 --- a/progs/samples/copy.c +++ b/progs/samples/copy.c @@ -25,6 +25,7 @@ #include #include #include +#include #include @@ -35,7 +36,6 @@ GLint windW, windH; char *fileName = 0; PPMImage *image; -float point[3]; float zoom; GLint x, y; @@ -97,27 +97,27 @@ static void Mouse(int button, int state, int mouseX, int mouseY) static void Draw(void) { + GLint src[3], dst[3]; glClear(GL_COLOR_BUFFER_BIT); - point[0] = (windW / 2) - (image->sizeX / 2); - point[1] = (windH / 2) - (image->sizeY / 2); - point[2] = 0; - glRasterPos3fv(point); + src[0] = (int) ((windW / 2.0) - (image->sizeX / 2.0)); + src[1] = (int) ((windH / 2.0) - (image->sizeY / 2.0)); + src[2] = 0; + glWindowPos3ivARB(src); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); glPixelZoom(1.0, 1.0); glDrawPixels(image->sizeX, image->sizeY, GL_RGB, GL_UNSIGNED_BYTE, image->data); - point[0] = (float)x; - point[1] = windH - (float)y; - point[2] = 0.0; - glRasterPos3fv(point); + dst[0] = x; + dst[1] = windH - y; + dst[2] = 0; + glWindowPos3ivARB(dst); glPixelZoom(zoom, zoom); - glCopyPixels((windW/2)-(image->sizeX/2), - (windH/2)-(image->sizeY/2), + glCopyPixels(src[0], src[1], image->sizeX, image->sizeY, GL_COLOR); glFlush(); @@ -170,8 +170,8 @@ int main(int argc, char **argv) image = LoadPPM(fileName); - windW = 300; - windH = 300; + windW = 2*300; + windH = 2*300; glutInitWindowPosition(0, 0); glutInitWindowSize( windW, windH); type = GLUT_RGB; @@ -182,6 +182,7 @@ int main(int argc, char **argv) exit(1); } + glewInit(); Init(); glutReshapeFunc(Reshape);