Proper window resize handling in GLES test application.

--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%403653
This commit is contained in:
Mike Gorchak 2009-06-11 06:03:05 +00:00
parent 83ca32e544
commit fa620100d8
3 changed files with 73 additions and 53 deletions

View File

@ -11,59 +11,56 @@
#define AUDIO_USAGE \
"[--rate N] [--format U8|S8|U16|U16LE|U16BE|S16|S16LE|S16BE] [--channels N] [--samples N]"
struct pformat
{
struct pformat {
Uint32 id;
const char *idstr;
} pixel_format[] = {
{
SDL_PIXELFORMAT_INDEX1LSB, "SDL_PIXELFORMAT_INDEX1LSB"}, {
SDL_PIXELFORMAT_INDEX1MSB, "SDL_PIXELFORMAT_INDEX1MSB"}, {
SDL_PIXELFORMAT_INDEX4LSB, "SDL_PIXELFORMAT_INDEX4LSB"}, {
SDL_PIXELFORMAT_INDEX4MSB, "SDL_PIXELFORMAT_INDEX4MSB"}, {
SDL_PIXELFORMAT_INDEX8, "SDL_PIXELFORMAT_INDEX8"}, {
SDL_PIXELFORMAT_RGB332, "SDL_PIXELFORMAT_RGB332"}, {
SDL_PIXELFORMAT_RGB444, "SDL_PIXELFORMAT_RGB444"}, {
SDL_PIXELFORMAT_RGB555, "SDL_PIXELFORMAT_RGB555"}, {
SDL_PIXELFORMAT_BGR555, "SDL_PIXELFORMAT_BGR555"}, {
SDL_PIXELFORMAT_ARGB4444, "SDL_PIXELFORMAT_ARGB4444"}, {
SDL_PIXELFORMAT_ABGR4444, "SDL_PIXELFORMAT_ABGR4444"}, {
SDL_PIXELFORMAT_ARGB1555, "SDL_PIXELFORMAT_ARGB1555"}, {
SDL_PIXELFORMAT_ABGR1555, "SDL_PIXELFORMAT_ABGR1555"}, {
SDL_PIXELFORMAT_RGB565, "SDL_PIXELFORMAT_RGB565"}, {
SDL_PIXELFORMAT_BGR565, "SDL_PIXELFORMAT_BGR565"}, {
SDL_PIXELFORMAT_RGB24, "SDL_PIXELFORMAT_RGB24"}, {
SDL_PIXELFORMAT_BGR24, "SDL_PIXELFORMAT_BGR24"}, {
SDL_PIXELFORMAT_RGB888, "SDL_PIXELFORMAT_RGB888"}, {
SDL_PIXELFORMAT_BGR888, "SDL_PIXELFORMAT_BGR888"}, {
SDL_PIXELFORMAT_ARGB8888, "SDL_PIXELFORMAT_ARGB8888"}, {
SDL_PIXELFORMAT_RGBA8888, "SDL_PIXELFORMAT_RGBA8888"}, {
SDL_PIXELFORMAT_ABGR8888, "SDL_PIXELFORMAT_ABGR8888"}, {
SDL_PIXELFORMAT_BGRA8888, "SDL_PIXELFORMAT_BGRA8888"}, {
SDL_PIXELFORMAT_ARGB2101010, "SDL_PIXELFORMAT_ARGB2101010"}, {
SDL_PIXELFORMAT_YV12, "SDL_PIXELFORMAT_YV12"}, {
SDL_PIXELFORMAT_IYUV, "SDL_PIXELFORMAT_IYUV"}, {
SDL_PIXELFORMAT_YUY2, "SDL_PIXELFORMAT_YUY2"}, {
SDL_PIXELFORMAT_UYVY, "SDL_PIXELFORMAT_UYVY"}, {
SDL_PIXELFORMAT_YVYU, "SDL_PIXELFORMAT_YVYU"}
const char* idstr;
} pixel_format[]={
{SDL_PIXELFORMAT_INDEX1LSB, "SDL_PIXELFORMAT_INDEX1LSB"},
{SDL_PIXELFORMAT_INDEX1MSB, "SDL_PIXELFORMAT_INDEX1MSB"},
{SDL_PIXELFORMAT_INDEX4LSB, "SDL_PIXELFORMAT_INDEX4LSB"},
{SDL_PIXELFORMAT_INDEX4MSB, "SDL_PIXELFORMAT_INDEX4MSB"},
{SDL_PIXELFORMAT_INDEX8, "SDL_PIXELFORMAT_INDEX8"},
{SDL_PIXELFORMAT_RGB332, "SDL_PIXELFORMAT_RGB332"},
{SDL_PIXELFORMAT_RGB444, "SDL_PIXELFORMAT_RGB444"},
{SDL_PIXELFORMAT_RGB555, "SDL_PIXELFORMAT_RGB555"},
{SDL_PIXELFORMAT_BGR555, "SDL_PIXELFORMAT_BGR555"},
{SDL_PIXELFORMAT_ARGB4444, "SDL_PIXELFORMAT_ARGB4444"},
{SDL_PIXELFORMAT_ABGR4444, "SDL_PIXELFORMAT_ABGR4444"},
{SDL_PIXELFORMAT_ARGB1555, "SDL_PIXELFORMAT_ARGB1555"},
{SDL_PIXELFORMAT_ABGR1555, "SDL_PIXELFORMAT_ABGR1555"},
{SDL_PIXELFORMAT_RGB565, "SDL_PIXELFORMAT_RGB565"},
{SDL_PIXELFORMAT_BGR565, "SDL_PIXELFORMAT_BGR565"},
{SDL_PIXELFORMAT_RGB24, "SDL_PIXELFORMAT_RGB24"},
{SDL_PIXELFORMAT_BGR24, "SDL_PIXELFORMAT_BGR24"},
{SDL_PIXELFORMAT_RGB888, "SDL_PIXELFORMAT_RGB888"},
{SDL_PIXELFORMAT_BGR888, "SDL_PIXELFORMAT_BGR888"},
{SDL_PIXELFORMAT_ARGB8888, "SDL_PIXELFORMAT_ARGB8888"},
{SDL_PIXELFORMAT_RGBA8888, "SDL_PIXELFORMAT_RGBA8888"},
{SDL_PIXELFORMAT_ABGR8888, "SDL_PIXELFORMAT_ABGR8888"},
{SDL_PIXELFORMAT_BGRA8888, "SDL_PIXELFORMAT_BGRA8888"},
{SDL_PIXELFORMAT_ARGB2101010, "SDL_PIXELFORMAT_ARGB2101010"},
{SDL_PIXELFORMAT_YV12, "SDL_PIXELFORMAT_YV12"},
{SDL_PIXELFORMAT_IYUV, "SDL_PIXELFORMAT_IYUV"},
{SDL_PIXELFORMAT_YUY2, "SDL_PIXELFORMAT_YUY2"},
{SDL_PIXELFORMAT_UYVY, "SDL_PIXELFORMAT_UYVY"},
{SDL_PIXELFORMAT_YVYU, "SDL_PIXELFORMAT_YVYU"}
};
const char *
PixelFormatToString(Uint32 pformat)
const char* PixelFormatToString(Uint32 pformat)
{
Uint32 it = 0;
Uint32 it=0;
do {
if (pixel_format[it].idstr == NULL) {
break;
}
if (pixel_format[it].id == pformat) {
return pixel_format[it].idstr;
}
it++;
} while (1);
do {
if (pixel_format[it].idstr == NULL) {
break;
}
if (pixel_format[it].id == pformat) {
return pixel_format[it].idstr;
}
it++;
} while(1);
return "SDL_PIXELFORMAT_UNKNOWN";
return "SDL_PIXELFORMAT_UNKNOWN";
}
CommonState *
@ -82,8 +79,8 @@ CommonCreateState(char **argv, Uint32 flags)
state->window_flags = SDL_WINDOW_SHOWN;
state->window_x = SDL_WINDOWPOS_UNDEFINED;
state->window_y = SDL_WINDOWPOS_UNDEFINED;
state->window_w = 640;
state->window_h = 480;
state->window_w = DEFAULT_WINDOW_WIDTH;
state->window_h = DEFAULT_WINDOW_HEIGHT;
state->num_windows = 1;
state->audiospec.freq = 22050;
state->audiospec.format = AUDIO_S16;
@ -709,7 +706,7 @@ CommonInit(CommonState * state)
fullscreen_mode.w = state->window_w;
fullscreen_mode.h = state->window_h;
fullscreen_mode.refresh_rate = state->refresh_rate;
if (SDL_SetFullscreenDisplayMode(&fullscreen_mode) < 0) {
if (SDL_SetFullscreenDisplayMode(&fullscreen_mode)<0) {
fprintf(stderr, "Can't switch to fullscreen display mode: %s\n",
SDL_GetError());
return SDL_FALSE;

View File

@ -3,6 +3,9 @@
#include "SDL.h"
#define DEFAULT_WINDOW_WIDTH 640
#define DEFAULT_WINDOW_HEIGHT 480
#define VERBOSE_VIDEO 0x00000001
#define VERBOSE_MODES 0x00000002
#define VERBOSE_RENDER 0x00000004

View File

@ -242,6 +242,7 @@ main(int argc, char *argv[])
continue;
}
glViewport(0, 0, DEFAULT_WINDOW_WIDTH, DEFAULT_WINDOW_HEIGHT);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrthof(-2.0, 2.0, -2.0, 2.0, -20.0, 20.0);
@ -260,10 +261,31 @@ main(int argc, char *argv[])
/* Check for events */
++frames;
while (SDL_PollEvent(&event)) {
switch (event.type) {
case SDL_WINDOWEVENT:
switch (event.window.event) {
case SDL_WINDOWEVENT_RESIZED:
for (i = 0; i < state->num_windows; ++i) {
if (event.window.windowID == state->windows[i]) {
status = SDL_GL_MakeCurrent(state->windows[i], context[i]);
if (status) {
printf("SDL_GL_MakeCurrent(): %s\n", SDL_GetError());
break;
}
/* Change view port to the new window dimensions */
glViewport(0, 0, event.window.data1, event.window.data2);
/* Update window content */
Render();
SDL_GL_SwapWindow(state->windows[i]);
break;
}
}
break;
}
}
CommonEvent(state, &event, &done);
}
for (i = 0; i < state->num_windows; ++i) {
int w, h;
status = SDL_GL_MakeCurrent(state->windows[i], context[i]);
if (status) {
printf("SDL_GL_MakeCurrent(): %s\n", SDL_GetError());
@ -271,8 +293,6 @@ main(int argc, char *argv[])
/* Continue for next window */
continue;
}
SDL_GetWindowSize(state->windows[i], &w, &h);
glViewport(0, 0, w, h);
Render();
SDL_GL_SwapWindow(state->windows[i]);
}