Module: Demos Branch: master Commit: 613e19b8cd2094bd05cb7480de9e13edd54de18c URL: http://cgit.freedesktop.org/mesa/demos/commit/?id=613e19b8cd2094bd05cb7480de9e13edd54de18c
Author: Brian Paul <bri...@vmware.com> Date: Wed Jul 24 11:28:24 2013 -0600 trivial/tri-rotate: draw a triangle with rotation Specify initial rotation on command line. Press r/R to rotate interactively. --- src/trivial/CMakeLists.txt | 1 + src/trivial/Makefile.am | 1 + src/trivial/tri-rotate.c | 107 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 109 insertions(+), 0 deletions(-) diff --git a/src/trivial/CMakeLists.txt b/src/trivial/CMakeLists.txt index ed6445b..b42d1f9 100644 --- a/src/trivial/CMakeLists.txt +++ b/src/trivial/CMakeLists.txt @@ -147,6 +147,7 @@ set (targets tri-point-line-clipped tri-query tri-repeat + tri-rotate tri-scissor-tri tri-square tri-stencil diff --git a/src/trivial/Makefile.am b/src/trivial/Makefile.am index 2543068..87d4e40 100644 --- a/src/trivial/Makefile.am +++ b/src/trivial/Makefile.am @@ -159,6 +159,7 @@ bin_PROGRAMS = \ tri-point-line-clipped \ tri-query \ tri-repeat \ + tri-rotate \ tri-scissor-tri \ tri-square \ tri-stencil \ diff --git a/src/trivial/tri-rotate.c b/src/trivial/tri-rotate.c new file mode 100644 index 0000000..357de59 --- /dev/null +++ b/src/trivial/tri-rotate.c @@ -0,0 +1,107 @@ +/* + * Draw a triangle with rotation + */ + +#include <stdio.h> +#include <stdlib.h> +#include "glut_wrap.h" + + +static int win; +static float rot = 0.0f; + + +static void +Reshape(int width, int height) +{ + glViewport(0, 0, width, height); + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); +} + + +static void +Key(unsigned char key, int x, int y) +{ + if (key == 27) { + glutDestroyWindow(win); + exit(0); + } + else if (key == 'r') { + rot += 5.0f; + glutPostRedisplay(); + } + else if (key == 'R') { + rot -= 5.0f; + glutPostRedisplay(); + } +} + + +static void +Draw(void) +{ + glClear(GL_COLOR_BUFFER_BIT); + + glPushMatrix(); + glRotatef(rot, 0.0, 0.0, 1.0f); + + glBegin(GL_TRIANGLES); + glColor3f(1.0f, 0.0f, 0.0f); + glVertex3f(-0.8f, -0.8f, 0.0f); + glColor3f(0.0f, 1.0f, 0.0f); + glVertex3f(0.8f, -0.8f, 0.0f); + glColor3f(0.0f, 0.0f, 1.0f); + glVertex3f(0.0f, 0.8f, 0.0f); + glEnd(); + + glPopMatrix(); + + glutSwapBuffers(); +} + + +static void +Init(void) +{ + fprintf(stderr, "GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER)); + fprintf(stderr, "GL_VERSION = %s\n", (char *) glGetString(GL_VERSION)); + fprintf(stderr, "GL_VENDOR = %s\n", (char *) glGetString(GL_VENDOR)); + fflush(stderr); + + glClearColor(0.3, 0.3, 0.7, 0.0); +} + + +int +main(int argc, char **argv) +{ + glutInit(&argc, argv); + + if (argc > 1) { + rot = atof(argv[1]); + printf("Using rotation %g\n", rot); + fflush(stdout); + } + + glutInitWindowPosition(0, 0); + glutInitWindowSize(250, 250); + + glutInitDisplayMode(GLUT_RGB | GLUT_ALPHA | GLUT_DOUBLE); + + win = glutCreateWindow(*argv); + if (!win) { + exit(1); + } + + Init(); + + glutReshapeFunc(Reshape); + glutKeyboardFunc(Key); + glutDisplayFunc(Draw); + glutMainLoop(); + return 0; +} _______________________________________________ mesa-commit mailing list mesa-commit@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/mesa-commit