--- /dev/null
+#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
*/
GLuint loadTexture(const char *fileName);
+ void initColorIndex();
+ vec2 getIndex(Color c);
}
/**
#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.
*/
float blue;
} Color;
+#include <Texture.h>
+
/**
* Define the game's name (displayed in the window title).
*/
float velx;
float vely;
Color color;
+ vec2 index;
+ //GLuint tex;
float duration;
bool canMove;
bool fountain;
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;
}
};
+void initEntity();
+
class Entity{
public:
Inventory *inv;
GLuint fragShader;
GLuint shaderProgram;
+GLuint colorIndex;
Mix_Chunk *crickets;
SDL_ShowCursor(SDL_DISABLE);
+ Texture::initColorIndex();
+ initEntity();
/*
* Initializes our shaders so that the game has shadows.
*/
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;
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;
}
unsigned int LoadedTextureCounter = 0;
namespace Texture{
+ Color pixels[8][4];
GLuint loadTexture(const char *fileName){
SDL_Surface *image;
GLuint object = 0;
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, ...){
"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;