aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorClyne Sullivan <tullivan99@gmail.com>2016-01-20 08:47:05 -0500
committerClyne Sullivan <tullivan99@gmail.com>2016-01-20 08:47:05 -0500
commitd6469d0cafc03c468c5977ec345d08b3ccb6fd0a (patch)
treec9b21ddcae956cc9d419d4d56997063eb95fc5f4 /src
parent1e6676c35ce4990981e8cda389ba39108437d66d (diff)
parentc1774c591f7897c1cfa28e05fdb7c72e07890933 (diff)
merge, particles
Diffstat (limited to 'src')
-rw-r--r--src/Texture.cpp67
-rw-r--r--src/entities.cpp6
-rw-r--r--src/ui.cpp1
3 files changed, 74 insertions, 0 deletions
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;
diff --git a/src/ui.cpp b/src/ui.cpp
index 2896102..76e2777 100644
--- a/src/ui.cpp
+++ b/src/ui.cpp
@@ -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;