Commit e19a77c7 authored by Sam Lantinga's avatar Sam Lantinga

SDL_OPENGLBLIT is deprecated, show the "right way" of doing things

--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%40234
parent 383e24e3
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#define SHADED_CUBE #define SHADED_CUBE
static SDL_bool USE_DEPRECATED_OPENGLBLIT = SDL_FALSE;
void HotKey_ToggleFullScreen(void) void HotKey_ToggleFullScreen(void)
{ {
...@@ -95,11 +96,51 @@ int HandleEvent(SDL_Event *event) ...@@ -95,11 +96,51 @@ int HandleEvent(SDL_Event *event)
return(done); return(done);
} }
void SDL_GL_Enter2DMode()
{
SDL_Surface *screen = SDL_GetVideoSurface();
/* Note, there may be other things you need to change,
depending on how you have your OpenGL state set up.
*/
glPushAttrib(GL_ENABLE_BIT);
glDisable(GL_DEPTH_TEST);
glDisable(GL_CULL_FACE);
glEnable(GL_TEXTURE_2D);
glViewport(0, 0, screen->w, screen->h);
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
glOrtho(0.0, (GLdouble)screen->w, (GLdouble)screen->h, 0.0, 0.0, 1.0);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
}
void SDL_GL_Leave2DMode()
{
glMatrixMode(GL_MODELVIEW);
glPopMatrix();
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glPopAttrib();
}
void DrawSDLLogo(void) void DrawSDLLogo(void)
{ {
static SDL_Surface *image = NULL; static SDL_Surface *image = NULL;
static GLuint texture;
static int x = 0; static int x = 0;
static int y = 0; static int y = 0;
static int w, h;
static int delta_x = 1; static int delta_x = 1;
static int delta_y = 1; static int delta_y = 1;
static Uint32 last_moved = 0; static Uint32 last_moved = 0;
...@@ -118,16 +159,16 @@ void DrawSDLLogo(void) ...@@ -118,16 +159,16 @@ void DrawSDLLogo(void)
SDL_SWSURFACE, SDL_SWSURFACE,
temp->w, temp->h, temp->w, temp->h,
32, 32,
#if SDL_BYTEORDER == SDL_LIL_ENDIAN #if SDL_BYTEORDER == SDL_LIL_ENDIAN /* OpenGL RGBA masks */
0x000000FF, 0x000000FF,
0x0000FF00, 0x0000FF00,
0x00FF0000, 0x00FF0000,
0xFF000000 0xFF000000
#else #else
0xFF000000, 0xFF000000,
0x00FF0000, 0x00FF0000,
0x0000FF00, 0x0000FF00,
0x000000FF 0x000000FF
#endif #endif
); );
if ( image != NULL ) { if ( image != NULL ) {
...@@ -137,6 +178,29 @@ void DrawSDLLogo(void) ...@@ -137,6 +178,29 @@ void DrawSDLLogo(void)
if ( image == NULL ) { if ( image == NULL ) {
return; return;
} }
w = image->w;
h = image->h;
/* Create an OpenGL texture for the image */
if ( ! USE_DEPRECATED_OPENGLBLIT ) {
glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_2D, texture);
glTexParameteri(GL_TEXTURE_2D,
GL_TEXTURE_MAG_FILTER,
GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D,
GL_TEXTURE_MIN_FILTER,
GL_NEAREST);
glTexImage2D(GL_TEXTURE_2D,
0,
GL_RGBA,
w, h,
0,
GL_RGBA,
GL_UNSIGNED_BYTE,
image->pixels);
SDL_FreeSurface(image); /* No longer needed */
}
} }
screen = SDL_GetVideoSurface(); screen = SDL_GetVideoSurface();
...@@ -144,8 +208,8 @@ void DrawSDLLogo(void) ...@@ -144,8 +208,8 @@ void DrawSDLLogo(void)
/* Show the image on the screen */ /* Show the image on the screen */
dst.x = x; dst.x = x;
dst.y = y; dst.y = y;
dst.w = image->w; dst.w = w;
dst.h = image->h; dst.h = h;
/* Move it around /* Move it around
Note that we do not clear the old position. This is because we Note that we do not clear the old position. This is because we
...@@ -160,8 +224,8 @@ void DrawSDLLogo(void) ...@@ -160,8 +224,8 @@ void DrawSDLLogo(void)
x = 0; x = 0;
delta_x = -delta_x; delta_x = -delta_x;
} else } else
if ( (x+image->w) > screen->w ) { if ( (x+w) > screen->w ) {
x = screen->w-image->w; x = screen->w-w;
delta_x = -delta_x; delta_x = -delta_x;
} }
y += delta_y; y += delta_y;
...@@ -169,13 +233,27 @@ void DrawSDLLogo(void) ...@@ -169,13 +233,27 @@ void DrawSDLLogo(void)
y = 0; y = 0;
delta_y = -delta_y; delta_y = -delta_y;
} else } else
if ( (y+image->h) > screen->h ) { if ( (y+h) > screen->h ) {
y = screen->h-image->h; y = screen->h-h;
delta_y = -delta_y; delta_y = -delta_y;
} }
SDL_BlitSurface(image, NULL, screen, &dst); if ( USE_DEPRECATED_OPENGLBLIT ) {
SDL_BlitSurface(image, NULL, screen, &dst);
} else {
SDL_GL_Enter2DMode();
glBindTexture(GL_TEXTURE_2D, texture);
glBegin(GL_TRIANGLE_STRIP);
glTexCoord2f(0.0, 0.0); glVertex2i(x, y );
glTexCoord2f(1.0, 0.0); glVertex2i(x+w, y );
glTexCoord2f(0.0, 1.0); glVertex2i(x, y+h);
glTexCoord2f(1.0, 1.0); glVertex2i(x+w, y+h);
glEnd();
SDL_GL_Leave2DMode();
}
}
if ( USE_DEPRECATED_OPENGLBLIT ) {
SDL_UpdateRects(screen, 1, &dst);
} }
SDL_UpdateRects(screen, 1, &dst);
} }
int RunGLTest( int argc, char* argv[], int RunGLTest( int argc, char* argv[],
...@@ -222,7 +300,7 @@ int RunGLTest( int argc, char* argv[], ...@@ -222,7 +300,7 @@ int RunGLTest( int argc, char* argv[],
} }
/* Set the flags we want to use for setting the video mode */ /* Set the flags we want to use for setting the video mode */
if ( logo ) { if ( logo && USE_DEPRECATED_OPENGLBLIT ) {
video_flags = SDL_OPENGLBLIT; video_flags = SDL_OPENGLBLIT;
} else { } else {
video_flags = SDL_OPENGL; video_flags = SDL_OPENGL;
...@@ -478,6 +556,11 @@ int main(int argc, char *argv[]) ...@@ -478,6 +556,11 @@ int main(int argc, char *argv[])
} }
if ( strcmp(argv[i], "-logo") == 0 ) { if ( strcmp(argv[i], "-logo") == 0 ) {
logo = 1; logo = 1;
USE_DEPRECATED_OPENGLBLIT = SDL_FALSE;
}
if ( strcmp(argv[i], "-logoblit") == 0 ) {
logo = 1;
USE_DEPRECATED_OPENGLBLIT = SDL_TRUE;
} }
if ( strcmp(argv[i], "-slow") == 0 ) { if ( strcmp(argv[i], "-slow") == 0 ) {
slowly = 1; slowly = 1;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment