Improve windows build.

Don't report error when `in_normal` is not used in the shader.
This commit is contained in:
Syoyo Fujita 2016-06-11 16:10:39 +09:00
parent 9a478238c7
commit 8317ffbe8a
3 changed files with 51 additions and 41 deletions

View File

@ -15,10 +15,15 @@ Simple OpenGL viewer for glTF geometry.
> premake4 gmake > premake4 gmake
$ make $ make
### Windows(not tested) ### Windows(not tested well)
Edit glew and glfw path in `premake4.lua`, then
> premake5.exe vs2013 > premake5.exe vs2013
Open .sln in Visual Studio 2013
Open .sln in Visual Studio 2013
When running .exe, glew and glfw dll must exist in the working directory.
## TODO ## TODO

View File

@ -360,6 +360,8 @@ void DrawMesh(tinygltf::Scene &scene, const tinygltf::Mesh &mesh) {
if ((it->first.compare("POSITION") == 0) || if ((it->first.compare("POSITION") == 0) ||
(it->first.compare("NORMAL") == 0) || (it->first.compare("NORMAL") == 0) ||
(it->first.compare("TEXCOORD_0") == 0)) { (it->first.compare("TEXCOORD_0") == 0)) {
if (gGLProgramState.attribs[it->first] >= 0) {
glVertexAttribPointer( glVertexAttribPointer(
gGLProgramState.attribs[it->first], count, accessor.componentType, gGLProgramState.attribs[it->first], count, accessor.componentType,
GL_FALSE, accessor.byteStride, BUFFER_OFFSET(accessor.byteOffset)); GL_FALSE, accessor.byteStride, BUFFER_OFFSET(accessor.byteOffset));
@ -368,6 +370,7 @@ void DrawMesh(tinygltf::Scene &scene, const tinygltf::Mesh &mesh) {
CheckErrors("enable vertex attrib array"); CheckErrors("enable vertex attrib array");
} }
} }
}
const tinygltf::Accessor &indexAccessor = scene.accessors[primitive.indices]; const tinygltf::Accessor &indexAccessor = scene.accessors[primitive.indices];
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,
@ -403,11 +406,13 @@ void DrawMesh(tinygltf::Scene &scene, const tinygltf::Mesh &mesh) {
if ((it->first.compare("POSITION") == 0) || if ((it->first.compare("POSITION") == 0) ||
(it->first.compare("NORMAL") == 0) || (it->first.compare("NORMAL") == 0) ||
(it->first.compare("TEXCOORD_0") == 0)) { (it->first.compare("TEXCOORD_0") == 0)) {
if (gGLProgramState.attribs[it->first] >= 0) {
glDisableVertexAttribArray(gGLProgramState.attribs[it->first]); glDisableVertexAttribArray(gGLProgramState.attribs[it->first]);
} }
} }
} }
} }
}
} }
void DrawScene(tinygltf::Scene &scene) { void DrawScene(tinygltf::Scene &scene) {
@ -497,7 +502,7 @@ int main(int argc, char **argv) {
glfwSetMouseButtonCallback(window, clickFunc); glfwSetMouseButtonCallback(window, clickFunc);
glfwSetCursorPosCallback(window, motionFunc); glfwSetCursorPosCallback(window, motionFunc);
glewExperimental = true; glewExperimental = true; // This may be only true for linux environment.
if (glewInit() != GLEW_OK) { if (glewInit() != GLEW_OK) {
std::cerr << "Failed to initialize GLEW." << std::endl; std::cerr << "Failed to initialize GLEW." << std::endl;
return -1; return -1;
@ -523,17 +528,12 @@ int main(int argc, char **argv) {
CheckErrors("link"); CheckErrors("link");
{ {
// At least `in_vertex` should be used in the shader.
GLint vtxLoc = glGetAttribLocation(progId, "in_vertex"); GLint vtxLoc = glGetAttribLocation(progId, "in_vertex");
if (vtxLoc < 0) { if (vtxLoc < 0) {
printf("vertex loc not found.\n"); printf("vertex loc not found.\n");
exit(-1); exit(-1);
} }
GLint tnLoc = glGetAttribLocation(progId, "in_normal");
if (tnLoc < 0) {
printf("normal loc not found.\n");
exit(-1);
}
} }
glUseProgram(progId); glUseProgram(progId);

View File

@ -16,7 +16,12 @@ solution "glview"
links { "GL", "GLU", "m", "GLEW", "X11", "Xrandr", "Xinerama", "Xi", "Xxf86vm", "Xcursor", "dl" } links { "GL", "GLU", "m", "GLEW", "X11", "Xrandr", "Xinerama", "Xi", "Xxf86vm", "Xcursor", "dl" }
configuration { "windows" } configuration { "windows" }
links { "glfw3", "gdi32", "winmm", "user32", "GLEW", "glu32","opengl32", "kernel32" } -- Edit path to glew and GLFW3 fit to your environment.
includedirs { "../../../../local/glew-1.13.0/include/" }
includedirs { "../../../../local/glfw-3.2.bin.WIN32/include/" }
libdirs { "../../../../local/glew-1.13.0/lib/Release/Win32/" }
libdirs { "../../../../local/glfw-3.2.bin.WIN32/lib-vc2013/" }
links { "glfw3", "gdi32", "winmm", "user32", "glew32", "glu32","opengl32", "kernel32" }
defines { "_CRT_SECURE_NO_WARNINGS" } defines { "_CRT_SECURE_NO_WARNINGS" }
configuration { "macosx" } configuration { "macosx" }