]> code.bitgloo.com Git - clyne/gamedev.git/commitdiff
Stuff
authordrumsetmonkey <abelleisle@roadrunner.com>
Tue, 19 Jan 2016 12:33:46 +0000 (07:33 -0500)
committerdrumsetmonkey <abelleisle@roadrunner.com>
Tue, 19 Jan 2016 12:33:46 +0000 (07:33 -0500)
assets/colorIndex.png [new file with mode: 0644]
frig.frag [new file with mode: 0644]
include/Texture.h
include/common.h
include/entities.h
main.cpp
src/Texture.cpp
src/entities.cpp

diff --git a/assets/colorIndex.png b/assets/colorIndex.png
new file mode 100644 (file)
index 0000000..620b6ec
Binary files /dev/null and b/assets/colorIndex.png differ
diff --git a/frig.frag b/frig.frag
new file mode 100644 (file)
index 0000000..07b4a8a
--- /dev/null
+++ b/frig.frag
@@ -0,0 +1,39 @@
+#version 120\r
+uniform sampler2D sampler;\r
+\r
+uniform int numLight;\r
+uniform vec2 lightLocation[64];\r
+uniform vec3 lightColor;\r
+uniform float amb;\r
+\r
+float b = .0005;\r
+float minLight = .05;\r
+float radius = sqrt(1.0 / (b * minLight));\r
+\r
+//float radius = b*minlight;\r
+\r
+void main(){\r
+       vec4 color = vec4(0.0,0.0,0.0,0.0);\r
+       for(int i = 0; i < numLight; i++){\r
+               vec2 loc = lightLocation[i];\r
+               float dist = length(loc - gl_FragCoord.xy);\r
+               //float attenuation=1.0/(1.0+0.01*dist+0.00000000001*dist*dist);\r
+               float attenuation = clamp(1.0 - dist*dist/(radius*radius), 0.0, 1.0); attenuation *= attenuation;\r
+\r
+               color += vec4(attenuation, attenuation, attenuation, 1.0) * vec4(lightColor, 1.0);\r
+       }\r
+       vec2 coords = gl_TexCoord[0].st;\r
+       vec4 tex = texture2D(sampler, coords);\r
+\r
+       color += vec4(amb,amb,amb,1.0+amb);\r
+       gl_FragColor = tex * vec4(color)*tex.a;\r
+}\r
+\r
+/*     b values\r
+       .002            10\r
+       .008            50\r
+       .0005           200\r
+       .00008          500\r
+       .00002          1000\r
+       .00005          2000\r
+*/
\ No newline at end of file
index 85225d841cbd39aae85406d3f652ebc8ebe67823..7160d37886665f737fd8ad732532599b1fb3ab5f 100644 (file)
@@ -28,6 +28,8 @@ namespace Texture{
         */
        
        GLuint loadTexture(const char *fileName);
+       void initColorIndex();
+       vec2 getIndex(Color c);
 }
 
 /**
index ae832f1bed777c09fe06f22895c8f6e27d42ba0a..f5952ebfdb318b983a026a7ca85d7aa37a55fd84 100644 (file)
@@ -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).
  */
index d434546914614038dcc0e59b72e49dd2822a9030..51032efb1f9969e661c2a926532442ade04e341e 100644 (file)
@@ -57,6 +57,8 @@ public:
        float velx;
        float vely;
        Color color;
+       vec2 index;
+       //GLuint tex;
        float duration;
        bool canMove;
        bool fountain;
@@ -76,13 +78,26 @@ 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);
+               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);
+               glEnd();
+               glDisable(GL_TEXTURE_2D);
+               //glRectf(loc.x,loc.y,loc.x+width,loc.y+height);
        }
        bool kill(float delta){
                duration -= delta;
@@ -93,6 +108,8 @@ public:
        }
 };
 
+void initEntity();
+
 class Entity{
 public:
        Inventory *inv;
index 7487e4c0df48d868198e6ca07b1fe285fc913465..c10faee59f2a93f016dc02f62251d2295fb22d13 100644 (file)
--- a/main.cpp
+++ b/main.cpp
@@ -119,6 +119,7 @@ unsigned int deltaTime = 0;
 
 GLuint fragShader;
 GLuint shaderProgram;
+GLuint colorIndex;
 
 Mix_Chunk *crickets;
 
@@ -349,6 +350,8 @@ int main(/*int argc, char *argv[]*/){
        
        SDL_ShowCursor(SDL_DISABLE);
 
+       Texture::initColorIndex();
+       initEntity();
        /*
         *      Initializes our shaders so that the game has shadows.
        */
@@ -357,7 +360,7 @@ int main(/*int argc, char *argv[]*/){
 
        fragShader = glCreateShader(GL_FRAGMENT_SHADER);
 
-       std::string shaderFileContents = readFile("test.frag");
+       std::string shaderFileContents = readFile("frig.frag");
        const GLchar *shaderSource = shaderFileContents.c_str();
 
        GLint bufferln = GL_FALSE;
@@ -956,13 +959,13 @@ 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,HLINE, rand()%2 == 0?-(rand()%7)*.01:(rand()%7)*.01,((4+rand()%6)*.05), {0,0,255}, 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;
                                }
index 5e367a969dcd131088ee899eff6433b8844b3e27..296595930d12704e67fb34860513d13077a23a73 100644 (file)
@@ -10,6 +10,7 @@ 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 +64,47 @@ namespace Texture{
                
                return object;
        }
+
+       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_RGBA, GL_UNSIGNED_BYTE, buffer);
+               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;
+                               }
+                               //std::cout << std::endl;
+                       }
+               }
+
+       }
+
+       //sqrt((255-145)^2+(90-145)^2+(0-0)^2);
+       vec2 getIndex(Color c){
+               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));
+                               //std::cout << buff << std::endl;
+                               if(buff < shit){
+                                       shit = buff;
+                                       buf[0] = o;
+                                       buf[1] = t;
+                               }
+                       }
+               }
+               std::cout << float(buf[1]) << ", " << float(buf[0]) << std::endl;
+               return {float(buf[1]),float(buf[0])};
+       }
 }
 
 Texturec::Texturec(uint amt, ...){
index ec335c7cde3073f007415104ae38f29018abeabf..76b9aa4284af92a7c61635fddbfc8c083d5d8800 100644 (file)
@@ -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;