]> code.bitgloo.com Git - clyne/gamedev.git/commitdiff
Added glew and shader loading
authordrumsetmonkey <abelleisle@roadrunner.com>
Thu, 15 Oct 2015 13:07:05 +0000 (09:07 -0400)
committerdrumsetmonkey <abelleisle@roadrunner.com>
Thu, 15 Oct 2015 13:07:05 +0000 (09:07 -0400)
Makefile
include/common.h
include/entities.h
main.cpp
shader.frag [new file with mode: 0644]
src/entities.cpp
src/ui.cpp

index 387f5f388e61a811983fc7d571cd9410326c6452..da4e36ab6151995f96134aeef117aba0151f9164 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,10 +1,10 @@
 LIBS = -lGL\r
 WIN_LIBS = -lopengl32 -lmingw32\r
 \r
-FLAGS = -m32 -std=c++11 -Iinclude -Iinclude/freetype2 -lSDL2main -lSDL2 -lfreetype -lSDL2_image -lSDL2_mixer\r
+FLAGS = -m32 -std=c++11 -Iinclude -Iinclude/freetype2 -lGL -lGLEW -lSDL2main -lSDL2 -lfreetype -lSDL2_image -lSDL2_mixer\r
 \r
-all:
-       @rm -f out/*.o
+all:\r
+       @rm -f out/*.o\r
        @cd src; $(MAKE) $(MFLAGS)\r
        @echo "  CXX  main.cpp"\r
        @g++ $(FLAGS) -o main main.cpp out/*.o $(LIBS)\r
index b2ef8a33d2f833a13c5633de506b7a4f3ab17233..2cf98e445f37b6072b34b02d41afd321c1a44166 100644 (file)
@@ -8,9 +8,10 @@
 #include <math.h>
 #include <cstdlib>
 #include <SDL2/SDL.h>
+#include <GL/glew.h>
+#include <SDL2/SDL_opengl.h>
 #include <SDL2/SDL_image.h>
 #include <SDL2/SDL_mixer.h>
-#include <SDL2/SDL_opengl.h>
 
 typedef struct { float x; float y; }vec2;
 
index fc2f35ca06bf2b8084a3d4359c86b0dbe08c4560..5b6bcf197c3c704a9402b52738da16da25e69ab5 100644 (file)
@@ -100,7 +100,3 @@ ENTITY TYPES
 <<<<<<< HEAD
 |->1 Rabbit
 **/
-=======
-|->1 Skirl
-**/
->>>>>>> 58716d5e4f20eb5a30025c88fe5119a0e40c4187
index 5595c7ecfbe382b982d1018d9b0152633d9c0fb5..a8c6cd214752a0ba3f045ae652c99fe6fc5e441c 100644 (file)
--- a/main.cpp
+++ b/main.cpp
@@ -48,6 +48,10 @@ unsigned int millis(void){
 
 int main(int argc, char *argv[]){
        // Initialize SDL
+       if(glewInit() < 0){
+               std::cout << "GLEW was not able to initialize! Error: " << std::endl;
+               return -1;
+       }
        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;
@@ -93,6 +97,31 @@ int main(int argc, char *argv[]){
        glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
        SDL_ShowCursor(SDL_DISABLE);                                            // Hide mouse cursor so we can draw our own
 
+       /**
+       *               SHADERS
+       **/
+
+       /*GLuint fragShader;
+       GLuint shaderProgram;
+
+       const GLchar *shaderSource = "shader.frag";
+       GLint bufferln = GL_FALSE;
+
+       shaderProgram = glCreateProgram();
+       fragShader = glCreateShader(GL_FRAGMENT_SHADER);
+       glShaderSource(fragShader, 1, &shaderSource, NULL);
+       glCompileShader(fragShader);
+       glGetShaderiv(fragShader, GL_COMPILE_STATUS, &bufferln);
+       if (bufferln == GL_TRUE){
+               std::cout << "Error compiling shader" << std::endl;
+       }
+       glAttachShader(shaderProgram, fragShader);
+       glLinkProgram(shaderProgram);
+       glValidateProgram(shaderProgram);
+
+       //glEnable(GL_DEPTH_TEST);
+       //glEnable(GL_MULTISAMPLE);*/
+
        names = fopen("assets/names_en-us", "r+");      // Open the names file
        
        initEverything();                                                       // Run world maker thing in src/gameplay.cpp
diff --git a/shader.frag b/shader.frag
new file mode 100644 (file)
index 0000000..7627a12
--- /dev/null
@@ -0,0 +1,13 @@
+#version 140\r
+\r
+uniform vec2 lightLocation;\r
+uniform vec3 lightColor;\r
+uniform float screenHeight;\r
+\r
+void main(){\r
+       float distance = length(lightLocation - gl_FragCoord.xy);\r
+       float attenuation = 1.0 / distance;\r
+       vec4 color = vec4(attenuation, attenuation, attenuation, pow(attenuation, 3)) * vec4(lightColor, 1);\r
+       \r
+       gl_FragColor = color;\r
+}
\ No newline at end of file
index 0457ba17f09bc66f988de680edcb46f2a3b5816e..f9bd015ac0cc9e254e72d45ffa627714e282ba55 100644 (file)
@@ -109,10 +109,10 @@ void Entity::draw(void){          //draws the entities
                                texState-=1;
                                if(texState==0)up=true;
                        }
-               }if(ground == 0){
-                       glBindTexture(GL_TEXTURE_2D, texture[1]);
                }
-               else if(vel.x != 0){
+               if(ground == 0){
+                       glBindTexture(GL_TEXTURE_2D, texture[1]);
+               }else if(vel.x != 0){
                        switch(texState){
                                case 0:
                                        glBindTexture(GL_TEXTURE_2D,texture[1]);
@@ -156,7 +156,7 @@ void Entity::draw(void){            //draws the entities
                ui::setFontSize(16);
                ui::putText(((SCREEN_WIDTH / 2 ) + loc.x) - 125, SCREEN_HEIGHT - ui::fontSize, "Health: %d/%d",health,maxHealth);
                glColor3ub(255,0,0);
-               glRectf((SCREEN_WIDTH / 2 + loc.x) - 125, SCREEN_HEIGHT - 32, ((SCREEN_WIDTH / 2 + loc.x) - 125) + (int)((int)(health / maxHealth) * 100), SCREEN_HEIGHT - 32 + 12);
+               glRectf((SCREEN_WIDTH / 2 + loc.x) - 125, SCREEN_HEIGHT - 32, ((SCREEN_WIDTH / 2 + loc.x) - 125) + (((float)health / (float)maxHealth) * 100), SCREEN_HEIGHT - 32 + 12);
        }
        if(near){
                ui::setFontSize(14);
index fe5414cdb14ba26e65ca2b574c0b0835f6a2cd5d..5c5df20c4d5ff1fe707d5e2e49e52f8be94c761f 100644 (file)
@@ -55,7 +55,7 @@ namespace ui {
                        abort();
                }
                // Load the bitmap with OpenGL
-               glActiveTexture(GL_TEXTURE0);
+               //glActiveTexture(GL_TEXTURE0);
                glGenTextures(1,&ftex);
                glBindTexture(GL_TEXTURE_2D,ftex);
                glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_CLAMP_TO_EDGE);