mirror of
https://github.com/joel16/SDL2.git
synced 2024-12-13 14:07:38 +00:00
Support for GL initialization parameters has been added.
--HG-- extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%404131
This commit is contained in:
parent
1cbfd5b6e0
commit
78dec43e00
@ -86,6 +86,28 @@ CommonCreateState(char **argv, Uint32 flags)
|
||||
state->audiospec.format = AUDIO_S16;
|
||||
state->audiospec.channels = 2;
|
||||
state->audiospec.samples = 2048;
|
||||
|
||||
/* Set some very sane GL defaults */
|
||||
state->gl_red_size = 3;
|
||||
state->gl_green_size = 3;
|
||||
state->gl_blue_size = 2;
|
||||
state->gl_alpha_size = 0;
|
||||
state->gl_buffer_size = 0;
|
||||
state->gl_depth_size = 16;
|
||||
state->gl_stencil_size = 0;
|
||||
state->gl_double_buffer = 1;
|
||||
state->gl_accum_red_size = 0;
|
||||
state->gl_accum_green_size = 0;
|
||||
state->gl_accum_blue_size = 0;
|
||||
state->gl_accum_alpha_size = 0;
|
||||
state->gl_stereo = 0;
|
||||
state->gl_multisamplebuffers = 0;
|
||||
state->gl_multisamplesamples = 0;
|
||||
state->gl_retained_backing = 1;
|
||||
state->gl_accelerated = 1;
|
||||
state->gl_major_version = 2;
|
||||
state->gl_minor_version = 1;
|
||||
|
||||
return state;
|
||||
}
|
||||
|
||||
@ -621,6 +643,27 @@ CommonInit(CommonState * state)
|
||||
SDL_GetCurrentVideoDriver());
|
||||
}
|
||||
|
||||
/* Upload GL settings */
|
||||
SDL_GL_SetAttribute(SDL_GL_RED_SIZE, state->gl_red_size);
|
||||
SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, state->gl_green_size);
|
||||
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, state->gl_blue_size);
|
||||
SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, state->gl_alpha_size);
|
||||
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, state->gl_double_buffer);
|
||||
SDL_GL_SetAttribute(SDL_GL_BUFFER_SIZE, state->gl_buffer_size);
|
||||
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, state->gl_depth_size);
|
||||
SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, state->gl_stencil_size);
|
||||
SDL_GL_SetAttribute(SDL_GL_ACCUM_RED_SIZE, state->gl_accum_red_size);
|
||||
SDL_GL_SetAttribute(SDL_GL_ACCUM_GREEN_SIZE, state->gl_accum_green_size);
|
||||
SDL_GL_SetAttribute(SDL_GL_ACCUM_BLUE_SIZE, state->gl_accum_blue_size);
|
||||
SDL_GL_SetAttribute(SDL_GL_ACCUM_ALPHA_SIZE, state->gl_accum_alpha_size);
|
||||
SDL_GL_SetAttribute(SDL_GL_STEREO, state->gl_stereo);
|
||||
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, state->gl_multisamplebuffers);
|
||||
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, state->gl_multisamplesamples);
|
||||
SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL, state->gl_accelerated);
|
||||
SDL_GL_SetAttribute(SDL_GL_RETAINED_BACKING, state->gl_retained_backing);
|
||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, state->gl_major_version);
|
||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, state->gl_minor_version);
|
||||
|
||||
if (state->verbose & VERBOSE_MODES) {
|
||||
SDL_DisplayMode mode;
|
||||
int bpp;
|
||||
|
@ -41,6 +41,27 @@ typedef struct
|
||||
/* Audio info */
|
||||
const char *audiodriver;
|
||||
SDL_AudioSpec audiospec;
|
||||
|
||||
/* GL settings */
|
||||
int gl_red_size;
|
||||
int gl_green_size;
|
||||
int gl_blue_size;
|
||||
int gl_alpha_size;
|
||||
int gl_buffer_size;
|
||||
int gl_depth_size;
|
||||
int gl_stencil_size;
|
||||
int gl_double_buffer;
|
||||
int gl_accum_red_size;
|
||||
int gl_accum_green_size;
|
||||
int gl_accum_blue_size;
|
||||
int gl_accum_alpha_size;
|
||||
int gl_stereo;
|
||||
int gl_multisamplebuffers;
|
||||
int gl_multisamplesamples;
|
||||
int gl_retained_backing;
|
||||
int gl_accelerated;
|
||||
int gl_major_version;
|
||||
int gl_minor_version;
|
||||
} CommonState;
|
||||
|
||||
extern CommonState *CommonCreateState(char **argv, Uint32 flags);
|
||||
|
@ -204,18 +204,19 @@ main(int argc, char *argv[])
|
||||
|
||||
/* Set OpenGL parameters */
|
||||
state->window_flags |= SDL_WINDOW_OPENGL;
|
||||
SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5);
|
||||
SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5);
|
||||
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5);
|
||||
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
|
||||
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
|
||||
state->gl_red_size = 5;
|
||||
state->gl_green_size = 5;
|
||||
state->gl_blue_size = 5;
|
||||
state->gl_depth_size = 16;
|
||||
state->gl_doublebuffer = 1;
|
||||
if (fsaa) {
|
||||
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1);
|
||||
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, fsaa);
|
||||
state->gl_multisamplebuffers = 1;
|
||||
state->gl_multisamplesamples = fsaa;
|
||||
}
|
||||
if (accel) {
|
||||
SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL, 1);
|
||||
state->gl_accelerated=1;
|
||||
}
|
||||
|
||||
if (!CommonInit(state)) {
|
||||
quit(2);
|
||||
}
|
||||
|
@ -15,6 +15,7 @@
|
||||
|
||||
static CommonState *state;
|
||||
static SDL_GLContext *context = NULL;
|
||||
static int depth = 16;
|
||||
|
||||
/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
|
||||
static void
|
||||
@ -118,12 +119,20 @@ main(int argc, char *argv[])
|
||||
} else if (SDL_strcasecmp(argv[i], "--accel") == 0) {
|
||||
++accel;
|
||||
consumed = 1;
|
||||
} else if (SDL_strcasecmp(argv[i], "--zdepth") == 0) {
|
||||
i++;
|
||||
if (!argv[i]) {
|
||||
consumed = -1;
|
||||
} else {
|
||||
depth = SDL_atoi(argv[i]);
|
||||
consumed = 1;
|
||||
}
|
||||
} else {
|
||||
consumed = -1;
|
||||
}
|
||||
}
|
||||
if (consumed < 0) {
|
||||
fprintf(stderr, "Usage: %s %s [--fsaa] [--accel]\n", argv[0],
|
||||
fprintf(stderr, "Usage: %s %s [--fsaa] [--accel] [--zdepth %%d]\n", argv[0],
|
||||
CommonUsage(state));
|
||||
quit(1);
|
||||
}
|
||||
@ -132,16 +141,16 @@ main(int argc, char *argv[])
|
||||
|
||||
/* Set OpenGL parameters */
|
||||
state->window_flags |= SDL_WINDOW_OPENGL;
|
||||
SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5);
|
||||
SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5);
|
||||
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5);
|
||||
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
|
||||
state->gl_red_size = 5;
|
||||
state->gl_green_size = 5;
|
||||
state->gl_blue_size = 5;
|
||||
state->gl_depth_size = depth;
|
||||
if (fsaa) {
|
||||
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1);
|
||||
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, fsaa);
|
||||
state->gl_multisamplebuffers=1;
|
||||
state->gl_multisamplesamples=fsaa;
|
||||
}
|
||||
if (accel) {
|
||||
SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL, 1);
|
||||
state->gl_accelerated=1;
|
||||
}
|
||||
if (!CommonInit(state)) {
|
||||
quit(2);
|
||||
@ -169,7 +178,7 @@ main(int argc, char *argv[])
|
||||
}
|
||||
|
||||
SDL_GetCurrentDisplayMode(&mode);
|
||||
printf("Screen BPP: %d\n", SDL_BITSPERPIXEL(mode.format));
|
||||
printf("Screen bpp: %d\n", SDL_BITSPERPIXEL(mode.format));
|
||||
printf("\n");
|
||||
printf("Vendor : %s\n", glGetString(GL_VENDOR));
|
||||
printf("Renderer : %s\n", glGetString(GL_RENDERER));
|
||||
@ -200,7 +209,7 @@ main(int argc, char *argv[])
|
||||
}
|
||||
status = SDL_GL_GetAttribute(SDL_GL_DEPTH_SIZE, &value);
|
||||
if (!status) {
|
||||
printf("SDL_GL_DEPTH_SIZE: requested %d, got %d\n", 16, value);
|
||||
printf("SDL_GL_DEPTH_SIZE: requested %d, got %d\n", depth, value);
|
||||
} else {
|
||||
fprintf(stderr, "Failed to get SDL_GL_DEPTH_SIZE: %s\n",
|
||||
SDL_GetError());
|
||||
|
Loading…
Reference in New Issue
Block a user