Fix for #29 Normal Generation by Smoothing Group Id - Commit 2
This commit is contained in:
@@ -1,5 +1,3 @@
|
|||||||
#include "stdafx.h" // Required to be included in a Visual Studio Win32 application
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* (c) Copyright 1993, 1994, Silicon Graphics, Inc.
|
* (c) Copyright 1993, 1994, Silicon Graphics, Inc.
|
||||||
* ALL RIGHTS RESERVED
|
* ALL RIGHTS RESERVED
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
#include "stdafx.h" // Required to be included in a Visual Studio Win32 application
|
|
||||||
//
|
//
|
||||||
// Simple .obj viewer(vertex only)
|
// Simple .obj viewer(vertex only)
|
||||||
//
|
//
|
||||||
@@ -775,13 +774,6 @@ static void Init() {
|
|||||||
up[2] = 0.0f;
|
up[2] = 0.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Gopal: I am commenting out the original main function.
|
|
||||||
// Then, I make a copy and split in to two fuctions -
|
|
||||||
// tinyObjectViewerMainCreateWindow and tinyObjectViewerMainLoop.
|
|
||||||
// I need to separate these two functions in my windows project.
|
|
||||||
// Ths first one is used to create the OpenGL window and link it to my
|
|
||||||
// main application window. After that the second function is called.
|
|
||||||
/*
|
|
||||||
int main(int argc, char** argv) {
|
int main(int argc, char** argv) {
|
||||||
if (argc < 2) {
|
if (argc < 2) {
|
||||||
std::cout << "Needs input.obj\n" << std::endl;
|
std::cout << "Needs input.obj\n" << std::endl;
|
||||||
@@ -866,96 +858,3 @@ int main(int argc, char** argv) {
|
|||||||
|
|
||||||
glfwTerminate();
|
glfwTerminate();
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
// The parameters bmin, bmax, materials and textures are shared between the two funations.
|
|
||||||
// They are also declared as static to retain the values.
|
|
||||||
static float bmin[3], bmax[3];
|
|
||||||
static std::vector<tinyobj::material_t> materials;
|
|
||||||
static std::map<std::string, GLuint> textures;
|
|
||||||
|
|
||||||
int tinyObjectViewerMainCreateWindow(int argc, char** argv) {
|
|
||||||
if (argc < 2) {
|
|
||||||
std::cout << "Needs input.obj\n" << std::endl;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
Init();
|
|
||||||
|
|
||||||
if (!glfwInit()) {
|
|
||||||
std::cerr << "Failed to initialize GLFW." << std::endl;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
window = glfwCreateWindow(width, height, "Obj viewer", NULL, NULL);
|
|
||||||
if (window == NULL) {
|
|
||||||
std::cerr << "Failed to open GLFW window. " << std::endl;
|
|
||||||
glfwTerminate();
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
glfwMakeContextCurrent(window);
|
|
||||||
glfwSwapInterval(1);
|
|
||||||
|
|
||||||
// Callback
|
|
||||||
glfwSetWindowSizeCallback(window, reshapeFunc);
|
|
||||||
glfwSetKeyCallback(window, keyboardFunc);
|
|
||||||
glfwSetMouseButtonCallback(window, clickFunc);
|
|
||||||
glfwSetCursorPosCallback(window, motionFunc);
|
|
||||||
|
|
||||||
glewExperimental = true;
|
|
||||||
if (glewInit() != GLEW_OK) {
|
|
||||||
std::cerr << "Failed to initialize GLEW." << std::endl;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
reshapeFunc(window, width, height);
|
|
||||||
|
|
||||||
if (false == LoadObjAndConvert(bmin, bmax, &gDrawObjects, materials, textures, argv[1])) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void tinyObjectViewerMainLoop()
|
|
||||||
{
|
|
||||||
float maxExtent = 0.5f * (bmax[0] - bmin[0]);
|
|
||||||
if (maxExtent < 0.5f * (bmax[1] - bmin[1])) {
|
|
||||||
maxExtent = 0.5f * (bmax[1] - bmin[1]);
|
|
||||||
}
|
|
||||||
if (maxExtent < 0.5f * (bmax[2] - bmin[2])) {
|
|
||||||
maxExtent = 0.5f * (bmax[2] - bmin[2]);
|
|
||||||
}
|
|
||||||
|
|
||||||
while (glfwWindowShouldClose(window) == GL_FALSE) {
|
|
||||||
glfwPollEvents();
|
|
||||||
glClearColor(0.1f, 0.2f, 0.3f, 1.0f);
|
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
|
||||||
|
|
||||||
glEnable(GL_DEPTH_TEST);
|
|
||||||
glEnable(GL_TEXTURE_2D);
|
|
||||||
|
|
||||||
// camera & rotate
|
|
||||||
glMatrixMode(GL_MODELVIEW);
|
|
||||||
glLoadIdentity();
|
|
||||||
GLfloat mat[4][4];
|
|
||||||
gluLookAt(eye[0], eye[1], eye[2], lookat[0], lookat[1], lookat[2], up[0],
|
|
||||||
up[1], up[2]);
|
|
||||||
build_rotmatrix(mat, curr_quat);
|
|
||||||
glMultMatrixf(&mat[0][0]);
|
|
||||||
|
|
||||||
// Fit to -1, 1
|
|
||||||
glScalef(1.0f / maxExtent, 1.0f / maxExtent, 1.0f / maxExtent);
|
|
||||||
|
|
||||||
// Centerize object.
|
|
||||||
glTranslatef(-0.5 * (bmax[0] + bmin[0]), -0.5 * (bmax[1] + bmin[1]),
|
|
||||||
-0.5 * (bmax[2] + bmin[2]));
|
|
||||||
|
|
||||||
Draw(gDrawObjects, materials, textures);
|
|
||||||
|
|
||||||
glfwSwapBuffers(window);
|
|
||||||
}
|
|
||||||
|
|
||||||
glfwTerminate();
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user