]> code.bitgloo.com Git - clyne/gamedev.git/commitdiff
Z INDEXING
authordrumsetmonkey <abelleisle@roadrunner.com>
Wed, 18 May 2016 12:15:13 +0000 (08:15 -0400)
committerdrumsetmonkey <abelleisle@roadrunner.com>
Wed, 18 May 2016 12:15:13 +0000 (08:15 -0400)
assets/player/playerk4.png
include/common.hpp
include/entities.hpp
include/ui.hpp
main.cpp
src/common.cpp
src/entities.cpp
src/inventory.cpp
src/ui.cpp
src/ui_menu.cpp
src/world.cpp

index 767a6fc2c0b894aad91c45cbdae647ecf79831d8..fa572826a8ae503700469b23ff628fdd0e6c1a15 100644 (file)
Binary files a/assets/player/playerk4.png and b/assets/player/playerk4.png differ
index 153c46e8d4193ffa2147753d280645f57c3549e4..d0806523b1b23ab7b8f4d86d431cb778433d026b 100644 (file)
@@ -197,7 +197,7 @@ 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);
+void drawRect(vec2 ll, vec2 ur, float z);
 
 // gets the length of `n` HLINEs
 template<typename T>
index 83b47b9b3d2273301caf489d458eae9b0dfa46c5..93c1caa5984f6e60bed90e09c019b92a3f3b9340 100644 (file)
@@ -150,7 +150,7 @@ public:
        ~Particles(void){}
 
        // draws the particle
-       void draw(std::vector<GLfloat> &p) const;
+       void draw(GLfloat*& p) const;
 
        // updates a particle
        void update(float _gravity, float ground_y);
