As title says, here is picture of what i mean: http://puu.sh/lVLIz/8b839ba8c6.png
My question is: Is this a problem? If so what could/would be the cause?
As title says, here is picture of what i mean: http://puu.sh/lVLIz/8b839ba8c6.png
My question is: Is this a problem? If so what could/would be the cause?
Are you maybe getting some kind of depth fighting?
Try calling this before you render the lines
https://www.opengl.org/sdk/docs/man/html/glLineWidth.xhtml
And what theagendd is talking about is decreasing the size of your perspective fustrum.
Say if you had this:
gluPerspective(fov, aspectRatio, 0.00000001,1000000000.0);
Those are some very small and very large values. The fustrum is going to be really big and the values in the “Depth component” (Z Buffer) of the image will be skewed because of inaccuracies. The box is only taking up an extremely small part of that fustrum, which means part of the box will fight with the other part for who will be drawn.
You can fix this by shortening your fustrum.
gluPerspective(fov, aspectRatio, 0.1,1000.0);
.1 and 1000 are reasonable values for small objects. Try that and post some results.
If you’re not using the fixed function pipeline and it still seems as though your depth test isn’t working, check if you’re calling setIdentity() on your projection matrix. You shouldn’t be doing that.
If he’s calling setIdentity he would be having bigger problems than just z fighting. He wouldn’t see his box! xD
Not true, actually. Calling setIdentity() on the projection matrix causes z-fighting. Trust me, I spent 2 days trying to figure the same problem, thinking that it was because the depth test was somehow disabled. It was actually because I was calling setIdentity() on the proj matrix.
I’d hate to derail op’s thread. But setting a matrix to an identity means canceling all it’s operations out. [icode]matrix * identity_matrix = matrix[/icode]
The projection matrix does the calculation from world - > clipspace, so without the projection matrix it would still be in world space. Without the projection calculation, things would be translated off-screen (unless the coordinates were normalized of course).
I don’t know what happened in your code for you to even see the object, but best chance is you probably did the gluPerspective in the modelview matrix, then maybe reset it (set identity) and set it incorrectly again? I donno.
I’m not using gluPerspective. I’m not using the OpenGL fixed function legacy pipeline. I followed ThinMatrix tutorial on how to create a projection matrix without gluPerspective() but I accidentally called setIdentity(), because I did that for the transformation and view matrices. That caused z-fighting. Took me 2 days to figure out the problem. I normally don’t follow tutorials much, but I was still an OpenGL noob so I had no choice.
I think op should show some code. If he/she is using setIdentity correctly we wouldn’t want to create more problems.
I am using LWJGL3 along with JOML(Java OpenGL Math Library) for matrices. When i have finished setting up window i call this and keep reference to output in Window class:
public static void updatePerspective(float fov, float aspect, float zNear, float zFar){
Matrix4f matrix = new Matrix4f();
matrix.identity();
matrix.perspective(fov, aspect, zNear, zFar);
perspective = matrix;
}
Commenting out the setidentity their didnt change anything.
Thats how i create the projection matrix. I also changed the zNear to 0.1f and zFar was already 1000.0f.
That is slightly incorrect. The projection matrix - as typically used in OpenGL when decomposing the model -> clip-space transformation into ‘modelview’ and ‘projection’ matrix - is used to convert from view/eye/camera-space to clip-space. It is of course always arbitrary and conventional how those spaces are being called, but in view-space the camera is always at the origin and (by convention) is looking along the negative Z axis.
See: http://www.songho.ca/opengl/gl_transform.html
How are you rendering the cube? Because it seems like some of the lines have some blue pixels.
Do you know how sometimes you discover that you’ve gone all your life misspelling a certain word and thinking it’s correct? Sure has happened to me a couple of times. Also, it’s frustum.