Proper window resize handling in GLES test application.
authorMike Gorchak <lestat@i.com.ua>
Thu, 11 Jun 2009 06:03:05 +0000
changeset 3194c18c03927a77
parent 3193 64e4442676a6
child 3195 08747e24a50f
Proper window resize handling in GLES test application.
test/common.c
test/common.h
test/testgles.c
     1.1 --- a/test/common.c	Thu Jun 11 05:57:32 2009 +0000
     1.2 +++ b/test/common.c	Thu Jun 11 06:03:05 2009 +0000
     1.3 @@ -11,59 +11,56 @@
     1.4  #define AUDIO_USAGE \
     1.5  "[--rate N] [--format U8|S8|U16|U16LE|U16BE|S16|S16LE|S16BE] [--channels N] [--samples N]"
     1.6  
     1.7 -struct pformat
     1.8 -{
     1.9 +struct pformat {
    1.10      Uint32 id;
    1.11 -    const char *idstr;
    1.12 -} pixel_format[] = {
    1.13 -    {
    1.14 -    SDL_PIXELFORMAT_INDEX1LSB, "SDL_PIXELFORMAT_INDEX1LSB"}, {
    1.15 -    SDL_PIXELFORMAT_INDEX1MSB, "SDL_PIXELFORMAT_INDEX1MSB"}, {
    1.16 -    SDL_PIXELFORMAT_INDEX4LSB, "SDL_PIXELFORMAT_INDEX4LSB"}, {
    1.17 -    SDL_PIXELFORMAT_INDEX4MSB, "SDL_PIXELFORMAT_INDEX4MSB"}, {
    1.18 -    SDL_PIXELFORMAT_INDEX8, "SDL_PIXELFORMAT_INDEX8"}, {
    1.19 -    SDL_PIXELFORMAT_RGB332, "SDL_PIXELFORMAT_RGB332"}, {
    1.20 -    SDL_PIXELFORMAT_RGB444, "SDL_PIXELFORMAT_RGB444"}, {
    1.21 -    SDL_PIXELFORMAT_RGB555, "SDL_PIXELFORMAT_RGB555"}, {
    1.22 -    SDL_PIXELFORMAT_BGR555, "SDL_PIXELFORMAT_BGR555"}, {
    1.23 -    SDL_PIXELFORMAT_ARGB4444, "SDL_PIXELFORMAT_ARGB4444"}, {
    1.24 -    SDL_PIXELFORMAT_ABGR4444, "SDL_PIXELFORMAT_ABGR4444"}, {
    1.25 -    SDL_PIXELFORMAT_ARGB1555, "SDL_PIXELFORMAT_ARGB1555"}, {
    1.26 -    SDL_PIXELFORMAT_ABGR1555, "SDL_PIXELFORMAT_ABGR1555"}, {
    1.27 -    SDL_PIXELFORMAT_RGB565, "SDL_PIXELFORMAT_RGB565"}, {
    1.28 -    SDL_PIXELFORMAT_BGR565, "SDL_PIXELFORMAT_BGR565"}, {
    1.29 -    SDL_PIXELFORMAT_RGB24, "SDL_PIXELFORMAT_RGB24"}, {
    1.30 -    SDL_PIXELFORMAT_BGR24, "SDL_PIXELFORMAT_BGR24"}, {
    1.31 -    SDL_PIXELFORMAT_RGB888, "SDL_PIXELFORMAT_RGB888"}, {
    1.32 -    SDL_PIXELFORMAT_BGR888, "SDL_PIXELFORMAT_BGR888"}, {
    1.33 -    SDL_PIXELFORMAT_ARGB8888, "SDL_PIXELFORMAT_ARGB8888"}, {
    1.34 -    SDL_PIXELFORMAT_RGBA8888, "SDL_PIXELFORMAT_RGBA8888"}, {
    1.35 -    SDL_PIXELFORMAT_ABGR8888, "SDL_PIXELFORMAT_ABGR8888"}, {
    1.36 -    SDL_PIXELFORMAT_BGRA8888, "SDL_PIXELFORMAT_BGRA8888"}, {
    1.37 -    SDL_PIXELFORMAT_ARGB2101010, "SDL_PIXELFORMAT_ARGB2101010"}, {
    1.38 -    SDL_PIXELFORMAT_YV12, "SDL_PIXELFORMAT_YV12"}, {
    1.39 -    SDL_PIXELFORMAT_IYUV, "SDL_PIXELFORMAT_IYUV"}, {
    1.40 -    SDL_PIXELFORMAT_YUY2, "SDL_PIXELFORMAT_YUY2"}, {
    1.41 -    SDL_PIXELFORMAT_UYVY, "SDL_PIXELFORMAT_UYVY"}, {
    1.42 -    SDL_PIXELFORMAT_YVYU, "SDL_PIXELFORMAT_YVYU"}
    1.43 +    const char* idstr;
    1.44 +} pixel_format[]={
    1.45 +    {SDL_PIXELFORMAT_INDEX1LSB, "SDL_PIXELFORMAT_INDEX1LSB"},
    1.46 +    {SDL_PIXELFORMAT_INDEX1MSB, "SDL_PIXELFORMAT_INDEX1MSB"},
    1.47 +    {SDL_PIXELFORMAT_INDEX4LSB, "SDL_PIXELFORMAT_INDEX4LSB"},
    1.48 +    {SDL_PIXELFORMAT_INDEX4MSB, "SDL_PIXELFORMAT_INDEX4MSB"},
    1.49 +    {SDL_PIXELFORMAT_INDEX8, "SDL_PIXELFORMAT_INDEX8"},
    1.50 +    {SDL_PIXELFORMAT_RGB332, "SDL_PIXELFORMAT_RGB332"},
    1.51 +    {SDL_PIXELFORMAT_RGB444, "SDL_PIXELFORMAT_RGB444"},
    1.52 +    {SDL_PIXELFORMAT_RGB555, "SDL_PIXELFORMAT_RGB555"},
    1.53 +    {SDL_PIXELFORMAT_BGR555, "SDL_PIXELFORMAT_BGR555"},
    1.54 +    {SDL_PIXELFORMAT_ARGB4444, "SDL_PIXELFORMAT_ARGB4444"},
    1.55 +    {SDL_PIXELFORMAT_ABGR4444, "SDL_PIXELFORMAT_ABGR4444"},
    1.56 +    {SDL_PIXELFORMAT_ARGB1555, "SDL_PIXELFORMAT_ARGB1555"},
    1.57 +    {SDL_PIXELFORMAT_ABGR1555, "SDL_PIXELFORMAT_ABGR1555"},
    1.58 +    {SDL_PIXELFORMAT_RGB565, "SDL_PIXELFORMAT_RGB565"},
    1.59 +    {SDL_PIXELFORMAT_BGR565, "SDL_PIXELFORMAT_BGR565"},
    1.60 +    {SDL_PIXELFORMAT_RGB24, "SDL_PIXELFORMAT_RGB24"},
    1.61 +    {SDL_PIXELFORMAT_BGR24, "SDL_PIXELFORMAT_BGR24"},
    1.62 +    {SDL_PIXELFORMAT_RGB888, "SDL_PIXELFORMAT_RGB888"},
    1.63 +    {SDL_PIXELFORMAT_BGR888, "SDL_PIXELFORMAT_BGR888"},
    1.64 +    {SDL_PIXELFORMAT_ARGB8888, "SDL_PIXELFORMAT_ARGB8888"},
    1.65 +    {SDL_PIXELFORMAT_RGBA8888, "SDL_PIXELFORMAT_RGBA8888"},
    1.66 +    {SDL_PIXELFORMAT_ABGR8888, "SDL_PIXELFORMAT_ABGR8888"},
    1.67 +    {SDL_PIXELFORMAT_BGRA8888, "SDL_PIXELFORMAT_BGRA8888"},
    1.68 +    {SDL_PIXELFORMAT_ARGB2101010, "SDL_PIXELFORMAT_ARGB2101010"},
    1.69 +    {SDL_PIXELFORMAT_YV12, "SDL_PIXELFORMAT_YV12"},
    1.70 +    {SDL_PIXELFORMAT_IYUV, "SDL_PIXELFORMAT_IYUV"},
    1.71 +    {SDL_PIXELFORMAT_YUY2, "SDL_PIXELFORMAT_YUY2"},
    1.72 +    {SDL_PIXELFORMAT_UYVY, "SDL_PIXELFORMAT_UYVY"},
    1.73 +    {SDL_PIXELFORMAT_YVYU, "SDL_PIXELFORMAT_YVYU"}
    1.74  };
    1.75  
    1.76 -const char *
    1.77 -PixelFormatToString(Uint32 pformat)
    1.78 +const char* PixelFormatToString(Uint32 pformat)
    1.79  {
    1.80 -    Uint32 it = 0;
    1.81 +   Uint32 it=0;
    1.82  
    1.83 -    do {
    1.84 -        if (pixel_format[it].idstr == NULL) {
    1.85 -            break;
    1.86 -        }
    1.87 -        if (pixel_format[it].id == pformat) {
    1.88 -            return pixel_format[it].idstr;
    1.89 -        }
    1.90 -        it++;
    1.91 -    } while (1);
    1.92 +   do {
    1.93 +      if (pixel_format[it].idstr == NULL) {
    1.94 +          break;
    1.95 +      }
    1.96 +      if (pixel_format[it].id == pformat) {
    1.97 +          return pixel_format[it].idstr;
    1.98 +      }
    1.99 +      it++;
   1.100 +   } while(1);
   1.101  
   1.102 -    return "SDL_PIXELFORMAT_UNKNOWN";
   1.103 +   return "SDL_PIXELFORMAT_UNKNOWN";
   1.104  }
   1.105  
   1.106  CommonState *
   1.107 @@ -82,8 +79,8 @@
   1.108      state->window_flags = SDL_WINDOW_SHOWN;
   1.109      state->window_x = SDL_WINDOWPOS_UNDEFINED;
   1.110      state->window_y = SDL_WINDOWPOS_UNDEFINED;
   1.111 -    state->window_w = 640;
   1.112 -    state->window_h = 480;
   1.113 +    state->window_w = DEFAULT_WINDOW_WIDTH;
   1.114 +    state->window_h = DEFAULT_WINDOW_HEIGHT;
   1.115      state->num_windows = 1;
   1.116      state->audiospec.freq = 22050;
   1.117      state->audiospec.format = AUDIO_S16;
   1.118 @@ -709,7 +706,7 @@
   1.119          fullscreen_mode.w = state->window_w;
   1.120          fullscreen_mode.h = state->window_h;
   1.121          fullscreen_mode.refresh_rate = state->refresh_rate;
   1.122 -        if (SDL_SetFullscreenDisplayMode(&fullscreen_mode) < 0) {
   1.123 +        if (SDL_SetFullscreenDisplayMode(&fullscreen_mode)<0) {
   1.124              fprintf(stderr, "Can't switch to fullscreen display mode: %s\n",
   1.125                      SDL_GetError());
   1.126              return SDL_FALSE;
     2.1 --- a/test/common.h	Thu Jun 11 05:57:32 2009 +0000
     2.2 +++ b/test/common.h	Thu Jun 11 06:03:05 2009 +0000
     2.3 @@ -3,6 +3,9 @@
     2.4  
     2.5  #include "SDL.h"
     2.6  
     2.7 +#define DEFAULT_WINDOW_WIDTH  640
     2.8 +#define DEFAULT_WINDOW_HEIGHT 480
     2.9 +
    2.10  #define VERBOSE_VIDEO   0x00000001
    2.11  #define VERBOSE_MODES   0x00000002
    2.12  #define VERBOSE_RENDER  0x00000004
     3.1 --- a/test/testgles.c	Thu Jun 11 05:57:32 2009 +0000
     3.2 +++ b/test/testgles.c	Thu Jun 11 06:03:05 2009 +0000
     3.3 @@ -242,6 +242,7 @@
     3.4              continue;
     3.5          }
     3.6  
     3.7 +        glViewport(0, 0, DEFAULT_WINDOW_WIDTH, DEFAULT_WINDOW_HEIGHT);
     3.8          glMatrixMode(GL_PROJECTION);
     3.9          glLoadIdentity();
    3.10          glOrthof(-2.0, 2.0, -2.0, 2.0, -20.0, 20.0);
    3.11 @@ -260,10 +261,31 @@
    3.12          /* Check for events */
    3.13          ++frames;
    3.14          while (SDL_PollEvent(&event)) {
    3.15 +            switch (event.type) {
    3.16 +            case SDL_WINDOWEVENT:
    3.17 +                switch (event.window.event) {
    3.18 +                    case SDL_WINDOWEVENT_RESIZED:
    3.19 +                        for (i = 0; i < state->num_windows; ++i) {
    3.20 +                            if (event.window.windowID == state->windows[i]) {
    3.21 +                                status = SDL_GL_MakeCurrent(state->windows[i], context[i]);
    3.22 +                                if (status) {
    3.23 +                                    printf("SDL_GL_MakeCurrent(): %s\n", SDL_GetError());
    3.24 +                                    break;
    3.25 +                                }
    3.26 +                                /* Change view port to the new window dimensions */
    3.27 +                                glViewport(0, 0, event.window.data1, event.window.data2);
    3.28 +                                /* Update window content */
    3.29 +                                Render();
    3.30 +                                SDL_GL_SwapWindow(state->windows[i]);
    3.31 +                                break;
    3.32 +                            }
    3.33 +                        }
    3.34 +                        break;
    3.35 +                }
    3.36 +            }
    3.37              CommonEvent(state, &event, &done);
    3.38          }
    3.39          for (i = 0; i < state->num_windows; ++i) {
    3.40 -            int w, h;
    3.41              status = SDL_GL_MakeCurrent(state->windows[i], context[i]);
    3.42              if (status) {
    3.43                  printf("SDL_GL_MakeCurrent(): %s\n", SDL_GetError());
    3.44 @@ -271,8 +293,6 @@
    3.45                  /* Continue for next window */
    3.46                  continue;
    3.47              }
    3.48 -            SDL_GetWindowSize(state->windows[i], &w, &h);
    3.49 -            glViewport(0, 0, w, h);
    3.50              Render();
    3.51              SDL_GL_SwapWindow(state->windows[i]);
    3.52          }