Comment out some debug; change FPS calc; misc changes

This commit is contained in:
2015-03-08 13:55:46 +01:00
parent bdc2ef58f4
commit 31e3a307b5
5 changed files with 47 additions and 46 deletions

View File

@@ -27,5 +27,7 @@ clean:
.PHONY: clean all
objs/objectParser.o: object.pb.h
-include $(addprefix objs/,$(CXXSRCS:.cc=.P))
-include $(addprefix objs/,$(BINIFY_SRCS:.cc=.P))

24
main.cc
View File

@@ -201,7 +201,7 @@ int main(int argc, char *argv[])
Object pyramid(vboManager, "objects/pyramid.obj", prog);
Object plane(vboManager, "objects/plane.obj", prog);
float px20_width = 2.0f*(20.0f/width);
float px20_width = 2.0f*(60.0f/width);
float px20_height = 2.0f*(20.0f/height);
std::vector<ovlVertexAttribs> ovlAttribs{
@@ -217,6 +217,9 @@ int main(int argc, char *argv[])
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
bool close = false;
Texture2D fpsTex{64, 64, true};
unsigned fpsTime = 0, fpsCount = 0;
while (!close) {
SDL_Event event;
@@ -315,20 +318,19 @@ int main(int argc, char *argv[])
glm::rotate(0.35f, glm::vec3(0.0f, 1.0f, 0.0f)));
redTex.bind();
pyramid.draw(glm::translate(glm::vec3(-2.0f, 0.0f, 0.0f)));
// glUseProgram(0);
// sf::Time now = clock.getElapsedTime();
// sf::Time elapsed = now - last;
// last = now;
// fpsText.setString(std::to_string(static_cast<int>(std::roundf(1.0f/elapsed.asSeconds()))));
// fpsText.setPosition({1680-fpsText.getLocalBounds().width, 0});
// window.draw(fpsText);
auto now = SDL_GetTicks();
auto elapsed = now - last;
last = now;
std::string fpsText = std::to_string(static_cast<unsigned>(1000.0/elapsed));
auto fpsTex = font.render(fpsText);
if (fpsTime+elapsed > 1000) {
const std::string fpsText{std::to_string(fpsCount + 1) + " FPS"s};
fpsTex = font.render(fpsText);
fpsCount = 0;
fpsTime = 0;
} else {
++fpsCount;
fpsTime += elapsed;
}
glDisable(GL_DEPTH_TEST);
glEnable(GL_BLEND);

View File

@@ -31,13 +31,13 @@ private:
std::cout << "Warning: Clamping texture coordinate V to [0.0, 1.0]" << std::endl;
uint16_t c_v = glm::packUnorm1x16(v);
_texCoords.emplace_back(glm::u16vec2(c_u, c_v));
std::cout << "vt " << c_u << " " << c_v << "\n";
//std::cout << "vt " << c_u << " " << c_v << "\n";
}
void geometric_vertex_callback(obj::float_type x, obj::float_type y, obj::float_type z)
{
_vertices.emplace_back(glm::vec3(x, y, z));
std::cout << "v " << x << " " << y << " " << z << "\n";
//std::cout << "v " << x << " " << y << " " << z << "\n";
}
void vertex_normal_callback(obj::float_type x, obj::float_type y, obj::float_type z)
@@ -63,7 +63,7 @@ private:
std::cout << "Warning: Clamping normal Z to [-1.0, 1.0]" << std::endl;
pack_10.all = glm::packSnorm3x10_1x2(glm::vec4(x, y, z, 0.0f));
_normals.push_back(pack_10.all);
std::cout << "vn " << pack_10.bits.x << " " << pack_10.bits.y << " " << pack_10.bits.z << "\n";
// std::cout << "vn " << pack_10.bits.x << " " << pack_10.bits.y << " " << pack_10.bits.z << "\n";
}
size_t _find_vertex_tc_norm(size_t vert, size_t tc, size_t norm)
@@ -134,9 +134,9 @@ private:
_vertices[c-1]);
size_t tc = _generateTC();
std::cout << "f (" << a << ", " << tc << ", " << norm << ")" <<
" (" << b << ", " << tc << ", " << norm << ")" <<
" (" << c << ", " << tc << ", " << norm << ")\n";
//std::cout << "f (" << a << ", " << tc << ", " << norm << ")" <<
// " (" << b << ", " << tc << ", " << norm << ")" <<
// " (" << c << ", " << tc << ", " << norm << ")\n";
size_t a_pos = _find_vertex_tc_norm(a-1,
tc,
@@ -149,7 +149,7 @@ private:
norm);
_faces.emplace_back(a_pos, b_pos, c_pos);
std::cout << "\t [" << a_pos << ", " << b_pos << ", " << c_pos << "]\n";
//std::cout << "\t [" << a_pos << ", " << b_pos << ", " << c_pos << "]\n";
}
void triangular_face_geometric_vertices_texture_vertices_callback(index_2_tuple_type a, index_2_tuple_type b, index_2_tuple_type c)
@@ -167,9 +167,9 @@ private:
_vertices[std::tr1::get<0>(b)-1],
_vertices[std::tr1::get<0>(c)-1]);
std::cout << "f (" << std::tr1::get<0>(a) << ", " << std::tr1::get<1>(a) << ", " << norm << ")" <<
" (" << std::tr1::get<0>(b) << ", " << std::tr1::get<1>(b) << ", " << norm << ")" <<
" (" << std::tr1::get<0>(c) << ", " << std::tr1::get<1>(c) << ", " << norm << ")\n";
//std::cout << "f (" << std::tr1::get<0>(a) << ", " << std::tr1::get<1>(a) << ", " << norm << ")" <<
// " (" << std::tr1::get<0>(b) << ", " << std::tr1::get<1>(b) << ", " << norm << ")" <<
// " (" << std::tr1::get<0>(c) << ", " << std::tr1::get<1>(c) << ", " << norm << ")\n";
size_t a_pos = _find_vertex_tc_norm(std::tr1::get<0>(a)-1,
std::tr1::get<1>(a)-1,
@@ -182,7 +182,7 @@ private:
norm);
_faces.emplace_back(a_pos, b_pos, c_pos);
std::cout << "\t [" << a_pos << ", " << b_pos << ", " << c_pos << "]\n";
//std::cout << "\t [" << a_pos << ", " << b_pos << ", " << c_pos << "]\n";
}
void triangular_face_geometric_vertices_vertex_normals_callback(index_2_tuple_type a, index_2_tuple_type b, index_2_tuple_type c)
@@ -198,9 +198,9 @@ private:
size_t tc = _generateTC();
std::cout << "f (" << std::tr1::get<0>(a) << ", " << tc << ", " << std::tr1::get<1>(a) << ")" <<
" (" << std::tr1::get<0>(b) << ", " << tc << "," << std::tr1::get<1>(b) << ")" <<
" (" << std::tr1::get<0>(c) << ", " << tc << ", " << std::tr1::get<1>(c) << ")\n";
//std::cout << "f (" << std::tr1::get<0>(a) << ", " << tc << ", " << std::tr1::get<1>(a) << ")" <<
// " (" << std::tr1::get<0>(b) << ", " << tc << "," << std::tr1::get<1>(b) << ")" <<
// " (" << std::tr1::get<0>(c) << ", " << tc << ", " << std::tr1::get<1>(c) << ")\n";
size_t a_pos = _find_vertex_tc_norm(std::tr1::get<0>(a)-1,
tc,
@@ -213,7 +213,7 @@ private:
std::tr1::get<1>(c)-1);
_faces.emplace_back(a_pos, b_pos, c_pos);
std::cout << "\t [" << a_pos << ", " << b_pos << ", " << c_pos << "]\n";
//std::cout << "\t [" << a_pos << ", " << b_pos << ", " << c_pos << "]\n";
}
void triangular_face_geometric_vertices_texture_vertices_vertex_normals_callback(index_3_tuple_type a, index_3_tuple_type b,
@@ -232,9 +232,9 @@ private:
(_normals.size() < std::tr1::get<2>(c)))
throw ParseException("Normal Index out of range");
std::cout << "f (" << std::tr1::get<0>(a) << ", " << std::tr1::get<1>(a) << ", " << std::tr1::get<2>(a) << ")" <<
" (" << std::tr1::get<0>(b) << ", " << std::tr1::get<1>(b) << ", " << std::tr1::get<2>(b) << ")" <<
" (" << std::tr1::get<0>(c) << ", " << std::tr1::get<1>(c) << ", " << std::tr1::get<2>(c) << ")\n";
//std::cout << "f (" << std::tr1::get<0>(a) << ", " << std::tr1::get<1>(a) << ", " << std::tr1::get<2>(a) << ")" <<
// " (" << std::tr1::get<0>(b) << ", " << std::tr1::get<1>(b) << ", " << std::tr1::get<2>(b) << ")" <<
// " (" << std::tr1::get<0>(c) << ", " << std::tr1::get<1>(c) << ", " << std::tr1::get<2>(c) << ")\n";
size_t a_pos = _find_vertex_tc_norm(std::tr1::get<0>(a)-1,
std::tr1::get<1>(a)-1,
@@ -247,7 +247,7 @@ private:
std::tr1::get<2>(c)-1);
_faces.emplace_back(a_pos, b_pos, c_pos);
std::cout << "\t [" << a_pos << ", " << b_pos << ", " << c_pos << "]\n";
//std::cout << "\t [" << a_pos << ", " << b_pos << ", " << c_pos << "]\n";
}
void quadrilateral_face_geometric_vertices_callback(index_type a, index_type b, index_type c, index_type d)

