aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--brice.dat4
-rw-r--r--include/common.hpp27
-rw-r--r--include/entities.hpp2
-rw-r--r--include/texture.hpp1
-rw-r--r--main.cpp13
-rw-r--r--shaders/new.frag6
-rw-r--r--shaders/new.vert3
-rw-r--r--src/common.cpp44
-rw-r--r--src/entities.cpp65
-rw-r--r--src/inventory.cpp226
-rw-r--r--src/texture.cpp56
-rw-r--r--src/ui.cpp285
-rw-r--r--src/world.cpp66
-rw-r--r--ttf/atomics.TTFbin0 -> 8300 bytes
-rw-r--r--ttf/atomicsc.TTFbin0 -> 12844 bytes
-rw-r--r--ttf/yapix.ttfbin0 -> 54352 bytes
-rw-r--r--xml/playerSpawnHill1.xml4
17 files changed, 534 insertions, 268 deletions
diff --git a/brice.dat b/brice.dat
index ea71945..61d57c2 100644
--- a/brice.dat
+++ b/brice.dat
@@ -1,5 +1,5 @@
2
-canSprint
-0
canJump
0
+canSprint
+0
diff --git a/include/common.hpp b/include/common.hpp
index e082a87..2442f5c 100644
--- a/include/common.hpp
+++ b/include/common.hpp
@@ -151,16 +151,25 @@ public:
float red;
float green;
float blue;
- Color()
+ float alpha;
+ Color()
{
- red = green = blue = 0;
+ red = green = blue = alpha = 0;
}
Color(float r, float g ,float b)
{
red = r;
green = g;
blue = b;
+ alpha = 255;
}
+ Color(float r, float g, float b, float a)
+ {
+ red = r;
+ green = g;
+ blue = b;
+ alpha = a;
+ }
Color operator-=(float a) {
red-=a;
green-=a;
@@ -175,6 +184,19 @@ public:
}
};
+/*
+ * A function used to tell the program what shader, attributes, and uniforms
+ * we want to draw our rectangles to. See below |
+ * \|/
+ */
+void useShader(GLuint *sh, GLint *tu, GLint *ca, GLint *ta);
+
+/*
+ * A function to draw a colored box for opengl
+ * To use it, the lower left hand and upper right hand coords are passed along
+ */
+void drawRect(vec2 ll, vec2 ur);
+
// gets the length of `n` HLINEs
template<typename T>
inline T HLINES(const T &n)
@@ -201,6 +223,7 @@ extern GLuint textShader;
extern GLint textShader_attribute_coord;
extern GLint textShader_attribute_tex;
extern GLint textShader_uniform_texture;
+extern GLint textShader_uniform_color;
extern GLuint worldShader;
extern GLint worldShader_attribute_coord;
diff --git a/include/entities.hpp b/include/entities.hpp
index 85b0ec1..ce2e14d 100644
--- a/include/entities.hpp
+++ b/include/entities.hpp
@@ -150,7 +150,7 @@ public:
~Particles(void){}
// draws the particle
- std::vector<std::pair<vec2, vec3>> draw(void) const;
+ void draw(std::vector<GLfloat> &verts, std::vector<GLfloat> &tex) const;
// updates a particle
void update(float _gravity, float ground_y);
diff --git a/include/texture.hpp b/include/texture.hpp
index ecf85e4..df2a83c 100644
--- a/include/texture.hpp
+++ b/include/texture.hpp
@@ -26,6 +26,7 @@ namespace Texture {
*/
GLuint loadTexture(std::string fileName);
+ GLuint genColor(Color c);
void freeTextures(void);
diff --git a/main.cpp b/main.cpp
index 4f84af5..4c3ba81 100644
--- a/main.cpp
+++ b/main.cpp
@@ -64,6 +64,7 @@ GLint textShader_attribute_coord;
GLint textShader_attribute_tex;
GLint textShader_uniform_texture;
GLint textShader_uniform_transform;
+GLint textShader_uniform_color;
/**
* These are the source and index variables for the world
@@ -218,7 +219,7 @@ int main(int argc, char *argv[]){
textShader_attribute_tex = get_attrib(textShader, "tex_coord");
textShader_uniform_texture = get_uniform(textShader, "sampler");
textShader_uniform_transform = get_uniform(textShader, "ortho");
-
+ textShader_uniform_color = get_uniform(textShader, "tex_color");
/**
* Creating the world's shader and its attributes/uniforms
@@ -371,18 +372,20 @@ void render() {
10.0f, //near
-10.0f); //far
- glm::mat4 view = glm::lookAt(glm::vec3(0,0,10.0f), //pos
- glm::vec3(0,0,0.0f), //looking at
+ glm::mat4 view = glm::lookAt(glm::vec3(0,0,0.0f), //pos
+ glm::vec3(0,0,-10.0f), //looking at
glm::vec3(0,1.0f,0)); //up vector
glm::mat4 ortho = projection * view;
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
- //glEnable(GL_DEPTH_TEST);
+ // TODO add depth
+ //glEnable(GL_DEPTH_TEST);
glUseProgram(textShader);
glUniformMatrix4fv(textShader_uniform_transform, 1, GL_FALSE, glm::value_ptr(ortho));
- glUseProgram(worldShader);
+ glUniform4f(textShader_uniform_color, 1.0, 1.0, 1.0, 1.0);
+ glUseProgram(worldShader);
glUniformMatrix4fv(worldShader_uniform_transform, 1, GL_FALSE, glm::value_ptr(ortho));
/**************************
diff --git a/shaders/new.frag b/shaders/new.frag
index 8812d72..fa8a260 100644
--- a/shaders/new.frag
+++ b/shaders/new.frag
@@ -1,9 +1,9 @@
uniform sampler2D sampler;
varying vec2 texCoord;
-varying float join;
+varying vec4 color;
void main(){
- vec4 color = texture2D(sampler, vec2(texCoord.x, texCoord.y));
- gl_FragColor = color;
+ vec4 pixelColor = texture2D(sampler, vec2(texCoord.x, texCoord.y));
+ gl_FragColor = pixelColor * color;
}
diff --git a/shaders/new.vert b/shaders/new.vert
index 1bedfd3..b2fcba4 100644
--- a/shaders/new.vert
+++ b/shaders/new.vert
@@ -2,10 +2,13 @@ attribute vec3 coord2d;
attribute vec2 tex_coord;
uniform mat4 ortho;
+uniform vec4 tex_color;
varying vec2 texCoord;
+varying vec4 color;
void main(){
texCoord = tex_coord;
+ color = tex_color;
gl_Position = ortho * vec4(coord2d.xyz, 1.0);
}
diff --git a/src/common.cpp b/src/common.cpp
index 45ab5b6..060da00 100644
--- a/src/common.cpp
+++ b/src/common.cpp
@@ -34,6 +34,50 @@ std::vector<std::string> StringTokenizer(const std::string& str, char delim)
return tokens;
}
+static GLuint *Gshader;
+static GLint *tex_uni;
+static GLint *coord_attrib;
+static GLint *tex_attrib;
+
+void useShader(GLuint *sh, GLint *tu, GLint *ca, GLint *ta)
+{
+ Gshader = sh;
+ tex_uni = tu;
+ coord_attrib = ca;
+ tex_attrib = ta;
+}
+
+void drawRect(vec2 ll, vec2 ur)
+{
+ GLfloat verts[] = {ll.x, ll.y, 1.0,
+ ur.x, ll.y, 1.0,
+ ur.x, ur.y, 1.0,
+
+ ur.x, ur.y, 1.0,
+ ll.x, ur.y, 1.0,
+ ll.x, ll.y, 1.0};
+
+ GLfloat tex[] = {0.0, 1.0,
+ 1.0, 1.0,
+ 1.0, 0.0,
+
+ 1.0, 0.0,
+ 0.0, 0.0,
+ 0.0, 1.0};
+
+ glUniform1i(*tex_uni, 0);
+
+ glEnableVertexAttribArray(*coord_attrib);
+ glEnableVertexAttribArray(*tex_attrib);
+
+ glVertexAttribPointer(*coord_attrib, 3, GL_FLOAT, GL_FALSE, 0, verts);
+ glVertexAttribPointer(*tex_attrib, 2, GL_FLOAT, GL_FALSE, 0, tex);
+ glDrawArrays(GL_TRIANGLES, 0, 6);
+
+ glDisableVertexAttribArray(*tex_attrib);
+ glDisableVertexAttribArray(*coord_attrib);
+}
+
void DEBUG_prints(const char* file, int line, const char *s,...)
{
va_list args;
diff --git a/src/entities.cpp b/src/entities.cpp
index 64feaa5..5084fd6 100644
--- a/src/entities.cpp
+++ b/src/entities.cpp
@@ -92,6 +92,7 @@ Entity::Entity(void)
canMove = true;
ground = false;
forcedMove = false;
+ z = -1.0f;
// clear counters
ticksToUse = 0;
@@ -426,23 +427,23 @@ if (health != maxHealth) {
glUniform1i(worldShader_uniform_texture, 0);
GLfloat coord_back[] = {
- loc.x, loc.y + height, 1.0,
- loc.x + width, loc.y + height, 1.0,
- loc.x + width, loc.y + height + game::HLINE * 2, 1.0,
+ loc.x, loc.y + height, z,
+ loc.x + width, loc.y + height, z,
+ loc.x + width, loc.y + height + game::HLINE * 2,z,
- loc.x + width, loc.y + height + game::HLINE * 2, 1.0,
- loc.x, loc.y + height + game::HLINE * 2, 1.0,
- loc.x, loc.y + height, 1.0,
+ loc.x + width, loc.y + height + game::HLINE * 2,z,
+ loc.x, loc.y + height + game::HLINE * 2,z,
+ loc.x, loc.y + height, z,
};
GLfloat coord_front[] = {
- loc.x, loc.y + height, 1.0,
- loc.x + health / maxHealth * width, loc.y + height, 1.0,
- loc.x + health / maxHealth * width, loc.y + height + game::HLINE * 2, 1.0,
+ loc.x, loc.y + height, z,
+ loc.x + health / maxHealth * width, loc.y + height, z,
+ loc.x + health / maxHealth * width, loc.y + height + game::HLINE * 2, z,
- loc.x + health / maxHealth * width, loc.y + height + game::HLINE * 2, 1.0,
- loc.x, loc.y + height + game::HLINE * 2, 1.0,
- loc.x, loc.y + height, 1.0,
+ loc.x + health / maxHealth * width, loc.y + height + game::HLINE * 2, z,
+ loc.x, loc.y + height + game::HLINE * 2, z,
+ loc.x, loc.y + height, z,
};
static const vec2 index1 = Texture::getIndex(Color(0,0,0));
@@ -861,21 +862,43 @@ Particles::Particles(float x, float y, float w, float h, float vx, float vy, Col
index = Texture::getIndex(c);
}
-std::vector<std::pair<vec2, vec3>> Particles::draw(void) const
+void Particles::draw(std::vector<GLfloat> &verts, std::vector<GLfloat> &tex) const
{
vec2 tc = vec2 {0.25f * index.x, 0.125f * (8-index.y)};
- std::vector<std::pair<vec2, vec3>> tmp;
+ float z = 0.0;
+ if (behind)
+ z = 2.0;
- tmp.push_back(std::make_pair(vec2(tc.x, tc.y), vec3(loc.x, loc.y, 1.0)));
- tmp.push_back(std::make_pair(vec2(tc.x, tc.y), vec3(loc.x + width, loc.y, 1.0)));
- tmp.push_back(std::make_pair(vec2(tc.x, tc.y), vec3(loc.x + width, loc.y + height, 1.0)));
+ verts.push_back(loc.x);
+ verts.push_back(loc.y);
+ verts.push_back(z);
- tmp.push_back(std::make_pair(vec2(tc.x, tc.y), vec3(loc.x + width, loc.y + height, 1.0)));
- tmp.push_back(std::make_pair(vec2(tc.x, tc.y), vec3(loc.x, loc.y + height, 1.0)));
- tmp.push_back(std::make_pair(vec2(tc.x, tc.y), vec3(loc.x, loc.y, 1.0)));
+ verts.push_back(loc.x + width);
+ verts.push_back(loc.y);
+ verts.push_back(z);
+
+ verts.push_back(loc.x + width);
+ verts.push_back(loc.y + height);
+ verts.push_back(z);
- return tmp;
+
+ verts.push_back(loc.x + width);
+ verts.push_back(loc.y + height);
+ verts.push_back(z);
+
+ verts.push_back(loc.x);
+ verts.push_back(loc.y + height);
+ verts.push_back(z);
+
+ verts.push_back(loc.x);
+ verts.push_back(loc.y);
+ verts.push_back(z);
+
+ for (int i = 0; i < 6; i++){
+ tex.push_back(tc.x);
+ tex.push_back(tc.y);
+ }
}
void Particles::update(float _gravity, float ground_y)
diff --git a/src/inventory.cpp b/src/inventory.cpp
index 5445aa9..c64f62f 100644
--- a/src/inventory.cpp
+++ b/src/inventory.cpp
@@ -342,7 +342,7 @@ void Inventory::draw(void) {
if (invOpening) {
for (auto &d : dfp) {
if (!a || dfp[a - 1] > 50)
- d += 1.65f * deltaTime;
+ d += 4.0f * deltaTime;
if (d > range)
d = range;
a++;
@@ -350,7 +350,7 @@ void Inventory::draw(void) {
for (auto &cd : curdfp) {
if (!a || curdfp[a - 1] > 90)
- cd += 1.5f * deltaTime;
+ cd += 3.0f * deltaTime;
if (cd > curRange)
cd = curRange;
a++;
@@ -358,7 +358,7 @@ void Inventory::draw(void) {
while (a < massOrder.size()) {
if (!a || massDfp[massOrder[a - 1]] > massRange * 0.75f)
- massDfp[massOrder[a]] += 5.0f * deltaTime;
+ massDfp[massOrder[a]] += 20.0f * deltaTime;
if (massDfp[massOrder[a]] > massRange)
massDfp[massOrder[a]] = massRange;
a++;
@@ -369,16 +369,16 @@ void Inventory::draw(void) {
} else {
for (auto &d : dfp) {
if (d > 0)
- d -= 1.65f * deltaTime;
+ d -= 4.5f * deltaTime;
}
for (auto &cd : curdfp) {
if (cd > 0)
- cd -= 1.0f * deltaTime;
+ cd -= 3.0f * deltaTime;
}
while (a < massRay.size()) {
if (!a || massDfp[massOrderClosing[a - 1]] <= 0)
- massDfp[massOrderClosing[a]] -= 10.0f * deltaTime;
+ massDfp[massOrderClosing[a]] -= 30.0f * deltaTime;
else if (massDfp[massOrderClosing[a - 1]] < 0)
massDfp[massOrderClosing[a - 1]] = 0;
a++;
@@ -400,36 +400,36 @@ void Inventory::draw(void) {
C("Start drawing inventory");
if (invOpen) {
-
+ useShader(&textShader,
+ &textShader_uniform_texture,
+ &textShader_attribute_coord,
+ &textShader_attribute_tex);
for(auto &mr : massRay) {
- glColor4f(0.0f,0.0f,0.0f, ((float)massDfp[a]/(float)massRange)*.5f);
- glBegin(GL_QUADS);
- glVertex2i(mr.x-(itemWide/2), mr.y-(itemWide/2));
- glVertex2i(mr.x-(itemWide/2)+itemWide,mr.y-(itemWide/2));
- glVertex2i(mr.x-(itemWide/2)+itemWide,mr.y-(itemWide/2)+itemWide);
- glVertex2i(mr.x-(itemWide/2), mr.y-(itemWide/2)+itemWide);
- glEnd();
+ float t = (((float)massDfp[a]/(float)massRange)*.5f);
+ glActiveTexture(GL_TEXTURE0);
+ glUseProgram(textShader);
+
+ glBindTexture(GL_TEXTURE_2D, Texture::genColor(Color(0.0f,0.0f,0.0f, t >= 0? 255*t : 0)));
+ glUniform1i(textShader_uniform_texture, 0);
+
+ drawRect(vec2(mr.x-(itemWide/2), mr.y-(itemWide/2)), vec2(mr.x-(itemWide/2)+itemWide, mr.y-(itemWide/2)+itemWide));
+
+ glUseProgram(0);
if (!Items.empty() && a+numSlot < Items.size() && Items[a+numSlot].second) {
- glEnable(GL_TEXTURE_2D);
- glBindTexture(GL_TEXTURE_2D, Items[a+numSlot].first->tex->image[0]);//itemtex[items[a+numSlot].id]);
- glColor4f(1.0f, 1.0f, 1.0f, ((float)massDfp[a]/(float)(massRange?massRange:1))*0.8f);
- glBegin(GL_QUADS);
- if (Items[a+numSlot].first->dim.y > Items[a+numSlot].first->dim.x) {
- glTexCoord2i(0,1);glVertex2i(mr.x-((itemWide/2)*((float)Items[a+numSlot].first->dim.x/(float)Items[a+numSlot].first->dim.y)), mr.y-(itemWide/2));
- glTexCoord2i(1,1);glVertex2i(mr.x+((itemWide/2)*((float)Items[a+numSlot].first->dim.x/(float)Items[a+numSlot].first->dim.y)), mr.y-(itemWide/2));
- glTexCoord2i(1,0);glVertex2i(mr.x+((itemWide/2)*((float)Items[a+numSlot].first->dim.x/(float)Items[a+numSlot].first->dim.y)), mr.y+(itemWide/2));
- glTexCoord2i(0,0);glVertex2i(mr.x-((itemWide/2)*((float)Items[a+numSlot].first->dim.x/(float)Items[a+numSlot].first->dim.y)), mr.y+(itemWide/2));
- }else{
- glTexCoord2i(0,1);glVertex2i(mr.x-(itemWide/2),mr.y-(itemWide/2)*((float)Items[a+numSlot].first->dim.y/(float)Items[a+numSlot].first->dim.x));
- glTexCoord2i(1,1);glVertex2i(mr.x+(itemWide/2),mr.y-(itemWide/2)*((float)Items[a+numSlot].first->dim.y/(float)Items[a+numSlot].first->dim.x));
- glTexCoord2i(1,0);glVertex2i(mr.x+(itemWide/2),mr.y+(itemWide/2)*((float)Items[a+numSlot].first->dim.y/(float)Items[a+numSlot].first->dim.x));
- glTexCoord2i(0,0);glVertex2i(mr.x-(itemWide/2),mr.y+(itemWide/2)*((float)Items[a+numSlot].first->dim.y/(float)Items[a+numSlot].first->dim.x));
- }
- glEnd();
- glDisable(GL_TEXTURE_2D);
+ glUseProgram(textShader);
+ glBindTexture(GL_TEXTURE_2D, Items[a+numSlot].first->tex->image[0]);//itemtex[items[a+numSlot].id]);
+ glUniform4f(textShader_uniform_color, 1.0f, 1.0f, 1.0f, ((float)massDfp[a]/(float)(massRange?massRange:1))*0.8f);
+ if (Items[a+numSlot].first->dim.y > Items[a+numSlot].first->dim.x) {
+ drawRect(vec2(mr.x-((itemWide/2)*((float)Items[a+numSlot].first->dim.x/(float)Items[a+numSlot].first->dim.y)), mr.y-(itemWide/2)),
+ vec2(mr.x+((itemWide/2)*((float)Items[a+numSlot].first->dim.x/(float)Items[a+numSlot].first->dim.y)), mr.y+(itemWide/2)));
+ }else{
+ drawRect(vec2(mr.x-(itemWide/2),mr.y-(itemWide/2)*((float)Items[a+numSlot].first->dim.y/(float)Items[a+numSlot].first->dim.x)),
+ vec2(mr.x-(itemWide/2),mr.y+(itemWide/2)*((float)Items[a+numSlot].first->dim.y/(float)Items[a+numSlot].first->dim.x)));
+ }
ui::setFontColor(255,255,255,((float)massDfp[a]/(float)(massRange?massRange:1))*255);
ui::putText(mr.x-(itemWide/2)+(itemWide*.85),mr.y-(itemWide/2),"%d",Items[a+numSlot].second);
ui::setFontColor(255,255,255,255);
+ glUseProgram(0);
}
a++;
}a=0;
@@ -438,14 +438,14 @@ void Inventory::draw(void) {
curCurCoord[a].x -= float((curdfp[a]) * cos(-1));
curCurCoord[a].y += float((curdfp[a]) * sin(0));
cr.end = curCurCoord[a];
-
- glColor4f(0.0f, 0.0f, 0.0f, ((float)curdfp[a]/(float)(curRange?curRange:1))*0.5f);
- glBegin(GL_QUADS);
- glVertex2i(cr.end.x-(itemWide/2), cr.end.y-(itemWide/2));
- glVertex2i(cr.end.x-(itemWide/2)+itemWide,cr.end.y-(itemWide/2));
- glVertex2i(cr.end.x-(itemWide/2)+itemWide,cr.end.y-(itemWide/2)+itemWide);
- glVertex2i(cr.end.x-(itemWide/2), cr.end.y-(itemWide/2)+itemWide);
- glEnd();
+
+ float curTrans = (((float)curdfp[a]/(float)(curRange?curRange:1))*0.5f);
+
+ glUseProgram(textShader);
+ glBindTexture(GL_TEXTURE_2D, Texture::genColor(Color(0.0f, 0.0f, 0.0f, curTrans >= 0 ? 255 * curTrans : 0)));
+ drawRect(vec2(cr.end.x-(itemWide/2), cr.end.y-(itemWide/2)),
+ vec2(cr.end.x-(itemWide/2)+itemWide,cr.end.y-(itemWide/2)+itemWide));
+ glUseProgram(0);
a++;
}a=0;
@@ -455,42 +455,33 @@ void Inventory::draw(void) {
curCoord[a].y += float((dfp[a]) * sin(angle*PI/180));
r.end = curCoord[a];
- glColor4f(0.0f, 0.0f, 0.0f, ((float)dfp[a]/(float)(range?range:1))*0.5f);
- glBegin(GL_QUADS);
- glVertex2i(r.end.x-(itemWide/2), r.end.y-(itemWide/2));
- glVertex2i(r.end.x-(itemWide/2)+itemWide,r.end.y-(itemWide/2));
- glVertex2i(r.end.x-(itemWide/2)+itemWide,r.end.y-(itemWide/2)+itemWide);
- glVertex2i(r.end.x-(itemWide/2), r.end.y-(itemWide/2)+itemWide);
- glEnd();
+ float t = ((float)dfp[a]/(float)(range?range:1))*0.5f;
+
+ glUseProgram(textShader);
+ glBindTexture(GL_TEXTURE_2D, Texture::genColor(Color(0.0f, 0.0f, 0.0f, t >= 0 ? 255 * t : 0)));
+ drawRect(vec2(r.end.x-(itemWide/2), r.end.y-(itemWide/2)),
+ vec2(r.end.x-(itemWide/2)+itemWide,r.end.y-(itemWide/2)+itemWide));
if (!Items.empty() && a < numSlot && Items[a].second) {
- glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, Items[a].first->tex->image[0]);//itemtex[items[a].id]);
- glColor4f(1.0f, 1.0f, 1.0f, ((float)dfp[a]/(float)(range?range:1))*0.8f);
- glBegin(GL_QUADS);
+ glUniform4f(textShader_uniform_color, 1.0f, 1.0f, 1.0f, ((float)dfp[a]/(float)(range?range:1))*0.8f);
if (Items[a].first->dim.y > Items[a].first->dim.x) {
- glTexCoord2i(0,1);glVertex2i(r.end.x-((itemWide/2)*((float)Items[a].first->dim.x/(float)Items[a].first->dim.y)), r.end.y-(itemWide/2));
- glTexCoord2i(1,1);glVertex2i(r.end.x+((itemWide/2)*((float)Items[a].first->dim.x/(float)Items[a].first->dim.y)), r.end.y-(itemWide/2));
- glTexCoord2i(1,0);glVertex2i(r.end.x+((itemWide/2)*((float)Items[a].first->dim.x/(float)Items[a].first->dim.y)), r.end.y+(itemWide/2));
- glTexCoord2i(0,0);glVertex2i(r.end.x-((itemWide/2)*((float)Items[a].first->dim.x/(float)Items[a].first->dim.y)), r.end.y+(itemWide/2));
- }else{
- glTexCoord2i(0,1);glVertex2i(r.end.x-(itemWide/2),r.end.y-(itemWide/2)*((float)Items[a].first->dim.y/(float)Items[a].first->dim.x));
- glTexCoord2i(1,1);glVertex2i(r.end.x+(itemWide/2),r.end.y-(itemWide/2)*((float)Items[a].first->dim.y/(float)Items[a].first->dim.x));
- glTexCoord2i(1,0);glVertex2i(r.end.x+(itemWide/2),r.end.y+(itemWide/2)*((float)Items[a].first->dim.y/(float)Items[a].first->dim.x));
- glTexCoord2i(0,0);glVertex2i(r.end.x-(itemWide/2),r.end.y+(itemWide/2)*((float)Items[a].first->dim.y/(float)Items[a].first->dim.x));
+ drawRect(vec2(r.end.x-((itemWide/2)*((float)Items[a].first->dim.x/(float)Items[a].first->dim.y)), r.end.y-(itemWide/2)),
+ vec2(r.end.x+((itemWide/2)*((float)Items[a].first->dim.x/(float)Items[a].first->dim.y)), r.end.y+(itemWide/2)));
+ }else{
+ drawRect(vec2(r.end.x-(itemWide/2),r.end.y-(itemWide/2)*((float)Items[a].first->dim.y/(float)Items[a].first->dim.x)),
+ vec2(r.end.x+(itemWide/2),r.end.y+(itemWide/2)*((float)Items[a].first->dim.y/(float)Items[a].first->dim.x)));
}
- glEnd();
- glDisable(GL_TEXTURE_2D);
ui::setFontColor(255,255,255,((float)dfp[a]/(float)(range?range:1))*255);
ui::putStringCentered(r.end.x,r.end.y-(itemWide*.9),Items[a].first->name);//itemMap[items[a].id]->name);
ui::putText(r.end.x-(itemWide/2)+(itemWide*.85),r.end.y-(itemWide/2),"%d",Items[a].second);
ui::setFontColor(255,255,255,255);
}
-
+ glUseProgram(0);
if (sel == a) {
static float sc = 1;
static bool up;
- up ? sc += .0005*deltaTime : sc -= .0005*deltaTime;
+ up ? sc += .0025*deltaTime : sc -= .0025*deltaTime;
if (sc > 1.2) {
up = false;
sc = 1.2;
@@ -499,28 +490,36 @@ void Inventory::draw(void) {
up = true;
sc = 1.0;
}
- glBegin(GL_QUADS);
- glColor4f(1.0f, 1.0f, 1.0f, ((float)dfp[a]/(float)(range?range:1)));
- glVertex2f(r.end.x - (itemWide*sc)/2 - (itemWide*sc)*.09,r.end.y - (itemWide*sc)/2 - (itemWide*sc)*.09);
- glVertex2f(r.end.x + (itemWide*sc)/2 + (itemWide*sc)*.09,r.end.y - (itemWide*sc)/2 - (itemWide*sc)*.09);
- glVertex2f(r.end.x + (itemWide*sc)/2 + (itemWide*sc)*.09,r.end.y - (itemWide*sc)/2);
- glVertex2f(r.end.x - (itemWide*sc)/2 - (itemWide*sc)*.09,r.end.y - (itemWide*sc)/2);
-
- glVertex2f(r.end.x - (itemWide*sc)/2 - (itemWide*sc)*.09,r.end.y + (itemWide*sc)/2 + (itemWide*sc)*.09);
- glVertex2f(r.end.x + (itemWide*sc)/2 + (itemWide*sc)*.09,r.end.y + (itemWide*sc)/2 + (itemWide*sc)*.09);
- glVertex2f(r.end.x + (itemWide*sc)/2 + (itemWide*sc)*.09,r.end.y + (itemWide*sc)/2);
- glVertex2f(r.end.x - (itemWide*sc)/2 - (itemWide*sc)*.09,r.end.y + (itemWide*sc)/2);
-
- glVertex2f(r.end.x - (itemWide*sc)/2 - (itemWide*sc)*.09,r.end.y - (itemWide*sc)/2 - (itemWide*sc)*.09);
- glVertex2f(r.end.x - (itemWide*sc)/2 ,r.end.y - (itemWide*sc)/2 - (itemWide*sc)*.09);
- glVertex2f(r.end.x - (itemWide*sc)/2 ,r.end.y + (itemWide*sc)/2 + (itemWide*sc)*.09);
- glVertex2f(r.end.x - (itemWide*sc)/2 - (itemWide*sc)*.09,r.end.y + (itemWide*sc)/2 + (itemWide*sc)*.09);
-
- glVertex2f(r.end.x + (itemWide*sc)/2 ,r.end.y - (itemWide*sc)/2 - (itemWide*sc)*.09);
- glVertex2f(r.end.x + (itemWide*sc)/2 + (itemWide*sc)*.09,r.end.y - (itemWide*sc)/2 - (itemWide*sc)*.09);
- glVertex2f(r.end.x + (itemWide*sc)/2 + (itemWide*sc)*.09,r.end.y + (itemWide*sc)/2 + (itemWide*sc)*.09);
- glVertex2f(r.end.x + (itemWide*sc)/2 ,r.end.y + (itemWide*sc)/2 + (itemWide*sc)*.09);
- glEnd();
+ float t = ((float)dfp[a]/(float)(range?range:1));
+ useShader(&textShader,
+ &textShader_uniform_texture,
+ &textShader_attribute_coord,
+ &textShader_attribute_tex);
+
+ glUseProgram(textShader);
+ glUniform4f(textShader_uniform_color, 1.0, 1.0, 1.0, 1.0);
+
+ // bottom
+ glBindTexture(GL_TEXTURE_2D, Texture::genColor(Color(255, 255, 255, t >= 0 ? 255 * t : 0)));
+ drawRect(vec2(r.end.x - (itemWide*sc)/2 - (itemWide*sc)*.09,r.end.y - (itemWide*sc)/2 - (itemWide*sc)*.09),
+ vec2(r.end.x + (itemWide*sc)/2 + (itemWide*sc)*.09,r.end.y - (itemWide*sc)/2));
+
+ // top
+ glBindTexture(GL_TEXTURE_2D, Texture::genColor(Color(255, 255, 255, t >= 0 ? 255 * t : 0)));
+ drawRect(vec2(r.end.x - (itemWide*sc)/2 - (itemWide*sc)*.09,r.end.y + (itemWide*sc)/2 + (itemWide*sc)*.09),
+ vec2(r.end.x + (itemWide*sc)/2 + (itemWide*sc)*.09,r.end.y + (itemWide*sc)/2));
+
+ // left
+ glBindTexture(GL_TEXTURE_2D, Texture::genColor(Color(255, 255, 255, t >= 0 ? 255 * t : 0)));
+ drawRect(vec2(r.end.x - (itemWide*sc)/2 - (itemWide*sc)*.09,r.end.y - (itemWide*sc)/2 - (itemWide*sc)*.09),
+ vec2(r.end.x - (itemWide*sc)/2 ,r.end.y + (itemWide*sc)/2 + (itemWide*sc)*.09));
+
+ // right
+ glBindTexture(GL_TEXTURE_2D, Texture::genColor(Color(255, 255, 255, t >= 0 ? 255 * t : 0)));
+ drawRect(vec2(r.end.x + (itemWide*sc)/2 ,r.end.y - (itemWide*sc)/2 - (itemWide*sc)*.09),
+ vec2(r.end.x + (itemWide*sc)/2 + (itemWide*sc)*.09,r.end.y + (itemWide*sc)/2 + (itemWide*sc)*.09));
+
+ //glUseProgram(0);
}
a++;
}
@@ -617,10 +616,7 @@ void itemDraw(Player *p, Item *d) {
itemLoc.y = p->loc.y+(p->height/3);
itemLoc.x = p->left?p->loc.x-d->dim.x/2:p->loc.x+p->width-d->dim.x/2;
- glPushMatrix();
- glUseProgram(shaderProgram);
- glUniform1i(glGetUniformLocation(shaderProgram, "sampler"), 0);
if (p->left) {
glTranslatef(itemLoc.x+d->dim.x/2,itemLoc.y,0);
glRotatef(d->rotation, 0.0f, 0.0f, 1.0f);
@@ -630,26 +626,44 @@ void itemDraw(Player *p, Item *d) {
glRotatef(d->rotation, 0.0f, 0.0f, 1.0f);
glTranslatef(-itemLoc.x-d->dim.x/2,-itemLoc.y,0);
}
- glEnable(GL_TEXTURE_2D);
+
+ GLfloat itemTex[12] = {0.0, 0.0,
+ 1.0, 0.0,
+ 1.0, 1.0,
+
+ 1.0, 1.0,
+ 0.0, 1.0,
+ 0.0, 0.0};
+ if (!p->left) {
+ itemTex[0] = 1.0;
+ itemTex[2] = 0.0;
+ itemTex[4] = 0.0;
+ itemTex[6] = 0.0;
+ itemTex[8] = 1.0;
+ itemTex[10] = 1.0;
+ }
+
+ GLfloat itemCoords[] = {itemLoc.x, itemLoc.y, 1.0,
+ itemLoc.x+d->dim.x, itemLoc.y, 1.0,
+ itemLoc.x+d->dim.x, itemLoc.y+d->dim.y, 1.0,
+
+ itemLoc.x+d->dim.x, itemLoc.y+d->dim.y, 1.0,
+ itemLoc.x, itemLoc.y+d->dim.y, 1.0,
+ itemLoc.x, itemLoc.y, 1.0};
+ glUseProgram(worldShader);
glBindTexture(GL_TEXTURE_2D,d->tex->image[0]);
- glColor4ub(255,255,255,255);
- glBegin(GL_QUADS);
- if (p->left) {
- glTexCoord2i(0,1);glVertex2f(itemLoc.x, itemLoc.y);
- glTexCoord2i(1,1);glVertex2f(itemLoc.x+d->dim.x,itemLoc.y);
- glTexCoord2i(1,0);glVertex2f(itemLoc.x+d->dim.x,itemLoc.y+d->dim.y);
- glTexCoord2i(0,0);glVertex2f(itemLoc.x, itemLoc.y+d->dim.y);
- } else {
- glTexCoord2i(1,1);glVertex2f(itemLoc.x, itemLoc.y);
- glTexCoord2i(0,1);glVertex2f(itemLoc.x+d->dim.x,itemLoc.y);
- glTexCoord2i(0,0);glVertex2f(itemLoc.x+d->dim.x,itemLoc.y+d->dim.y);
- glTexCoord2i(1,0);glVertex2f(itemLoc.x, itemLoc.y+d->dim.y);
- }
- glEnd();
- glDisable(GL_TEXTURE_2D);
- glTranslatef(player->loc.x*2,0,0);
- glPopMatrix();
- glUseProgram(0);
+
+ glEnableVertexAttribArray(worldShader_attribute_coord);
+ glEnableVertexAttribArray(worldShader_attribute_tex);
+
+ glVertexAttribPointer(worldShader_attribute_coord, 3, GL_FLOAT, GL_FALSE, 0, itemCoords);
+ glVertexAttribPointer(worldShader_attribute_tex, 2, GL_FLOAT, GL_FALSE, 0, itemTex);
+ glDrawArrays(GL_TRIANGLES, 0, 6);
+
+ glDisableVertexAttribArray(worldShader_attribute_coord);
+ glDisableVertexAttribArray(worldShader_attribute_tex);
+
+ glUseProgram(0);
}
/*
diff --git a/src/texture.cpp b/src/texture.cpp
index d457831..0f01c83 100644
--- a/src/texture.cpp
+++ b/src/texture.cpp
@@ -19,6 +19,19 @@ struct index_t {
int indexy;
};
+// convert any type to octal
+template <typename T>
+uint toOctal(T toConvert)
+{
+ int n = 0;
+ uint t = 0;
+ while (toConvert > 0) {
+ t += (pow(10, n++)) * (static_cast<int>(toConvert) % 8);
+ toConvert /= 8;
+ }
+ return t;
+}
+
/**
* A vector of all loaded textures.
*
@@ -89,6 +102,49 @@ namespace Texture{
return object;
}
+ GLuint genColor(Color c)
+ {
+ std::string out;
+
+ // add the red
+ out += static_cast<int>(c.red);
+
+ // add the green
+ out += static_cast<int>(c.green);
+
+ // add the blue
+ out += static_cast<int>(c.blue);
+
+ // add the alpha
+ out += static_cast<int>(c.alpha);
+
+ GLuint object;
+
+ glActiveTexture(GL_TEXTURE0);
+ glGenTextures(1,&object); // Turns "object" into a texture
+ glBindTexture(GL_TEXTURE_2D,object); // Binds "object" to the top of the stack
+ //glPixelStorei(GL_UNPACK_ALIGNMENT,1);
+
+ //glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); // Sets the "min" filter
+ //glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); // The the "max" filter of the stack
+
+ //glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); // Wrap the texture to the matrix
+ //glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); //
+
+ glTexImage2D(GL_TEXTURE_2D, // Sets the texture to the image file loaded above
+ 0, // level
+ GL_RGBA, // internal format
+ 1, // width
+ 1, // height
+ 0, // border
+ GL_RGBA, // image format
+ GL_UNSIGNED_BYTE, // type
+ out.data() // source
+ );
+
+ return object;
+ }
+
dim2 imageDim(std::string fileName) {
for(auto &t : LoadedTexture) {
if (t.name == fileName)
diff --git a/src/ui.cpp b/src/ui.cpp
index 384ce53..64e18fe 100644
--- a/src/ui.cpp
+++ b/src/ui.cpp
@@ -294,8 +294,8 @@ namespace ui {
*/
glActiveTexture(GL_TEXTURE0);
- glUniform1i(textShader_uniform_texture, 0);
glBindTexture(GL_TEXTURE_2D,(*ftex)[c-33]);
+ glUniform1i(textShader_uniform_texture, 0);
//glDisable(GL_DEPTH_TEST);
@@ -324,11 +324,19 @@ namespace ui {
c1.x, c1.y+c2.y-c2.y, 1.0, //top left
c1.x, c1.y -c2.y, 1.0, //bottom left
};
+
+ glUniform4f(textShader_uniform_color,
+ static_cast<float>(fontColor[0]/255),
+ static_cast<float>(fontColor[1]/255),
+ static_cast<float>(fontColor[2]/255),
+ static_cast<float>(fontColor[3]/255));
glVertexAttribPointer(textShader_attribute_coord, 3, GL_FLOAT, GL_FALSE, 0, text_vert);
glVertexAttribPointer(textShader_attribute_tex, 2, GL_FLOAT, GL_FALSE, 0, tex_coord);
glDrawArrays(GL_TRIANGLES, 0, 6);
+ glUniform4f(textShader_uniform_color, 1.0, 1.0, 1.0, 1.0);
+
glDisableVertexAttribArray(textShader_attribute_tex);
glDisableVertexAttribArray(textShader_attribute_coord);
@@ -639,11 +647,6 @@ namespace ui {
}
void drawBox(vec2 c1, vec2 c2) {
- static vec2 lineIndexF = Texture::getIndex(Color(255, 255, 255));
- static vec2 lineIndex = vec2(0.25f * lineIndexF.x, 0.125f * (8-lineIndexF.y));
- static vec2 boxIndexF = Texture::getIndex(Color(0, 0, 0));
- static vec2 boxIndex = vec2(0.25f * boxIndexF.x, 0.125f * (8-boxIndexF.y));
-
GLfloat box[] = {c1.x, c1.y, 1.0,
c2.x, c1.y, 1.0,
c2.x, c2.y, 1.0,
@@ -655,26 +658,23 @@ namespace ui {
GLfloat line_strip[] = {c1.x, c1.y, 1.0,
c2.x + 1, c1.y, 1.0,
c2.x + 1, c2.y, 1.0,
- c1.x - 1, c2.y, 1.0,
+ c1.x, c2.y, 1.0,
c1.x, c1.y, 1.0};
- static GLfloat box_tex[] = {boxIndex.x,boxIndex.y,
- boxIndex.x,boxIndex.y,
- boxIndex.x,boxIndex.y,
+ GLfloat box_tex[] = {0,0,
+ 1,0,
+ 1,1,
- boxIndex.x,boxIndex.y,
- boxIndex.x,boxIndex.y,
- boxIndex.x,boxIndex.y};
+ 1,1,
+ 0,1,
+ 0,0};
- static GLfloat line_tex[] = {lineIndex.x, lineIndex.y,
- lineIndex.x, lineIndex.y,
- lineIndex.x, lineIndex.y,
- lineIndex.x, lineIndex.y,
- lineIndex.x, lineIndex.y};
+ static GLuint boxT = Texture::genColor(Color(0,0,0));
+ static GLuint lineT = Texture::genColor(Color(255,255,255));
- glActiveTexture(GL_TEXTURE9);
- glBindTexture(GL_TEXTURE_2D, colorIndex);
- glUniform1i(textShader_uniform_texture, 9);
+ glActiveTexture(GL_TEXTURE0);
+ glBindTexture(GL_TEXTURE_2D, boxT);
+ glUniform1i(textShader_uniform_texture, 0);
glUseProgram(textShader);
glEnableVertexAttribArray(textShader_attribute_coord);
@@ -683,16 +683,18 @@ namespace ui {
glVertexAttribPointer(textShader_attribute_coord, 3, GL_FLOAT, GL_FALSE, 0, box);
glVertexAttribPointer(textShader_attribute_tex, 2, GL_FLOAT, GL_FALSE, 0, box_tex);
glDrawArrays(GL_TRIANGLES, 0 ,6);
-
- glVertexAttribPointer(textShader_attribute_coord, 3, GL_FLOAT, GL_FALSE, 0, line_strip);
- glVertexAttribPointer(textShader_attribute_tex, 2, GL_FLOAT, GL_FALSE, 0, line_tex);
- glDrawArrays(GL_LINE_STRIP, 0 ,5);
+
+ glBindTexture(GL_TEXTURE_2D, lineT);
+ glUniform1i(textShader_uniform_texture, 0);
+ glVertexAttribPointer(textShader_attribute_coord, 3, GL_FLOAT, GL_FALSE, 0, line_strip);
+ glVertexAttribPointer(textShader_attribute_tex, 2, GL_FLOAT, GL_FALSE, 0, box_tex);
+ glDrawArrays(GL_LINE_STRIP, 0 ,8);
+
glDisableVertexAttribArray(textShader_attribute_coord);
glDisableVertexAttribArray(textShader_attribute_tex);
glUseProgram(0);
- glActiveTexture(GL_TEXTURE0);
}
void draw(void){
@@ -700,22 +702,46 @@ namespace ui {
float x,y,tmp;
std::string rtext;
- auto SCREEN_WIDTH = game::SCREEN_WIDTH;
- auto SCREEN_HEIGHT = game::SCREEN_HEIGHT;
+ auto SCREEN_WIDTH = static_cast<float>(game::SCREEN_WIDTH);
+ auto SCREEN_HEIGHT = static_cast<float>(game::SCREEN_HEIGHT);
// will return if not toggled
action::draw(vec2 {player->loc.x + player->width / 2, player->loc.y + player->height + game::HLINE});
if (pageTexReady) {
- glEnable(GL_TEXTURE_2D);
- glBindTexture(GL_TEXTURE_2D, pageTex);
- glBegin(GL_QUADS);
- glTexCoord2i(0, 0); glVertex2i(offset.x - 300, SCREEN_HEIGHT - 100);
- glTexCoord2i(1, 0); glVertex2i(offset.x + 300, SCREEN_HEIGHT - 100);
- glTexCoord2i(1, 1); glVertex2i(offset.x + 300, SCREEN_HEIGHT - 600);
- glTexCoord2i(0, 1); glVertex2i(offset.x - 300, SCREEN_HEIGHT - 600);
- glEnd();
- glDisable(GL_TEXTURE_2D);
+
+ GLfloat page_loc[] = {offset.x - 300, SCREEN_HEIGHT - 100, 1.0,
+ offset.x + 300, SCREEN_HEIGHT - 100, 1.0,
+ offset.x + 300, SCREEN_HEIGHT - 600, 1.0,
+
+ offset.x + 300, SCREEN_HEIGHT - 600, 1.0,
+ offset.x - 300, SCREEN_HEIGHT - 600, 1.0,
+ offset.x - 300, SCREEN_HEIGHT - 100, 1.0};
+
+ GLfloat page_tex[] = {0.0, 0.0,
+ 1.0, 0.0,
+ 1.0, 1.0,
+
+ 1.0, 1.0,
+ 0.0, 1.0,
+ 0.0, 0.0};
+
+ glActiveTexture(GL_TEXTURE0);
+ glBindTexture(GL_TEXTURE_2D, pageTex);
+ glUniform1i(textShader_uniform_texture, 0);
+ glUseProgram(textShader);
+
+ glEnableVertexAttribArray(textShader_attribute_coord);
+ glEnableVertexAttribArray(textShader_attribute_tex);
+
+ glVertexAttribPointer(textShader_attribute_coord, 3, GL_FLOAT, GL_FALSE, 0, page_loc);
+ glVertexAttribPointer(textShader_attribute_tex, 2, GL_FLOAT, GL_FALSE, 0, page_tex);
+ glDrawArrays(GL_TRIANGLES, 0 ,6);
+
+ glDisableVertexAttribArray(textShader_attribute_coord);
+ glDisableVertexAttribArray(textShader_attribute_tex);
+
+ glUseProgram(0);
} else if (dialogBoxExists) {
rtext = typeOut(dialogBoxText);
@@ -756,25 +782,53 @@ namespace ui {
putStringCentered(merchBase.x - SCREEN_WIDTH / 10 , merchBase.y + 40 + fontSize , merchTrade.item[1]);
putStringCentered(offset.x, merchBase.y + 60, "for");
- glEnable(GL_TEXTURE_2D);
-
- glBindTexture(GL_TEXTURE_2D, getItemTexture(merchTrade.item[0]));
- glBegin(GL_QUADS);
- glTexCoord2d(0,1);glVertex2f(offset.x - (SCREEN_WIDTH / 10) ,offset.y + (SCREEN_HEIGHT/5));
- glTexCoord2d(1,1);glVertex2f(offset.x - (SCREEN_WIDTH / 10) + 40,offset.y + (SCREEN_HEIGHT/5));
- glTexCoord2d(1,0);glVertex2f(offset.x - (SCREEN_WIDTH / 10) + 40,offset.y + (SCREEN_HEIGHT/5) + 40);
- glTexCoord2d(0,0);glVertex2f(offset.x - (SCREEN_WIDTH / 10) ,offset.y + (SCREEN_HEIGHT/5) + 40);
- glEnd();
-
- glBindTexture(GL_TEXTURE_2D, getItemTexture(merchTrade.item[1]));
- glBegin(GL_QUADS);
- glTexCoord2d(0,1);glVertex2f(offset.x + (SCREEN_WIDTH / 10) - 40,offset.y + (SCREEN_HEIGHT/5));
- glTexCoord2d(1,1);glVertex2f(offset.x + (SCREEN_WIDTH / 10) ,offset.y + (SCREEN_HEIGHT/5));
- glTexCoord2d(1,0);glVertex2f(offset.x + (SCREEN_WIDTH / 10) ,offset.y + (SCREEN_HEIGHT/5) + 40);
- glTexCoord2d(0,0);glVertex2f(offset.x + (SCREEN_WIDTH / 10) - 40,offset.y + (SCREEN_HEIGHT/5) + 40);
- glEnd();
-
- glDisable(GL_TEXTURE_2D);
+ // render the two items we are trading
+ GLfloat item_tex[] = {0.0, 1.0,
+ 1.0, 1.0,
+ 1.0, 0.0,
+
+ 1.0, 0.0,
+ 0.0, 0.0,
+ 0.0, 1.0};
+
+ GLfloat left_item[] = {offset.x - (SCREEN_WIDTH / 10), offset.y + (SCREEN_HEIGHT / 5), 1.0,
+ offset.x - (SCREEN_WIDTH / 10) + 40, offset.y + (SCREEN_HEIGHT / 5), 1.0,
+ offset.x - (SCREEN_WIDTH / 10) + 40, offset.y + (SCREEN_HEIGHT / 5) + 40,1.0,
+
+ offset.x - (SCREEN_WIDTH / 10) + 40, offset.y + (SCREEN_HEIGHT / 5) + 40,1.0,
+ offset.x - (SCREEN_WIDTH / 10), offset.y + (SCREEN_HEIGHT / 5) + 40,1.0,
+ offset.x - (SCREEN_WIDTH / 10), offset.y + (SCREEN_HEIGHT / 5), 1.0};
+
+ GLfloat right_item[] = {offset.x + (SCREEN_WIDTH / 10) - 40, offset.y + (SCREEN_HEIGHT / 5), 1.0,
+ offset.x + (SCREEN_WIDTH / 10), offset.y + (SCREEN_HEIGHT / 5), 1.0,
+ offset.x + (SCREEN_WIDTH / 10), offset.y + (SCREEN_HEIGHT / 5) + 40,1.0,
+
+ offset.x + (SCREEN_WIDTH / 10), offset.y + (SCREEN_HEIGHT / 5) + 40,1.0,
+ offset.x + (SCREEN_WIDTH / 10) - 40, offset.y + (SCREEN_HEIGHT / 5) + 40,1.0,
+ offset.x + (SCREEN_WIDTH / 10) - 40, offset.y + (SCREEN_HEIGHT / 5), 1.0};
+
+ glActiveTexture(GL_TEXTURE0);
+ glBindTexture(GL_TEXTURE_2D, getItemTexture(merchTrade.item[0]));
+ glUniform1i(textShader_uniform_texture, 0);
+ glUseProgram(textShader);
+
+ glEnableVertexAttribArray(textShader_attribute_coord);
+ glEnableVertexAttribArray(textShader_attribute_tex);
+
+ glVertexAttribPointer(textShader_attribute_coord, 3, GL_FLOAT, GL_FALSE, 0, left_item);
+ glVertexAttribPointer(textShader_attribute_tex, 2, GL_FLOAT, GL_FALSE, 0, item_tex);
+ glDrawArrays(GL_TRIANGLES, 0 ,6);
+
+ glBindTexture(GL_TEXTURE_2D, getItemTexture(merchTrade.item[1]));
+
+ glVertexAttribPointer(textShader_attribute_coord, 3, GL_FLOAT, GL_FALSE, 0, right_item);
+ glVertexAttribPointer(textShader_attribute_tex, 2, GL_FLOAT, GL_FALSE, 0, item_tex);
+ glDrawArrays(GL_TRIANGLES, 0 ,6);
+
+ glDisableVertexAttribArray(textShader_attribute_coord);
+ glDisableVertexAttribArray(textShader_attribute_tex);
+
+ glUseProgram(0);
merchArrowLoc[0].x = offset.x - (SCREEN_WIDTH / 8.5) - 16;
merchArrowLoc[1].x = offset.x + (SCREEN_WIDTH / 8.5) + 16;
@@ -789,14 +843,34 @@ namespace ui {
(mouse.x < merchArrowLoc[i].x && mouse.x > merchArrowLoc[i].z)) &&
mouse.y > merchArrowLoc[i].y - 8 && mouse.y < merchArrowLoc[i].y + 8) {
glColor3ub(255,255, 0);
- }else{
+ glBindTexture(GL_TEXTURE_2D, Texture::genColor(Color(255,255,0)));
+ }else{
glColor3ub(255,255,255);
+ glBindTexture(GL_TEXTURE_2D, Texture::genColor(Color(255,255,255)));
}
- glBegin(GL_TRIANGLES);
- glVertex2f(merchArrowLoc[i].x,merchArrowLoc[i].y);
- glVertex2f(merchArrowLoc[i].z,merchArrowLoc[i].y-8);
- glVertex2f(merchArrowLoc[i].z,merchArrowLoc[i].y+8);
- glEnd();
+
+ GLfloat tri_t[] = {0.0, 0.0,
+ 0.0, 1.0,
+ 1.0, 1.0};
+
+ GLfloat tri_c[] = {merchArrowLoc[i].x, merchArrowLoc[i].y, 1.0,
+ merchArrowLoc[i].z, merchArrowLoc[i].y - 8, 1.0,
+ merchArrowLoc[i].z, merchArrowLoc[i].y + 8, 1.0};
+
+ glUniform1i(textShader_uniform_texture, 0);
+ glUseProgram(textShader);
+
+ glEnableVertexAttribArray(textShader_attribute_coord);
+ glEnableVertexAttribArray(textShader_attribute_tex);
+
+ glVertexAttribPointer(textShader_attribute_coord, 3, GL_FLOAT, GL_FALSE, 0, tri_c);
+ glVertexAttribPointer(textShader_attribute_tex, 2, GL_FLOAT, GL_FALSE, 0, tri_t);
+ glDrawArrays(GL_TRIANGLES, 0 ,6);
+
+ glDisableVertexAttribArray(textShader_attribute_coord);
+ glDisableVertexAttribArray(textShader_attribute_tex);
+
+ glUseProgram(0);
}
@@ -865,18 +939,47 @@ namespace ui {
(unsigned)player->maxHealth
);
if (player->isAlive()) {
- glColor3ub(150,0,0);
hub.y-=fontSize*1.15;
- glRectf(hub.x,
- hub.y,
- hub.x+150,
- hub.y+12);
- glColor3ub(255,0,0);
- glRectf(hub.x,
- hub.y,
- hub.x+(player->health/player->maxHealth * 150),
- hub.y+12);
- }
+
+ GLfloat tex[] = {0.0, 0.0,
+ 1.0, 0.0,
+ 0.0, 1.0,
+ 1.0, 1.0};
+
+ GLfloat back[] = {hub.x, hub.y, 1.0,
+ hub.x + 150, hub.y, 1.0,
+ hub.x, hub.y + 12, 1.0,
+ hub.x + 150, hub.y + 12, 1.0};
+
+ GLfloat front[] = {hub.x, hub.y, 1.0,
+ hub.x + 150, hub.y, 1.0,
+ hub.x, hub.y + 12, 1.0,
+ hub.x + 150, hub.y + 12, 1.0};
+
+
+ glUniform1i(textShader_uniform_texture, 0);
+ glUseProgram(textShader);
+
+ glEnableVertexAttribArray(textShader_attribute_coord);
+ glEnableVertexAttribArray(textShader_attribute_tex);
+
+ glBindTexture(GL_TEXTURE_2D, Texture::genColor(Color(150,0,0)));
+
+ glVertexAttribPointer(textShader_attribute_coord, 3, GL_FLOAT, GL_FALSE, 0, front);
+ glVertexAttribPointer(textShader_attribute_tex, 2, GL_FLOAT, GL_FALSE, 0, tex);
+ glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
+
+ glBindTexture(GL_TEXTURE_2D, Texture::genColor(Color(255,0,0)));
+
+ glVertexAttribPointer(textShader_attribute_coord, 3, GL_FLOAT, GL_FALSE, 0, back);
+ glVertexAttribPointer(textShader_attribute_tex, 2, GL_FLOAT, GL_FALSE, 0, tex);
+ glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
+
+ glDisableVertexAttribArray(textShader_attribute_coord);
+ glDisableVertexAttribArray(textShader_attribute_tex);
+
+ glUseProgram(0);
+ }
/*
* Lists all of the quests the player is currently taking.
@@ -1312,16 +1415,36 @@ EXIT:
}
if (fadeWhite)
- safeSetColorA(255, 255, 255, fadeIntensity);
+ glBindTexture(GL_TEXTURE_2D, Texture::genColor(Color(255, 255, 255, fadeIntensity)));
else
- safeSetColorA(0, 0, 0, fadeIntensity);
+ glBindTexture(GL_TEXTURE_2D, Texture::genColor(Color(0, 0, 0, fadeIntensity)));
+
+ GLfloat tex[] = {0.0, 0.0,
+ 1.0, 0.0,
+ 0.0, 1.0,
+ 1.0, 1.0};
+
+ GLfloat backdrop[] = {offset.x - SCREEN_WIDTH / 2, offset.y - SCREEN_HEIGHT / 2, 1.0,
+ offset.x + SCREEN_WIDTH / 2, offset.y - SCREEN_HEIGHT / 2, 1.0,
+ offset.x - SCREEN_WIDTH / 2, offset.y + SCREEN_HEIGHT / 2, 1.0,
+ offset.x + SCREEN_WIDTH / 2, offset.y + SCREEN_HEIGHT / 2, 1.0};
+
+ glUniform1i(textShader_uniform_texture, 0);
+ glUseProgram(textShader);
- glRectf(offset.x - SCREEN_WIDTH / 2,
- offset.y - SCREEN_HEIGHT / 2,
- offset.x + SCREEN_WIDTH / 2,
- offset.y + SCREEN_HEIGHT / 2
- );
- }
+ glEnableVertexAttribArray(textShader_attribute_coord);
+ glEnableVertexAttribArray(textShader_attribute_tex);
+
+ glVertexAttribPointer(textShader_attribute_coord, 3, GL_FLOAT, GL_FALSE, 0, backdrop);
+ glVertexAttribPointer(textShader_attribute_tex, 2, GL_FLOAT, GL_FALSE, 0, tex);
+ glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
+
+ glDisableVertexAttribArray(textShader_attribute_coord);
+ glDisableVertexAttribArray(textShader_attribute_tex);
+
+ glUseProgram(0);
+
+ }
void fadeUpdate(void) {
if (fadeEnable) {
diff --git a/src/world.cpp b/src/world.cpp
index 4fe2743..88ef57a 100644
--- a/src/world.cpp
+++ b/src/world.cpp
@@ -277,13 +277,13 @@ void World::drawBackgrounds(void)
vec2(0.0f, 0.0f)};
bgTex(0);
- GLfloat back_tex_coord[] = {offset.x - backgroundOffset.x - 5, offset.y + backgroundOffset.y, 1.0f,
- offset.x + backgroundOffset.x + 5, offset.y + backgroundOffset.y, 1.0f,
- offset.x + backgroundOffset.x + 5, offset.y - backgroundOffset.y, 1.0f,
+ GLfloat back_tex_coord[] = {offset.x - backgroundOffset.x - 5, offset.y + backgroundOffset.y, 10.0f,
+ offset.x + backgroundOffset.x + 5, offset.y + backgroundOffset.y, 10.0f,
+ offset.x + backgroundOffset.x + 5, offset.y - backgroundOffset.y, 10.0f,
- offset.x + backgroundOffset.x + 5, offset.y - backgroundOffset.y, 1.0f,
- offset.x - backgroundOffset.x - 5, offset.y - backgroundOffset.y, 1.0f,
- offset.x - backgroundOffset.x - 5, offset.y + backgroundOffset.y, 1.0f};
+ offset.x + backgroundOffset.x + 5, offset.y - backgroundOffset.y, 10.0f,
+ offset.x - backgroundOffset.x - 5, offset.y - backgroundOffset.y, 10.0f,
+ offset.x - backgroundOffset.x - 5, offset.y + backgroundOffset.y, 10.0f};
glUseProgram(worldShader);
@@ -307,13 +307,13 @@ void World::drawBackgrounds(void)
bgTex++;
auto xcoord = width / 2 * -1 + offset.x * 0.85f;
for (unsigned int i = 0; i <= worldData.size() * HLINE / 1920; i++) {
- bg_items.push_back(vec3(1920 * i + xcoord, GROUND_HEIGHT_MINIMUM, 1.0f));
- bg_items.push_back(vec3(1920 * (i + 1) + xcoord, GROUND_HEIGHT_MINIMUM, 1.0f));
- bg_items.push_back(vec3(1920 * (i + 1) + xcoord, GROUND_HEIGHT_MINIMUM + 1080, 1.0f));
+ bg_items.push_back(vec3(1920 * i + xcoord, GROUND_HEIGHT_MINIMUM, 8.0f));
+ bg_items.push_back(vec3(1920 * (i + 1) + xcoord, GROUND_HEIGHT_MINIMUM, 8.0f));
+ bg_items.push_back(vec3(1920 * (i + 1) + xcoord, GROUND_HEIGHT_MINIMUM + 1080, 8.0f));
- bg_items.push_back(vec3(1920 * (i + 1) + xcoord, GROUND_HEIGHT_MINIMUM + 1080, 1.0f));
- bg_items.push_back(vec3(1920 * i + xcoord, GROUND_HEIGHT_MINIMUM + 1080, 1.0f));
- bg_items.push_back(vec3(1920 * i + xcoord, GROUND_HEIGHT_MINIMUM, 1.0f));
+ bg_items.push_back(vec3(1920 * (i + 1) + xcoord, GROUND_HEIGHT_MINIMUM + 1080, 8.0f));
+ bg_items.push_back(vec3(1920 * i + xcoord, GROUND_HEIGHT_MINIMUM + 1080, 8.0f));
+ bg_items.push_back(vec3(1920 * i + xcoord, GROUND_HEIGHT_MINIMUM, 8.0f));
}
std::vector<GLfloat> bg_i;
@@ -352,13 +352,13 @@ void World::drawBackgrounds(void)
bgTex++;
auto xcoord = offset.x * bgDraw[i][2];
for (int j = worldStart; j <= -worldStart; j += 600) {
- c.push_back(vec3(j + xcoord, GROUND_HEIGHT_MINIMUM, 1));
- c.push_back(vec3(j + 600 + xcoord, GROUND_HEIGHT_MINIMUM, 1));
- c.push_back(vec3(j + 600 + xcoord, GROUND_HEIGHT_MINIMUM + 400, 1));
+ c.push_back(vec3(j + xcoord, GROUND_HEIGHT_MINIMUM, 7-(i*.1)));
+ c.push_back(vec3(j + 600 + xcoord, GROUND_HEIGHT_MINIMUM, 7-(i*.1)));
+ c.push_back(vec3(j + 600 + xcoord, GROUND_HEIGHT_MINIMUM + 400, 7-(i*.1)));
- c.push_back(vec3(j + 600 + xcoord, GROUND_HEIGHT_MINIMUM + 400, 1));
- c.push_back(vec3(j + xcoord, GROUND_HEIGHT_MINIMUM + 400, 1));
- c.push_back(vec3(j + xcoord, GROUND_HEIGHT_MINIMUM, 1));
+ c.push_back(vec3(j + 600 + xcoord, GROUND_HEIGHT_MINIMUM + 400, 7-(i*.1)));
+ c.push_back(vec3(j + xcoord, GROUND_HEIGHT_MINIMUM + 400, 7-(i*.1)));
+ c.push_back(vec3(j + xcoord, GROUND_HEIGHT_MINIMUM, 7-(i*.1)));
}
bg_i.clear();
@@ -410,24 +410,12 @@ void World::draw(Player *p)
glEnableVertexAttribArray(worldShader_attribute_coord);
glEnableVertexAttribArray(worldShader_attribute_tex);
- std::vector<std::vector<std::pair<vec2, vec3>>> partv(0);
std::vector<GLfloat> partc(0);
std::vector<GLfloat> partt(0);
for (auto &p : particles) {
if (p.behind)
- partv.push_back(p.draw());
- }
-
- for (auto &pv : partv) {
- for (auto &v : pv){
- partc.push_back(v.second.x);
- partc.push_back(v.second.y);
- partc.push_back(v.second.z);
-
- partt.push_back(v.first.x);
- partt.push_back(v.first.y);
- }
+ p.draw(partc, partt);
}
glVertexAttribPointer(worldShader_attribute_coord, 3, GL_FLOAT, GL_FALSE, 0, &partc[0]);
@@ -630,24 +618,12 @@ void World::draw(Player *p)
glEnableVertexAttribArray(worldShader_attribute_coord);
glEnableVertexAttribArray(worldShader_attribute_tex);
- partv.clear();
partc.clear();
partt.clear();
for (auto &p : particles) {
if (!p.behind)
- partv.push_back(p.draw());
- }
-
- for (auto &pv : partv) {
- for (auto &v : pv){
- partc.push_back(v.second.x);
- partc.push_back(v.second.y);
- partc.push_back(v.second.z);
-
- partt.push_back(v.first.x);
- partt.push_back(v.first.y);
- }
+ p.draw(partc, partt);
}
glVertexAttribPointer(worldShader_attribute_coord, 3, GL_FLOAT, GL_FALSE, 0, &partc[0]);
@@ -1663,7 +1639,7 @@ draw(Player *p)
glUniform1i(glGetUniformLocation(shaderProgram, "sampler"), 0);
glUseProgram(shaderProgram);
- std::for_each(particles.begin(), particles.end(), [](Particles &part) { part.draw(); });
+ //std::for_each(particles.begin(), particles.end(), [](Particles &part) { part.draw(); });
glUseProgram(0);
diff --git a/ttf/atomics.TTF b/ttf/atomics.TTF
new file mode 100644
index 0000000..44c2753
--- /dev/null
+++ b/ttf/atomics.TTF
Binary files differ
diff --git a/ttf/atomicsc.TTF b/ttf/atomicsc.TTF
new file mode 100644
index 0000000..c346518
--- /dev/null
+++ b/ttf/atomicsc.TTF
Binary files differ
diff --git a/ttf/yapix.ttf b/ttf/yapix.ttf
new file mode 100644
index 0000000..692718a
--- /dev/null
+++ b/ttf/yapix.ttf
Binary files differ
diff --git a/xml/playerSpawnHill1.xml b/xml/playerSpawnHill1.xml
index 82563e9..3a831ce 100644
--- a/xml/playerSpawnHill1.xml
+++ b/xml/playerSpawnHill1.xml
@@ -71,13 +71,13 @@ And it wasn't stormy.
</text>
<text id="1" nextid="1" pause="true" >
- Broooooooooooooo...
+ Broooooooooooooo...
</text>
</Dialog>
<Dialog name="Big Dave">
<text id="0" pause="true">
- Here have this sword!
+ Hey friend! It's dangerous out there, here take these!
<give id="Wood Sword" count="1"/>
<give id="Hunters Bow" count="1"/>
<give id="Crude Arrow" count="110"/>