aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Makefile6
-rw-r--r--include/common.h3
-rw-r--r--include/entities.h2
-rw-r--r--main.cpp29
-rw-r--r--shader.frag13
-rw-r--r--src/entities.cpp6
-rw-r--r--src/ui.cpp2
7 files changed, 53 insertions, 8 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 1f2b249..431407b 100644
--- a/include/entities.h
+++ b/include/entities.h
@@ -100,5 +100,5 @@ ENTITY TYPES
|->1 Merchant
|
2 MOBS
-|->1 Skirl
+|->1 Rabbit
**/
diff --git a/main.cpp b/main.cpp
index 6897902..bb93a07 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 080da3e..32b74fe 100644
--- a/src/entities.cpp
+++ b/src/entities.cpp
@@ -113,7 +113,9 @@ void Entity::draw(void){ //draws the entities
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]);
@@ -158,7 +160,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 8e80341..2689766 100644
--- a/src/ui.cpp
+++ b/src/ui.cpp
@@ -57,7 +57,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);