aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordrumsetmonkey <abelleisle@roadrunner.com>2015-10-15 09:07:05 -0400
committerdrumsetmonkey <abelleisle@roadrunner.com>2015-10-15 09:07:05 -0400
commitef74ae83db1d3049e4e890df77d25ac6e1f7719f (patch)
tree15b01f3ac4f4f2ef06e6fe463ce5e053b26a02e2
parent5adabb82443b9b10b25cdd8b4db3cfe890e36fa1 (diff)
Added glew and shader loading
-rw-r--r--Makefile6
-rw-r--r--include/common.h3
-rw-r--r--include/entities.h4
-rw-r--r--main.cpp29
-rw-r--r--shader.frag13
-rw-r--r--src/entities.cpp8
-rw-r--r--src/ui.cpp2
7 files changed, 52 insertions, 13 deletions
diff --git a/Makefile b/Makefile
index 387f5f3..da4e36a 100644
--- a/Makefile
+++ b/Makefile
@@ -1,10 +1,10 @@
LIBS = -lGL
WIN_LIBS = -lopengl32 -lmingw32
-FLAGS = -m32 -std=c++11 -Iinclude -Iinclude/freetype2 -lSDL2main -lSDL2 -lfreetype -lSDL2_image -lSDL2_mixer
+FLAGS = -m32 -std=c++11 -Iinclude -Iinclude/freetype2 -lGL -lGLEW -lSDL2main -lSDL2 -lfreetype -lSDL2_image -lSDL2_mixer
-all:
- @rm -f out/*.o
+all:
+ @rm -f out/*.o
@cd src; $(MAKE) $(MFLAGS)
@echo " CXX main.cpp"
@g++ $(FLAGS) -o main main.cpp out/*.o $(LIBS)
diff --git a/include/common.h b/include/common.h
index b2ef8a3..2cf98e4 100644
--- a/include/common.h
+++ b/include/common.h
@@ -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;
diff --git a/include/entities.h b/include/entities.h
index fc2f35c..5b6bcf1 100644
--- a/include/entities.h
+++ b/include/entities.h
@@ -100,7 +100,3 @@ ENTITY TYPES
<<<<<<< HEAD
|->1 Rabbit
**/
-=======
-|->1 Skirl
-**/
->>>>>>> 58716d5e4f20eb5a30025c88fe5119a0e40c4187
diff --git a/main.cpp b/main.cpp
index 5595c7e..a8c6cd2 100644
--- 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
index 0000000..7627a12
--- /dev/null
+++ b/shader.frag
@@ -0,0 +1,13 @@
+#version 140
+
+uniform vec2 lightLocation;
+uniform vec3 lightColor;
+uniform float screenHeight;
+
+void main(){
+ float distance = length(lightLocation - gl_FragCoord.xy);
+ float attenuation = 1.0 / distance;
+ vec4 color = vec4(attenuation, attenuation, attenuation, pow(attenuation, 3)) * vec4(lightColor, 1);
+
+ gl_FragColor = color;
+} \ No newline at end of file
diff --git a/src/entities.cpp b/src/entities.cpp
index 0457ba1..f9bd015 100644
--- a/src/entities.cpp
+++ b/src/entities.cpp
@@ -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);
diff --git a/src/ui.cpp b/src/ui.cpp
index fe5414c..5c5df20 100644
--- a/src/ui.cpp
+++ b/src/ui.cpp
@@ -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);