]> code.bitgloo.com Git - clyne/gamedev.git/commitdiff
Added lights
authordrumsetmonkey <abelleisle@roadrunner.com>
Fri, 18 Dec 2015 12:32:05 +0000 (07:32 -0500)
committerdrumsetmonkey <abelleisle@roadrunner.com>
Fri, 18 Dec 2015 12:32:05 +0000 (07:32 -0500)
include/common.h
main.cpp
src/entities.cpp
src/world.cpp
test.frag

index 5c90222f06dea94dc1ef1d181524d9d8e97e5e82..9dcc1104bafbdbf6aed6e0512bc64d273c9531d3 100644 (file)
@@ -14,6 +14,7 @@
 #include <math.h>
 #include <string>
 #include <fstream>     
+#include <thread>
 
 #define GLEW_STATIC
 #include <GL/glew.h>
@@ -34,7 +35,7 @@ typedef unsigned int uint;
  * This flag lets the compiler know that we want to use shaders.
  */
 
-#define SHADERSs
+#define SHADERS
 
 /**
  * This structure contains a set of coordinates for ease of coding.
index 80bbeb9f072e119bffd876c4038ea9de7017b129..014d9504b0fcb20913c3b7974cea540e5525a320 100644 (file)
--- a/main.cpp
+++ b/main.cpp
@@ -595,7 +595,6 @@ void render(){
         *      Call the world's draw function, drawing the player, the world, the background, and entities. Also
         *      draw the player's inventory if it exists.
        */
-       glUseProgramObjectARB(shaderProgram);
 
        player->near=true;                      // Draw the player's name
 
@@ -676,12 +675,20 @@ void render(){
                }
                glUseProgramObjectARB(0);
        }
+
+       glUseProgramObjectARB(shaderProgram);
+       glUniform2f(glGetUniformLocation(shaderProgram, "lightLocation"), 250,250);
+       glUniform3f(glGetUniformLocation(shaderProgram, "lightColor"), 1,0,0);
+       glColor4f(0.0f,0.0f,0.0f,1.0f);
+       glRectf(-SCREEN_WIDTH/2,0,SCREEN_WIDTH/2,SCREEN_HEIGHT);
+       glUseProgramObjectARB(0);
+
        player->inv->draw();
        
        /*
         *      Here we draw a black overlay if it's been requested.
        */
-       glUseProgramObjectARB(0);
+       //glUseProgramObjectARB(0);
 
        
        if(fadeIntensity){
@@ -772,6 +779,7 @@ void render(){
 static volatile bool objectInteracting = false;
 
 void logic(){
+
        /*
         *      NPCSelected is used to insure that only one NPC is made interactable with the mouse
         *      if, for example, multiple entities are occupying one space.
index 6a2f4db1386616a27accf0d9944ed5dac40f74be..cd8d29e67e68f4093f14ca0bcec18d2b767cac99 100644 (file)
@@ -83,8 +83,8 @@ Player::Player(){ //sets all of the player specific traits on object creation
        subtype = 0;    
        health = maxHealth = 100;
        speed = 1;
-       //tex = new Texturec(3, "assets/player1.png", "assets/player.png", "assets/player2.png");
-       tex = new Texturec(3, "assets/maybeplayer.png", "assets/maybeplayer.png", "assets/maybeplayer.png");
+       tex = new Texturec(3, "assets/player1.png", "assets/player.png", "assets/player2.png");
+       //tex = new Texturec(3, "assets/maybeplayer.png", "assets/maybeplayer.png", "assets/maybeplayer.png");
        inv = new Inventory(PLAYER_INV_SIZE);
 }
 Player::~Player(){
index 7f4d6f62d2c9828c6bd9307f7df1eb90ad7326e3..0ecf7ee74f61d0a136b61f73702fd1afe3f495b3 100644 (file)
@@ -555,7 +555,6 @@ LOOP2:
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); //for the s direction
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); //for the t direction
        glBegin(GL_QUADS);
-               std::cout<<shade<<std::endl;
                for(i=is;i<(unsigned)ie-GEN_INC;i++){
                        cline[i].y+=(yoff-DRAW_Y_OFFSET);                                                                                                                       // Add the y offset
                        if(!cline[i].y){
index 13fe6bc526dfac8ca8ec3ea11b2ef47ae6828c08..18b03df044732e496bbc5c324524aab3d621f3fd 100644 (file)
--- a/test.frag
+++ b/test.frag
@@ -1,4 +1,17 @@
-#version 120\r
-void main(){\r
-       gl_FragColor = glColor;\r
-}\r
+uniform vec2 lightLocation;\r
+uniform vec3 lightColor;\r
+uniform float screenHeight;\r
+\r
+float radius = 4.9;\r
+float minLight = .01;\r
+float a = .01;\r
+float b = 1.0 / (radius*radius * minLight);\r
+\r
+void main() {\r
+       float distance = length(lightLocation - gl_FragCoord.xy);\r
+       //float attenuation = 1.0 / (1.0 + a*distance + b*distance*distance);\r
+       float attenuation = clamp(1.0 - distance*distance/(radius*radius), 0.0, 1.0); attenuation *= attenuation;\r
+       vec4 color = vec4(attenuation, attenuation, attenuation, attenuation) * vec4(lightColor, 1);\r
+\r
+       gl_FragColor = color;\r
+}
\ No newline at end of file