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 bool fullscreen = false;
23 static const float vertices[] ={-0.6f, -0.6f, -0.5f, /* Square 1 */
27 0.3f, 0.8f, 0.1f, /* Degenerate vertices */
29 -0.3f, -0.6f, 0.5f, /* Square 2 */
34 static const float colors[] = { 1.0f, 0.0f, 0.0f, 1.0f,
35 1.0f, 0.0f, 0.0f, 1.0f,
36 1.0f, 0.0f, 0.0f, 1.0f,
37 1.0f, 0.0f, 0.0f, 1.0f,
38 0.0f, 0.0f, 0.0f, 1.0f,
39 0.0f, 0.0f, 1.0f, 1.0f,
40 0.0f, 0.0f, 1.0f, 1.0f,
41 0.0f, 0.0f, 1.0f, 1.0f,
42 0.0f, 0.0f, 1.0f, 1.0f,
43 0.0f, 0.0f, 1.0f, 1.0f,
48 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
49 glDrawArrays(GL_TRIANGLE_STRIP, 0, 10);
50 SDL_GLES_SwapBuffers();
53 static void toggle_fullscreen()
57 fullscreen = !fullscreen;
59 screen = SDL_SetVideoMode(0, 0, 16, SDL_SWSURFACE |
60 (fullscreen ? SDL_FULLSCREEN : 0));
63 res = SDL_GLES_SetVideoMode();
72 res = SDL_Init(SDL_INIT_VIDEO);
75 res = SDL_GLES_Init(SDL_GLES_VERSION_1_1);
78 screen = SDL_SetVideoMode(0, 0, 16, SDL_SWSURFACE);
81 SDL_WM_SetCaption("SDLgles attrib test", "SDLgles v1 test");
82 SDL_ShowCursor(SDL_DISABLE);
84 #define ENABLE_DEPTH_BUFFER 1
86 #ifdef ENABLE_DEPTH_BUFFER
87 /* With a depth buffer, the red square will be partially over the blue sq. */
88 res = SDL_GLES_SetAttribute(SDL_GLES_DEPTH_SIZE, 4);
91 res = SDL_GLES_GetAttribute(SDL_GLES_DEPTH_SIZE, &value);
94 printf("Wanted depth buffer size is %d\n", value);
96 /* Without a depth buffer, the blue square will be over the red square. */
97 printf("Wanted depth buffer size is %d\n", 0);
100 context = SDL_GLES_CreateContext();
103 res = SDL_GLES_MakeCurrent(context);
107 res = SDL_GLES_GetAttribute(SDL_GLES_DEPTH_SIZE, &value);
109 printf("Depth buffer size is %d\n", value);
111 glMatrixMode(GL_MODELVIEW);
114 glEnable(GL_DEPTH_TEST);
115 glClearColor(0.0f, 0.2f, 0.0f, 0.0f);
116 glEnableClientState(GL_VERTEX_ARRAY);
117 glEnableClientState(GL_COLOR_ARRAY);
118 glVertexPointer(3, GL_FLOAT, 0, vertices);
119 glColorPointer(4, GL_FLOAT, 0, colors);
124 while (SDL_WaitEvent(&event)) {
125 switch (event.type) {
128 case SDL_MOUSEBUTTONDOWN:
135 SDL_GLES_DeleteContext(context);