Converted graphics to use OpenGL.

This commit is contained in:
Rob Pearce 2016-07-24 18:27:15 +12:00
parent 02854f09b3
commit 39f85d7e89
8 changed files with 493 additions and 624 deletions

View File

@ -3,10 +3,10 @@ LIBS = libs/libSDL-1.2.0.dylib libs/libSDL_image-1.2.0.dylib libs/libSDL_mixer-1
all: rc edit all: rc edit
rc: rc.c shared.c rc.h shared.h globals.h defs.h rc: rc.c shared.c rc.h shared.h globals.h defs.h
gcc -Wall -DREV=\"`git rev-parse HEAD`\" -o rc -g rc.c shared.c `sdl-config --cflags --libs` -lsqlite3 -lSDLmain -lSDL -lSDL_image -lSDL_gfx -lSDL_ttf -lSDL_Mixer gcc -Wall -DOPENGL -DREV=\"`git rev-parse HEAD`\" -o rc -g rc.c shared.c `sdl-config --cflags --libs` -lsqlite3 -lSDLmain -lSDL -lSDL_image -lSDL_gfx -lSDL_ttf -lSDL_Mixer -framework OpenGL
edit: edit.c shared.c edit.h shared.h globals.h defs.h edit: edit.c shared.c edit.h shared.h globals.h defs.h
gcc -DREV=\"`git rev-parse HEAD`\" -D__EDITOR -Wall -o edit -g edit.c shared.c `sdl-config --cflags --libs` -lSDLmain -lSDL -lSDL_image -lSDL_gfx -lSDL_ttf gcc -DOPENGL -DREV=\"`git rev-parse HEAD`\" -D__EDITOR -Wall -o edit -g edit.c shared.c `sdl-config --cflags --libs` -lSDLmain -lSDL -lSDL_image -lSDL_gfx -lSDL_ttf -framework OpenGL
app: rc app: rc
if [ `uname -s` != "Darwin" ]; then echo "Mac .app bundle generation is only available under OSX."; exit 1; fi; if [ `uname -s` != "Darwin" ]; then echo "Mac .app bundle generation is only available under OSX."; exit 1; fi;

14
defs.h
View File

@ -8,6 +8,13 @@
#define FILE_TILEDEFS "tiledefs.dat" #define FILE_TILEDEFS "tiledefs.dat"
#define DIR_LEVELS "levels" #define DIR_LEVELS "levels"
// sizes
#define SCREENW 640
#define SCREENH 480
#define B_CLEAR -1
#define B_NOCLEAR 0
/* Macros */ /* Macros */
//#define OPENGL //#define OPENGL
@ -1165,6 +1172,13 @@ typedef struct imageset_s {
} imageset_t; } imageset_t;
imageset_t imageset[MAXPTYPES]; imageset_t imageset[MAXPTYPES];
typedef struct levscrollinfo_s {
int dstx[2],dsty[2],xdis[2],ydis[2];
double pspeed[2];
sprite_t *player, *player2;
sprite_t *cloud, *cloud2;
} levscrollinfo_t;
/* external globals */ /* external globals */
extern char progname[]; extern char progname[];
extern SDL_Color black; extern SDL_Color black;

4
edit.c
View File

@ -232,7 +232,7 @@ int main (int argc, char **argv) {
draweditorlevel(); draweditorlevel();
drawpalette(); drawpalette();
drawsprites(); drawsprites();
flip(); flip(B_TRUE);
timer = 0; timer = 0;
@ -743,7 +743,7 @@ int main (int argc, char **argv) {
} }
flip(); flip(B_TRUE);
if (++timer == 100) timer = 0; if (++timer == 100) timer = 0;
if (toggletimer > 0) toggletimer--; if (toggletimer > 0) toggletimer--;

965
rc.c

File diff suppressed because it is too large Load Diff

7
rc.h
View File

@ -76,6 +76,7 @@ int getmonjumpspeed(sprite_t *s);
int getjumpdelay(int mid); int getjumpdelay(int mid);
void togglepause(void); void togglepause(void);
void togglefullscreen(void); void togglefullscreen(void);
void initgl(void);
void initsdl(void); void initsdl(void);
void getfruit(sprite_t *giveto, sprite_t *fruit, int multiplier); void getfruit(sprite_t *giveto, sprite_t *fruit, int multiplier);
int haspowerup(sprite_t *s, int pid); int haspowerup(sprite_t *s, int pid);
@ -87,6 +88,12 @@ char *getpokermsg(int effect);
char *getpokermsg2(int effect, char *buf); char *getpokermsg2(int effect, char *buf);
void handleinput(void); void handleinput(void);
int keydown(int whichplayer, int checkfor); int keydown(int whichplayer, int checkfor);
void leveltransition_blit(levscrollinfo_t *l, SDL_Surface *copybuffer);
void leveltransition_moveplayer(levscrollinfo_t *l);
void leveltransition_scrolllevel(int srcx, int srcy, int srcw, int srch,
int dstx, int dsty, int dstw, int dsth,
int nextcolx, int nextcoly, int nextcolw, int nextcolh,
int nextcol_dstx, int nextcol_dsty, int nextcol_dstw, int nextcol_dsth);
void trytojump(sprite_t *pl); void trytojump(sprite_t *pl);
void trytoslam(sprite_t *pl); void trytoslam(sprite_t *pl);
void trytoshoot(sprite_t *pl); void trytoshoot(sprite_t *pl);

View File

