As was said in the title, for some reason, my colors are rendering on top of other colors no matter how I orient my 3D cube. I think it's an issue with how I actually render it, but I've no idea what.
Here's my .love file (Warning, minor spaghetti code ahead!)
The problematic function is drawBox3D in graphics.lua, but I have no clue as to why it's rendering the colors that weirdly.
Also, to move around the box(s) it's WASD
[SOLVED] Colors rendering on top of other colors weirdness?
-
- Prole
- Posts: 16
- Joined: Thu May 27, 2021 12:32 am
[SOLVED] Colors rendering on top of other colors weirdness?
Last edited by ThatCodingGuy78 on Mon Jun 28, 2021 5:35 pm, edited 1 time in total.
"There is no such thing as a mistake, only happy accidents"
Re: Colors rendering on top of other colors weirdness?
You need to draw the farthest polygons first and the closest polygons last, i.e. sort by depth (you can sort by depth of face centroid, for example), or alternatively, draw or not depending on visual handedness (backface culling). Backface culling only works as a method for convex objects, like a cube. Maybe I have missed where you do either of those.
Of course, you can also draw in actual 3D and let OpenGL handle the hidden surface invisibility, either with a depth buffer or with backface culling, or both (good for performance, but overkill for this case).
There should be 12 faces but you only have 11 listed in lines2. You also have a duplicate face, {8,3,4} is the same as {4,3,8} (except for handedness but you don't use it currently). Face {8,2,3} doesn't make sense, it does not lay in one of the cube faces, it crosses the cube through the inside.
Advice on how to build the faces: list the four vertices of each cube face (you need 6 lists), and for each, determine two diagonal points and place them in both triangles.
Handling handedness is a bit more complicated. Instead of that, you can draw an unfolded cube and label the vertices. Once labelled, you can easily create the list.
Edit: Here it is for you; this labelling follows your vertex order choice. Always enumerate them in counter-clockwise direction. Advice: Place diagonal vertices first. If you do it right, you should have one pair of vertices of the diagonal with one order, and one with the opposite.
Example:
Note how the first one starts with 8, 5 and the second with 5, 8, and so on. Each pair should have them swapped like that.
Note also how going from 8 to 5 to 6 to 8 to 5 to 6... follows a path that turns left (counter-clockwise). That gives you the right handedness.
Of course, you can also draw in actual 3D and let OpenGL handle the hidden surface invisibility, either with a depth buffer or with backface culling, or both (good for performance, but overkill for this case).
There should be 12 faces but you only have 11 listed in lines2. You also have a duplicate face, {8,3,4} is the same as {4,3,8} (except for handedness but you don't use it currently). Face {8,2,3} doesn't make sense, it does not lay in one of the cube faces, it crosses the cube through the inside.
Advice on how to build the faces: list the four vertices of each cube face (you need 6 lists), and for each, determine two diagonal points and place them in both triangles.
Code: Select all
lines2 = {
-- face 1, 2, 3, 4 - 2 and 3 are diagonal
{1, 2, 3}, {3, 2, 4},
-- face 1, 2, 5, 6 - 2 and 5 are diagonal
{1, 2, 5}, {5, 2, 6},
-- ... and so on
}
Edit: Here it is for you; this labelling follows your vertex order choice. Always enumerate them in counter-clockwise direction. Advice: Place diagonal vertices first. If you do it right, you should have one pair of vertices of the diagonal with one order, and one with the opposite.
Example:
Code: Select all
{8, 5, 6}, {5, 8, 7}, {7, 1, 5}, {1, 7, 3}, ...
Note also how going from 8 to 5 to 6 to 8 to 5 to 6... follows a path that turns left (counter-clockwise). That gives you the right handedness.
-
- Prole
- Posts: 16
- Joined: Thu May 27, 2021 12:32 am
Re: Colors rendering on top of other colors weirdness?
I just got it working, but now the way I did it causes the polygon colors to always keep facing the camera. I have no clue how to fix this.. Here's the new .love file:
Edit: I fixed it, my code works now!
The problematic functions are drawShape3D in graphics.lua and sortByDistance, also in graphics.lua.Edit: I fixed it, my code works now!
"There is no such thing as a mistake, only happy accidents"
Who is online
Users browsing this forum: Bing [Bot] and 3 guests