Could I kindly ask to confirm, that the calculated normals are correct, please? I have calculated them on my own, but my testcube is still strangely lighted within OpenGLES 2.0.
- The vertices were exported from 3D authoring application.
- The vertex normals were calculated using matrix cross product.
- The vertex and fragment shaders I were exact copies from the book, so there should not be a bug.
The output in OpenGL looks like the sphere is lighted from its bottom. Moreover, it looks, like the box is visible from inside, as the top part is always transparent. Any idea, where can be a problem?
Added:
The vertex normals are calculated based on triangulated quad-polygons. The triangulation is performed internally, by the 3d application. Vertices/ indices are generated by calling API calls of that application.
#begin 8 vertices
vs 24
v -25.000000 -25.000000 -25.000000
v 25.000000 -25.000000 -25.000000
v -25.000000 25.000000 -25.000000
v 25.000000 25.000000 -25.000000
v -25.000000 -25.000000 25.000000
v 25.000000 -25.000000 25.000000
v -25.000000 25.000000 25.000000
v 25.000000 25.000000 25.000000
#end 8 vertices
#begin 12 faces
fs 36
f 0 2 3
f 0 3 1
f 0 1 5
f 0 5 4
f 0 4 6
f 0 6 2
f 1 3 7
f 1 7 5
f 2 6 7
f 2 7 3
f 4 5 7
f 4 7 6
#end 12 faces
#begin 8 calculated normals
ns 24
n -0.577350 -0.577350 -0.577350
n 0.816497 -0.408248 -0.408248
n -0.408248 0.816497 -0.408248
n 0.408248 0.408248 -0.816497
n -0.408248 -0.408248 0.816497
n 0.408248 -0.816497 0.408248
n -0.816497 0.408248 0.408248
n 0.577350 0.577350 0.577350
#end 8 calculated normals
I use OpenGL ES 2.0, but that should not be relevant at this moment.
Update:
I can confirm now, that the calculated vertex normals are correct, and can therefore be used by others, to verify correctness of their triangulated cube vertex normals calculations.
However, I still have a problem that all the vertices, which are in positive z axis, are not rendered. Not sure if they are culled, but I have pretty large frustum. Vertices in the -z axis are kept, so the rendered mesh looks like cut in half, as it is position in 0 z-axis.
This lines below show that I should not concsicously setup small render area:
mProjection = glm::perspective (45.0f, (float)WINDOW_WIDTH / (float)WINDOW_HEIGHT, 1130.0f, -1130.0f);
mViewTransformation = glm::lookAt(glm::vec3(vIntCamera.x, vIntCamera.y, 1130.0f), glm::vec3(vIntCamera.x, vIntCamera.y, 0.0f), glm::vec3(0.0f, 1.0f, 0.0f));
Any ideas, please, what else should I check?
Solved:
Eye position of the camera (in glm::lookAt() function) should be above the top of the perspective frustum, defined by glm::perspective().
Thanks for your support guys, especially with the upper part of my question.