@ -14,6 +14,9 @@
#include <SDL_rotozoom.h> #include <SDL_rotozoom.h>
#include <SDL_ttf.h> #include <SDL_ttf.h>
#include <SDL_framerate.h> #include <SDL_framerate.h>
#ifdef OPENGL
#include <SDL_opengl.h>
#endif
#include "defs.h" #include "defs.h"
#include "globals.h" #include "globals.h"
@ -25,6 +28,83 @@ extern int nfadingtiles;
extern SDL_Surface *temptilesurf; extern SDL_Surface *temptilesurf;
#endif #endif
#ifdef OPENGL
extern SDL_Surface *realscreen;
GLuint tex = -1; // texture which is created based on realscreen.
float texw = 0,texh = 0;
GLint sampleBuffers, samples;
#endif
void blittoscreen(void) {
GLfloat texcoords[8];
GLfloat vertices[8];
// clear screen first
glClearColor( 0, 0, 0, 1.0);
glClear( GL_COLOR_BUFFER_BIT );
// Bind the texture to which subsequent calls refer to
glBindTexture( GL_TEXTURE_2D, tex );
// translate to move to specified spot
//
glLoadIdentity();
glRotatef(0, 1.0, 0, 0);
glTranslatef( texw/2, texh/2, 0);
texcoords[0] = 0; texcoords[1] = 0;
texcoords[2] = 0; texcoords[3] = 1.0;
texcoords[4] = 1.0; texcoords[5] = 1.0;
texcoords[6] = 1.0; texcoords[7] = 0;
vertices[0] = -texw/2; vertices[1] = -texh/2;
vertices[2] = -texw/2; vertices[3] = texh/2;
vertices[4] = texw/2; vertices[5] = texh/2;
vertices[6] = texw/2; vertices[7] = -texh/2;
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glVertexPointer(2, GL_FLOAT, 0, vertices);
glTexCoordPointer(2, GL_FLOAT, 0, texcoords);
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glLoadIdentity();
// unbind
glBindTexture( GL_TEXTURE_2D, 0);
// override
//glClearColor( 0, 0, 1.0, 1.0);
//glClear( GL_COLOR_BUFFER_BIT );
SDL_GL_SwapBuffers();
}
void gengl(SDL_Surface *surf) {
int ncol;
GLenum texform;
ncol = surf->format->BytesPerPixel;
glTexEnvi(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_COMBINE);
// del old texture
glDeleteTextures( 1, &tex );
// Have OpenGL generate a texture object handle for us
glGenTextures( 1, &tex );
// Bind the texture object
glBindTexture( GL_TEXTURE_2D, tex );
// Set the texture's stretching properties
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
// remember w/h
texw = surf->w;
texh = surf->h;
ncol = 4;
texform = GL_RGBA;
glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, texw, texh, 0, texform, GL_UNSIGNED_BYTE, surf->pixels );
}
int loadlevel(int lnum, int wantmonsters) { int loadlevel(int lnum, int wantmonsters) {
FILE *f; FILE *f;
int x,y; int x,y;
@ -2760,7 +2840,6 @@ void drawsprite(sprite_t *s) {
// draw it // draw it
doblit(s->iceimg, screen, &area); doblit(s->iceimg, screen, &area);
//SDL_BlitSurface(s->iceimg, NULL, screen, &area); //SDL_BlitSurface(s->iceimg, NULL, screen, &area);
} }
// anchor // anchor
@ -2790,8 +2869,6 @@ void drawsprite(sprite_t *s) {
s->caughtby->x,s->caughtby->y-(s->caughtby->img->h/2), *col1,*col2); s->caughtby->x,s->caughtby->y-(s->caughtby->img->h/2), *col1,*col2);
} }
} }
} }
@ -2871,10 +2948,13 @@ void killsprite(sprite_t *s) {
} }
void flip(void) { void flip(int wantclear) {
#ifdef OPENGL #ifdef OPENGL
SDL_UpdateRect(screen,0,0,screen->w,screen->h); gengl(screen);
SDL_GL_SwapBuffers(); blittoscreen();
if (wantclear) {
SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, black.r, black.g, black.b));
}
#else #else
SDL_Flip(screen); SDL_Flip(screen);
#endif #endif

View File

@ -5,6 +5,8 @@
#include "defs.h" #include "defs.h"
/* functions */ /* functions */
void blittoscreen(void);
void gengl(SDL_Surface *surf);
int loadlevel(int lnum, int wantmonsters); int loadlevel(int lnum, int wantmonsters);
void setdefaults(sprite_t *s); void setdefaults(sprite_t *s);
int loadtiletypes(char *filename); int loadtiletypes(char *filename);
@ -13,7 +15,7 @@ tiletype_t *gettileat(int pixx,int pixy, int *tilex, int *tiley);
tiletype_t *gettilexy(int tilex,int tiley); tiletype_t *gettilexy(int tilex,int tiley);
int loadimagesets(void); int loadimagesets(void);
int isbullet(int id); int isbullet(int id);
void flip(void); void flip(int wantclear);
void killsprite(sprite_t *s); void killsprite(sprite_t *s);
void drawsprite(sprite_t *s); void drawsprite(sprite_t *s);
int gettileframecount(int tid); int gettileframecount(int tid);

23
todo Normal file
View File

@ -0,0 +1,23 @@
- On spike school, allow 40 more seconds before hurryup.
- Convert to openGL so it will run properly in non-fullsecreen mode.
*initial conversion
cloud isn't being cleared properly during level transition
- get it working not super slow while in non-fullscreen mode.
might have to convert to opengl.
- Draw graphics for between-level sequences.
- draw and scan ?
- had a plan for this somewhere, i think in an old omnioutliner doc
- Compose original music tracks.
- Review difficulty curve over all levels.
1-5 little room in the middle is a bit tricky for level 5
although the rest of the level is pretty easy.
maybe move it slightly later