1 /* gles1 - a simple SDL_gles OpenGL|ES 1.1 sample
3 * This file is in the public domain, furnished "as is", without technical
4 * support, and with no warranty, express or implied, as to its usefulness for
18 static SDL_Surface *screen;
19 static SDL_GLES_Context *context;
21 static float box_step = 0.1f;
23 static const float w = 0.28f, h = 0.4f;
24 static float x = -1.0f, y = 0.0f;
25 static float box_v[4*3];
27 static Uint32 tick(Uint32 interval, void* param)
30 e.type = SDL_VIDEOEXPOSE;
33 if (x >= 1.0f || x <= -1.0f) {
37 const float x1 = x - w/2, y1 = y - h/2;
38 const float x2 = x + w/2, y2 = y + h/2;
40 box_v[0] = x1; box_v[1] = y1; box_v[2] = z;
41 box_v[3] = x2; box_v[4] = y1; box_v[5] = z;
42 box_v[6] = x1; box_v[7] = y2; box_v[8] = z;
43 box_v[9] = x2; box_v[10] = y2; box_v[11] = z;
53 res = SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER);
56 res = SDL_GLES_Init(SDL_GLES_VERSION_1_1);
59 screen = SDL_SetVideoMode(0, 0, 16, SDL_SWSURFACE);
62 SDL_TimerID timer = SDL_AddTimer(10, tick, NULL);
63 assert(timer != NULL);
65 context = SDL_GLES_CreateContext();
68 SDL_GLES_MakeCurrent(context);
70 glMatrixMode(GL_MODELVIEW);
73 glClearColor(0.0f, 0.0f, 1.0f, 0.0f);
74 glColor4f(0.0f, 1.0f, 0.0f, 1.0f);
75 glEnableClientState(GL_VERTEX_ARRAY);
76 glVertexPointer(3, GL_FLOAT, 0, box_v);
79 while (SDL_WaitEvent(&event)) {
84 glClear(GL_COLOR_BUFFER_BIT);
85 glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
86 SDL_GLES_SwapBuffers();
92 SDL_GLES_DeleteContext(context);