]> code.bitgloo.com Git - clyne/gamedev.git/commitdiff
Added new project for lighting test
authordrumsetmonkey <abelleisle@roadrunner.com>
Mon, 2 Nov 2015 13:50:39 +0000 (08:50 -0500)
committerdrumsetmonkey <abelleisle@roadrunner.com>
Mon, 2 Nov 2015 13:50:39 +0000 (08:50 -0500)
assets/lightTest/Makefile [new file with mode: 0644]
assets/lightTest/main.cp [new file with mode: 0644]
assets/lightTest/main.cpp [new file with mode: 0644]
include/common.h
main.cpp
shader.frag

diff --git a/assets/lightTest/Makefile b/assets/lightTest/Makefile
new file mode 100644 (file)
index 0000000..c4d1042
--- /dev/null
@@ -0,0 +1,6 @@
+LIBS = -lGL -lGLEW -lSDL2main -lSDL2 -lfreetype -lSDL2_image -lSDL2_mixer
+
+FLAGS = -m32 -std=c++11 -Iinclude -Iinclude/freetype2
+
+all:
+       @g++ $(FLAGS) -o main main.cpp $(LIBS)
\ No newline at end of file
diff --git a/assets/lightTest/main.cp b/assets/lightTest/main.cp
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/assets/lightTest/main.cpp b/assets/lightTest/main.cpp
new file mode 100644 (file)
index 0000000..4091389
--- /dev/null
@@ -0,0 +1,67 @@
+#include <GL/glew.h>
+
+#include <SDL2/SDL.h>
+#include <SDL2/SDL_opengl.h>
+#include <SDL2/SDL_image.h>
+#include <SDL2/SDL_mixer.h>
+#include <iostream>
+
+#define SCREEN_WIDTH 1280
+#define        SCREEN_HEIGHT 720
+
+SDL_Window* window;
+SDL_GLContext  mainGLContext = NULL;
+
+int main(void){
+       if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) < 0){
+               std::cout << "SDL was not able to initialize! Error: " << SDL_GetError() << std::endl;
+               return -1;
+       }
+       // Run SDL_Quit when main returns
+    atexit(SDL_Quit);
+
+           window = SDL_CreateWindow("Ass",
+                                                         SDL_WINDOWPOS_UNDEFINED,      // Spawn the window at random (undefined) x and y coordinates
+                                                         SDL_WINDOWPOS_UNDEFINED,      //
+                                                         SCREEN_WIDTH,
+                                                         SCREEN_HEIGHT,
+                                                         SDL_WINDOW_SHOWN | SDL_WINDOW_OPENGL
+#ifdef FULLSCREEN
+                                                         | SDL_WINDOW_FULLSCREEN
+#endif // FULLSCREEN
+                              );
+
+       if(window==NULL){
+               std::cout << "The window failed to generate! SDL_Error: " << SDL_GetError() << std::endl;
+        return -1;
+    }
+
+    if((mainGLContext = SDL_GL_CreateContext(window)) == NULL){
+               std::cout << "The OpenGL context failed to initialize! SDL_Error: " << SDL_GetError() << std::endl;
+        return -1;
+    }
+       
+
+    GLenum err;
+       glewExperimental = GL_TRUE;
+       if((err=glewInit()) != GLEW_OK){
+               std::cout << "GLEW was not able to initialize! Error: " << glewGetErrorString(err) << std::endl;
+               return -1;
+       }
+
+       SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
+       
+       glViewport(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
+       
+       glEnable(GL_BLEND);
+       glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+
+
+       bool gameRunning = true;
+    while(gameRunning){
+
+    }
+    SDL_GL_DeleteContext(mainGLContext);
+    SDL_DestroyWindow(window);
+    return 0;
+}
\ No newline at end of file
index 359e82528eb943098cfb244cbaf7e67b3404f209..0e4373b0b325118a21dee8e6ba66810a7f58fd74 100644 (file)
@@ -32,7 +32,7 @@
  *     This flag lets the compiler know that we are using shaders
 */
 
- #define SHADERSere
+ #define SHADERS
 
 /*
  *     Create a basic 2-point structure for coordinate saving
index f017023c5b61647c51951f87eb766fcfbac3133e..848d80f5d75c1d8d9929047a20ef19b974091567 100644 (file)
--- a/main.cpp
+++ b/main.cpp
@@ -210,7 +210,7 @@ typedef enum {
        RAIN
 } WEATHER;
 
-#define DAY_CYCLE 10000
+#define DAY_CYCLE 3000
 
 static WEATHER weather = SUNNY;
 static vec2 star[100];
@@ -362,7 +362,7 @@ int main(int argc, char *argv[]){
 
                fragShader = glCreateShader(GL_FRAGMENT_SHADER);
 
-               std::string shaderFileContents = readFile("test.frag");
+               std::string shaderFileContents = readFile("shader.frag");
                const GLchar *shaderSource = shaderFileContents.c_str();
 
                GLint bufferln = GL_FALSE;
@@ -724,15 +724,20 @@ void render(){
        */
 
        player->near=true;                      // Draw the player's name
+       
+       currentWorld->draw(player);
 
        #ifdef SHADERS
                glUseProgramObjectARB(shaderProgram);
-               glUniform2f(glGetUniformLocation(shaderProgram, "lightLocation"), 0,100);
-               glUniform3f(glGetUniformLocation(shaderProgram, "lightColor"), 255,255,255);
+               glUniform2f(glGetUniformLocation(shaderProgram, "lightLocation"), 640,100);
+               glUniform3f(glGetUniformLocation(shaderProgram, "lightColor"), 1,1,1);
+               glUniform1f(glGetUniformLocation(shaderProgram, "lightStrength"), 100 + (1000-(shade*10)));
+               std::cout << 100 + (1000-(shade*10)) << std::endl;
                //glBlendFunc(GL_ONE, GL_ONE);
        #endif //SHADERS
-       
-       currentWorld->draw(player);
+
+       glColor4ub(0,0,0,200);
+       glRectf(offset.x-SCREEN_WIDTH/2,0,offset.x+SCREEN_WIDTH/2,SCREEN_HEIGHT);
 
        #ifdef SHADERS
                glUseProgramObjectARB(0);
index 83c8bdcb2eec9f8063b98158622488395c584a15..6f90a5f9cea2503751c9650318a7313e7a6e11bc 100644 (file)
@@ -2,12 +2,19 @@
 \r
 uniform vec2 lightLocation;\r
 uniform vec3 lightColor;\r
+uniform float lightStrength;\r
 uniform float screenHeight;\r
 \r
+uniform vec2 rayStart;\r
+uniform vec2 rayEnd;\r
+\r
+uniform sampler2D tex;\r
+uniform vec2 resolution;\r
+\r
 void main(){\r
        float distance = length(lightLocation - gl_FragCoord.xy);\r
-       float attenuation = 3.0 / distance;\r
-       vec4 color = vec4(attenuation, attenuation, attenuation, pow(attenuation, 3)) * vec4(lightColor, 1);\r
+       float attenuation = lightStrength / distance;\r
+       vec4 color = vec4(0, 0, 0, 0.8f - pow(attenuation, 3)) * vec4(lightColor, 1);\r
        \r
        gl_FragColor = color;\r
 }
\ No newline at end of file