summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDusan Durech <dusan@debian.debian>2009-04-14 21:04:13 +0200
committerDusan Durech <dusan@debian.debian>2009-04-14 21:04:13 +0200
commit6173c73b0322057589c498fc31dbf1d0876e6fe3 (patch)
treee8d4da058f791637e6b4eec08c10bd3e90ee7737 /src
parentbaeb3552f84ba0a930289ce2a6446fa70f2ef70c (diff)
support disable openGL ( --disable-opengl )
Diffstat (limited to 'src')
-rw-r--r--src/client/image.c58
-rw-r--r--src/client/image.h1
-rw-r--r--src/client/interface.c51
-rw-r--r--src/client/interface.h1
4 files changed, 91 insertions, 20 deletions
diff --git a/src/client/image.c b/src/client/image.c
index bbff3cb..fa34760 100644
--- a/src/client/image.c
+++ b/src/client/image.c
@@ -64,8 +64,7 @@ static SDL_Surface *loadImage(const char *filename, int alpha)
}
-#ifndef SUPPORT_OPENGL
-image_t *image_new(SDL_Surface * surface)
+image_t *image_new_sdl(SDL_Surface * surface)
{
image_t *new;
@@ -78,7 +77,6 @@ image_t *image_new(SDL_Surface * surface)
return new;
}
-#endif
#ifdef SUPPORT_OPENGL
/*
@@ -100,7 +98,7 @@ unsigned int closestpoweroftwo(unsigned int i)
* surface is not needed for image_t after execution of image_new
*/
-image_t* image_new(SDL_Surface *surface)
+image_t* image_new_opengl(SDL_Surface *surface)
{
image_t *new;
Uint32 rmask, gmask, bmask, amask;
@@ -151,6 +149,24 @@ image_t* image_new(SDL_Surface *surface)
}
#endif
+image_t* image_new(SDL_Surface *surface)
+{
+#ifdef SUPPORT_OPENGL
+ if( interface_is_use_open_gl() )
+ {
+ return image_new_opengl(surface);
+ }
+ else
+ {
+ return image_new_sdl(surface);
+ }
+#endif
+
+#ifndef SUPPORT_OPENGL
+ return image_new_sdl(surface);
+#endif
+}
+
void image_destroy(image_t * p)
{
assert(p != NULL);
@@ -160,7 +176,14 @@ void image_destroy(image_t * p)
#endif
#ifdef SUPPORT_OPENGL
- glDeleteTextures(1, &p->tex_id);
+ if( interface_is_use_open_gl() )
+ {
+ glDeleteTextures(1, &p->tex_id);
+ }
+ else
+ {
+ SDL_FreeSurface((SDL_Surface *) p->image);
+ }
#endif
free(p);
@@ -218,8 +241,7 @@ void image_del_all_image_in_group(char *group)
storage_del_all(listStorage, group, image_destroy);
}
-#ifndef SUPPORT_OPENGL
-void image_draw(image_t * p, int x, int y, int px, int py, int w, int h)
+void image_draw_sdl(image_t * p, int x, int y, int px, int py, int w, int h)
{
static SDL_Surface *screen = NULL;
SDL_Rect dst_rect, src_rect;
@@ -238,13 +260,13 @@ void image_draw(image_t * p, int x, int y, int px, int py, int w, int h)
SDL_BlitSurface(p->image, &src_rect, screen, &dst_rect);
}
-#endif
+
#ifdef SUPPORT_OPENGL
/*
* Draws image on screen at [x,y], with width w and height h, top-left corner on image is at [px,py]
*/
-void image_draw(image_t *image, int x,int y, int px, int py, int w, int h)
+void image_draw_opengl(image_t *image, int x,int y, int px, int py, int w, int h)
{
/* x -coordinate of left border xx- coordinate of right border,
* y -coordinate of top border yy- coordinate of bottom border,
@@ -288,6 +310,24 @@ void image_draw(image_t *image, int x,int y, int px, int py, int w, int h)
}
#endif
+void image_draw(image_t *image, int x,int y, int px, int py, int w, int h)
+{
+#ifdef SUPPORT_OPENGL
+ if( interface_is_use_open_gl() )
+ {
+ image_draw_opengl(image, x, y, px, py, w, h);
+ }
+ else
+ {
+ image_draw_sdl(image, x, y, px, py, w, h);
+ }
+#endif
+
+#ifndef SUPPORT_OPENGL
+ image_draw_sdl(image, x, y, px, py, w, h);
+#endif
+}
+
/*
* Odstrani zoznam obrazkov z pamate
*/
diff --git a/src/client/image.h b/src/client/image.h
index b6347db..352654a 100644
--- a/src/client/image.h
+++ b/src/client/image.h
@@ -40,6 +40,7 @@ typedef struct image_struct
{
int w; // width of actual picture
int h; // height of actual picture
+ SDL_Surface *image;
GLuint tw; // width of allocated texture
GLuint th; // height of allocated texture
GLuint tex_id; // texture id
diff --git a/src/client/interface.c b/src/client/interface.c
index a3fb535..ab374b5 100644
--- a/src/client/interface.c
+++ b/src/client/interface.c
@@ -17,18 +17,18 @@ static SDL_Surface *screen;
static SDL_TimerID timer;
// window flags
-#ifndef SUPPORT_OPENGL
-static Uint32 g_win_flags = SDL_HWSURFACE | SDL_DOUBLEBUF | SDL_ANYFORMAT;
-#endif
-
-#ifdef SUPPORT_OPENGL
-static Uint32 g_win_flags = SDL_OPENGL;
-#endif
+static Uint32 g_win_flags;
static bool_t isInterfaceInit = FALSE;
// flag, kterym se ridi zarazovani klaves do bufferu
static bool_t keyboardBufferEnabled = FALSE;
+static bool_t use_open_gl;
+
+bool_t interface_is_use_open_gl()
+{
+ return use_open_gl;
+}
bool_t interface_is_inicialized()
{
@@ -124,21 +124,43 @@ int interface_init()
#endif
// initialization of SDL
if (SDL_Init(SDL_SUBSYSTEMS) == -1) {
- fprintf(stderr, "%s\n", SDL_GetError());
+ fprintf(stderr, "SDL_Init %s\n", SDL_GetError());
SDL_Quit();
return -1;
}
#ifndef SUPPORT_OPENGL
+ use_open_gl = FALSE;
+ g_win_flags = SDL_HWSURFACE | SDL_DOUBLEBUF | SDL_ANYFORMAT;
+
screen = SDL_SetVideoMode(WINDOW_SIZE_X, WINDOW_SIZE_Y, 0, g_win_flags);
#endif
#ifdef SUPPORT_OPENGL
- screen = SetVideoMode(WINDOW_SIZE_X, WINDOW_SIZE_Y, 0, g_win_flags);
+ use_open_gl = ! isParamFlag("--disable-opengl");
+
+ if( interface_is_use_open_gl() )
+ {
+ g_win_flags = SDL_OPENGL;
+ screen = SetVideoMode(WINDOW_SIZE_X, WINDOW_SIZE_Y, 0, g_win_flags);
+
+ if( screen == NULL )
+ {
+ use_open_gl = FALSE;
+ g_win_flags = SDL_HWSURFACE | SDL_DOUBLEBUF | SDL_ANYFORMAT;
+
+ screen = SDL_SetVideoMode(WINDOW_SIZE_X, WINDOW_SIZE_Y, 0, g_win_flags);
+ }
+ }
+ else
+ {
+ g_win_flags = SDL_HWSURFACE | SDL_DOUBLEBUF | SDL_ANYFORMAT;
+ screen = SDL_SetVideoMode(WINDOW_SIZE_X, WINDOW_SIZE_Y, 0, g_win_flags);
+ }
#endif
if (screen == NULL) {
- fprintf(stderr, "%s\n", SDL_GetError());
+ fprintf(stderr, "SDL_SetVideoMode %s\n", SDL_GetError());
SDL_Quit();
return -1;
}
@@ -175,7 +197,14 @@ void interface_refresh()
#endif
#ifdef SUPPORT_OPENGL
- SDL_GL_SwapBuffers();
+ if( interface_is_use_open_gl() )
+ {
+ SDL_GL_SwapBuffers();
+ }
+ else
+ {
+ SDL_Flip(screen);
+ }
#endif
}
diff --git a/src/client/interface.h b/src/client/interface.h
index d6b2715..304e29c 100644
--- a/src/client/interface.h
+++ b/src/client/interface.h
@@ -34,6 +34,7 @@
# define KEYBOARD_BUFFER_SIZE 256
extern bool_t interface_is_inicialized();
+extern bool_t interface_is_use_open_gl();
extern void interface_enable_keyboard_buffer();
extern void interface_disable_keyboard_buffer();
extern int interface_init();