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.025f;
23 static const float w = 0.28f, h = 0.4f;
24 static float x = -0.5f, y = 0.0f;
25 static float box_v[4*3];
26 static bool fullscreen = false;
28 static Uint32 tick(Uint32 interval, void* param)
31 e.type = SDL_VIDEOEXPOSE;
34 if ((x + w/2) >= 1.0f || (x - w/2) <= -1.0f) {
38 const float x1 = x - w/2, y1 = y - h/2;
39 const float x2 = x + w/2, y2 = y + h/2;
41 box_v[0] = x1; box_v[1] = y1; box_v[2] = z;
42 box_v[3] = x2; box_v[4] = y1; box_v[5] = z;
43 box_v[6] = x1; box_v[7] = y2; box_v[8] = z;
44 box_v[9] = x2; box_v[10] = y2; box_v[11] = z;
46 SDL_PushEvent(&e); /* Since SDL calls timers in another thread, we cannot
47 call rendering functions from here. */
52 static void toggle_fullscreen()
56 fullscreen = !fullscreen;
58 screen = SDL_SetVideoMode(0, 0, 16, SDL_SWSURFACE |
59 (fullscreen ? SDL_FULLSCREEN : 0));
62 res = SDL_GLES_SetVideoMode();
63 if (res != 0) puts(SDL_GetError());
70 res = SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER);
73 res = SDL_GLES_Init(SDL_GLES_VERSION_1_1);
76 screen = SDL_SetVideoMode(0, 0, 16, SDL_SWSURFACE);
79 SDL_WM_SetCaption("SDLgles v1 test");
80 SDL_ShowCursor(SDL_DISABLE);
82 SDL_TimerID timer = SDL_AddTimer(30, tick, NULL);
83 assert(timer != NULL);
85 context = SDL_GLES_CreateContext();
88 res = SDL_GLES_MakeCurrent(context);
91 glMatrixMode(GL_MODELVIEW);
94 glClearColor(0.0f, 0.0f, 1.0f, 0.0f);
95 glColor4f(0.0f, 1.0f, 0.0f, 1.0f);
96 glEnableClientState(GL_VERTEX_ARRAY);
97 glVertexPointer(3, GL_FLOAT, 0, box_v);
100 while (SDL_WaitEvent(&event)) {
101 switch (event.type) {
104 case SDL_VIDEOEXPOSE:
105 glClear(GL_COLOR_BUFFER_BIT);
106 glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
107 SDL_GLES_SwapBuffers();
109 case SDL_MOUSEBUTTONDOWN:
116 SDL_GLES_DeleteContext(context);