Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add hacky checkpoints #14

Merged
merged 1 commit into from
Apr 30, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 56 additions & 18 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtc/type_ptr.hpp>
#include <glm/gtx/rotate_vector.hpp>

#include "sound.h"
#include "mesh.h"
Expand Down Expand Up @@ -67,6 +68,25 @@ int main(int argc, char* argv[]) {
std::shared_ptr<Texture> texture = std::make_shared<Texture>("data/font/main");

std::shared_ptr<Text> text = std::make_shared<Text>("data/font/liberation_sans_bold_65");
auto drawText = [&](glm::vec2 position, std::string message) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of making a lambda, why not move this into text.cpp?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but it's beyond the scope of this PR. I'm still not sure what actual features the text renderer will require.
So instead of adding complexity now (which may be unnecessary / removed later), we can just keep this hacky temporarily and then decide what we really need, once and for all (when we have more logic implemented).

glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
//glBlendFunc(GL_SRC_COLOR, GL_ONE_MINUS_SRC_COLOR);

glPushMatrix();
glLoadIdentity();

glTranslatef(position.x, position.y, 0.0f);

//FIXME: Do AR correction elsewhere
float aspectRatio = 800.0f / 450.0f;
glScalef(0.0005f, 0.0005f * aspectRatio, 1.0f);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe glScalef's parameters should be parametrized as well?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but not now / in this PR.


// Test text
text->draw(message);

glPopMatrix();
};

std::string meshPath = "data/mesh/cube";
std::shared_ptr<Mesh> mesh = std::make_shared<Mesh>();
Expand Down Expand Up @@ -308,9 +328,43 @@ int main(int argc, char* argv[]) {
}
#endif


struct Checkpoint {
glm::vec3 origin;
float angle;
};
std::vector<Checkpoint> checkpoints{
{ glm::vec3(-100.0f, 400.0f, 0.0f), glm::radians<float>(0.0f) },
{ glm::vec3(0.0f, 500.0f, 0.0f), glm::radians<float>(90.0f) },
{ glm::vec3(100.0f, 400.0f, 0.0f), glm::radians<float>(180.0f) },
{ glm::vec3(100.0f, -400.0f, 0.0f), glm::radians<float>(180.0f) },
{ glm::vec3(0.0f, -500.0f, 0.0f), glm::radians<float>(270.0f) },
{ glm::vec3(-100.0f, -400.0f, 0.0f), glm::radians<float>(180.0f) },
};
for(unsigned int i = 0; i < checkpoints.size(); i++) {
auto& cp = checkpoints[i];

// Draw imaginary checkpoint wall
genericShader->activate();
Plane cpPlane = Plane(glm::rotateZ(glm::vec3(0.0f, 1.0f, 0.0f), cp.angle), cp.origin);
glColor3f(1.0f, 0.0f, 1.0f);
cpPlane.draw(1.0f, 100, 100, glm::vec3(0.0f, 0.0f, 1.0f));

// Draw tag text
genericTexturedShader->activate();
genericTexturedShader->set("texture", 0u);
glm::vec3 screenPosition = camera->project(cp.origin);
glColor4f(0.0f, 0.0f, 0.0f, 1.0f);
if (screenPosition.z >= 0.0f && screenPosition.z <= 1.0f) {
drawText(glm::vec2(screenPosition) / glm::vec2(800.0f, 480.0f) * glm::vec2(2.0f, -2.0f) - glm::vec2(1.0f, -1.0f), std::string("Checkpoint ") + std::to_string(i));
}
}


genericShader->activate();

float gap = 10.0f;
glColor3f(1.0f, 1.0f, 1.0f);
slicePlane.draw(gap, 1100.0f / gap, 1100.0f / gap);

glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
Expand Down Expand Up @@ -451,25 +505,9 @@ int main(int argc, char* argv[]) {
#endif

#if 1
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
//glBlendFunc(GL_SRC_COLOR, GL_ONE_MINUS_SRC_COLOR);

glPushMatrix();
glLoadIdentity();

glTranslatef(-0.95f, 0.9f - 0.2f, 0.0f);

//FIXME: Do AR correction elsewhere
float aspectRatio = 800.0f / 450.0f;
glScalef(0.0005f, 0.0005f * aspectRatio, 1.0f);

// Test text
glColor3f(0.1f, 0.2f, 0.5f);
glColor4f(0.1f, 0.2f, 0.5f, 1.0f);
char symbolMicro = '\xB5';
text->draw(std::string("boats: ") + std::to_string(boats.size()) + std::string("\nsparks: ") + std::to_string(sparks.size()) + "\n" + symbolMicro + "/F: " + std::to_string(uspf.count()));

glPopMatrix();
drawText(glm::vec2(-0.95f, 0.9f - 0.2f), std::string("boats: ") + std::to_string(boats.size()) + std::string("\nsparks: ") + std::to_string(sparks.size()) + "\n" + symbolMicro + "/F: " + std::to_string(uspf.count()));
#endif

glFinish();
Expand Down
1 change: 0 additions & 1 deletion platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ namespace Platform {
static void drawLine(glm::vec3 a, glm::vec3 b) {
//FIXME!!!
glBegin(GL_LINES);
glColor3f(1.0f, 1.0f, 1.0f);
glVertex3f(a.x, a.y, a.z);
glVertex3f(b.x, b.y, b.z);
glEnd();
Expand Down