Comment out some debug; change FPS calc; misc changes
This commit is contained in:
2
Makefile
2
Makefile
@@ -27,5 +27,7 @@ clean:
|
|||||||
|
|
||||||
.PHONY: clean all
|
.PHONY: clean all
|
||||||
|
|
||||||
|
objs/objectParser.o: object.pb.h
|
||||||
|
|
||||||
-include $(addprefix objs/,$(CXXSRCS:.cc=.P))
|
-include $(addprefix objs/,$(CXXSRCS:.cc=.P))
|
||||||
-include $(addprefix objs/,$(BINIFY_SRCS:.cc=.P))
|
-include $(addprefix objs/,$(BINIFY_SRCS:.cc=.P))
|
||||||
|
|||||||
24
main.cc
24
main.cc
@@ -201,7 +201,7 @@ int main(int argc, char *argv[])
|
|||||||
Object pyramid(vboManager, "objects/pyramid.obj", prog);
|
Object pyramid(vboManager, "objects/pyramid.obj", prog);
|
||||||
Object plane(vboManager, "objects/plane.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);
|
float px20_height = 2.0f*(20.0f/height);
|
||||||
|
|
||||||
std::vector<ovlVertexAttribs> ovlAttribs{
|
std::vector<ovlVertexAttribs> ovlAttribs{
|
||||||
@@ -218,6 +218,9 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
bool close = false;
|
bool close = false;
|
||||||
|
|
||||||
|
Texture2D fpsTex{64, 64, true};
|
||||||
|
unsigned fpsTime = 0, fpsCount = 0;
|
||||||
|
|
||||||
while (!close) {
|
while (!close) {
|
||||||
SDL_Event event;
|
SDL_Event event;
|
||||||
while (SDL_PollEvent(&event)) {
|
while (SDL_PollEvent(&event)) {
|
||||||
@@ -316,19 +319,18 @@ int main(int argc, char *argv[])
|
|||||||
redTex.bind();
|
redTex.bind();
|
||||||
pyramid.draw(glm::translate(glm::vec3(-2.0f, 0.0f, 0.0f)));
|
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 now = SDL_GetTicks();
|
||||||
auto elapsed = now - last;
|
auto elapsed = now - last;
|
||||||
last = now;
|
last = now;
|
||||||
std::string fpsText = std::to_string(static_cast<unsigned>(1000.0/elapsed));
|
if (fpsTime+elapsed > 1000) {
|
||||||
auto fpsTex = font.render(fpsText);
|
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);
|
glDisable(GL_DEPTH_TEST);
|
||||||
glEnable(GL_BLEND);
|
glEnable(GL_BLEND);
|
||||||
|
|||||||
@@ -31,13 +31,13 @@ private:
|
|||||||
std::cout << "Warning: Clamping texture coordinate V to [0.0, 1.0]" << std::endl;
|
std::cout << "Warning: Clamping texture coordinate V to [0.0, 1.0]" << std::endl;
|
||||||
uint16_t c_v = glm::packUnorm1x16(v);
|
uint16_t c_v = glm::packUnorm1x16(v);
|
||||||
_texCoords.emplace_back(glm::u16vec2(c_u, c_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)
|
void geometric_vertex_callback(obj::float_type x, obj::float_type y, obj::float_type z)
|
||||||
{
|
{
|
||||||
_vertices.emplace_back(glm::vec3(x, y, 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)
|
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;
|
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));
|
pack_10.all = glm::packSnorm3x10_1x2(glm::vec4(x, y, z, 0.0f));
|
||||||
_normals.push_back(pack_10.all);
|
_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)
|
size_t _find_vertex_tc_norm(size_t vert, size_t tc, size_t norm)
|
||||||
@@ -134,9 +134,9 @@ private:
|
|||||||
_vertices[c-1]);
|
_vertices[c-1]);
|
||||||
size_t tc = _generateTC();
|
size_t tc = _generateTC();
|
||||||
|
|
||||||
std::cout << "f (" << a << ", " << tc << ", " << norm << ")" <<
|
//std::cout << "f (" << a << ", " << tc << ", " << norm << ")" <<
|
||||||
" (" << b << ", " << tc << ", " << norm << ")" <<
|
// " (" << b << ", " << tc << ", " << norm << ")" <<
|
||||||
" (" << c << ", " << tc << ", " << norm << ")\n";
|
// " (" << c << ", " << tc << ", " << norm << ")\n";
|
||||||
|
|
||||||
size_t a_pos = _find_vertex_tc_norm(a-1,
|
size_t a_pos = _find_vertex_tc_norm(a-1,
|
||||||
tc,
|
tc,
|
||||||
@@ -149,7 +149,7 @@ private:
|
|||||||
norm);
|
norm);
|
||||||
_faces.emplace_back(a_pos, b_pos, c_pos);
|
_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)
|
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>(b)-1],
|
||||||
_vertices[std::tr1::get<0>(c)-1]);
|
_vertices[std::tr1::get<0>(c)-1]);
|
||||||
|
|
||||||
std::cout << "f (" << std::tr1::get<0>(a) << ", " << std::tr1::get<1>(a) << ", " << norm << ")" <<
|
//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>(b) << ", " << std::tr1::get<1>(b) << ", " << norm << ")" <<
|
||||||
" (" << std::tr1::get<0>(c) << ", " << std::tr1::get<1>(c) << ", " << norm << ")\n";
|
// " (" << 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,
|
size_t a_pos = _find_vertex_tc_norm(std::tr1::get<0>(a)-1,
|
||||||
std::tr1::get<1>(a)-1,
|
std::tr1::get<1>(a)-1,
|
||||||
@@ -182,7 +182,7 @@ private:
|
|||||||
norm);
|
norm);
|
||||||
_faces.emplace_back(a_pos, b_pos, c_pos);
|
_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)
|
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();
|
size_t tc = _generateTC();
|
||||||
|
|
||||||
std::cout << "f (" << std::tr1::get<0>(a) << ", " << tc << ", " << std::tr1::get<1>(a) << ")" <<
|
//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>(b) << ", " << tc << "," << std::tr1::get<1>(b) << ")" <<
|
||||||
" (" << std::tr1::get<0>(c) << ", " << tc << ", " << std::tr1::get<1>(c) << ")\n";
|
// " (" << 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,
|
size_t a_pos = _find_vertex_tc_norm(std::tr1::get<0>(a)-1,
|
||||||
tc,
|
tc,
|
||||||
@@ -213,7 +213,7 @@ private:
|
|||||||
std::tr1::get<1>(c)-1);
|
std::tr1::get<1>(c)-1);
|
||||||
_faces.emplace_back(a_pos, b_pos, c_pos);
|
_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,
|
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)))
|
(_normals.size() < std::tr1::get<2>(c)))
|
||||||
throw ParseException("Normal Index out of range");
|
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::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>(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::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,
|
size_t a_pos = _find_vertex_tc_norm(std::tr1::get<0>(a)-1,
|
||||||
std::tr1::get<1>(a)-1,
|
std::tr1::get<1>(a)-1,
|
||||||
@@ -247,7 +247,7 @@ private:
|
|||||||
std::tr1::get<2>(c)-1);
|
std::tr1::get<2>(c)-1);
|
||||||
_faces.emplace_back(a_pos, b_pos, c_pos);
|
_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)
|
void quadrilateral_face_geometric_vertices_callback(index_type a, index_type b, index_type c, index_type d)
|
||||||
|
|||||||
23
texture.cc
23
texture.cc
@@ -102,10 +102,10 @@ void TextureCubeMap::bind() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Texture2D::Texture2D(unsigned width, unsigned height)
|
Texture2D::Texture2D(unsigned width, unsigned height, bool alpha)
|
||||||
: texID_(0), width_(width), height_(height), alpha_(false)
|
: texID_(0), width_(width), height_(height), alpha_(alpha)
|
||||||
{
|
{
|
||||||
_glCreate(width, height);
|
_glCreate(width, height, alpha);
|
||||||
}
|
}
|
||||||
|
|
||||||
Texture2D::Texture2D(std::string const& file)
|
Texture2D::Texture2D(std::string const& file)
|
||||||
@@ -115,23 +115,20 @@ Texture2D::Texture2D(std::string const& file)
|
|||||||
if (!surf)
|
if (!surf)
|
||||||
throw SDLException();
|
throw SDLException();
|
||||||
|
|
||||||
try {
|
if(surf->format->Amask == 0)
|
||||||
_glCreate(surf->w, surf->h);
|
_glCreate(surf->w, surf->h);
|
||||||
|
else {
|
||||||
|
_glCreate(surf->w, surf->h, true);
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
assert(surf->format->format == SDL_PIXELFORMAT_RGB24); // TODO: Proper support of many formats
|
copyFromSurface(surf);
|
||||||
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 (...) {
|
} catch (...) {
|
||||||
glDeleteTextures(1, &texID_);
|
glDeleteTextures(1, &texID_);
|
||||||
throw;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch(...) {
|
|
||||||
SDL_FreeSurface(surf);
|
SDL_FreeSurface(surf);
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_FreeSurface(surf);
|
SDL_FreeSurface(surf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ private:
|
|||||||
|
|
||||||
class Texture2D {
|
class Texture2D {
|
||||||
public:
|
public:
|
||||||
Texture2D(unsigned width, unsigned height);
|
Texture2D(unsigned width, unsigned height, bool alpha = false);
|
||||||
Texture2D(std::string const& file);
|
Texture2D(std::string const& file);
|
||||||
Texture2D(SDL_Surface *surface);
|
Texture2D(SDL_Surface *surface);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user