From de36d85107a306828482c910731f164ab46e936d Mon Sep 17 00:00:00 2001 From: Clyne Sullivan Date: Wed, 9 Sep 2015 19:54:58 -0400 Subject: [PATCH] World stuff --- include/World.h | 22 ++++++++++++++++++++++ res/dirt.jpg | Bin 0 -> 1033 bytes res/dirt.png | Bin 0 -> 3212 bytes res/dirt.xcf | Bin 0 -> 1067 bytes src/World.cpp | 38 ++++++++++++++++++++++++++++++++++++++ 5 files changed, 60 insertions(+) create mode 100644 include/World.h create mode 100644 res/dirt.jpg create mode 100644 res/dirt.png create mode 100644 res/dirt.xcf create mode 100644 src/World.cpp diff --git a/include/World.h b/include/World.h new file mode 100644 index 0000000..4a097a6 --- /dev/null +++ b/include/World.h @@ -0,0 +1,22 @@ +#ifndef WORLD_H +#define WORLD_H + +#include +#include + +#define LAYER0_Y (-0.8f) +#define TEX_SIZE ( 0.2f) + +class World { +private: + struct layer_t { + unsigned int tex; + float offset; + } layer[4]; +public: + World(const char *l1,const char *l2,const char *l3,const char *bg); + void draw(void); + void update(int player_accel); +}; + +#endif // WORLD_H diff --git a/res/dirt.jpg b/res/dirt.jpg new file mode 100644 index 0000000000000000000000000000000000000000..ebe4ea0e9447a722c43da73b76d3c71e2c687a80 GIT binary patch literal 1033 zcmex=LJ%Z3brsW+o;O z0s6Oj-S z5fuR$!pIEN!@|nR%E~Fi%grl7GWdUpL6Cz%fkASTwf1b-Q;(Oa zQ!ht}cTJvo8EA@>00U4LvMEf=42;4oB0ys}fZ~j-Oc&CcO(Ykb_6TQ**WBu56>Y29 zs*(z6KhgD!{ve^!c!6x-kbkDv3K*O>yAe^ z_PdrW<+7NSEAAZS(^Vpze`a>exo1nBIdJz+iwA`OFesUr7?G_IWKa}v3{)^IT=?N5 zEI{oQUwq&D%*kWQtb@^wdL9Z6A0?Q|<*s%Y*lg*pJ+oc>mE%h`!)2z6rSj_@o=Q0O zc$+;?CpbpIVJo0AyUlX%H=up;g23njCRliYGcYn39{eC6sOT72_z-LzD8K~{=NjDh zF}uvW#U=OoyZ)*LLgw?@I8Gkao|4GDuH7{1z|?%JdZ2M~K;wY!M@npr41xlRhCss_ zA*O)>SzuYP=9Gi6Uw<~mUYsE{?~sc0&I6xZ`g3e+k}l^~90vyj&{-@%W8e-0Mit1I ziys9N8z;hpLEvNT^{#h&!b>0RUURH~^-xfPLQkq4L+{K;h6p8To3q}_o@qDb6dLyi z`8c^QX*h2)d*#yGsk5WhO8#Ac%6)^+h}*hAS9zBx?}3G4jlo|(EEU{4K{4p5<4NZ3 Rzzy6`sfeNIjuS%#ID_S|G(;L-MUaSZX`WmMp~|Cv#3z5-Ac?EuJqGzFs;5Dea-A4H7P z>^KQ}lM)3q4C^ZBQVABhYVaj`4#|;K(+&yC!iJ}D}`H56$TZ`B4oE? zI+UUyBF2kUumIE5$QGk#G-Npl8y*7q4Z_q25g}{=E}h8YckG@W=6d=?;^g5R0QD$&>kf(T7DGM7jziShxFW+7V-XXEn$CFa5{ eAj$`D)nqVUc^kZM($AX@((38z=d#Wzp$Pzh5K0OF literal 0 HcmV?d00001 diff --git a/res/dirt.xcf b/res/dirt.xcf new file mode 100644 index 0000000000000000000000000000000000000000..ad721978bdcf92c076bcacdd93d3812f6f3b3543 GIT binary patch literal 1067 zcmZ{i&2F1O6op~HEkDL}-5)PNVpf&2aFx6Oi*ylnQK^#GUJyJGR2w27O0uZ>1d+00 z+c)U@uM{WBL5Q7b$q;ntn)`rBcWbH zrqWwQntOx!3((8(wacX3?L^U_*XVHep%QT;HvBekuK2~rPoL>zDo68OoQY*t(h)qQ2$N)`EK3no!%PV{D6MTIuCLsjn2W$xHUT)^dRCyl1T>eJ``Yn3R#NO zQ*MGY?C)uGBiYjq>sBpp@_ilYLXQkFKcF8m;X$sXAsoz%BU9L*2N5TdOfrD?p#bw! z$Wo-9aub|ke@{bl<&J&kZAd)i^)%Ki=D0KL)x literal 0 HcmV?d00001 diff --git a/src/World.cpp b/src/World.cpp new file mode 100644 index 0000000..feeeb1f --- /dev/null +++ b/src/World.cpp @@ -0,0 +1,38 @@ +#include + +World::World(const char *l1,const char *l2,const char *l3,const char *bg){ + unsigned char i=0; + SDL_Surface *l; + const char *f[4]={l1,l2,l3,bg}; + memset(layer,0,sizeof(struct layer_t)*4); + for(;i<4;i++){ + l=IMG_Load(f[i]); + if(l!=NULL){ + glGenTextures(1,&layer[i].tex); + glBindTexture(GL_TEXTURE_2D,layer[i].tex); + glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); + glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); + glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_CLAMP_TO_EDGE); + glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_CLAMP_TO_EDGE); + glTexImage2D(GL_TEXTURE_2D,0,GL_RGB,l->w,l->h,0,GL_RGB,GL_UNSIGNED_BYTE,l->pixels); + SDL_FreeSurface(l); + } + } +} +void World::draw(void){ + int i; + float x; + glEnable(GL_TEXTURE_2D); + for(i=2;i>=0;i--){ + glBindTexture(GL_TEXTURE_2D,layer[i].tex); + glBegin(GL_QUADS); + for(x=-1;x<=1;x+=(TEX_SIZE/(float)(i+1))){ + glTexCoord2d(1,1);glVertex2f(x ,LAYER0_Y-TEX_SIZE+(i*.2)); + glTexCoord2d(0,1);glVertex2f(x+TEX_SIZE,LAYER0_Y-TEX_SIZE+(i*.2)); + glTexCoord2d(0,0);glVertex2f(x+TEX_SIZE,LAYER0_Y +(i*.2)); + glTexCoord2d(1,0);glVertex2f(x ,LAYER0_Y +(i*.2)); + } + glEnd(); + } + glDisable(GL_TEXTURE_2D); +} -- 2.39.5