GLint worldShader_attribute_tex;
GLint worldShader_uniform_texture;
GLint worldShader_uniform_transform;
+GLint worldShader_uniform_ortho;
GLint worldShader_uniform_color;
// keeps a simple palette of colors for single-color draws
int main(int argc, char *argv[]){
static SDL_GLContext mainGLContext = NULL;
-
+
// handle command line arguments
if (argc > 1) {
std::vector<std::string> args (argc, "");
system("rm -f xml/*.dat");
}
}
-
+
// attempt to initialize SDL
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) != 0)
UserError(std::string("SDL was not able to initialize! Error: ") + SDL_GetError());
worldShader_attribute_coord = get_attrib(worldShader, "coord2d");
worldShader_attribute_tex = get_attrib(worldShader, "tex_coord");
worldShader_uniform_texture = get_uniform(worldShader, "sampler");
- worldShader_uniform_transform = get_uniform(worldShader, "ortho");
+ worldShader_uniform_transform = get_uniform(worldShader, "transform");
+ worldShader_uniform_ortho = get_uniform(worldShader, "ortho");
worldShader_uniform_color = get_uniform(worldShader, "tex_color");
//glEnable(GL_MULTISAMPLE);
// load sprites used in the inventory menu. See src/inventory.cpp
initInventorySprites();
-
+
// load mouse texture, and other inventory textures
mouseTex = Texture::loadTexture("assets/mouse.png");
// alphabetically sort files
strVectorSortAlpha(&xmlFiles);
-
+
// load the first valid XML file for the world
for (const auto &xf : xmlFiles) {
if (xf[0] != '.' && strcmp(&xf[xf.size() - 3], "dat")){
break;
}
}
-
+
// make sure the world was made
if (currentWorld == NULL)
UserError("Plot twist: The world never existed...?");
-
+
// spawn the player
player = new Player();
player->sspawn(0,100);
// put away the brice for later
game::briceSave();
-
+
// free library resources
Mix_HaltMusic();
Mix_CloseAudio();
glUniformMatrix4fv(textShader_uniform_transform, 1, GL_FALSE, glm::value_ptr(ortho));
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));
+ glUniformMatrix4fv(worldShader_uniform_ortho, 1, GL_FALSE, glm::value_ptr(ortho));
+ glUniformMatrix4fv(worldShader_uniform_transform, 1, GL_FALSE, glm::value_ptr(glm::mat4(1.0f)));
glUniform4f(worldShader_uniform_color, 1.0, 1.0, 1.0, 1.0);
/**************************
**** RENDER STUFF HERE ****
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);
curCurCoord[a].x -= float((curdfp[a]) * cos(-1));
curCurCoord[a].y += float((curdfp[a]) * sin(0));
cr.end = curCurCoord[a];
-
+
float curTrans = (((float)curdfp[a]/(float)(curRange?curRange:1))*0.5f);
glUseProgram(textShader);
&textShader_uniform_texture,
&textShader_attribute_coord,
&textShader_attribute_tex);
-
+
glUseProgram(textShader);
glUniform4f(textShader_uniform_color, 1.0, 1.0, 1.0, 1.0);
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),
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;
+ glUseProgram(worldShader);
+
if (p->left) {
- glTranslatef(itemLoc.x+d->dim.x/2,itemLoc.y,0);
- glRotatef(d->rotation, 0.0f, 0.0f, 1.0f);
- glTranslatef(-itemLoc.x-d->dim.x/2,-itemLoc.y,0);
+ // move to center of screen
+ glm::mat4 tro = glm::translate(glm::mat4(1.0f),
+ glm::vec3(itemLoc.x+d->dim.x/2, itemLoc.y, 0));
+ // rotate off center
+ glm::mat4 rot = glm::rotate(glm::mat4(1.0f),
+ static_cast<GLfloat>((d->rotation*3.14159)/180.0f),
+ glm::vec3(0.0f, 0.0f, 1.0f));
+ // move back to player
+ glm::mat4 trt = glm::translate(glm::mat4(1.0f),
+ glm::vec3(-itemLoc.x-d->dim.x/2, -itemLoc.y, 0));
+ // tell shader to translate the object using steps above
+ glUniformMatrix4fv(worldShader_uniform_transform, 1, GL_FALSE, glm::value_ptr(tro * rot * trt));
} else {
- glTranslatef(itemLoc.x+d->dim.x/2,itemLoc.y,0);
- glRotatef(d->rotation, 0.0f, 0.0f, 1.0f);
- glTranslatef(-itemLoc.x-d->dim.x/2,-itemLoc.y,0);
+ // move to center of screen
+ glm::mat4 tro = glm::translate(glm::mat4(1.0f),
+ glm::vec3(itemLoc.x+d->dim.x/2,itemLoc.y,0));
+ // rotate off center
+ glm::mat4 rot = glm::rotate(glm::mat4(1.0f),
+ static_cast<GLfloat>((d->rotation*3.14159)/180.0f),
+ glm::vec3(0.0f, 0.0f, 1.0f));
+ // move back to player
+ glm::mat4 trt = glm::translate(glm::mat4(1.0f),
+ glm::vec3(-itemLoc.x-d->dim.x/2,-itemLoc.y,0));
+ // tell shader to translate the object using steps above
+ glUniformMatrix4fv(worldShader_uniform_transform, 1, GL_FALSE, glm::value_ptr(tro * rot * trt));
}
GLfloat itemTex[12] = {0.0, 0.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]);
glEnableVertexAttribArray(worldShader_attribute_coord);
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));
+
+ 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);
static GLuint boxT = Texture::genColor(Color(0,0,0));
static GLuint lineT = Texture::genColor(Color(255,255,255));
- glActiveTexture(GL_TEXTURE0);
+ glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, boxT);
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, box);
glVertexAttribPointer(textShader_attribute_tex, 2, GL_FLOAT, GL_FALSE, 0, box_tex);
glDrawArrays(GL_TRIANGLES, 0 ,6);
-
+
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);
}
0.0, 1.0,
0.0, 0.0};
- glActiveTexture(GL_TEXTURE0);
+ 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) {
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);
+ glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, getItemTexture(merchTrade.item[1]));
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[0]));
glVertexAttribPointer(textShader_attribute_coord, 3, GL_FLOAT, GL_FALSE, 0, right_item);
glDisableVertexAttribArray(textShader_attribute_coord);
glDisableVertexAttribArray(textShader_attribute_tex);
-
+
glUseProgram(0);
merchArrowLoc[0].x = offset.x - (SCREEN_WIDTH / 8.5) - 16;
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);
}
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);
+ glDisableVertexAttribArray(textShader_attribute_tex);
glUseProgram(0);
}
void dialogAdvance(void) {
unsigned char i;
-
+
dialogPassive = false;
dialogPassiveTime = 0;
toggleBlackFast();
player->canMove = true;
};
-
+
while(SDL_PollEvent(&e)) {
switch(e.type) {
if (e.button.button & SDL_BUTTON_LEFT) {
if ((en = currentWorld->getNearMob(*player)) != nullptr) {
player->inv->currentAddInteract(en);
- player->inv->useCurrent();
}
+ player->inv->useCurrent();
}
}
if (player->speed == 4)
Mix_FadeOutChannel(1,2000);
- // fall through
+ // fall through
case SDLK_LCTRL:
player->speed = 1;
break;
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);
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);
}