diff options
author | Keith Whitwell <[email protected]> | 2009-04-20 17:30:53 +0100 |
---|---|---|
committer | Keith Whitwell <[email protected]> | 2009-04-21 11:13:15 +0100 |
commit | 6bfcffa79e8b7999e8193e721e07dbb3de4a1658 (patch) | |
tree | 35d299e8c3410257d69cc4add13d346e7709bbe5 /progs/trivial/tri-viewport.c | |
parent | d27d79db4a52327e437146cde3fa3fb85b37de9a (diff) |
trivial/tri_viewport: add width/height keys
Diffstat (limited to 'progs/trivial/tri-viewport.c')
-rw-r--r-- | progs/trivial/tri-viewport.c | 67 |
1 files changed, 49 insertions, 18 deletions
diff --git a/progs/trivial/tri-viewport.c b/progs/trivial/tri-viewport.c index 4cd64e07818..c08089b9dd7 100644 --- a/progs/trivial/tri-viewport.c +++ b/progs/trivial/tri-viewport.c @@ -31,8 +31,11 @@ GLenum doubleBuffer = 1; int win; static float tx = 0; static float ty = 0; -static float tw = 250; -static float th = 250; +static float tw = 0; +static float th = 0; + +static float win_width = 250; +static float win_height = 250; static void Init(void) { @@ -41,33 +44,49 @@ static void Init(void) fprintf(stderr, "GL_VENDOR = %s\n", (char *) glGetString(GL_VENDOR)); fflush(stderr); - glClearColor(0.3, 0.1, 0.3, 0.0); + glClearColor(0, 0, 0, 0.0); } static void Reshape(int width, int height) { - tw = width; - th = height; + win_width = width; + win_height = height; + glutPostRedisplay(); } static void Key(unsigned char key, int x, int y) { switch (key) { - case 27: - exit(0); - default: - glutPostRedisplay(); - return; + case 27: + exit(0); + case 'w': + tw += 1.0; + break; + case 'W': + tw -= 1.0; + break; + case 'h': + th += 1.0; + break; + case 'H': + th -= 1.0; + break; + + default: + break; } + glutPostRedisplay(); } static void Draw(void) { int i; + float w = tw + win_width; + float h = th + win_height; - fprintf(stderr, "%f %f\n", tx, ty); + fprintf(stderr, "glViewport(%f %f %f %f)\n", tx, ty, w, h); fflush(stderr); glMatrixMode(GL_PROJECTION); @@ -77,8 +96,22 @@ static void Draw(void) glClear(GL_COLOR_BUFFER_BIT); - glViewport(0, 0, tw, th); + /*********************************************************************** + * Should be clipped to be no larger than the triangles: + */ + glViewport(tx, ty, w, h); + glBegin(GL_POLYGON); + glColor3f(.5,.5,1); + glVertex3f(-2, -2, -30.0); + glVertex3f(-2, 2, -30.0); + glVertex3f(2, 2, -30.0); + glVertex3f(2, -2, -30.0); + glEnd(); + + /*********************************************************************** + */ + glViewport(0, 0, win_width, win_height); glBegin(GL_LINES); glColor3f(1,1,0); glVertex3f(-1, 0, -30.0); @@ -89,11 +122,9 @@ static void Draw(void) glEnd(); - /* + /*********************************************************************** */ - glViewport(tx, ty, tw, th); - - + glViewport(tx, ty, w, h); glBegin(GL_TRIANGLES); glColor3f(1,0,0); glVertex3f(-1, -1, -30.0); @@ -127,7 +158,7 @@ static void Draw(void) glEnd(); - glViewport(0, 0, tw, th); + glViewport(0, 0, win_width, win_height); glBegin(GL_LINES); glColor3f(.5,.5,0); @@ -196,7 +227,7 @@ special(int k, int x, int y) tx += 1.0; break; default: - return; + break; } glutPostRedisplay(); } |