diff options
author | Clyne Sullivan <tullivan99@gmail.com> | 2016-01-20 08:47:05 -0500 |
---|---|---|
committer | Clyne Sullivan <tullivan99@gmail.com> | 2016-01-20 08:47:05 -0500 |
commit | d6469d0cafc03c468c5977ec345d08b3ccb6fd0a (patch) | |
tree | c9b21ddcae956cc9d419d4d56997063eb95fc5f4 | |
parent | 1e6676c35ce4990981e8cda389ba39108437d66d (diff) | |
parent | c1774c591f7897c1cfa28e05fdb7c72e07890933 (diff) |
merge, particles
-rw-r--r-- | Changelog | 7 | ||||
-rw-r--r-- | assets/colorIndex.png | bin | 0 -> 149 bytes | |||
-rw-r--r-- | frig.frag | 39 | ||||
-rw-r--r-- | include/Texture.h | 3 | ||||
-rw-r--r-- | include/common.h | 14 | ||||
-rw-r--r-- | include/entities.h | 24 | ||||
-rw-r--r-- | main.cpp | 15 | ||||
-rw-r--r-- | src/Texture.cpp | 67 | ||||
-rw-r--r-- | src/entities.cpp | 6 | ||||
-rw-r--r-- | src/ui.cpp | 1 | ||||
-rw-r--r-- | xcf/player.xcf | bin | 2357 -> 2457 bytes |
11 files changed, 170 insertions, 6 deletions
@@ -553,3 +553,10 @@ - memory management - began reconsidering save/load stuff + +1/20/2015: +========== + + - can save npc dialog positions + - worked on player sprite redesign + - greatly simplified/documented gameplay.cpp diff --git a/assets/colorIndex.png b/assets/colorIndex.png Binary files differnew file mode 100644 index 0000000..620b6ec --- /dev/null +++ b/assets/colorIndex.png diff --git a/frig.frag b/frig.frag new file mode 100644 index 0000000..07b4a8a --- /dev/null +++ b/frig.frag @@ -0,0 +1,39 @@ +#version 120
+uniform sampler2D sampler;
+
+uniform int numLight;
+uniform vec2 lightLocation[64];
+uniform vec3 lightColor;
+uniform float amb;
+
+float b = .0005;
+float minLight = .05;
+float radius = sqrt(1.0 / (b * minLight));
+
+//float radius = b*minlight;
+
+void main(){
+ vec4 color = vec4(0.0,0.0,0.0,0.0);
+ for(int i = 0; i < numLight; i++){
+ vec2 loc = lightLocation[i];
+ float dist = length(loc - gl_FragCoord.xy);
+ //float attenuation=1.0/(1.0+0.01*dist+0.00000000001*dist*dist);
+ float attenuation = clamp(1.0 - dist*dist/(radius*radius), 0.0, 1.0); attenuation *= attenuation;
+
+ color += vec4(attenuation, attenuation, attenuation, 1.0) * vec4(lightColor, 1.0);
+ }
+ vec2 coords = gl_TexCoord[0].st;
+ vec4 tex = texture2D(sampler, coords);
+
+ color += vec4(amb,amb,amb,1.0+amb);
+ gl_FragColor = tex * vec4(color)*tex.a;
+}
+
+/* b values
+ .002 10
+ .008 50
+ .0005 200
+ .00008 500
+ .00002 1000
+ .00005 2000
+*/
\ No newline at end of file diff --git a/include/Texture.h b/include/Texture.h index 03593bf..50681bf 100644 --- a/include/Texture.h +++ b/include/Texture.h @@ -30,6 +30,9 @@ namespace Texture{ GLuint loadTexture(const char *fileName); void freeTextures(void); + + void initColorIndex(); + vec2 getIndex(Color c); } /** diff --git a/include/common.h b/include/common.h index fa7356a..0df6533 100644 --- a/include/common.h +++ b/include/common.h @@ -30,14 +30,22 @@ typedef unsigned int uint; #undef near #endif -#include <Texture.h> - /** * This flag lets the compiler know that we want to use shaders. */ #define SHADERS +template<typename N> +N abso(N v){ + if(v < 0.0){ + return v * -1; + }else + return v; +} + +extern GLuint colorIndex; + /** * This structure contains a set of coordinates for ease of coding. */ @@ -68,6 +76,8 @@ typedef struct{ float blue; } Color; +#include <Texture.h> + /** * Define the game's name (displayed in the window title). */ diff --git a/include/entities.h b/include/entities.h index 6328770..fa98285 100644 --- a/include/entities.h +++ b/include/entities.h @@ -57,6 +57,8 @@ public: float velx; float vely; Color color; + vec2 index; + //GLuint tex; float duration; bool canMove; bool fountain; @@ -74,13 +76,29 @@ public: fountain = false; gravity = true; behind = false; + index = Texture::getIndex(c); + //tex = text; } ~Particles(){ } void draw(){ - glColor3f(color.red,color.green,color.blue); - glRectf(loc.x,loc.y,loc.x+width,loc.y+height); + //glColor3f(color.red,color.green,color.blue); + glActiveTexture(GL_TEXTURE0); + glBindTexture(GL_TEXTURE_2D, colorIndex); + glUseProgram(shaderProgram); + glUniform1i(glGetUniformLocation(shaderProgram, "sampler"), 0); + glEnable(GL_TEXTURE_2D); + glColor3ub(255,255,255); + glBegin(GL_QUADS); + glTexCoord2f(.25*index.x, .126*index.y); glVertex2i(loc.x, loc.y); + glTexCoord2f(.26*index.x, .126*index.y); glVertex2i(loc.x + width, loc.y); + glTexCoord2f(.26*index.x, .125*index.y); glVertex2i(loc.x + width, loc.y + height); + glTexCoord2f(.25*index.x, .125*index.y); glVertex2i(loc.x, loc.y + width); + glEnd(); + glDisable(GL_TEXTURE_2D); + glUseProgram(0); + //glRectf(loc.x,loc.y,loc.x+width,loc.y+height); } bool kill(float delta){ duration -= delta; @@ -91,6 +109,8 @@ public: } }; +void initEntity(); + class Entity{ public: Inventory *inv; @@ -119,6 +119,7 @@ unsigned int deltaTime = 0; GLuint fragShader; GLuint shaderProgram; +GLuint colorIndex; Mix_Chunk *crickets; @@ -329,6 +330,8 @@ int main(/*int argc, char *argv[]*/){ SDL_ShowCursor(SDL_DISABLE); + Texture::initColorIndex(); + initEntity(); /* * Initializes our shaders so that the game has shadows. */ @@ -942,13 +945,21 @@ void logic(){ switch(b->bsubtype){ case FOUNTAIN: for(int r = 0; r < (rand()%25)+10;r++){ - currentWorld->addParticle(rand()%HLINE*3 + b->loc.x + b->width/2,b->loc.y + b->height, HLINE,HLINE, rand()%2 == 0?-(rand()%7)*.01:(rand()%7)*.01,((4+rand()%6)*.05), {0,0,1.0f}, 2500); + currentWorld->addParticle( rand()%HLINE*3 + b->loc.x + b->width/2, + b->loc.y + b->height, + HLINE*1.25, + HLINE*1.25, + rand()%2 == 0?-(rand()%7)*.01:(rand()%7)*.01, + ((4+rand()%6)*.05), + {0.0f,0.0f,255.0f}, + 2500); + currentWorld->particles.back()->fountain = true; } break; case FIRE_PIT: for(int r = 0; r < (rand()%20)+10;r++){ - currentWorld->addParticle(rand()%(int)(b->width/2) + b->loc.x+b->width/4, b->loc.y+3*HLINE, HLINE, HLINE, rand()%2 == 0?-(rand()%3)*.01:(rand()%3)*.01,((4+rand()%6)*.005), {1.0f,0.0f,0.0f}, 400); + currentWorld->addParticle(rand()%(int)(b->width/2) + b->loc.x+b->width/4, b->loc.y+3*HLINE, HLINE, HLINE, rand()%2 == 0?-(rand()%3)*.01:(rand()%3)*.01,((4+rand()%6)*.005), {255,0,0}, 400); currentWorld->particles.back()->gravity = false; currentWorld->particles.back()->behind = true; } diff --git a/src/Texture.cpp b/src/Texture.cpp index 0dd1eff..4418a3b 100644 --- a/src/Texture.cpp +++ b/src/Texture.cpp @@ -6,10 +6,17 @@ struct texture_t { GLuint tex; } __attribute__ ((packed)); +struct index_t{ + Color color; + int indexx; + int indexy; +}; + struct texture_t *LoadedTexture[256]; unsigned int LoadedTextureCounter = 0; namespace Texture{ + Color pixels[8][4]; GLuint loadTexture(const char *fileName){ SDL_Surface *image; GLuint object = 0; @@ -63,6 +70,7 @@ namespace Texture{ return object; } + void freeTextures(void){ for(unsigned int i=0;i<LoadedTextureCounter;i++){ glDeleteTextures(1,&LoadedTexture[i]->tex); @@ -70,6 +78,65 @@ namespace Texture{ delete LoadedTexture[i]; } } + + void initColorIndex(){ + colorIndex = loadTexture("assets/colorIndex.png"); + glActiveTexture(GL_TEXTURE0); + glBindTexture(GL_TEXTURE_2D, colorIndex); + GLubyte* buffer = new GLubyte[8*4*3]; + glGetTexImage(GL_TEXTURE_2D, 0, GL_RGB, GL_UNSIGNED_BYTE, buffer); + GLfloat* bufferf = new GLfloat[8*4*3]; + for(uint iu = 0; iu < 8*4*3; iu++){ + bufferf[iu] = float(buffer[iu]) / 255.0f; + } + uint i = 0; + for(uint y = 0; y < 8; y++){ + for(uint x = 0; x < 4; x++){ + if(i >= 8*4*3){ + return; + } + pixels[y][x].red = buffer[i++]; + pixels[y][x].green = buffer[i++]; + pixels[y][x].blue = buffer[i++]; + //std::cout << pixels[y][x].red << "," << pixels[y][x].green << "," << pixels[y][x].blue << std::endl; + //std::cout << std::endl; + } + } + + } + + //sqrt((255-145)^2+(90-145)^2+(0-0)^2); + std::vector<index_t>ind; + vec2 getIndex(Color c){ + for(auto &i : ind){ + if(c.red == i.color.red && c.green == i.color.green && c.blue == i.color.blue){ + //std::cout << float(i.indexy) << "," << float(i.indexx) << std::endl; + return {float(i.indexx), float(i.indexy)}; + } + } + uint buf[2]; + float buff = 999; + float shit = 999; + for(uint y = 0; y < 8; y++){ + for(uint x = 0; x < 4; x++){ + //std::cout << y << "," << x << ":" << pixels[y][x].red << "," << pixels[y][x].green << "," << pixels[y][x].blue << std::endl; + buff = sqrt(pow((pixels[y][x].red- c.red), 2)+ + pow((pixels[y][x].green-c.green),2)+ + pow((pixels[y][x].blue- c.blue), 2)); + //std::cout << buff << std::endl; + if(buff < shit){ + shit = buff; + buf[0] = y; + buf[1] = x; + } + // + //std::cout << shit << std::endl; + } + } + ind.push_back({c, (int)buf[1], (int)buf[0]}); + //std::cout << float(buf[1]) << ", " << float(buf[0]) << std::endl; + return {float(buf[1]),float(buf[0])}; + } } Texturec::Texturec(uint amt, ...){ diff --git a/src/entities.cpp b/src/entities.cpp index faf415b..65085ae 100644 --- a/src/entities.cpp +++ b/src/entities.cpp @@ -22,6 +22,12 @@ std::string sTexLoc[] = { "assets/townhall.png", "assets/lampPost1.png", "assets/brazzier.png"}; +GLuint waterTex; + +void initEntity(){ + waterTex = Texture::loadTexture("assets/waterTex.png"); +} + void getRandomName(Entity *e){ unsigned int tempNum,max=0; char *bufs; @@ -846,6 +846,7 @@ DONE: break; case SDLK_b: currentWorld->addStructure(FIRE_PIT, player->loc.x, player->loc.y, NULL); + currentWorld->addLight({player->loc.x + SCREEN_WIDTH/2, player->loc.y},{1.0f,1.0f,1.0f}); break; case SDLK_F12: std::cout << "Took screenshot" << std::endl; diff --git a/xcf/player.xcf b/xcf/player.xcf Binary files differindex 8815a08..c99fb42 100644 --- a/xcf/player.xcf +++ b/xcf/player.xcf |