index 099bebf4161442f9b853d315b7e4fb11c87f4524..f1b44bbef68bfdbe3cb544e9eea661e9c39399a5 100644 (file)
@@ -81,6 +81,7 @@ namespace ui {
        void setFontFace(const char *ttf);
        void setFontSize(unsigned int size);
        void setFontColor(unsigned char r,unsigned char g,unsigned char b, unsigned char a);
+       void setFontZ(float z);
 
        /*
         *      Draw a centered string.
index e61073a31041ef7c592542e6fc9ef47aa744f067..375a2706235ea19cf94895c35da1ac013afdfff1 100644 (file)
--- a/main.cpp
+++ b/main.cpp
@@ -384,7 +384,7 @@ void render() {
 
        glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
        // TODO add depth
-    //glEnable(GL_DEPTH_TEST);
+    glEnable(GL_DEPTH_TEST);
 
        glUseProgram(textShader);
        glUniformMatrix4fv(textShader_uniform_transform, 1, GL_FALSE, glm::value_ptr(ortho));
@@ -432,17 +432,48 @@ void render() {
                                        currentWorld->getWeatherStr().c_str()
                                        );
 
+               static GLuint tracerText = Texture::genColor(Color(100,100,255));
+
+               uint es = currentWorld->entity.size();
+               GLfloat tpoint[es * 2 * 5];
+               GLfloat *tp = &tpoint[0];
+
+               glUseProgram(textShader);
+               glBindTexture(GL_TEXTURE_2D, tracerText);
+
                if (ui::posFlag) {
-                       glBegin(GL_LINES);
-                               glColor3ub(100,100,255);
-                               for (auto &e : currentWorld->entity) {
-                                       glVertex2i(player->loc.x + player->width / 2, player->loc.y + player->height / 2);
-                                       glVertex2i(e->loc.x + e->width / 2, e->loc.y + e->height / 2);
-                               }
-                       glEnd();
+                       for (auto &e : currentWorld->entity) {
+                               *(tp++) = player->loc.x + player->width / 2;
+                               *(tp++) = player->loc.y + player->height / 2;
+                               *(tp++) = -5.0;
+
+                               *(tp++) = 0.0;
+                               *(tp++) = 0.0;
+
+                               *(tp++) = e->loc.x + e->width / 2;
+                               *(tp++) = e->loc.y + e->height / 2;
+                               *(tp++) = -5.0;
+
+                               *(tp++) = 1.0;
+                               *(tp++) = 1.0;
+                       }
                }
+               
+               glEnableVertexAttribArray(worldShader_attribute_coord);
+               glEnableVertexAttribArray(worldShader_attribute_coord);
+               
+               glVertexAttribPointer(worldShader_attribute_coord, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), &tpoint[0]);
+               glVertexAttribPointer(worldShader_attribute_tex, 2, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), &tpoint[3]);
+               glDrawArrays(GL_LINES, 0, es * 2);
+
+               glDisableVertexAttribArray(worldShader_attribute_tex);
+               glDisableVertexAttribArray(worldShader_attribute_tex);
+               glUseProgram(0);
+               
        }
 
+
+
        if (currentMenu)
                ui::menu::draw();
 
index 060da0088a74bb0a952786b547c5303df304adad..c643174d6eeae38803e23e124f76a1aeb7dca5a4 100644 (file)
@@ -47,15 +47,15 @@ void useShader(GLuint *sh, GLint *tu, GLint *ca, GLint *ta)
     tex_attrib = ta;
 }
 
-void drawRect(vec2 ll, vec2 ur)
+void drawRect(vec2 ll, vec2 ur, float z)
 {
-    GLfloat verts[] = {ll.x, ll.y, 1.0,
-                       ur.x, ll.y, 1.0,
-                       ur.x, ur.y, 1.0,
+    GLfloat verts[] = {ll.x, ll.y, z,
+                       ur.x, ll.y, z,
+                       ur.x, ur.y, z,
                        
-                       ur.x, ur.y, 1.0,
-                       ll.x, ur.y, 1.0,
-                       ll.x, ll.y, 1.0};
+                       ur.x, ur.y, z,
+                       ll.x, ur.y, z,
+                       ll.x, ll.y, z};
    
     GLfloat tex[] = {0.0, 1.0,
                      1.0, 1.0,
index ff8dd5d2f11af1099a3d26996e78c3968c3dd01f..442c823bc10ff1ad743a2d8b4c5603bc009fa91e 100644 (file)
@@ -80,7 +80,6 @@ Entity::Entity(void)
        health = 0;
        maxHealth = 0;
        outnabout = 0;
-       z = 1.0f;
        targetx = 0.9112001f;
 
        type = UNKNOWNT;
@@ -93,7 +92,7 @@ Entity::Entity(void)
        canMove    = true;
        ground     = false;
        forcedMove = false;
-       z = -1.0f;
+       z = 0.0f;
 
        // clear counters
        ticksToUse = 0;
@@ -213,6 +212,8 @@ Player::Player() : Entity()
        dim2 tmpDim = Texture::imageDim(tex.getTexturePath(0));
        width = HLINES(tmpDim.x/2);
        height = HLINES(tmpDim.y/2);
+       
+       z = -2.0;
 }
 
 Player::~Player()
@@ -348,24 +349,24 @@ void NPC::drawThingy(void) const
                        c[0], c[1], z, c[2], c[1], z, c[2], c[3], z,
                        c[2], c[3], z, c[0], c[3], z, c[0], c[1], z
                };
-               
+
                // TODO use texture made for this
                static GLuint thingyColor = Texture::genColor(Color(236, 238, 15));
-       
+
                glUseProgram(worldShader);
-               
+
                glEnableVertexAttribArray(worldShader_attribute_coord);
                glEnableVertexAttribArray(worldShader_attribute_tex);
-               
+
                glBindTexture(GL_TEXTURE_2D, thingyColor);
-                       
+
                glVertexAttribPointer(worldShader_attribute_coord, 3, GL_FLOAT, GL_FALSE, 0, coords);
                glVertexAttribPointer(worldShader_attribute_tex, 2, GL_FLOAT, GL_FALSE, 0, tex_coord);
                glDrawArrays(GL_TRIANGLES, 0, 6);
-               
+
                glDisableVertexAttribArray(worldShader_attribute_coord);
                glDisableVertexAttribArray(worldShader_attribute_tex);
-               
+
                glUseProgram(0);
        }
 }
@@ -448,12 +449,6 @@ void Entity::draw(void)
                break;
        }
 
-       //TODO
-       /*if (hitCooldown)
-               glColor3ub(255,255,0);
-       else
-               glColor3ub(255,255,255);*/
-
        glUseProgram(worldShader);
        // make the entity hit flash red
        if (maxHitDuration-hitDuration) {
@@ -483,13 +478,13 @@ if (health != maxHealth) {
        glUniform1i(worldShader_uniform_texture, 0);
 
        GLfloat coord_back[] = {
-               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,                  loc.y + height,                               z + 0.1f,
+               loc.x + width,  loc.y + height,                               z + 0.1f,
+               loc.x + width,  loc.y + height + game::HLINE * 2, z + 0.1f,
 
-               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,
+               loc.x + width,  loc.y + height + game::HLINE * 2, z + 0.1f,
+               loc.x,                  loc.y + height + game::HLINE * 2, z + 0.1f,
+               loc.x,                  loc.y + height,                               z + 0.1f,
        };
 
        GLfloat coord_front[] = {
@@ -504,12 +499,12 @@ if (health != maxHealth) {
 
        glBindTexture(GL_TEXTURE_2D, backH);
        GLfloat tex[] = { 0.0, 0.0,
-                                                  1.0, 0.0,
-                                                  1.0, 1.0,
+                                         1.0, 0.0,
+                                         1.0, 1.0,
 
-                                                  1.0, 1.0,
-                                                  0.0, 1.0,
-                                                  0.0, 0.0,
+                                         1.0, 1.0,
+                                         0.0, 1.0,
+                                         0.0, 0.0,
        };
        glVertexAttribPointer(worldShader_attribute_coord, 3, GL_FLOAT, GL_FALSE, 0, coord_back);
        glVertexAttribPointer(worldShader_attribute_tex, 2, GL_FLOAT, GL_FALSE, 0, tex);
@@ -873,6 +868,7 @@ unsigned int Structures::spawn(BUILD_SUB sub, float x, float y) {
        bsubtype = sub;
        dim2 dim;
 
+       z = 1.0;
        /*
         *      tempN is the amount of entities that will be spawned in the village. Currently the village
         *      will spawn bewteen 2 and 7 villagers for the starting hut.
@@ -922,7 +918,7 @@ Particles::Particles(float x, float y, float w, float h, float vx, float vy, Col
        index = Texture::getIndex(c);
 }
 
-void Particles::draw(std::vector<GLfloat> &p) const
+void Particles::draw(GLfloat*& p) const
 {
        vec2 tc = vec2 {0.25f * index.x, 0.125f * (8-index.y)};
 
@@ -931,52 +927,52 @@ void Particles::draw(std::vector<GLfloat> &p) const
         z = 2.0;
 
        // lower left
-    p.emplace_back(loc.x);
-    p.emplace_back(loc.y);
-    p.emplace_back(z);
+    *(p++) = loc.x;
+    *(p++) = loc.y;
+    *(p++) = z;
 
-       p.emplace_back(tc.x);
-       p.emplace_back(tc.y);
+       *(p++) = tc.x;
+       *(p++) = tc.y;
 
        // lower right
-    p.emplace_back(loc.x + width);
-    p.emplace_back(loc.y);
-    p.emplace_back(z);
+    *(p++) = loc.x + width;
+    *(p++) = loc.y;
+    *(p++) = z;
 
-       p.emplace_back(tc.x);
-       p.emplace_back(tc.y);
+       *(p++) = tc.x;
+       *(p++) = tc.y;
 
        // upper right
-    p.emplace_back(loc.x + width);
-    p.emplace_back(loc.y + height);
-    p.emplace_back(z);
+    *(p++) = loc.x + width;
+    *(p++) = loc.y + height;
+    *(p++) = z;
 
-       p.emplace_back(tc.x);
-       p.emplace_back(tc.y);
+       *(p++) = tc.x;
+       *(p++) = tc.y;
 
        // upper right
-    p.emplace_back(loc.x + width);
-    p.emplace_back(loc.y + height);
-    p.emplace_back(z);
+    *(p++) = loc.x + width;
+    *(p++) = loc.y + height;
+    *(p++) = z;
 
-       p.emplace_back(tc.x);
-       p.emplace_back(tc.y);
+       *(p++) = tc.x;
+       *(p++) = tc.y;
 
        // upper left
-    p.emplace_back(loc.x);
-    p.emplace_back(loc.y + height);
-    p.emplace_back(z);
+    *(p++) = loc.x;
+    *(p++) = loc.y + height;
+    *(p++) = z;
 
-       p.emplace_back(tc.x);
-    p.emplace_back(tc.y);
+       *(p++) = tc.x;
+    *(p++) = tc.y;
 
        // lower left
-    p.emplace_back(loc.x);
-    p.emplace_back(loc.y);
-    p.emplace_back(z);
+    *(p++) = loc.x;
+    *(p++) = loc.y;
+    *(p++) = z;
 
-    p.emplace_back(tc.x);
-    p.emplace_back(tc.y);
+    *(p++) = tc.x;
+    *(p++) = tc.y;
 }
 
 void Particles::update(float _gravity, float ground_y)
index 8c662c43644924a32d728616c8588cea40d3bd58..9727dc07401e506aac2b8b3d8e66522f036f329c 100644 (file)
@@ -414,7 +414,7 @@ void Inventory::draw(void) {
                        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));
+            drawRect(vec2(mr.x-(itemWide/2), mr.y-(itemWide/2)), vec2(mr.x-(itemWide/2)+itemWide, mr.y-(itemWide/2)+itemWide), -6.0);
 
             glUseProgram(0);
                        if (!Items.empty() && a+numSlot < Items.size() && Items[a+numSlot].second) {
@@ -423,10 +423,10 @@ void Inventory::draw(void) {
                                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)));
+                             vec2(mr.x+((itemWide/2)*((float)Items[a+numSlot].first->dim.x/(float)Items[a+numSlot].first->dim.y)),     mr.y+(itemWide/2)), -6.1);
                 }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)));
+                             vec2(mr.x-(itemWide/2),mr.y+(itemWide/2)*((float)Items[a+numSlot].first->dim.y/(float)Items[a+numSlot].first->dim.x)), -6.1);
                 }
                                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);
@@ -446,7 +446,7 @@ void Inventory::draw(void) {
             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));
+                     vec2(cr.end.x-(itemWide/2)+itemWide,cr.end.y-(itemWide/2)+itemWide), -6.0);
             glUseProgram(0);
                        a++;
                }a=0;
@@ -462,17 +462,17 @@ void Inventory::draw(void) {
             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));
+                     vec2(r.end.x-(itemWide/2)+itemWide,r.end.y-(itemWide/2)+itemWide), -6.1);
 
                        if (!Items.empty() && a < numSlot && Items[a].second) {
                                glBindTexture(GL_TEXTURE_2D, Items[a].first->tex->image[0]);//itemtex[items[a].id]);
                                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) {
                                    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)));
+                             vec2(r.end.x+((itemWide/2)*((float)Items[a].first->dim.x/(float)Items[a].first->dim.y)),  r.end.y+(itemWide/2)), -6.1);
                 }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)));
+                             vec2(r.end.x+(itemWide/2),r.end.y+(itemWide/2)*((float)Items[a].first->dim.y/(float)Items[a].first->dim.x)), -6.1);
                                }
                                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);
@@ -504,22 +504,22 @@ void Inventory::draw(void) {
                 // 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));
+                         vec2(r.end.x + (itemWide*sc)/2 + (itemWide*sc)*.09,r.end.y - (itemWide*sc)/2), -6.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));
+                         vec2(r.end.x + (itemWide*sc)/2 + (itemWide*sc)*.09,r.end.y + (itemWide*sc)/2), -6.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));
+                         vec2(r.end.x - (itemWide*sc)/2                                   ,r.end.y + (itemWide*sc)/2 + (itemWide*sc)*.09), -6.2);
 
                 // 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));
+                         vec2(r.end.x + (itemWide*sc)/2 + (itemWide*sc)*.09,r.end.y + (itemWide*sc)/2 + (itemWide*sc)*.09), -6.2);
 
                 //glUseProgram(0);
                        }
index a5bc2d7b63ca986144afc9748b9adaf2ca7b335c..2a7c22d412df076fb378463e0bd28ce7e91a2941 100644 (file)
@@ -184,6 +184,7 @@ namespace ui {
        */
 
        unsigned int fontSize;
+       float fontZ = -8.0;
 
     void takeScreenshot(GLubyte* pixels);
 
@@ -272,6 +273,13 @@ namespace ui {
                fontColor[3]=a;
        }
 
+       /*
+        *      Set the font's z layer
+        */
+       void setFontZ(float z) {
+               fontZ = z;
+       }
+
        /*
         *      Draws a character at the specified coordinates, aborting if the character is unknown.
        */
@@ -316,13 +324,13 @@ namespace ui {
                };
 
                GLfloat text_vert[] = {
-                       c1.x,           c1.y     -c2.y, 1.0,    //bottom left
-                       c1.x+c2.x,      c1.y     -c2.y, 1.0,    //bottom right
-                       c1.x+c2.x,      c1.y+c2.y-c2.y, 1.0,    //top right
+                       c1.x,           c1.y     -c2.y, fontZ,  //bottom left
+                       c1.x+c2.x,      c1.y     -c2.y, fontZ,  //bottom right
+                       c1.x+c2.x,      c1.y+c2.y-c2.y, fontZ,  //top right
 
-                       c1.x+c2.x,      c1.y+c2.y-c2.y, 1.0,    //top right
-                       c1.x,           c1.y+c2.y-c2.y, 1.0,    //top left
-                       c1.x,           c1.y     -c2.y, 1.0,    //bottom left
+                       c1.x+c2.x,      c1.y+c2.y-c2.y, fontZ,  //top right
+                       c1.x,           c1.y+c2.y-c2.y, fontZ,  //top left
+                       c1.x,           c1.y     -c2.y, fontZ   //bottom left
                };
 
         glUniform4f(textShader_uniform_color,
@@ -659,19 +667,19 @@ namespace ui {
        }
 
        void drawBox(vec2 c1, vec2 c2) {
-        GLfloat box[] = {c1.x, c1.y, 1.0,
-                         c2.x, c1.y, 1.0,
-                         c2.x, c2.y, 1.0,
+        GLfloat box[] = {c1.x, c1.y, -7.0,
+                         c2.x, c1.y, -7.0,
+                         c2.x, c2.y, -7.0,
 
-                         c2.x, c2.y, 1.0,
-                         c1.x, c2.y, 1.0,
-                         c1.x, c1.y, 1.0};
+                         c2.x, c2.y, -7.0,
+                         c1.x, c2.y, -7.0,
+                         c1.x, c1.y, -7.0};
 
-        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,     c2.y, 1.0,
-                                c1.x,     c1.y, 1.0};
+        GLfloat line_strip[] = {c1.x,     c1.y, -7.1,
+                                c2.x + 1, c1.y, -7.1,
+                                c2.x + 1, c2.y, -7.1,
+                                c1.x,     c2.y, -7.1,
+                                c1.x,     c1.y, -7.1};
 
         GLfloat box_tex[] = {0,0,
                              1,0,
@@ -722,13 +730,13 @@ namespace ui {
 
                if (pageTexReady) {
 
-            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,
+            GLfloat page_loc[] = {offset.x - 300, SCREEN_HEIGHT - 100, -6.0,
+                                  offset.x + 300, SCREEN_HEIGHT - 100, -6.0,
+                                  offset.x + 300, SCREEN_HEIGHT - 600, -6.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};
+                                  offset.x + 300, SCREEN_HEIGHT - 600, -6.0,
+                                  offset.x - 300, SCREEN_HEIGHT - 600, -6.0,
+                                  offset.x - 300, SCREEN_HEIGHT - 100, -6.0};
 
             GLfloat page_tex[] = {0.0, 0.0,
                                   1.0, 0.0,
@@ -803,21 +811,21 @@ namespace ui {
                                       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,
+                GLfloat left_item[] = {offset.x - (SCREEN_WIDTH / 10),      offset.y + (SCREEN_HEIGHT / 5),     -7.2,
+                                       offset.x - (SCREEN_WIDTH / 10) + 40, offset.y + (SCREEN_HEIGHT / 5),     -7.2,
+                                       offset.x - (SCREEN_WIDTH / 10) + 40, offset.y + (SCREEN_HEIGHT / 5) + 40,-7.2,
 
-                                       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};
+                                       offset.x - (SCREEN_WIDTH / 10) + 40, offset.y + (SCREEN_HEIGHT / 5) + 40,-7.2,
+                                       offset.x - (SCREEN_WIDTH / 10),      offset.y + (SCREEN_HEIGHT / 5) + 40,-7.2,
+                                       offset.x - (SCREEN_WIDTH / 10),      offset.y + (SCREEN_HEIGHT / 5),     -7.2};
 
-                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,
+                GLfloat right_item[] = {offset.x + (SCREEN_WIDTH / 10) - 40,    offset.y + (SCREEN_HEIGHT / 5),     -7.2,
+                                        offset.x + (SCREEN_WIDTH / 10),         offset.y + (SCREEN_HEIGHT / 5),     -7.2,
+                                        offset.x + (SCREEN_WIDTH / 10),         offset.y + (SCREEN_HEIGHT / 5) + 40,-7.2,
 
-                                        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};
+                                        offset.x + (SCREEN_WIDTH / 10),         offset.y + (SCREEN_HEIGHT / 5) + 40,-7.2,
+                                        offset.x + (SCREEN_WIDTH / 10) - 40,    offset.y + (SCREEN_HEIGHT / 5) + 40,-7.2,
+                                        offset.x + (SCREEN_WIDTH / 10) - 40,    offset.y + (SCREEN_HEIGHT / 5),     -7.2};
 
                 glActiveTexture(GL_TEXTURE0);
                 glBindTexture(GL_TEXTURE_2D, getItemTexture(merchTrade.item[1]));
@@ -865,9 +873,9 @@ namespace ui {
                                        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};
+                    GLfloat tri_c[] = {merchArrowLoc[i].x, merchArrowLoc[i].y,      -7.1,
+                                       merchArrowLoc[i].z, merchArrowLoc[i].y - 8,  -7.1,
+                                       merchArrowLoc[i].z, merchArrowLoc[i].y + 8,  -7.1};
 
                     glUniform1i(textShader_uniform_texture, 0);
                     glUseProgram(textShader);
@@ -950,6 +958,9 @@ namespace ui {
                        putText(hub.x,hub.y,"Health: %u/%u",player->health>0?(unsigned)player->health:0,
                                                                                                (unsigned)player->maxHealth
                                                                                                );
+                       static GLuint frontHealth = Texture::genColor(Color(255,0,0));
+                       static GLuint backHealth = Texture::genColor(Color(150,0,0));
+
                        if (player->isAlive()) {
                                hub.y-=fontSize*1.15;
 
@@ -958,15 +969,15 @@ namespace ui {
                                  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 back[] = {hub.x,        hub.y,      -7.0,
+                                  hub.x + 150,  hub.y,      -7.0,
+                                  hub.x,        hub.y + 12, -7.0,
+                                  hub.x + 150,  hub.y + 12, -7.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};
+                GLfloat front[] = {hub.x,       hub.y,      -7.1,
+                                   hub.x + 150, hub.y,      -7.1,
+                                   hub.x,       hub.y + 12, -7.1,
+                                   hub.x + 150, hub.y + 12, -7.1};
 
 
                 glUniform1i(textShader_uniform_texture, 0);
@@ -975,13 +986,13 @@ namespace ui {
                 glEnableVertexAttribArray(textShader_attribute_coord);
                 glEnableVertexAttribArray(textShader_attribute_tex);
 
-                glBindTexture(GL_TEXTURE_2D, Texture::genColor(Color(150,0,0)));
+                glBindTexture(GL_TEXTURE_2D, frontHealth);
 
                 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)));
+                glBindTexture(GL_TEXTURE_2D, backHealth);
 
                 glVertexAttribPointer(textShader_attribute_coord, 3, GL_FLOAT, GL_FALSE, 0, back);
                 glVertexAttribPointer(textShader_attribute_tex, 2, GL_FLOAT, GL_FALSE, 0, tex);
@@ -1155,7 +1166,7 @@ EXIT:
                                        /*player->inv->invHover =*/ edown = false;
 
                        if (dialogBoxExists || pageTexReady) {
-                                       // right click advances dialog
+                                       //right click advances dialog
                                        if ((e.button.button & SDL_BUTTON_RIGHT))
                                                dialogAdvance();
                                } else {
@@ -1420,7 +1431,7 @@ EXIT:
        void drawFade(void) {
                auto SCREEN_WIDTH = game::SCREEN_WIDTH;
                auto SCREEN_HEIGHT = game::SCREEN_HEIGHT;
-
+               
                if (!fadeIntensity) {
                        if (fontSize != 16)
                                setFontSize(16);
@@ -1437,11 +1448,12 @@ EXIT:
                         0.0, 1.0,
                         1.0, 1.0};
 
-        GLfloat backdrop[] = {offset.x - SCREEN_WIDTH / 2 - 1, offset.y - SCREEN_HEIGHT / 2, 1.0,
-                              offset.x + SCREEN_WIDTH / 2, offset.y - SCREEN_HEIGHT / 2, 1.0,
-                              offset.x - SCREEN_WIDTH / 2 - 1, offset.y + SCREEN_HEIGHT / 2, 1.0,
-                              offset.x + SCREEN_WIDTH / 2, offset.y + SCREEN_HEIGHT / 2, 1.0};
-
+        GLfloat backdrop[] = {offset.x - SCREEN_WIDTH / 2 - 1, offset.y - SCREEN_HEIGHT / 2, -8.1,
+                              offset.x + SCREEN_WIDTH / 2, offset.y - SCREEN_HEIGHT / 2,        -8.1,
+                              offset.x - SCREEN_WIDTH / 2 - 1, offset.y + SCREEN_HEIGHT / 2, -8.1,
+                              offset.x + SCREEN_WIDTH / 2, offset.y + SCREEN_HEIGHT / 2,        -8.1};
+               
+               setFontZ(-8.2);
         glUniform1i(textShader_uniform_texture, 0);
         glUseProgram(textShader);
 
@@ -1456,6 +1468,7 @@ EXIT:
         glDisableVertexAttribArray(textShader_attribute_tex);
 
         glUseProgram(0);
+               setFontZ(-8.0);
 
     }
 
index e766b6176432c80759edb236223220f77ac418c4..25782be487e7118fd31ce1eaab1e3c5f928acf9e 100644 (file)
@@ -113,6 +113,7 @@ namespace ui {
 
             setFontSize(24);
             game::config::update();
+                       setFontZ(-9.0);
 
             mouse.x = ui::premouse.x+offset.x-(SCREEN_WIDTH/2);
             mouse.y = (offset.y+SCREEN_HEIGHT/2)-ui::premouse.y;
@@ -153,7 +154,7 @@ namespace ui {
                        glUseProgram(textShader);
                        
                        glBindTexture(GL_TEXTURE_2D, backTex);
-                       drawRect(vec2(offset.x - SCREEN_WIDTH / 2, offset.y - (SCREEN_HEIGHT / 2)), vec2(offset.x + SCREEN_WIDTH / 2, offset.y + (SCREEN_HEIGHT / 2)));
+                       drawRect(vec2(offset.x - SCREEN_WIDTH / 2, offset.y - (SCREEN_HEIGHT / 2)), vec2(offset.x + SCREEN_WIDTH / 2, offset.y + (SCREEN_HEIGHT / 2)), -8.5);
 
                        glUseProgram(0);
 
@@ -169,7 +170,7 @@ namespace ui {
                                        glBindTexture(GL_TEXTURE_2D, bsTex);
 
                                        drawRect(vec2(offset.x + m.button.loc.x, offset.y + m.button.loc.y),
-                                                        vec2(offset.x + m.button.loc.x + m.button.dim.x, offset.y + m.button.loc.y + m.button.dim.y));
+                                                        vec2(offset.x + m.button.loc.x + m.button.dim.x, offset.y + m.button.loc.y + m.button.dim.y), -8.6);
                     //draw the button text
                     putStringCentered(offset.x + m.button.loc.x + (m.button.dim.x/2),
                                       (offset.y + m.button.loc.y + (m.button.dim.y/2)) - ui::fontSize/2,
@@ -182,11 +183,11 @@ namespace ui {
                             //if the mouse if over the button, it draws this white outline
                                                        glBindTexture(GL_TEXTURE_2D, border);
                                                
-                                                       GLfloat verts[] = {offset.x+m.button.loc.x,                                     offset.y+m.button.loc.y,                                1.0,
-                                                          offset.x+m.button.loc.x+m.button.dim.x,              offset.y+m.button.loc.y,                                1.0,
-                                                          offset.x+m.button.loc.x+m.button.dim.x,              offset.y+m.button.loc.y+m.button.dim.y, 1.0,
-                                                          offset.x+m.button.loc.x,                                     offset.y+m.button.loc.y+m.button.dim.y, 1.0,
-                                                          offset.x+m.button.loc.x,                                     offset.y+m.button.loc.y,                                1.0};
+                                                       GLfloat verts[] = {offset.x+m.button.loc.x,                                     offset.y+m.button.loc.y,                                -8.7,
+                                                          offset.x+m.button.loc.x+m.button.dim.x,              offset.y+m.button.loc.y,                                -8.7,
+                                                          offset.x+m.button.loc.x+m.button.dim.x,              offset.y+m.button.loc.y+m.button.dim.y, -8.7,
+                                                          offset.x+m.button.loc.x,                                     offset.y+m.button.loc.y+m.button.dim.y, -8.7,
+                                                          offset.x+m.button.loc.x,                                     offset.y+m.button.loc.y,                                -8.7};
 
                                                        glUseProgram(textShader);
                                                        glEnableVertexAttribArray(textShader_attribute_coord);
@@ -244,19 +245,19 @@ namespace ui {
 
                                        glBindTexture(GL_TEXTURE_2D, bsTex);
                                        drawRect(vec2(offset.x + m.slider.loc.x, offset.y + m.slider.loc.y),
-                                                        vec2(offset.x + m.slider.loc.x + m.slider.dim.x, offset.y + m.slider.loc.y + m.slider.dim.y));
+                                                        vec2(offset.x + m.slider.loc.x + m.slider.dim.x, offset.y + m.slider.loc.y + m.slider.dim.y), -8.6);
                            
                                        //draw the slider handle
                     glBindTexture(GL_TEXTURE_2D, hTex);
                                        if (m.slider.dim.y > m.slider.dim.x) {
                         drawRect(vec2(offset.x+m.slider.loc.x, offset.y+m.slider.loc.y + (m.slider.sliderLoc * 1.05)),
-                                vec2(offset.x+m.slider.loc.x + sliderW, offset.y+m.slider.loc.y + (m.slider.sliderLoc * 1.05) + sliderH));
+                                vec2(offset.x+m.slider.loc.x + sliderW, offset.y+m.slider.loc.y + (m.slider.sliderLoc * 1.05) + sliderH), -8.7);
 
                         //draw the now combined slider text
                         putStringCentered(offset.x + m.slider.loc.x + (m.slider.dim.x/2), (offset.y + m.slider.loc.y + (m.slider.dim.y*1.05)) - ui::fontSize/2, outSV);
                     }else{
                         drawRect(vec2(offset.x+m.slider.loc.x+m.slider.sliderLoc, offset.y+m.slider.loc.y),
-                                 vec2(offset.x+m.slider.loc.x + m.slider.sliderLoc + sliderW, offset.y+m.slider.loc.y + sliderH));
+                                 vec2(offset.x+m.slider.loc.x + m.slider.sliderLoc + sliderW, offset.y+m.slider.loc.y + sliderH), -8.7);
 
                         //draw the now combined slider text
                         putStringCentered(offset.x + m.slider.loc.x + (m.slider.dim.x/2), (offset.y + m.slider.loc.y + (m.slider.dim.y/2)) - ui::fontSize/2, outSV);
@@ -272,32 +273,32 @@ namespace ui {
                                                        glEnableVertexAttribArray(textShader_attribute_coord);
                                                        glEnableVertexAttribArray(textShader_attribute_tex);
                             
-                                                       GLfloat box_border[] = {offset.x+m.slider.loc.x,                                        offset.y+m.slider.loc.y,                                1.0,
-                                                                       offset.x+m.slider.loc.x+m.slider.dim.x,         offset.y+m.slider.loc.y,                                1.0,
-                                                                       offset.x+m.slider.loc.x+m.slider.dim.x,         offset.y+m.slider.loc.y+m.slider.dim.y, 1.0,
-                                                                       offset.x+m.slider.loc.x,                                        offset.y+m.slider.loc.y+m.slider.dim.y, 1.0,
-                                                                       offset.x+m.slider.loc.x,                                        offset.y+m.slider.loc.y,                                1.0};
+                                                       GLfloat box_border[] = {offset.x+m.slider.loc.x,                                        offset.y+m.slider.loc.y,                                -8.8,
+                                                                       offset.x+m.slider.loc.x+m.slider.dim.x,         offset.y+m.slider.loc.y,                                -8.8,
+                                                                       offset.x+m.slider.loc.x+m.slider.dim.x,         offset.y+m.slider.loc.y+m.slider.dim.y, -8.8,
+                                                                       offset.x+m.slider.loc.x,                                        offset.y+m.slider.loc.y+m.slider.dim.y, -8.8,
+                                                                       offset.x+m.slider.loc.x,                                        offset.y+m.slider.loc.y,                                -8.8};
 
                                                        glVertexAttribPointer(textShader_attribute_coord, 3, GL_FLOAT, GL_FALSE, 0, box_border);
                                                        glVertexAttribPointer(textShader_attribute_tex, 2, GL_FLOAT, GL_FALSE, 0, line_tex);
                                                        glDrawArrays(GL_LINE_STRIP, 0, 5);      
                             if (m.slider.dim.y > m.slider.dim.x) {
                                 //and a border around the slider handle
-                                GLfloat handle_border[] = {offset.x+m.slider.loc.x,              static_cast<GLfloat>(offset.y+m.slider.loc.y + (m.slider.sliderLoc * 1.05)),                          1.0,
-                                                                                  offset.x+m.slider.loc.x + sliderW, static_cast<GLfloat>(offset.y+m.slider.loc.y + (m.slider.sliderLoc * 1.05)),                              1.0,
-                                                                                  offset.x+m.slider.loc.x + sliderW, static_cast<GLfloat>(offset.y+m.slider.loc.y + (m.slider.sliderLoc * 1.05) + sliderH),    1.0,
-                                                                                  offset.x+m.slider.loc.x,           static_cast<GLfloat>(offset.y+m.slider.loc.y + (m.slider.sliderLoc * 1.05) + sliderH),    1.0,
-                                                                                  offset.x+m.slider.loc.x,           static_cast<GLfloat>(offset.y+m.slider.loc.y + (m.slider.sliderLoc * 1.05)),                              1.0};
+                                GLfloat handle_border[] = {offset.x+m.slider.loc.x,              static_cast<GLfloat>(offset.y+m.slider.loc.y + (m.slider.sliderLoc * 1.05)),                          -8.8,
+                                                                                  offset.x+m.slider.loc.x + sliderW, static_cast<GLfloat>(offset.y+m.slider.loc.y + (m.slider.sliderLoc * 1.05)),                              -8.8,
+                                                                                  offset.x+m.slider.loc.x + sliderW, static_cast<GLfloat>(offset.y+m.slider.loc.y + (m.slider.sliderLoc * 1.05) + sliderH),    -8.8,
+                                                                                  offset.x+m.slider.loc.x,           static_cast<GLfloat>(offset.y+m.slider.loc.y + (m.slider.sliderLoc * 1.05) + sliderH),    -8.8,
+                                                                                  offset.x+m.slider.loc.x,           static_cast<GLfloat>(offset.y+m.slider.loc.y + (m.slider.sliderLoc * 1.05)),                              -8.8};
                                                                glVertexAttribPointer(textShader_attribute_coord, 3, GL_FLOAT, GL_FALSE, 0, handle_border);
                                                                glVertexAttribPointer(textShader_attribute_tex, 2, GL_FLOAT, GL_FALSE, 0, line_tex);
                                                                glDrawArrays(GL_LINE_STRIP, 0, 5);      
                             }else{
                                 //and a border around the slider handle
-                                GLfloat handle_border[] = {offset.x+m.slider.loc.x + m.slider.sliderLoc, offset.y+m.slider.loc.y,                                                      1.0,
-                                                                                  offset.x+m.slider.loc.x + (m.slider.sliderLoc + sliderW), offset.y+m.slider.loc.y,                           1.0,
-                                                                                  offset.x+m.slider.loc.x + (m.slider.sliderLoc + sliderW), offset.y+m.slider.loc.y+m.slider.dim.y,1.0,
-                                                                                  offset.x+m.slider.loc.x + m.slider.sliderLoc, offset.y+m.slider.loc.y+m.slider.dim.y,                        1.0,
-                                                                                  offset.x+m.slider.loc.x + m.slider.sliderLoc, offset.y+m.slider.loc.y,                                                       1.0};
+                                GLfloat handle_border[] = {offset.x+m.slider.loc.x + m.slider.sliderLoc, offset.y+m.slider.loc.y,                                                      -8.8,
+                                                                                  offset.x+m.slider.loc.x + (m.slider.sliderLoc + sliderW), offset.y+m.slider.loc.y,                           -8.8,
+                                                                                  offset.x+m.slider.loc.x + (m.slider.sliderLoc + sliderW), offset.y+m.slider.loc.y+m.slider.dim.y,-8.8,
+                                                                                  offset.x+m.slider.loc.x + m.slider.sliderLoc, offset.y+m.slider.loc.y+m.slider.dim.y,                        -8.8,
+                                                                                  offset.x+m.slider.loc.x + m.slider.sliderLoc, offset.y+m.slider.loc.y,                                                       -8.8};
                                                                glVertexAttribPointer(textShader_attribute_coord, 3, GL_FLOAT, GL_FALSE, 0, handle_border);
                                                                glVertexAttribPointer(textShader_attribute_tex, 2, GL_FLOAT, GL_FALSE, 0, line_tex);
                                                                glDrawArrays(GL_LINE_STRIP, 0, 5);      
@@ -315,14 +316,14 @@ namespace ui {
                                     //draw a white box over the handle
                                     glBindTexture(GL_TEXTURE_2D, border);
                                                                        drawRect(vec2(offset.x+m.slider.loc.x, offset.y+m.slider.loc.y + (m.slider.sliderLoc * 1.05)),
-                                             vec2(offset.x+m.slider.loc.x + sliderW, offset.y+m.slider.loc.y + (m.slider.sliderLoc * 1.05) + sliderH));
+                                             vec2(offset.x+m.slider.loc.x + sliderW, offset.y+m.slider.loc.y + (m.slider.sliderLoc * 1.05) + sliderH), -8.9);
 
                                 }else{
                                     *m.slider.var = (((mouse.x-offset.x) - m.slider.loc.x)/m.slider.dim.x)*100;
                                     //draw a white box over the handle
                                     glBindTexture(GL_TEXTURE_2D, border);
                                                                        drawRect(vec2(offset.x+m.slider.loc.x + m.slider.sliderLoc, offset.y+m.slider.loc.y),
-                                             vec2(offset.x+m.slider.loc.x + (m.slider.sliderLoc + sliderW), offset.y+m.slider.loc.y + m.slider.dim.y));
+                                             vec2(offset.x+m.slider.loc.x + (m.slider.sliderLoc + sliderW), offset.y+m.slider.loc.y + m.slider.dim.y), -8.9);
                                 }
                             }
 
@@ -334,6 +335,7 @@ namespace ui {
                 }
             }
             setFontSize(16);
+                       setFontZ(-8.0);
         }
 
 
index 70ba9678ca3ba7de561d6dac7ba4810447f7e15e..005c06ffe6da313a909a9b7f71035b217784414c 100644 (file)
@@ -275,13 +275,13 @@ void World::drawBackgrounds(void)
                             vec2(0.0f, 1.0f),
                             vec2(0.0f, 0.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,
+    GLfloat back_tex_coord[] = {offset.x - backgroundOffset.x - 5, offset.y + backgroundOffset.y, 9.9f,
+                                offset.x + backgroundOffset.x + 5, offset.y + backgroundOffset.y, 9.9f,
+                                offset.x + backgroundOffset.x + 5, offset.y - backgroundOffset.y, 9.9f,
 
-                                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, 9.9f,
+                                offset.x - backgroundOffset.x - 5, offset.y - backgroundOffset.y, 9.9f,
+                                offset.x - backgroundOffset.x - 5, offset.y + backgroundOffset.y, 9.9f};
 
     glUseProgram(worldShader);
 
@@ -476,13 +476,13 @@ void World::draw(Player *p)
     glEnableVertexAttribArray(worldShader_attribute_tex);
 
     uint ps = particles.size();
-
-    std::vector<GLfloat> partVec;
-    partVec.reserve(ps * 6 * 5);
+       
+       GLfloat partVec[ps * 6 * 5 + 1];
+       GLfloat *pIndex = &partVec[0];
 
     for (auto &p : particles) {
         if (!p.behind)
-            p.draw(partVec);
+            p.draw(pIndex);
     }
 
     glVertexAttribPointer(worldShader_attribute_coord, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), &partVec[0]);
@@ -494,18 +494,6 @@ void World::draw(Player *p)
 
     glUseProgram(0);
 
-       for (auto &b : build) {
-        if (b->bsubtype == STALL_MARKET) {
-            for (auto &n : npc) {
-                if (n->type == MERCHT && static_cast<Merchant *>(n)->inside == b) {
-                    n->draw();
-                    break;
-                }
-            }
-        }
-        b->draw();
-    }
-
     for (auto &l : light) {
         if (l.belongsTo) {
             l.loc.x = l.following->loc.x + SCREEN_WIDTH / 2;
@@ -550,13 +538,13 @@ void World::draw(Player *p)
         // glTexCoord2i(1, ty); glVertex2i(worldStart + i * HLINE + HLINE, 0);
         // glTexCoord2i(0, ty); glVertex2i(worldStart + i * HLINE            , 0);
 
-               c.push_back(std::make_pair(vec2(0, 0), vec3(worldStart + HLINES(i),         worldData[i].groundHeight - GRASS_HEIGHT, 1.0f)));
-        c.push_back(std::make_pair(vec2(1, 0), vec3(worldStart + HLINES(i) + HLINE, worldData[i].groundHeight - GRASS_HEIGHT, 1.0f)));
-        c.push_back(std::make_pair(vec2(1, ty),vec3(worldStart + HLINES(i) + HLINE, 0,                                        1.0f)));
+               c.push_back(std::make_pair(vec2(0, 0), vec3(worldStart + HLINES(i),         worldData[i].groundHeight - GRASS_HEIGHT, -4.0f)));
+        c.push_back(std::make_pair(vec2(1, 0), vec3(worldStart + HLINES(i) + HLINE, worldData[i].groundHeight - GRASS_HEIGHT, -4.0f)));
+        c.push_back(std::make_pair(vec2(1, ty),vec3(worldStart + HLINES(i) + HLINE, 0,                                        -4.0f)));
 
-        c.push_back(std::make_pair(vec2(1, ty),vec3(worldStart + HLINES(i) + HLINE, 0,                                        1.0f)));
-        c.push_back(std::make_pair(vec2(0, ty),vec3(worldStart + HLINES(i),         0,                                        1.0f)));
-        c.push_back(std::make_pair(vec2(0, 0), vec3(worldStart + HLINES(i),         worldData[i].groundHeight - GRASS_HEIGHT, 1.0f)));
+        c.push_back(std::make_pair(vec2(1, ty),vec3(worldStart + HLINES(i) + HLINE, 0,                                        -4.0f)));
+        c.push_back(std::make_pair(vec2(0, ty),vec3(worldStart + HLINES(i),         0,                                        -4.0f)));
+        c.push_back(std::make_pair(vec2(0, 0), vec3(worldStart + HLINES(i),         worldData[i].groundHeight - GRASS_HEIGHT, -4.0f)));
 
         if (worldData[i].groundHeight == GROUND_HEIGHT_MINIMUM - 1)
             worldData[i].groundHeight = 0;
@@ -628,22 +616,22 @@ void World::draw(Player *p)
                        glTexCoord2i(1, 1); glVertex2i(worldStart + i * HLINE + HLINE    , wd.groundHeight - GRASS_HEIGHT);
                        glTexCoord2i(0, 1); glVertex2i(worldStart + i * HLINE + HLINE / 2, wd.groundHeight - GRASS_HEIGHT);*/
 
-                c.push_back(std::make_pair(vec2(0, 0),vec3(worldStart + HLINES(i)            , wd.groundHeight + gh[0])));
-                c.push_back(std::make_pair(vec2(1, 0),vec3(worldStart + HLINES(i) + HLINE / 2, wd.groundHeight + gh[0])));
-                c.push_back(std::make_pair(vec2(1, 1),vec3(worldStart + HLINES(i) + HLINE / 2, wd.groundHeight - GRASS_HEIGHT)));
+                c.push_back(std::make_pair(vec2(0, 0),vec3(worldStart + HLINES(i)            , wd.groundHeight + gh[0],                -3)));
+                c.push_back(std::make_pair(vec2(1, 0),vec3(worldStart + HLINES(i) + HLINE / 2, wd.groundHeight + gh[0],                -3)));
+                c.push_back(std::make_pair(vec2(1, 1),vec3(worldStart + HLINES(i) + HLINE / 2, wd.groundHeight - GRASS_HEIGHT,         -3)));
 
-                c.push_back(std::make_pair(vec2(1, 1),vec3(worldStart + HLINES(i) + HLINE / 2, wd.groundHeight - GRASS_HEIGHT)));
-                c.push_back(std::make_pair(vec2(0, 1),vec3(worldStart + HLINES(i)                   , wd.groundHeight - GRASS_HEIGHT)));
-                c.push_back(std::make_pair(vec2(0, 0),vec3(worldStart + HLINES(i)            , wd.groundHeight + gh[0])));
+                c.push_back(std::make_pair(vec2(1, 1),vec3(worldStart + HLINES(i) + HLINE / 2, wd.groundHeight - GRASS_HEIGHT, -3)));
+                c.push_back(std::make_pair(vec2(0, 1),vec3(worldStart + HLINES(i)                   , wd.groundHeight - GRASS_HEIGHT,  -3)));
+                c.push_back(std::make_pair(vec2(0, 0),vec3(worldStart + HLINES(i)            , wd.groundHeight + gh[0],                        -3)));
 
 
-                c.push_back(std::make_pair(vec2(0, 0),vec3(worldStart + HLINES(i) + HLINE / 2, wd.groundHeight + gh[1])));
-                c.push_back(std::make_pair(vec2(1, 0),vec3(worldStart + HLINES(i) + HLINE    , wd.groundHeight + gh[1])));
-                c.push_back(std::make_pair(vec2(1, 1),vec3(worldStart + HLINES(i) + HLINE    , wd.groundHeight - GRASS_HEIGHT)));
+                c.push_back(std::make_pair(vec2(0, 0),vec3(worldStart + HLINES(i) + HLINE / 2, wd.groundHeight + gh[1],                        -3)));
+                c.push_back(std::make_pair(vec2(1, 0),vec3(worldStart + HLINES(i) + HLINE    , wd.groundHeight + gh[1],                        -3)));
+                c.push_back(std::make_pair(vec2(1, 1),vec3(worldStart + HLINES(i) + HLINE    , wd.groundHeight - GRASS_HEIGHT, -3)));
 
-                c.push_back(std::make_pair(vec2(1, 1),vec3(worldStart + HLINES(i) + HLINE    , wd.groundHeight - GRASS_HEIGHT)));
-                c.push_back(std::make_pair(vec2(0, 1),vec3(worldStart + HLINES(i) + HLINE / 2, wd.groundHeight - GRASS_HEIGHT)));
-                c.push_back(std::make_pair(vec2(0, 0),vec3(worldStart + HLINES(i) + HLINE / 2, wd.groundHeight + gh[1])));
+                c.push_back(std::make_pair(vec2(1, 1),vec3(worldStart + HLINES(i) + HLINE    , wd.groundHeight - GRASS_HEIGHT, -3)));
+                c.push_back(std::make_pair(vec2(0, 1),vec3(worldStart + HLINES(i) + HLINE / 2, wd.groundHeight - GRASS_HEIGHT, -3)));
+                c.push_back(std::make_pair(vec2(0, 0),vec3(worldStart + HLINES(i) + HLINE / 2, wd.groundHeight + gh[1],                        -3)));
 
             //glEnd();
         }
@@ -685,27 +673,30 @@ void World::draw(Player *p)
     glEnableVertexAttribArray(worldShader_attribute_coord);
     glEnableVertexAttribArray(worldShader_attribute_tex);
 
-    partVec.clear();
-    partVec.reserve(ps * 6 * 5);
+       /*GLfloat *pIndexT = &partVec[0];
 
     for (auto &p : particles) {
         if (!p.behind)
-            p.draw(partVec);
+            p.draw(pIndexT);
     }
 
     glVertexAttribPointer(worldShader_attribute_coord, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), &partVec[0]);
     glVertexAttribPointer(worldShader_attribute_tex, 2, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), &partVec[3]);
     glDrawArrays(GL_TRIANGLES, 0, ps * 6);
-
+*/
     glDisableVertexAttribArray(worldShader_attribute_tex);
     glDisableVertexAttribArray(worldShader_attribute_coord);
 
     glUseProgram(0);
 
+       // draw the buildings
+       for (auto &b : build) {
+        b->draw();
+    }
+
     // draw remaining entities
        for (auto &n : npc) {
-               if (n->type != MERCHT)
-            n->draw();
+        n->draw();
     }
 
        for (auto &m : mob)
@@ -1453,7 +1444,8 @@ addMerchant(float x, float y, bool housed)
 
     if (housed) {
         merchant.back()->inside = build.back();
-    }
+       merchant.back()->z = build.back()->z+.1;
+       }
 
        npc.push_back(merchant.back());
        entity.push_back(npc.back());
@@ -1625,7 +1617,7 @@ singleDetect(Entity *e)
 void IndoorWorld::
 draw(Player *p)
 {
-       unsigned int i,f;
+       unsigned int i,fl;
        int x;
 
     auto SCREEN_WIDTH = game::SCREEN_WIDTH;
@@ -1646,7 +1638,7 @@ draw(Player *p)
             l.fireFlicker = 1.0f;
     }
 
-    std::unique_ptr<GLfloat[]> pointArrayBuf = std::make_unique<GLfloat[]> (2 * (light.size()));
+/*    std::unique_ptr<GLfloat[]> pointArrayBuf = std::make_unique<GLfloat[]> (2 * (light.size()));
        auto pointArray = pointArrayBuf.get();
     GLfloat flameArray[64];
 
@@ -1679,55 +1671,125 @@ draw(Player *p)
                glUniform3f (glGetUniformLocation(shaderProgram, "lightColor"), 1.0f, 1.0f, 1.0f);
         glUniform1fv(glGetUniformLocation(shaderProgram, "fireFlicker"), light.size(), flameArray);
        }
+*/
+       
+       glUseProgram(worldShader);
 
+       glActiveTexture(GL_TEXTURE0);
        bgTex(0);
+
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); //for the s direction
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); //for the t direction
-       glColor4ub(255,255,255,255);
 
-    glBegin(GL_QUADS);
-        glTexCoord2i(0,1);                                                          glVertex2i(worldStart - SCREEN_WIDTH / 2,0);
-               glTexCoord2i((-worldStart*2+SCREEN_WIDTH)/512,1);glVertex2i(-worldStart + SCREEN_WIDTH / 2,0);
-               glTexCoord2i((-worldStart*2+SCREEN_WIDTH)/512,0);glVertex2i(-worldStart + SCREEN_WIDTH / 2,SCREEN_HEIGHT);
-               glTexCoord2i(0,0);                                                           glVertex2i(worldStart - SCREEN_WIDTH / 2,SCREEN_HEIGHT);
-    glEnd();
+       glUniform1i(worldShader_uniform_texture, 0);
+       glUniform4f(worldShader_uniform_color, 1.0, 1.0, 1.0, 1.0);
 
-    glUseProgram(0);
+       GLfloat backTile[] = {worldStart - SCREEN_WIDTH / 2,    0,                                                                      9.9,
+                                                 -worldStart + SCREEN_WIDTH / 2,       0,                                                                      9.9,
+                                                 -worldStart + SCREEN_WIDTH / 2,       static_cast<float>(SCREEN_HEIGHT),      9.9,
+                                                 
+                                                 -worldStart + SCREEN_WIDTH / 2,       static_cast<float>(SCREEN_HEIGHT),      9.9,
+                                                 worldStart - SCREEN_WIDTH / 2,        static_cast<float>(SCREEN_HEIGHT),      9.9,
+                                                 worldStart - SCREEN_WIDTH / 2,        0,                                                                      9.9};
+
+       GLfloat backTile_tex[] = {0, 1,
+                                                         (-worldStart*2+SCREEN_WIDTH)/512, 1,
+                                                         (-worldStart*2+SCREEN_WIDTH)/512, 0,
+
+                                                         (-worldStart*2+SCREEN_WIDTH)/512, 0,
+                                                         0, 0,
+                                                         0, 1};
+
+       glEnableVertexAttribArray(worldShader_attribute_coord);
+       glEnableVertexAttribArray(worldShader_attribute_tex);
+
+       glVertexAttribPointer(worldShader_attribute_coord, 3, GL_FLOAT, GL_FALSE, 0, backTile);
+       glVertexAttribPointer(worldShader_attribute_tex, 2, GL_FLOAT, GL_FALSE, 0, backTile_tex);
+       glDrawArrays(GL_TRIANGLES, 0, 6);
+
+       glDisableVertexAttribArray(worldShader_attribute_coord);
+       glDisableVertexAttribArray(worldShader_attribute_tex);
+
+       glUseProgram(0);
 
        /*
         *      Draw the ground.
        */
 
-       glUseProgram(shaderProgram);
-       glUniform1i(glGetUniformLocation(shaderProgram, "sampler"), 0);
-       glBegin(GL_QUADS);
-        safeSetColor(150, 100, 50);
-        for (f = 0; f < floor.size(); f++) {
-            i = 0;
-               for (const auto &h : floor[f]) {
-                       x = worldStart + fstart[f] * HLINE + HLINES(i);
-                       glVertex2i(x        , h            );
-                       glVertex2i(x + HLINE, h            );
-                       glVertex2i(x + HLINE, h - INDOOR_FLOOR_THICKNESS);
-                       glVertex2i(x        , h - INDOOR_FLOOR_THICKNESS);
-                i++;
-               }
-        }
-       glEnd();
+       // TODO make floor texture
+
+       static GLuint floorTex = Texture::genColor(Color(150, 100, 50));
+
+       glUseProgram(worldShader);
+       glBindTexture(GL_TEXTURE_2D, floorTex);
+
+       std::vector<GLfloat>f;
+
+       for (fl = 0; fl < floor.size(); fl++) {
+        i = 0;
+       for (const auto &h : floor[fl]) {
+               x = worldStart + fstart[fl] * HLINE + HLINES(i);
+               
+                       f.emplace_back(x);
+               f.emplace_back(h);
+                       f.emplace_back(-3);
+                       f.emplace_back(0);
+                       f.emplace_back(0);
+               
+                       f.emplace_back(x + HLINE);
+                       f.emplace_back(h);
+                       f.emplace_back(-3);
+                       f.emplace_back(1);
+                       f.emplace_back(0);
+                       
+                       f.emplace_back(x + HLINE);
+                       f.emplace_back(h - INDOOR_FLOOR_THICKNESS);
+                       f.emplace_back(-3);
+                       f.emplace_back(1);
+                       f.emplace_back(1);
+
+
+                       f.emplace_back(x + HLINE);
+                       f.emplace_back(h - INDOOR_FLOOR_THICKNESS);
+                       f.emplace_back(-3);
+                       f.emplace_back(1);
+                       f.emplace_back(1);
+                       
+                       f.emplace_back(x);
+               f.emplace_back(h - INDOOR_FLOOR_THICKNESS);
+                       f.emplace_back(-3);
+                       f.emplace_back(0);
+                       f.emplace_back(1);
+
+                       f.emplace_back(x);
+               f.emplace_back(h);
+                       f.emplace_back(-3);
+                       f.emplace_back(0);
+                       f.emplace_back(0);
+
+                       i++;
+       }
+    }
+       
+       glEnableVertexAttribArray(worldShader_attribute_coord);
+       glEnableVertexAttribArray(worldShader_attribute_tex);
+
+       glVertexAttribPointer(worldShader_attribute_coord, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), &f[0]);
+       glVertexAttribPointer(worldShader_attribute_tex, 2, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), &f[3]);
+       glDrawArrays(GL_TRIANGLES, 0, floor.size() * 6);
+
+       glDisableVertexAttribArray(worldShader_attribute_coord);
+       glDisableVertexAttribArray(worldShader_attribute_tex);
+
        glUseProgram(0);
 
        /*
         *      Draw all entities.
        */
-    glActiveTexture(GL_TEXTURE0);
-    glBindTexture(GL_TEXTURE_2D, colorIndex);
-
-    glUniform1i(glGetUniformLocation(shaderProgram, "sampler"), 0);
-    glUseProgram(shaderProgram);
+    
+       // TODO draw particles
+       // glBindTexture(GL_TEXTURE_2D, colorIndex);
 
-    //std::for_each(particles.begin(), particles.end(), [](Particles &part) { part.draw(); });
-
-    glUseProgram(0);
 
        /*for (auto &part : particles)
                part.draw();*/