View File

@@ -102,10 +102,10 @@ void TextureCubeMap::bind() const
}
Texture2D::Texture2D(unsigned width, unsigned height)
: texID_(0), width_(width), height_(height), alpha_(false)
Texture2D::Texture2D(unsigned width, unsigned height, bool alpha)
: texID_(0), width_(width), height_(height), alpha_(alpha)
{
_glCreate(width, height);
_glCreate(width, height, alpha);
}
Texture2D::Texture2D(std::string const& file)
@@ -115,23 +115,20 @@ Texture2D::Texture2D(std::string const& file)
if (!surf)
throw SDLException();
try {
if(surf->format->Amask == 0)
_glCreate(surf->w, surf->h);
try {
assert(surf->format->format == SDL_PIXELFORMAT_RGB24); // TODO: Proper support of many formats
if (SDL_MUSTLOCK(surf))
SDL_LockSurface(surf);
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, surf->w, surf->h, GL_RGB, GL_UNSIGNED_BYTE, surf->pixels);
glGenerateMipmap(GL_TEXTURE_2D);
} catch(...) {
glDeleteTextures(1, &texID_);
throw;
}
else {
_glCreate(surf->w, surf->h, true);
}
catch(...) {
try {
copyFromSurface(surf);
} catch (...) {
glDeleteTextures(1, &texID_);
SDL_FreeSurface(surf);
throw;
}
SDL_FreeSurface(surf);
}

View File

@@ -61,7 +61,7 @@ private:
class Texture2D {
public:
Texture2D(unsigned width, unsigned height);
Texture2D(unsigned width, unsigned height, bool alpha = false);
Texture2D(std::string const& file);
Texture2D(SDL_Surface *surface);