break;
case CO_BADGUY:
pbad_c = p_c_object;
- if (pbad->mode != KICK)
+ if (pbad->mode != FLAT)
pbad->dir = !pbad->dir;
else
{
}
else if (pbad->kind == BAD_LAPTOP)
{
- if (pbad->mode != FLAT)
+ if (pbad->mode != KICK)
{
/* Flatten! */
{
/* We have detected a collision and now call the collision functions of the collided objects. */
badguy_collision(&bad_guys[j], &bad_guys[i], CO_BADGUY);
- }
+ badguy_collision(&bad_guys[i], &bad_guys[j], CO_BADGUY);
+ }
}
}
}
/* Load sprite images: */
-
texture_load(&bkgd, DATA_PREFIX "/images/intro/intro.png", IGNORE_ALPHA);
texture_load(&gown_sit, DATA_PREFIX "/images/intro/gown-sit.png", USE_ALPHA);
texture_load(&gown_lookup, DATA_PREFIX "/images/intro/gown-lookup.png", USE_ALPHA);
{
int xx, yy;
- yy = (y / 32);
- xx = (x / 32);
+ yy = ((int)y / 32);
+ xx = ((int)x / 32);
if (yy >= 0 && yy < 15 && xx >= 0 && xx <= plevel->width)
plevel->tiles[yy][xx] = c;
}
if (distro_counter <= 0)
- level_change(¤t_level,pplayer->base.x, pplayer->base.y, 'a');
+ level_change(¤t_level,pplayer->base.x,pplayer->base.y, 'a');
play_sound(sounds[SND_DISTRO], SOUND_CENTER_SPEAKER);
score = score + SCORE_DISTRO;
void clearscreen(float r, float g, float b)
{
+#ifndef NOOPENGL
if(use_gl)
{
glClearColor(r/256, g/256, b/256, 1.0);
glClear(GL_COLOR_BUFFER_BIT);
}
else
+#endif
SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, r, g, b));
}
return(surf);
}
-void create_gl_texture(SDL_Surface * surf, GLint * tex)
-{
-SDL_Surface *conv;
-conv = SDL_CreateRGBSurface(SDL_SWSURFACE , surf->w, surf->h, 32,
-#if SDL_BYTEORDER == SDL_BIG_ENDIAN
- 0xff000000, 0x00ff0000, 0x0000ff00, 0x000000ff);
-#else
- 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000);
-#endif
- SDL_BlitSurface(surf, 0, conv, 0);
- glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
- glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
-
- glGenTextures(1, &*tex);
-
- glBindTexture(GL_TEXTURE_RECTANGLE_NV , *tex);
- glEnable(GL_TEXTURE_RECTANGLE_NV);
- glTexParameteri(GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
- glPixelStorei(GL_UNPACK_ROW_LENGTH, conv->pitch / conv->format->BytesPerPixel);
- glTexImage2D(GL_TEXTURE_RECTANGLE_NV, 0, 3, conv->w, conv->h, 0, GL_RGBA, GL_UNSIGNED_BYTE, conv->pixels);
- //glCopyTexSubImage2D(GL_TEXTURE_RECTANGLE_NV, 0, 0, 0, 0, 0, conv->w, conv->h);
- glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
- SDL_FreeSurface(conv);
-}
-
-/* --- DRAW AN IMAGE ONTO THE SCREEN --- */
-/*
-void drawimage(SDL_Surface * surf, float x, float y, int update)
-{
-if(use_gl)
-{
-GLint gl_tex;
-create_gl_texture(surf,&gl_tex);
- glColor4ub(255, 255, 255,255);
-glBlendFunc (GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
-glEnable (GL_BLEND);
- glBindTexture(GL_TEXTURE_RECTANGLE_NV, gl_tex);
-
- glBegin(GL_QUADS);
- glTexCoord2f(0, 0); glVertex2f(x, y);
- glTexCoord2f((float)surf->w, 0); glVertex2f((float)surf->w+x, y);
- glTexCoord2f((float)surf->w, (float)surf->h); glVertex2f((float)surf->w+x, (float)surf->h+y);
- glTexCoord2f(0, (float)surf->h); glVertex2f(x, (float)surf->h+y);
- glEnd();
- glDeleteTextures(1, &gl_tex);
- }
-else
-{
- SDL_Rect dest;
-
- dest.x = x;
- dest.y = y;
- dest.w = surf->w;
- dest.h = surf->h;
-
- SDL_BlitSurface(surf, NULL, screen, &dest);
-
- if (update == UPDATE)
- SDL_UpdateRect(screen, dest.x, dest.y, dest.w, dest.h);
-}
-}
-*/
-/*
-drawbgimage(SDL_Surface * surf, int update)
-{
-if(use_gl)
-{
-GLint gl_tex;
-create_gl_texture(surf,&gl_tex);
- //glColor3ub(255, 255, 255);
-
- glEnable(GL_TEXTURE_RECTANGLE_NV);
- glBindTexture(GL_TEXTURE_RECTANGLE_NV, gl_tex);
-
- glBegin(GL_QUADS);
- glTexCoord2f(0, 0); glVertex2f(0, 0);
- glTexCoord2f((float)surf->w, 0); glVertex2f(screen->w, 0);
- glTexCoord2f((float)surf->w, (float)surf->h); glVertex2f(screen->w, screen->h);
- glTexCoord2f(0, (float)surf->h); glVertex2f(0, screen->h);
- glEnd();
- glDeleteTextures(1, &gl_tex);
-
-}
-else
-{
- SDL_Rect dest;
-
- dest.x = 0;
- dest.y = 0;
- dest.w = screen->w;
- dest.h = screen->h;
-
- SDL_BlitSurface(surf, NULL, screen, &dest);
-
- if (update == UPDATE)
- SDL_UpdateRect(screen, dest.x, dest.y, dest.w, dest.h);
-}
-}
-*/
void update_rect(SDL_Surface *scr, Sint32 x, Sint32 y, Sint32 w, Sint32 h)
{
if(!use_gl)
SDL_UpdateRect(scr, x, y, w, h);
}
-
-/* --- DRAW PART OF AN IMAGE ONTO THE SCREEN --- */
-/*
-void drawpart(SDL_Surface * surf, float x, float y, float w, float h, int update)
-{
-if(use_gl)
-{
-GLint gl_tex;
-create_gl_texture(surf,&gl_tex);
- glColor3ub(255, 255, 255);
-
- glEnable(GL_TEXTURE_RECTANGLE_NV);
- glBindTexture(GL_TEXTURE_RECTANGLE_NV, gl_tex);
-
- glBegin(GL_QUADS);
- glTexCoord2f(x, y); glVertex2f(x, y);
- glTexCoord2f(x+w, y); glVertex2f(w+x, y);
- glTexCoord2f(x+w, y+h); glVertex2f(w+x, h+y);
- glTexCoord2f(x, y+h); glVertex2f(x, h+y);
- glEnd();
- glDeleteTextures(1, &gl_tex);
- }
-else
-{
- SDL_Rect src, dest;
-
- src.x = x;
- src.y = y;
- src.w = w;
- src.h = h;
-
- dest.x = x;
- dest.y = y;
- dest.w = w;
- dest.h = h;
-
-
- SDL_BlitSurface(surf, &src, screen, &dest);
-
- if (update == UPDATE)
- update_rect(screen, dest.x, dest.y, dest.w, dest.h);
- }
-}
-*/
-/* --- DRAW TEXT ONTO THE SCREEN --- */
-
void drawtext(char * text, int x, int y, SDL_Surface * surf, int update, int shadowsize)
{
/* i - helps to keep tracking of the all string length
*/
#include <SDL.h>
+#ifndef NOOPENGL
#include <SDL_opengl.h>
-#define NO_UPDATE 0
-#define UPDATE 1
-#define USE_ALPHA 0
-#define IGNORE_ALPHA 1
-
#ifndef GL_NV_texture_rectangle
#define GL_TEXTURE_RECTANGLE_NV 0x84F5
#define GL_TEXTURE_BINDING_RECTANGLE_NV 0x84F6
#define GL_PROXY_TEXTURE_RECTANGLE_NV 0x84F7
#define GL_MAX_RECTANGLE_TEXTURE_SIZE_NV 0x84F8
#endif
+#endif
+
+#define NO_UPDATE 0
+#define UPDATE 1
+#define USE_ALPHA 0
+#define IGNORE_ALPHA 1
void load_and_display_image(char * file);
void clearscreen(float r, float g, float b);
void drawcenteredtext(char * text, int y, SDL_Surface * surf, int update, int shadowsize);
void erasetext(char * text, int x, int y, SDL_Surface * surf, int update, int shadowsize);
void erasecenteredtext(char * text, int y, SDL_Surface * surf, int update, int shadowsize);
-void create_gl_texture(SDL_Surface * surf, GLint * tex);
void update_rect(SDL_Surface *scr, Sint32 x, Sint32 y, Sint32 w, Sint32 h);
#include <unistd.h>
#include <SDL.h>
#include <SDL_image.h>
+#ifndef NOOPENGL
#include <SDL_opengl.h>
+#endif
#ifdef LINUX
#include <pwd.h>
#include "globals.h"
#include "setup.h"
#include "screen.h"
+#include "texture.h"
/* Local function prototypes: */
else
st_video_setup_sdl();
+ DEBUG_MSG("1");
+
+ texture_setup();
+
+ DEBUG_MSG("2");
+
/* Set window manager stuff: */
SDL_WM_SetCaption("Super Tux", "Super Tux");
void st_video_setup_gl(void)
{
+#ifndef NOOPENGL
SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5);
SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0.0f, 0.0f, 0.0f);
+
+#endif
}
void st_joystick_setup(void)
{
int i;
-
/* Set defaults: */
+
debug_mode = NO;
use_fullscreen = NO;
+
+ use_gl = NO;
+
#ifndef NOSOUND
use_sound = YES;
else if (strcmp(argv[i], "--opengl") == 0 ||
strcmp(argv[i], "-g") == 0)
{
- /* Use full screen: */
+ #ifndef NOOPENGL
+ /* Use OpengGL: */
use_gl = YES;
+ #endif
}
else if (strcmp(argv[i], "--usage") == 0)
{
printf("---------- Command-line options ----------\n\n");
+ printf(" --opengl - If opengl support was compiled in, this will enable the EXPERIMENTAL OpenGL mode.\n\n");
+
printf(" --disable-sound - If sound support was compiled in, this will\n disable sound for this session of the game.\n\n");
printf(" --disable-music - Like above, but this will disable music.\n\n");
/* Display the usage message: */
- fprintf(fi, "Usage: %s [--fullscreen] [--disable-sound] [--disable-music] [--debug-mode] | [--usage | --help | --version]\n",
+ fprintf(fi, "Usage: %s [--fullscreen] [--opengl] [--disable-sound] [--disable-music] [--debug-mode] | [--usage | --help | --version]\n",
prog);
#include <SDL/SDL.h>
#include <SDL/SDL_image.h>
-#include <SDL/SDL_opengl.h>
#include "globals.h"
#include "screen.h"
#include "setup.h"
#include "texture.h"
-void texture_load(texture_type* ptexture, char * file, int use_alpha)
+void texture_setup(void)
+{
+#ifdef NOOPENGL
+texture_load = texture_load_sdl;
+texture_free = texture_free_sdl;
+texture_draw = texture_draw_sdl;
+texture_draw_bg = texture_draw_bg_sdl;
+texture_draw_part = texture_draw_part_sdl;
+#else
+if(use_gl)
+{
+texture_load = texture_load_gl;
+texture_free = texture_free_gl;
+texture_draw = texture_draw_gl;
+texture_draw_bg = texture_draw_bg_gl;
+texture_draw_part = texture_draw_part_gl;
+}
+else
+{
+texture_load = texture_load_sdl;
+texture_free = texture_free_sdl;
+texture_draw = texture_draw_sdl;
+texture_draw_bg = texture_draw_bg_sdl;
+texture_draw_part = texture_draw_part_sdl;
+}
+#endif
+}
+
+#ifndef NOOPENGL
+void texture_load_gl(texture_type* ptexture, char * file, int use_alpha)
+{
+texture_load_sdl(ptexture,file,use_alpha);
+texture_create_gl(ptexture->sdl_surface,&ptexture->gl_texture);
+}
+
+void texture_draw_gl(texture_type* ptexture, float x, float y, int update)
+{
+ glColor4ub(255, 255, 255,255);
+ glBlendFunc (GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
+ glEnable (GL_BLEND);
+ glBindTexture(GL_TEXTURE_RECTANGLE_NV, ptexture->gl_texture);
+
+ glBegin(GL_QUADS);
+ glTexCoord2f(0, 0);
+ glVertex2f(x, y);
+ glTexCoord2f((float)ptexture->w, 0);
+ glVertex2f((float)ptexture->w+x, y);
+ glTexCoord2f((float)ptexture->w, (float)ptexture->h);
+ glVertex2f((float)ptexture->w+x, (float)ptexture->h+y);
+ glTexCoord2f(0, (float)ptexture->h);
+ glVertex2f(x, (float)ptexture->h+y);
+ glEnd();
+}
+
+void texture_draw_bg_gl(texture_type* ptexture, int update)
+{
+ //glColor3ub(255, 255, 255);
+
+ glEnable(GL_TEXTURE_RECTANGLE_NV);
+ glBindTexture(GL_TEXTURE_RECTANGLE_NV, ptexture->gl_texture);
+
+ glBegin(GL_QUADS);
+ glTexCoord2f(0, 0); glVertex2f(0, 0);
+ glTexCoord2f((float)ptexture->w, 0); glVertex2f(screen->w, 0);
+ glTexCoord2f((float)ptexture->w, (float)ptexture->h); glVertex2f(screen->w, screen->h);
+ glTexCoord2f(0, (float)ptexture->h); glVertex2f(0, screen->h);
+ glEnd();
+}
+
+void texture_draw_part_gl(texture_type* ptexture, float x, float y, float w, float h, int update)
+{
+ glColor3ub(255, 255, 255);
+
+ glEnable(GL_TEXTURE_RECTANGLE_NV);
+ glBindTexture(GL_TEXTURE_RECTANGLE_NV, ptexture->gl_texture);
+
+ glBegin(GL_QUADS);
+ glTexCoord2f(x, y);
+ glVertex2f(x, y);
+ glTexCoord2f(x+w, y);
+ glVertex2f(w+x, y);
+ glTexCoord2f(x+w, y+h);
+ glVertex2f(w+x, h+y);
+ glTexCoord2f(x, y+h);
+ glVertex2f(x, h+y);
+ glEnd();
+}
+
+void texture_create_gl(SDL_Surface * surf, GLint * tex)
+{
+SDL_Surface *conv;
+conv = SDL_CreateRGBSurface(SDL_SWSURFACE , surf->w, surf->h, 32,
+#if SDL_BYTEORDER == SDL_BIG_ENDIAN
+ 0xff000000, 0x00ff0000, 0x0000ff00, 0x000000ff);
+#else
+ 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000);
+#endif
+ SDL_BlitSurface(surf, 0, conv, 0);
+ glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
+ glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
+
+ glGenTextures(1, &*tex);
+
+ glBindTexture(GL_TEXTURE_RECTANGLE_NV , *tex);
+ glEnable(GL_TEXTURE_RECTANGLE_NV);
+ glTexParameteri(GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+ glTexParameteri(GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+ glPixelStorei(GL_UNPACK_ROW_LENGTH, conv->pitch / conv->format->BytesPerPixel);
+ glTexImage2D(GL_TEXTURE_RECTANGLE_NV, 0, 3, conv->w, conv->h, 0, GL_RGBA, GL_UNSIGNED_BYTE, conv->pixels);
+ //glCopyTexSubImage2D(GL_TEXTURE_RECTANGLE_NV, 0, 0, 0, 0, 0, conv->w, conv->h);
+ glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
+ SDL_FreeSurface(conv);
+}
+
+void texture_free_gl(texture_type* ptexture)
+{
+ SDL_FreeSurface(ptexture->sdl_surface);
+ glDeleteTextures(1, &ptexture->gl_texture);
+}
+#endif
+
+void texture_load_sdl(texture_type* ptexture, char * file, int use_alpha)
{
SDL_Surface * temp;
ptexture->w = ptexture->sdl_surface->w;
ptexture->h = ptexture->sdl_surface->h;
- if(use_gl)
- {
- create_gl_texture(ptexture->sdl_surface,&ptexture->gl_texture);
- }
}
void texture_from_sdl_surface(texture_type* ptexture, SDL_Surface* sdl_surf, int use_alpha)
{
+
/* SDL_Surface * temp;
temp = IMG_Load(file);
ptexture->w = ptexture->sdl_surface->w;
ptexture->h = ptexture->sdl_surface->h;
+ #ifndef NOOPENGL
if(use_gl)
{
- create_gl_texture(ptexture->sdl_surface,&ptexture->gl_texture);
+ texture_create_gl(ptexture->sdl_surface,&ptexture->gl_texture);
}
+ #endif
}
-void texture_draw(texture_type* ptexture, float x, float y, int update)
+void texture_draw_sdl(texture_type* ptexture, float x, float y, int update)
{
- if(use_gl)
- {
- glColor4ub(255, 255, 255,255);
- glBlendFunc (GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
- glEnable (GL_BLEND);
- glBindTexture(GL_TEXTURE_RECTANGLE_NV, ptexture->gl_texture);
-
- glBegin(GL_QUADS);
- glTexCoord2f(0, 0);
- glVertex2f(x, y);
- glTexCoord2f((float)ptexture->w, 0);
- glVertex2f((float)ptexture->w+x, y);
- glTexCoord2f((float)ptexture->w, (float)ptexture->h);
- glVertex2f((float)ptexture->w+x, (float)ptexture->h+y);
- glTexCoord2f(0, (float)ptexture->h);
- glVertex2f(x, (float)ptexture->h+y);
- glEnd();
- }
- else
- {
SDL_Rect dest;
dest.x = x;
if (update == UPDATE)
SDL_UpdateRect(screen, dest.x, dest.y, dest.w, dest.h);
- }
}
-void texture_draw_bg(texture_type* ptexture, int update)
-{
-if(use_gl)
-{
- //glColor3ub(255, 255, 255);
- glEnable(GL_TEXTURE_RECTANGLE_NV);
- glBindTexture(GL_TEXTURE_RECTANGLE_NV, ptexture->gl_texture);
-
- glBegin(GL_QUADS);
- glTexCoord2f(0, 0); glVertex2f(0, 0);
- glTexCoord2f((float)ptexture->w, 0); glVertex2f(screen->w, 0);
- glTexCoord2f((float)ptexture->w, (float)ptexture->h); glVertex2f(screen->w, screen->h);
- glTexCoord2f(0, (float)ptexture->h); glVertex2f(0, screen->h);
- glEnd();
-
-}
-else
+void texture_draw_bg_sdl(texture_type* ptexture, int update)
{
SDL_Rect dest;
if (update == UPDATE)
SDL_UpdateRect(screen, dest.x, dest.y, dest.w, dest.h);
}
-}
-void texture_draw_part(texture_type* ptexture, float x, float y, float w, float h, int update)
+void texture_draw_part_sdl(texture_type* ptexture, float x, float y, float w, float h, int update)
{
- if(use_gl)
- {
- glColor3ub(255, 255, 255);
-
- glEnable(GL_TEXTURE_RECTANGLE_NV);
- glBindTexture(GL_TEXTURE_RECTANGLE_NV, ptexture->gl_texture);
-
- glBegin(GL_QUADS);
- glTexCoord2f(x, y);
- glVertex2f(x, y);
- glTexCoord2f(x+w, y);
- glVertex2f(w+x, y);
- glTexCoord2f(x+w, y+h);
- glVertex2f(w+x, h+y);
- glTexCoord2f(x, y+h);
- glVertex2f(x, h+y);
- glEnd();
- }
- else
- {
SDL_Rect src, dest;
src.x = x;
if (update == UPDATE)
update_rect(screen, dest.x, dest.y, dest.w, dest.h);
- }
}
-void texture_free(texture_type* ptexture)
+void texture_free_sdl(texture_type* ptexture)
{
SDL_FreeSurface(ptexture->sdl_surface);
- if(use_gl)
- glDeleteTextures(1, &ptexture->gl_texture);
}
#ifndef SUPERTUX_TEXTURE_H
#define SUPERTUX_TEXTURE_H
+#include <SDL/SDL.h>
+#ifndef NOOPENGL
+#include <SDL/SDL_opengl.h>
+#endif
+
/* Texture type */
typedef struct texture_type
{
}
texture_type;
-void texture_setup(int opengl);
-void texture_load(texture_type* ptexture, char * file, int use_alpha);
+void texture_setup(void);
+void (*texture_load) (texture_type* ptexture, char * file, int use_alpha);
+void (*texture_free) (texture_type* ptexture);
+void (*texture_draw) (texture_type* ptexture, float x, float y, int update);
+void (*texture_draw_bg) (texture_type* ptexture, int update);
+void (*texture_draw_part) (texture_type* ptexture, float x, float y, float w, float h, int update);
+void texture_load_sdl(texture_type* ptexture, char * file, int use_alpha);
+void texture_free_sdl(texture_type* ptexture);
+void texture_draw_sdl(texture_type* ptexture, float x, float y, int update);
+void texture_draw_bg_sdl(texture_type* ptexture, int update);
+void texture_draw_part_sdl(texture_type* ptexture, float x, float y, float w, float h, int update);
void texture_from_sdl_surface(texture_type* ptexture, SDL_Surface * sdl_surf, int use_alpha);
-void texture_free(texture_type* ptexture);
-void texture_draw(texture_type* ptexture, float x, float y, int update);
-void texture_draw_bg(texture_type* ptexture, int update);
-void texture_draw_part(texture_type* ptexture, float x, float y, float w, float h, int update);
+#ifndef NOOPENGL
+void texture_load_gl(texture_type* ptexture, char * file, int use_alpha);
+void texture_free_gl(texture_type* ptexture);
+void texture_draw_gl(texture_type* ptexture, float x, float y, int update);
+void texture_draw_bg_gl(texture_type* ptexture, int update);
+void texture_draw_part_gl(texture_type* ptexture, float x, float y, float w, float h, int update);
+void texture_create_gl(SDL_Surface * surf, GLint * tex);
+#endif
#endif /*SUPERTUX_TEXTURE_H*/