X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=apps%2Fgl%2Fvarray.c;h=112c23c3265144e8eedf0bc4e120252c0626d80f;hb=d9858b16096ac4ec7c99f1430a6ee934e33db2e0;hp=8ec8914879452f38186085f4332243f88526518b;hpb=cbcb20d793b9710b48b1446f256f990eba47ef52;p=apitrace-tests diff --git a/apps/gl/varray.c b/apps/gl/varray.c index 8ec8914..112c23c 100644 --- a/apps/gl/varray.c +++ b/apps/gl/varray.c @@ -54,19 +54,45 @@ # include #endif +enum SetupMethod { + POINTER, + INTERLEAVED, +}; -#define POINTER 1 -#define INTERLEAVED 2 +enum DerefMethod { + DRAWARRAYS, + ARRAYELEMENT, + DRAWELEMENTS, +}; -#define DRAWARRAY 1 -#define ARRAYELEMENT 2 -#define DRAWELEMENTS 3 - -static int setupMethod = POINTER; -static int derefMethod = DRAWARRAY; +static enum SetupMethod setupMethod = POINTER; +static enum DerefMethod derefMethod = DRAWELEMENTS; static int win; +static void parseArgs(int argc, char** argv) +{ + int i; + + for (i = 1; i < argc; ++i) { + const char *arg = argv[i]; + if (strcmp(arg, "pointer") == 0) { + setupMethod = POINTER; + } else if (strcmp(arg, "interleaved") == 0) { + setupMethod = INTERLEAVED; + } else if (strcmp(arg, "drawarrays") == 0) { + derefMethod = DRAWARRAYS; + } else if (strcmp(arg, "arrayelement") == 0) { + derefMethod = ARRAYELEMENT; + } else if (strcmp(arg, "drawelements") == 0) { + derefMethod = DRAWELEMENTS; + } else { + fprintf(stderr, "error: unknown arg %s\n", arg); + exit(1); + } + } +} + static void setupPointers(void) { static GLint vertices[] = { @@ -89,19 +115,19 @@ static void setupPointers(void) glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_COLOR_ARRAY); - glVertexPointer(2, GL_INT, 0, vertices); - glColorPointer(3, GL_FLOAT, 0, colors); + glVertexPointer(2, GL_INT, 2 * sizeof(GLint), vertices); + glColorPointer(3, GL_FLOAT, 3 * sizeof(GLfloat), colors); } static void setupInterleave(void) { static GLfloat intertwined[] = { - 1.0, 0.2, 1.0, 100.0, 100.0, 0.0, - 1.0, 0.2, 0.2, 0.0, 200.0, 0.0, - 1.0, 1.0, 0.2, 100.0, 300.0, 0.0, - 0.2, 1.0, 0.2, 200.0, 300.0, 0.0, - 0.2, 1.0, 1.0, 300.0, 200.0, 0.0, - 0.2, 0.2, 1.0, 200.0, 100.0, 0.0 + 1.0 , 0.2 , 0.2 , 25.0, 25.0, 0.0, + 0.2 , 0.2 , 1.0 , 100.0, 325.0, 0.0, + 0.8 , 1.0 , 0.2 , 175.0, 25.0, 0.0, + 0.75, 0.75, 0.75, 175.0, 325.0, 0.0, + 0.35, 0.35, 0.35, 250.0, 25.0, 0.0, + 0.5 , 0.5 , 0.5 , 325.0, 325.0, 0.0 }; glInterleavedArrays(GL_C3F_V3F, 0, intertwined); @@ -109,7 +135,7 @@ static void setupInterleave(void) static void init(void) { - glClearColor(0.0, 0.0, 0.0, 0.0); + glClearColor(0.0, 0.0, 0.0, 1.0); glShadeModel(GL_SMOOTH); setupPointers(); } @@ -118,7 +144,7 @@ static void display(void) { glClear(GL_COLOR_BUFFER_BIT); - if (derefMethod == DRAWARRAY) + if (derefMethod == DRAWARRAYS) glDrawArrays(GL_TRIANGLES, 0, 6); else if (derefMethod == ARRAYELEMENT) { glBegin(GL_TRIANGLES); @@ -144,15 +170,15 @@ static void reshape(int w, int h) glViewport(0, 0, (GLsizei) w, (GLsizei) h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); - gluOrtho2D(0.0, (GLdouble) w, 0.0, (GLdouble) h); + glOrtho(0.0, (GLdouble) w, 0.0, (GLdouble) h, -1.0, 1.0); } int main(int argc, char** argv) { + parseArgs(argc, argv); glutInit(&argc, argv); glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); glutInitWindowSize(350, 350); - glutInitWindowPosition(100, 100); win = glutCreateWindow(argv[0]); init(); glutDisplayFunc(display);