Replace BMP image file loading with PNG image file loading
69
GameEnts.c
@@ -458,68 +458,69 @@ void GameEnts_Init(){
|
|||||||
// Load and initialize media.
|
// Load and initialize media.
|
||||||
//
|
//
|
||||||
|
|
||||||
img_player=Draw_LoadImage("data/player.bmp");
|
img_player=Draw_LoadImage("data/player.png");
|
||||||
img_platform=Draw_LoadImage("data/platform.bmp");
|
img_platform=Draw_LoadImage("data/platform.png");
|
||||||
img_block=Draw_LoadImage("data/block.bmp");
|
img_block=Draw_LoadImage("data/block.png");
|
||||||
|
|
||||||
// Wizard
|
// Wizard
|
||||||
img_wizard[0]=Draw_LoadImage("data/wizard_left.bmp");
|
img_wizard[0]=Draw_LoadImage("data/wizard_left.png");
|
||||||
img_wizard[1]=Draw_LoadImage("data/wizard_right.bmp");
|
//img_wizard[1]=Draw_LoadImage("data/wizard_right.png");
|
||||||
|
img_wizard[1]=Draw_LoadImage("data/wizard_right.png");
|
||||||
|
|
||||||
// Magik Ball
|
// Magik Ball
|
||||||
img_magikball=Draw_LoadImage("data/magikball.bmp");
|
img_magikball=Draw_LoadImage("data/magikball.png");
|
||||||
|
|
||||||
// Load the earth images
|
// Load the earth images
|
||||||
img_earth[ 0]=Draw_LoadImage("data/earth/0.bmp");
|
img_earth[ 0]=Draw_LoadImage("data/earth/0.png");
|
||||||
img_earth[ 1]=Draw_LoadImage("data/earth/1.bmp");
|
img_earth[ 1]=Draw_LoadImage("data/earth/1.png");
|
||||||
img_earth[ 2]=Draw_LoadImage("data/earth/2.bmp");
|
img_earth[ 2]=Draw_LoadImage("data/earth/2.png");
|
||||||
img_earth[ 3]=Draw_LoadImage("data/earth/3.bmp");
|
img_earth[ 3]=Draw_LoadImage("data/earth/3.png");
|
||||||
img_earth[ 4]=Draw_LoadImage("data/earth/4.bmp");
|
img_earth[ 4]=Draw_LoadImage("data/earth/4.png");
|
||||||
img_earth[ 5]=Draw_LoadImage("data/earth/5.bmp");
|
img_earth[ 5]=Draw_LoadImage("data/earth/5.png");
|
||||||
img_earth[ 6]=Draw_LoadImage("data/earth/6.bmp");
|
img_earth[ 6]=Draw_LoadImage("data/earth/6.png");
|
||||||
img_earth[ 7]=Draw_LoadImage("data/earth/7.bmp");
|
img_earth[ 7]=Draw_LoadImage("data/earth/7.png");
|
||||||
img_earth[ 8]=Draw_LoadImage("data/earth/8.bmp");
|
img_earth[ 8]=Draw_LoadImage("data/earth/8.png");
|
||||||
img_earth[ 9]=Draw_LoadImage("data/earth/9.bmp");
|
img_earth[ 9]=Draw_LoadImage("data/earth/9.png");
|
||||||
img_earth[10]=Draw_LoadImage("data/earth/A.bmp");
|
img_earth[10]=Draw_LoadImage("data/earth/A.png");
|
||||||
img_earth[11]=Draw_LoadImage("data/earth/B.bmp");
|
img_earth[11]=Draw_LoadImage("data/earth/B.png");
|
||||||
img_earth[12]=Draw_LoadImage("data/earth/C.bmp");
|
img_earth[12]=Draw_LoadImage("data/earth/C.png");
|
||||||
img_earth[13]=Draw_LoadImage("data/earth/D.bmp");
|
img_earth[13]=Draw_LoadImage("data/earth/D.png");
|
||||||
img_earth[14]=Draw_LoadImage("data/earth/E.bmp");
|
img_earth[14]=Draw_LoadImage("data/earth/E.png");
|
||||||
img_earth[15]=Draw_LoadImage("data/earth/F.bmp");
|
img_earth[15]=Draw_LoadImage("data/earth/F.png");
|
||||||
|
|
||||||
// FIXME: Earth back
|
// FIXME: Earth back
|
||||||
|
|
||||||
// Stone Brick
|
// Stone Brick
|
||||||
img_stoneBrick=Draw_LoadImage("data/rock.bmp");
|
img_stoneBrick=Draw_LoadImage("data/rock.png");
|
||||||
|
|
||||||
// FIXME: Stone Brick back
|
// FIXME: Stone Brick back
|
||||||
|
|
||||||
// Spiked Bush
|
// Spiked Bush
|
||||||
img_spikedBush=Draw_LoadImage("data/spikedbush.bmp");
|
img_spikedBush=Draw_LoadImage("data/spikedbush.png");
|
||||||
|
|
||||||
// FIXME: Lava Pit
|
// FIXME: Lava Pit
|
||||||
|
|
||||||
// FIXME: Fireball
|
// FIXME: Fireball
|
||||||
|
|
||||||
// Flower
|
// Flower
|
||||||
img_flower[0]=Draw_LoadImage("data/flower_left.bmp");
|
img_flower[0]=Draw_LoadImage("data/flower_left.png");
|
||||||
img_flower[1]=Draw_LoadImage("data/flower_right.bmp");
|
img_flower[1]=Draw_LoadImage("data/flower_right.png");
|
||||||
|
|
||||||
// Spike
|
// Spike
|
||||||
img_spike[0]=Draw_LoadImage("data/spike_left.bmp");
|
img_spike[0]=Draw_LoadImage("data/spike_left.png");
|
||||||
img_spike[1]=Draw_LoadImage("data/spike_right.bmp");
|
img_spike[1]=Draw_LoadImage("data/spike_right.png");
|
||||||
|
|
||||||
// Carnivore Plant
|
// Carnivore Plant
|
||||||
img_carnivorePlant[0]=Draw_LoadImage("data/carnivoreplant_left.bmp");
|
img_carnivorePlant[0]=Draw_LoadImage("data/carnivoreplant_left.png");
|
||||||
img_carnivorePlant[1]=Draw_LoadImage("data/carnivoreplant_right.bmp");
|
img_carnivorePlant[1]=Draw_LoadImage("data/carnivoreplant_right.png");
|
||||||
|
|
||||||
// Bunny
|
// Bunny
|
||||||
img_bunny[0]=Draw_LoadImage("data/bunny_left.bmp");
|
img_bunny[0]=Draw_LoadImage("data/bunny_left.png");
|
||||||
img_bunny[1]=Draw_LoadImage("data/bunny_right.bmp");
|
img_bunny[1]=Draw_LoadImage("data/bunny_right.png");
|
||||||
|
|
||||||
// Spider
|
// Spider
|
||||||
img_spider[0]=Draw_LoadImage("data/spider_left.bmp");
|
img_spider[0]=Draw_LoadImage("data/spider_left.png");
|
||||||
img_spider[1]=Draw_LoadImage("data/spider_right.bmp");
|
img_spider[1]=Draw_LoadImage("data/spider_right.png");
|
||||||
|
|
||||||
// FIXME: Guard
|
// FIXME: Guard
|
||||||
|
|
||||||
|
|||||||
241
GameLib/Draw.c
@@ -20,6 +20,7 @@
|
|||||||
#include <GL/gl.h>
|
#include <GL/gl.h>
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
#include "lodepng.c"
|
||||||
#include <SDL/SDL.h>
|
#include <SDL/SDL.h>
|
||||||
|
|
||||||
#include "Time.h"
|
#include "Time.h"
|
||||||
@@ -28,16 +29,33 @@
|
|||||||
#include "Draw.h"
|
#include "Draw.h"
|
||||||
|
|
||||||
|
|
||||||
|
////////////////////////////////////////////////
|
||||||
|
// DrawImage //
|
||||||
|
///////////////
|
||||||
|
// Image container.
|
||||||
|
typedef struct TDrawImage TDrawImage, *DrawImage;
|
||||||
|
struct TDrawImage {
|
||||||
|
unsigned char *data;
|
||||||
|
int x,y;
|
||||||
|
int w,h;
|
||||||
|
GLuint tex;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
// Globals
|
// Globals
|
||||||
SDL_Surface *_screen=NULL;
|
SDL_Surface *_screen=NULL;
|
||||||
int _width;
|
int _width;
|
||||||
int _height;
|
int _height;
|
||||||
long long proc_t_frame=33333;
|
long long proc_t_frame=33333;
|
||||||
long long draw_t_frame=16667;
|
long long draw_t_frame=16667;
|
||||||
|
int _fps=60;
|
||||||
QuadArray2D _quadArray=NULL;
|
QuadArray2D _quadArray=NULL;
|
||||||
GLuint _tex=-1;
|
DrawImage _currentImg=NULL;
|
||||||
float _color[4];
|
float _color[4];
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/////////////////////////////
|
/////////////////////////////
|
||||||
// Draw_Init
|
// Draw_Init
|
||||||
//
|
//
|
||||||
@@ -84,6 +102,7 @@ int Draw_Init(int width,int height,char *title,int pfps,int fps){
|
|||||||
SDL_WM_SetCaption(title, NULL);
|
SDL_WM_SetCaption(title, NULL);
|
||||||
proc_t_frame=1000000/pfps;
|
proc_t_frame=1000000/pfps;
|
||||||
draw_t_frame=1000000/fps;
|
draw_t_frame=1000000/fps;
|
||||||
|
_fps=fps;
|
||||||
_width=width;
|
_width=width;
|
||||||
_height=height;
|
_height=height;
|
||||||
|
|
||||||
@@ -228,118 +247,79 @@ void Draw_Clean(
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
|
||||||
// DrawImage //
|
|
||||||
///////////////
|
|
||||||
// Image container.
|
|
||||||
typedef struct Tag_DrawImage {
|
|
||||||
SDL_Surface *surf;
|
|
||||||
GLuint tex;
|
|
||||||
int x,y;
|
|
||||||
} DrawImage;
|
|
||||||
|
|
||||||
|
|
||||||
/////////////////////////////
|
|
||||||
// Draw_LoadSurface
|
|
||||||
//
|
|
||||||
// Loads a surface.
|
|
||||||
SDL_Surface *Draw_LoadSurface(char *filename){
|
|
||||||
SDL_Surface *surf;
|
|
||||||
|
|
||||||
// Load the BMP as a surface
|
|
||||||
surf=SDL_LoadBMP(filename);
|
|
||||||
if(surf == NULL){
|
|
||||||
printf("Draw_LoadImage: Failure Loading image: %s\n",filename);
|
|
||||||
printf("Draw_LoadImage: SDL Error: %s\n",SDL_GetError());
|
|
||||||
return(NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (surf->format->BytesPerPixel==4) {
|
|
||||||
// Swap RGB to BGR
|
|
||||||
Uint32 *ptr,*ptr_end;
|
|
||||||
ptr=(Uint32 *)surf->pixels;
|
|
||||||
ptr_end=ptr+(surf->w*surf->h);
|
|
||||||
while (ptr<ptr_end) {
|
|
||||||
unsigned char temp;
|
|
||||||
unsigned char *pixel;
|
|
||||||
pixel=(unsigned char *)ptr;
|
|
||||||
temp=pixel[2];
|
|
||||||
pixel[2]=pixel[0];
|
|
||||||
pixel[0]=temp;
|
|
||||||
ptr++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return(surf);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/////////////////////////////
|
/////////////////////////////
|
||||||
// Draw_UploadGLTexture
|
// Draw_UploadGLTexture
|
||||||
//
|
//
|
||||||
// Uploads a OpenGL texture.
|
// Uploads a OpenGL texture.
|
||||||
GLuint Draw_UploadGLTexture(SDL_Surface *surf){
|
GLuint Draw_UploadGLTexture(int w, int h, unsigned char *pixels){
|
||||||
GLuint tex;
|
GLuint tex;
|
||||||
|
|
||||||
// Generate OpenGL texture
|
// Generate OpenGL texture
|
||||||
glGenTextures(1, &tex);
|
glGenTextures(1, &tex);
|
||||||
glBindTexture(GL_TEXTURE_2D, tex);
|
glBindTexture(GL_TEXTURE_2D, tex);
|
||||||
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
|
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
|
||||||
//glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
|
|
||||||
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
|
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
|
||||||
//glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
|
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||||
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
|
||||||
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
|
||||||
|
|
||||||
|
|
||||||
// Load OpenGL texture
|
// Load OpenGL texture
|
||||||
glBindTexture(GL_TEXTURE_2D, tex);
|
glBindTexture(GL_TEXTURE_2D, tex);
|
||||||
glPixelStorei( GL_UNPACK_ROW_LENGTH, surf->w );
|
glPixelStorei( GL_UNPACK_ROW_LENGTH, w );
|
||||||
glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
|
glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
|
||||||
//glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8,
|
|
||||||
// surf->w, surf->h, 0,
|
|
||||||
// GL_RGBA, GL_UNSIGNED_BYTE, surf->pixels);
|
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA,
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA,
|
||||||
surf->w, surf->h, 0,
|
w, h, 0,
|
||||||
GL_RGBA, GL_UNSIGNED_BYTE, surf->pixels);
|
GL_RGBA, GL_UNSIGNED_BYTE, pixels);
|
||||||
//glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8,
|
|
||||||
// imagen->ancho, imagen->alto, 0,
|
|
||||||
// GL_RGB, GL_UNSIGNED_BYTE, imagen->data);
|
|
||||||
|
|
||||||
return(tex);
|
return(tex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/////////////////////////////
|
||||||
|
// Draw_CreateImage
|
||||||
|
//
|
||||||
|
DrawImg Draw_CreateImage(int w,int h){
|
||||||
|
DrawImage image;
|
||||||
|
|
||||||
|
// Create the image container
|
||||||
|
image=malloc(sizeof(TDrawImage));
|
||||||
|
image->data=malloc(w*h*4);
|
||||||
|
image->x=0;
|
||||||
|
image->y=0;
|
||||||
|
image->w=w;
|
||||||
|
image->h=h;
|
||||||
|
image->tex=-1;
|
||||||
|
|
||||||
|
return((DrawImg)image);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/////////////////////////////
|
/////////////////////////////
|
||||||
// Draw_LoadImage
|
// Draw_LoadImage
|
||||||
//
|
//
|
||||||
// Loads a image, giving a reference.
|
// Loads a image, giving a reference.
|
||||||
DrawImg Draw_LoadImage(char *filename){
|
DrawImg Draw_LoadImage(char *filename){
|
||||||
DrawImage *image;
|
DrawImage image;
|
||||||
SDL_Surface *surf;
|
|
||||||
|
|
||||||
|
// Try loading PNG images
|
||||||
// Loads the surface
|
if(EndsWith(filename,".png") || EndsWith(filename,".PNG")){
|
||||||
surf=Draw_LoadSurface(filename);
|
image=malloc(sizeof(TDrawImage));
|
||||||
if(surf == NULL){
|
unsigned error = lodepng_decode32_file(
|
||||||
return(NULL);
|
&image->data,
|
||||||
|
(unsigned*)&image->w,
|
||||||
|
(unsigned*)&image->h,
|
||||||
|
filename);
|
||||||
|
if(error){
|
||||||
|
printf("Draw_LoadImage: PNG decoder error %u: %s\n", error, lodepng_error_text(error));
|
||||||
|
return(NULL);
|
||||||
|
}
|
||||||
|
image->x=-(int)(image->w/2);
|
||||||
|
image->y=-(int)(image->h/2);
|
||||||
|
image->tex=-1;
|
||||||
|
return (DrawImg)image;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
printf("Draw_LoadImage: Image type not supported: %s\n",filename);
|
||||||
// Create the image container
|
return(NULL);
|
||||||
image=malloc(sizeof(DrawImage));
|
|
||||||
image->surf=surf;
|
|
||||||
image->tex=Draw_UploadGLTexture(surf);
|
|
||||||
//image->x=0;
|
|
||||||
//image->y=0;
|
|
||||||
image->x=-(surf->w/2);
|
|
||||||
image->y=-(surf->h/2);
|
|
||||||
|
|
||||||
|
|
||||||
return((DrawImg)image);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -348,11 +328,11 @@ DrawImg Draw_LoadImage(char *filename){
|
|||||||
//
|
//
|
||||||
// Gets the image size.
|
// Gets the image size.
|
||||||
void Draw_GetSize(DrawImg img,int *w,int *h){
|
void Draw_GetSize(DrawImg img,int *w,int *h){
|
||||||
DrawImage *image=img;
|
DrawImage image=img;
|
||||||
|
|
||||||
// Gets the image size
|
// Gets the image size
|
||||||
*w=image->surf->w;
|
*w=image->w;
|
||||||
*h=image->surf->h;
|
*h=image->h;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -362,14 +342,14 @@ void Draw_GetSize(DrawImg img,int *w,int *h){
|
|||||||
//
|
//
|
||||||
// Sets and Gets the image offset.
|
// Sets and Gets the image offset.
|
||||||
void Draw_SetOffset(DrawImg img,int x,int y){
|
void Draw_SetOffset(DrawImg img,int x,int y){
|
||||||
DrawImage *image=img;
|
DrawImage image=img;
|
||||||
|
|
||||||
// Sets the image offset
|
// Sets the image offset
|
||||||
image->x=x;
|
image->x=x;
|
||||||
image->y=y;
|
image->y=y;
|
||||||
}
|
}
|
||||||
void Draw_GetOffset(DrawImg img,int *x,int *y){
|
void Draw_GetOffset(DrawImg img,int *x,int *y){
|
||||||
DrawImage *image=img;
|
DrawImage image=img;
|
||||||
|
|
||||||
// Gets the image offset
|
// Gets the image offset
|
||||||
*x=image->x;
|
*x=image->x;
|
||||||
@@ -382,9 +362,15 @@ void Draw_GetOffset(DrawImg img,int *x,int *y){
|
|||||||
//
|
//
|
||||||
// Performs all the queued draw actions.
|
// Performs all the queued draw actions.
|
||||||
void Draw_Flush(){
|
void Draw_Flush(){
|
||||||
|
if(_currentImg==NULL){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if(_currentImg->tex==-1){
|
||||||
|
_currentImg->tex=Draw_UploadGLTexture(_currentImg->w, _currentImg->h, _currentImg->data);
|
||||||
|
}
|
||||||
|
|
||||||
// Draw the quad array
|
// Draw the quad array
|
||||||
glBindTexture(GL_TEXTURE_2D, _tex);
|
glBindTexture(GL_TEXTURE_2D, _currentImg->tex);
|
||||||
glEnableClientState(GL_COLOR_ARRAY);
|
glEnableClientState(GL_COLOR_ARRAY);
|
||||||
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||||
glEnableClientState(GL_VERTEX_ARRAY);
|
glEnableClientState(GL_VERTEX_ARRAY);
|
||||||
@@ -402,7 +388,6 @@ void Draw_Flush(){
|
|||||||
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||||
glDisableClientState(GL_VERTEX_ARRAY);
|
glDisableClientState(GL_VERTEX_ARRAY);
|
||||||
|
|
||||||
|
|
||||||
// Empty it
|
// Empty it
|
||||||
QuadArray2D_Clean(_quadArray);
|
QuadArray2D_Clean(_quadArray);
|
||||||
}
|
}
|
||||||
@@ -413,19 +398,19 @@ void Draw_Flush(){
|
|||||||
//
|
//
|
||||||
// Draws an image.
|
// Draws an image.
|
||||||
void Draw_DrawImg(DrawImg img,int x,int y){
|
void Draw_DrawImg(DrawImg img,int x,int y){
|
||||||
DrawImage *image=img;
|
DrawImage image=img;
|
||||||
float x1,x2,y1,y2;
|
float x1,x2,y1,y2;
|
||||||
|
|
||||||
// Prepare
|
// Prepare
|
||||||
x1=x+image->x;
|
x1=x+image->x;
|
||||||
y1=_height-(y+image->y);
|
y1=_height-(y+image->y);
|
||||||
x2=(x+image->x)+image->surf->w;
|
x2=(x+image->x)+image->w;
|
||||||
y2=_height-((y+image->y)+image->surf->h);
|
y2=_height-((y+image->y)+image->h);
|
||||||
|
|
||||||
// Draw a quad
|
// Draw a quad
|
||||||
if(_tex!=image->tex){
|
if(_currentImg!=image){
|
||||||
Draw_Flush();
|
Draw_Flush();
|
||||||
_tex=image->tex;
|
_currentImg=image;
|
||||||
}
|
}
|
||||||
QuadArray2D_AddQuad(_quadArray,
|
QuadArray2D_AddQuad(_quadArray,
|
||||||
x1,y1,0.0f,0.0f,
|
x1,y1,0.0f,0.0f,
|
||||||
@@ -439,7 +424,7 @@ void Draw_DrawImg(DrawImg img,int x,int y){
|
|||||||
//
|
//
|
||||||
// Draws an image, resizing.
|
// Draws an image, resizing.
|
||||||
void Draw_DrawImgResized(DrawImg img,int x,int y,float w,float h){
|
void Draw_DrawImgResized(DrawImg img,int x,int y,float w,float h){
|
||||||
DrawImage *image=img;
|
DrawImage image=img;
|
||||||
int x1,x2,y1,y2;
|
int x1,x2,y1,y2;
|
||||||
|
|
||||||
// Prepare
|
// Prepare
|
||||||
@@ -449,9 +434,9 @@ void Draw_DrawImgResized(DrawImg img,int x,int y,float w,float h){
|
|||||||
y2=_height-((y+image->y)+h);
|
y2=_height-((y+image->y)+h);
|
||||||
|
|
||||||
// Draw a quad
|
// Draw a quad
|
||||||
if(_tex!=image->tex){
|
if(_currentImg!=image){
|
||||||
Draw_Flush();
|
Draw_Flush();
|
||||||
_tex=image->tex;
|
_currentImg=image;
|
||||||
}
|
}
|
||||||
QuadArray2D_AddQuad(_quadArray,
|
QuadArray2D_AddQuad(_quadArray,
|
||||||
x1,y1,0.0f,0.0f,
|
x1,y1,0.0f,0.0f,
|
||||||
@@ -466,7 +451,7 @@ void Draw_DrawImgResized(DrawImg img,int x,int y,float w,float h){
|
|||||||
//
|
//
|
||||||
// Draws an image part.
|
// Draws an image part.
|
||||||
void Draw_DrawImgPart(DrawImg img,int x,int y,int w,int i){
|
void Draw_DrawImgPart(DrawImg img,int x,int y,int w,int i){
|
||||||
DrawImage *image=img;
|
DrawImage image=img;
|
||||||
int x1,x2,y1,y2;
|
int x1,x2,y1,y2;
|
||||||
float us,u1,u2;
|
float us,u1,u2;
|
||||||
|
|
||||||
@@ -474,15 +459,15 @@ void Draw_DrawImgPart(DrawImg img,int x,int y,int w,int i){
|
|||||||
x1=x+image->x;
|
x1=x+image->x;
|
||||||
y1=_height-(y+image->y);
|
y1=_height-(y+image->y);
|
||||||
x2=(x+image->x)+w;
|
x2=(x+image->x)+w;
|
||||||
y2=_height-((y+image->y)+image->surf->h);
|
y2=_height-((y+image->y)+image->h);
|
||||||
us=1.0f/image->surf->w;
|
us=1.0f/image->w;
|
||||||
u1=us*i*w;
|
u1=us*i*w;
|
||||||
u2=u1+us*w;
|
u2=u1+us*w;
|
||||||
|
|
||||||
// Draw a quad
|
// Draw a quad
|
||||||
if(_tex!=image->tex){
|
if(_currentImg!=image){
|
||||||
Draw_Flush();
|
Draw_Flush();
|
||||||
_tex=image->tex;
|
_currentImg=image;
|
||||||
}
|
}
|
||||||
QuadArray2D_AddQuad(_quadArray,
|
QuadArray2D_AddQuad(_quadArray,
|
||||||
x1,y1,u1,0.0f,
|
x1,y1,u1,0.0f,
|
||||||
@@ -516,51 +501,41 @@ typedef struct {
|
|||||||
|
|
||||||
|
|
||||||
/////////////////////////////
|
/////////////////////////////
|
||||||
// Draw_DefaultFont
|
// Draw_DefaultImage
|
||||||
//
|
//
|
||||||
// Creates a surface with the default font.
|
// Creates a image with the default font.
|
||||||
#include "FontData.h"
|
#include "FontData.h"
|
||||||
SDL_Surface *Draw_DefaultFontSurface(
|
DrawImage Draw_DefaultFontImage(
|
||||||
unsigned char r,
|
unsigned char r,
|
||||||
unsigned char g,
|
unsigned char g,
|
||||||
unsigned char b,
|
unsigned char b,
|
||||||
unsigned char a)
|
unsigned char a)
|
||||||
{
|
{
|
||||||
SDL_Surface *surf;
|
DrawImage img;
|
||||||
int x,y,c;
|
int x,y,c;
|
||||||
Uint32 color,color2;
|
Uint32 color,color2;
|
||||||
|
|
||||||
// Create the surface
|
// Create the image and colors
|
||||||
surf = SDL_CreateRGBSurface(SDL_SWSURFACE,
|
img=Draw_CreateImage(8*256,8);
|
||||||
8*256, 8, 32,0,0,0,0);
|
|
||||||
surf->format->Amask=0xFF000000;
|
|
||||||
surf->format->Ashift=24;
|
|
||||||
SDL_SetAlpha(surf, SDL_SRCALPHA, 255);
|
|
||||||
|
|
||||||
// HACK: Set the colors in BGR order
|
|
||||||
color =SDL_MapRGBA(surf->format,b,g,r,a);
|
|
||||||
color2=SDL_MapRGBA(surf->format,b,g,r,0);
|
|
||||||
|
|
||||||
// Draw the font
|
// Draw the font
|
||||||
//SDL_LockSurface(surf);
|
|
||||||
for(c=0;c<256;c++){
|
for(c=0;c<256;c++){
|
||||||
for(y=0;y<8;y++){
|
for(y=0;y<8;y++){
|
||||||
for(x=0;x<8;x++){
|
for(x=0;x<8;x++){
|
||||||
|
int offset=((c*8+x)+(8*256*y))*4;
|
||||||
|
img->data[offset+0]=r;
|
||||||
|
img->data[offset+1]=g;
|
||||||
|
img->data[offset+2]=b;
|
||||||
if(((fontdata_8x8[c*8+y]>>(7-x)) & 0x01)==1){
|
if(((fontdata_8x8[c*8+y]>>(7-x)) & 0x01)==1){
|
||||||
//Imagen_PutPixel(dest,c*8+x,y,color);
|
img->data[offset+3]=0xFF;
|
||||||
((Uint32 *)surf->pixels)[(c*8+x)+(8*256*y)]=
|
|
||||||
color;
|
|
||||||
}else{
|
}else{
|
||||||
//Imagen_PutPixel(dest,c*8+x,y,color2);
|
img->data[offset+3]=0x00;
|
||||||
((Uint32 *)surf->pixels)[(c*8+x)+(8*256*y)]=
|
|
||||||
color2;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//SDL_UnlockSurface(surf);
|
|
||||||
|
|
||||||
return(surf);
|
return(img);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -578,10 +553,7 @@ DrawFnt Draw_DefaultFont(
|
|||||||
|
|
||||||
// Create the default font
|
// Create the default font
|
||||||
font=malloc(sizeof(DrawFont));
|
font=malloc(sizeof(DrawFont));
|
||||||
font->img.surf=Draw_DefaultFontSurface(r,g,b,a);
|
font->img=Draw_DefaultFontImage(r,g,b,a);
|
||||||
font->img.tex=Draw_UploadGLTexture(font->img.surf);
|
|
||||||
font->img.x=0;
|
|
||||||
font->img.y=0;
|
|
||||||
font->w=8;
|
font->w=8;
|
||||||
font->h=8;
|
font->h=8;
|
||||||
font->min=0;
|
font->min=0;
|
||||||
@@ -599,12 +571,9 @@ DrawFnt Draw_LoadFont(char *fichero,int min,int max){
|
|||||||
|
|
||||||
// Create the font form the image
|
// Create the font form the image
|
||||||
font=malloc(sizeof(DrawFont));
|
font=malloc(sizeof(DrawFont));
|
||||||
font->img.surf=Draw_LoadSurface(fichero);
|
font->img=Draw_LoadImage(fichero);
|
||||||
font->img.tex=Draw_UploadGLTexture(font->img.surf);
|
font->w=font->img->w/(max-min);
|
||||||
font->img.x=0;
|
font->h=font->img->h;
|
||||||
font->img.y=0;
|
|
||||||
font->w=font->img.surf->w/(max-min);
|
|
||||||
font->h=font->img.surf->h;
|
|
||||||
font->min=min;
|
font->min=min;
|
||||||
font->max=max;
|
font->max=max;
|
||||||
|
|
||||||
@@ -624,7 +593,7 @@ void Draw_DrawText(DrawFnt f,char *text,int x,int y){
|
|||||||
ptr=text;
|
ptr=text;
|
||||||
while(*ptr){
|
while(*ptr){
|
||||||
if((*ptr)<font->max){
|
if((*ptr)<font->max){
|
||||||
Draw_DrawImgPart((DrawImg)&font->img,x,y,font->w,(*ptr)-font->min);
|
Draw_DrawImgPart(font->img,x,y,font->w,(*ptr)-font->min);
|
||||||
}
|
}
|
||||||
x+=font->w;
|
x+=font->w;
|
||||||
ptr++;
|
ptr++;
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ void Draw_Clean(
|
|||||||
// Performs all the queued draw actions.
|
// Performs all the queued draw actions.
|
||||||
void Draw_Flush();
|
void Draw_Flush();
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// DrawImg //
|
// DrawImg //
|
||||||
/////////////
|
/////////////
|
||||||
@@ -41,6 +42,12 @@ void Draw_Flush();
|
|||||||
typedef void *DrawImg;
|
typedef void *DrawImg;
|
||||||
|
|
||||||
|
|
||||||
|
/////////////////////////////
|
||||||
|
// Draw_CreateImage
|
||||||
|
//
|
||||||
|
DrawImg Draw_CreateImage(int w,int h);
|
||||||
|
|
||||||
|
|
||||||
/////////////////////////////
|
/////////////////////////////
|
||||||
// Draw_LoadImage
|
// Draw_LoadImage
|
||||||
//
|
//
|
||||||
|
|||||||
@@ -152,10 +152,10 @@ CollisionInfo CollisionInfo_New(int responseType,Entity ent1,Entity ent2,float t
|
|||||||
|
|
||||||
|
|
||||||
/////////////////////////////
|
/////////////////////////////
|
||||||
// CollisionInfo_Free
|
// CollisionInfo_Destroy
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
void CollisionInfo_Free(CollisionInfo *collInfoRef);
|
void CollisionInfo_Destroy(CollisionInfo *collInfoRef);
|
||||||
|
|
||||||
|
|
||||||
/////////////////////////////
|
/////////////////////////////
|
||||||
|
|||||||
@@ -200,3 +200,17 @@ float fabsmod(float v,int d){
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/////////////////////////////
|
||||||
|
// EndsWith
|
||||||
|
//
|
||||||
|
int EndsWith(char *str, char *suffix){
|
||||||
|
if (!str || !suffix)
|
||||||
|
return 0;
|
||||||
|
int lenStr = strlen(str);
|
||||||
|
int lenSuffix = strlen(suffix);
|
||||||
|
if (lenSuffix > lenStr)
|
||||||
|
return 0;
|
||||||
|
return strncmp(str+lenStr-lenSuffix, suffix, lenSuffix)==0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ float vec2_norm(vec2 v);
|
|||||||
// Intersection between a ray and a Unit Circle.
|
// Intersection between a ray and a Unit Circle.
|
||||||
int Intersec_RayUnitCircle(vec2 orig,vec2 vel,vec2 center,float *t);
|
int Intersec_RayUnitCircle(vec2 orig,vec2 vel,vec2 center,float *t);
|
||||||
|
|
||||||
|
|
||||||
/////////////////////////////
|
/////////////////////////////
|
||||||
// Intersect_CircleCircle
|
// Intersect_CircleCircle
|
||||||
//
|
//
|
||||||
@@ -46,6 +47,7 @@ int Colision_CircleCircle(
|
|||||||
vec2 cb,float rb,
|
vec2 cb,float rb,
|
||||||
float *t,vec2 n);
|
float *t,vec2 n);
|
||||||
|
|
||||||
|
|
||||||
/////////////////////////////
|
/////////////////////////////
|
||||||
// Intersect_RayEdge
|
// Intersect_RayEdge
|
||||||
//
|
//
|
||||||
@@ -56,7 +58,6 @@ int Intersect_RayEdge(
|
|||||||
float *t);
|
float *t);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/////////////////////////////
|
/////////////////////////////
|
||||||
// absmod
|
// absmod
|
||||||
//
|
//
|
||||||
@@ -64,4 +65,11 @@ int absmod(int v,int d);
|
|||||||
float fabsmod(float v,int d);
|
float fabsmod(float v,int d);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/////////////////////////////
|
||||||
|
// EndsWith
|
||||||
|
//
|
||||||
|
int EndsWith(char *str, char *suffix);
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
6285
GameLib/lodepng.c
Normal file
1710
GameLib/lodepng.h
Normal file
BIN
data/block.bmp
|
Before Width: | Height: | Size: 16 KiB |
BIN
data/block.png
Normal file
|
After Width: | Height: | Size: 4.2 KiB |
|
Before Width: | Height: | Size: 4.1 KiB |
BIN
data/bunny_left.png
Normal file
|
After Width: | Height: | Size: 1.8 KiB |
|
Before Width: | Height: | Size: 4.1 KiB |
BIN
data/bunny_right.png
Normal file
|
After Width: | Height: | Size: 1.9 KiB |
|
Before Width: | Height: | Size: 8.1 KiB |
BIN
data/carnivoreplant_left.png
Normal file
|
After Width: | Height: | Size: 2.6 KiB |
|
Before Width: | Height: | Size: 8.1 KiB |
BIN
data/carnivoreplant_right.png
Normal file
|
After Width: | Height: | Size: 2.6 KiB |
BIN
data/earth/0.bmp
|
Before Width: | Height: | Size: 4.1 KiB |
BIN
data/earth/0.png
Normal file
|
After Width: | Height: | Size: 2.6 KiB |
BIN
data/earth/1.bmp
|
Before Width: | Height: | Size: 4.1 KiB |
BIN
data/earth/1.png
Normal file
|
After Width: | Height: | Size: 2.7 KiB |
BIN
data/earth/2.bmp
|
Before Width: | Height: | Size: 4.1 KiB |
BIN
data/earth/2.png
Normal file
|
After Width: | Height: | Size: 2.7 KiB |
BIN
data/earth/3.bmp
|
Before Width: | Height: | Size: 4.1 KiB |
BIN
data/earth/3.png
Normal file
|
After Width: | Height: | Size: 2.7 KiB |
BIN
data/earth/4.bmp
|
Before Width: | Height: | Size: 4.1 KiB |
BIN
data/earth/4.png
Normal file
|
After Width: | Height: | Size: 2.6 KiB |
BIN
data/earth/5.bmp
|
Before Width: | Height: | Size: 4.1 KiB |
BIN
data/earth/5.png
Normal file
|
After Width: | Height: | Size: 2.7 KiB |
BIN
data/earth/6.bmp
|
Before Width: | Height: | Size: 4.1 KiB |
BIN
data/earth/6.png
Normal file
|
After Width: | Height: | Size: 2.8 KiB |
BIN
data/earth/7.bmp
|
Before Width: | Height: | Size: 4.1 KiB |
BIN
data/earth/7.png
Normal file
|
After Width: | Height: | Size: 2.9 KiB |
BIN
data/earth/8.bmp
|
Before Width: | Height: | Size: 4.1 KiB |
BIN
data/earth/8.png
Normal file
|
After Width: | Height: | Size: 2.7 KiB |
BIN
data/earth/9.bmp
|
Before Width: | Height: | Size: 4.1 KiB |
BIN
data/earth/9.png
Normal file
|
After Width: | Height: | Size: 2.8 KiB |
BIN
data/earth/A.bmp
|
Before Width: | Height: | Size: 4.1 KiB |
BIN
data/earth/A.png
Normal file
|
After Width: | Height: | Size: 2.9 KiB |
BIN
data/earth/B.bmp
|
Before Width: | Height: | Size: 4.1 KiB |
BIN
data/earth/B.png
Normal file
|
After Width: | Height: | Size: 2.8 KiB |
BIN
data/earth/C.bmp
|
Before Width: | Height: | Size: 4.1 KiB |
BIN
data/earth/C.png
Normal file
|
After Width: | Height: | Size: 2.8 KiB |
BIN
data/earth/D.bmp
|
Before Width: | Height: | Size: 4.1 KiB |
BIN
data/earth/D.png
Normal file
|
After Width: | Height: | Size: 2.9 KiB |
BIN
data/earth/E.bmp
|
Before Width: | Height: | Size: 4.1 KiB |
BIN
data/earth/E.png
Normal file
|
After Width: | Height: | Size: 2.9 KiB |
BIN
data/earth/F.bmp
|
Before Width: | Height: | Size: 4.1 KiB |
BIN
data/earth/F.png
Normal file
|
After Width: | Height: | Size: 2.9 KiB |
|
Before Width: | Height: | Size: 8.1 KiB |
BIN
data/flower_left.png
Normal file
|
After Width: | Height: | Size: 1.6 KiB |
|
Before Width: | Height: | Size: 8.1 KiB |
BIN
data/flower_right.png
Normal file
|
After Width: | Height: | Size: 1.6 KiB |
BIN
data/heaven.bmp
|
Before Width: | Height: | Size: 64 KiB |
BIN
data/heaven.png
Normal file
|
After Width: | Height: | Size: 12 KiB |
|
Before Width: | Height: | Size: 1.1 KiB |
BIN
data/magikball.png
Normal file
|
After Width: | Height: | Size: 597 B |
|
Before Width: | Height: | Size: 4.1 KiB |
BIN
data/platform.png
Normal file
|
After Width: | Height: | Size: 652 B |
BIN
data/player.bmp
|
Before Width: | Height: | Size: 4.1 KiB |
BIN
data/player.png
Normal file
|
After Width: | Height: | Size: 1.1 KiB |
BIN
data/rock.bmp
|
Before Width: | Height: | Size: 4.1 KiB |
BIN
data/rock.png
Normal file
|
After Width: | Height: | Size: 2.6 KiB |
BIN
data/soldier.bmp
|
Before Width: | Height: | Size: 6.1 KiB |
BIN
data/soldier.png
Normal file
|
After Width: | Height: | Size: 3.2 KiB |
|
Before Width: | Height: | Size: 4.1 KiB |
BIN
data/spider_left.png
Normal file
|
After Width: | Height: | Size: 1.3 KiB |
|
Before Width: | Height: | Size: 4.1 KiB |
BIN
data/spider_right.png
Normal file
|
After Width: | Height: | Size: 1.2 KiB |
|
Before Width: | Height: | Size: 1.1 KiB |
BIN
data/spike_left.png
Normal file
|
After Width: | Height: | Size: 364 B |
|
Before Width: | Height: | Size: 1.1 KiB |
BIN
data/spike_right.png
Normal file
|
After Width: | Height: | Size: 366 B |
|
Before Width: | Height: | Size: 4.1 KiB |
BIN
data/spikedbush.png
Normal file
|
After Width: | Height: | Size: 1.5 KiB |
|
Before Width: | Height: | Size: 8.1 KiB |
BIN
data/wizard_left.png
Normal file
|
After Width: | Height: | Size: 3.7 KiB |
|
Before Width: | Height: | Size: 8.1 KiB |
BIN
data/wizard_right.png
Normal file
|
After Width: | Height: | Size: 3.7 KiB |
2
main.c
@@ -69,7 +69,7 @@ int main(int argc,char *argv[]){
|
|||||||
font=Draw_DefaultFont(255,255,255,255);
|
font=Draw_DefaultFont(255,255,255,255);
|
||||||
font_shad=Draw_DefaultFont(0,0,0,127);
|
font_shad=Draw_DefaultFont(0,0,0,127);
|
||||||
|
|
||||||
img_background=Draw_LoadImage("data/heaven.bmp");
|
img_background=Draw_LoadImage("data/heaven.png");
|
||||||
Draw_SetOffset(img_background,0,0);
|
Draw_SetOffset(img_background,0,0);
|
||||||
|
|
||||||
GameEnts_Init();
|
GameEnts_Init();
|
||||||
|
|||||||