From c1774c591f7897c1cfa28e05fdb7c72e07890933 Mon Sep 17 00:00:00 2001 From: drumsetmonkey Date: Tue, 19 Jan 2016 13:20:45 -0500 Subject: [PATCH] Color Index can be used to color anything with a solid color --- include/entities.h | 11 ++++++---- main.cpp | 10 ++++++++- src/Texture.cpp | 52 +++++++++++++++++++++++++++++++++------------ src/ui.cpp | 1 + xcf/player.xcf | Bin 2357 -> 2457 bytes 5 files changed, 55 insertions(+), 19 deletions(-) diff --git a/include/entities.h b/include/entities.h index 51032ef..edf7022 100644 --- a/include/entities.h +++ b/include/entities.h @@ -88,15 +88,18 @@ public: //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, .125*(index.y + 1)); glVertex2i(loc.x, loc.y); - glTexCoord2f(.25*(index.x+1), .125*(index.y + 1)); glVertex2i(loc.x + width, loc.y); - glTexCoord2f(.25*(index.x+1), .125*index.y); glVertex2i(loc.x + width, loc.y + height); - glTexCoord2f(.25*index.x, .125*index.y); glVertex2i(loc.x, loc.y + width); + 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){ diff --git a/main.cpp b/main.cpp index c10faee..fb13b5a 100644 --- a/main.cpp +++ b/main.cpp @@ -959,7 +959,15 @@ 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,255}, 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; diff --git a/src/Texture.cpp b/src/Texture.cpp index 2965959..f688327 100644 --- a/src/Texture.cpp +++ b/src/Texture.cpp @@ -6,6 +6,12 @@ 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; @@ -70,16 +76,21 @@ namespace Texture{ glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, colorIndex); GLubyte* buffer = new GLubyte[8*4*3]; - glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, buffer); + 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 o = 0; o < 8; o++){ - for(uint t = 0; t < 4; t++){ - for (int r = 0; r < 3; r++){ - pixels[o][t].red = buffer[i++]; - pixels[o][t].green = buffer[i++]; - pixels[o][t].blue = buffer[i++]; - std::cout << pixels[o][t].red << "," << pixels[o][t].green << "," << pixels[o][t].blue << std::endl; - } + 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; } } @@ -87,21 +98,34 @@ namespace Texture{ } //sqrt((255-145)^2+(90-145)^2+(0-0)^2); + std::vectorind; 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 o = 0; o < 8; o++){ - for(uint t = 0; t < 4; t++){ - buff = sqrt(pow((c.red-pixels[o][t].red),2)+pow((c.green-pixels[o][t].green),2)+pow((c.blue-pixels[o][t].blue),2)); + 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] = o; - buf[1] = t; + 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])}; } diff --git a/src/ui.cpp b/src/ui.cpp index eecd7ef..6dd5cd7 100644 --- a/src/ui.cpp +++ b/src/ui.cpp @@ -835,6 +835,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 index 8815a08fd51ac0d85ba6fa0b41f4da670f922119..c99fb42ef3c804f91e7bc05c8d68a0504fbced2c 100644 GI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