Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Minecraft Clone with OpenGL
#38
Hi!

At first I thought I would describe in detail how to do it. But even though I found theoretical material and chatgpt also helped me understand lighting half a year ago, it still took me a long time to apply it. Fortunately, this went quickly.That's why I thought I'd better incorporate it into your code. After all, you can find theoretical material on the net, but at least it works this way and you can expand it and experiment.

I didn't delete anything from your code.
Changes:

In addition to the correct direction of the normals, the order of the vertices is very important. You used 'gl_quads' in drawarrays. This is not good, because the 2 triangles made from 4 points will be in opposite directions. That's why I drew your long array not all at once, but in quads, with 'triangles_fan'.
In the 'cube' vertex file, the order of the vertices had to be changed somewhere to make them look good.

You need as many normals as there are vertices. A normal array is also generated in parallel with the vertex array. At the beginning of the program, it calculates the normals when reading the cube vertices.

You will see it in the rendering section under 'light'. I set 1 directional light. The direction of the light is the direction of your sun and moon. I think I set it correctly, from where the sun shines, it casts light and shadow on the entire path.

There are many options in OpenGL to make it run faster. It should be more optimized. For example, drawelements and the use of vertex indexes. You can also see that 1 vertex occurs multiple times. It calculates the same vertex over and over again exactly 8 times. Using drawelements, it is possible to calculate 1 point only once.
CULLFACE . I put it in, but I'm not sure if I put it in correctly. Knowing the normals, the renderer can determine which plane shapes have their backs. This is useful for closed and non-transparent textured geometric shapes, because it doesn't draw what has its backs. A cube is the best example. It's impossible to look at a cube and see more than 3 sides at once. That's why it doesn't draw the 'back' three. Cullface only works if there are normals, because it can decide based on that who is facing which direction.

By the way, I really like your code, because it's nice and tidy and transparent. I can't see into everyone's code like that, but yours is very easy to understand.
The game is great, I'm curious about further development!

https://drive.google.com/file/d/1j7cVpK4...sp=sharing
[Image: lighting.jpg]
Reply


Messages In This Thread
Minecraft Clone with OpenGL - by aadityap0901 - 07-19-2024, 07:21 AM
RE: Minecraft Clone with OpenGL - by MasterGy - 07-19-2024, 06:34 PM
RE: Minecraft Clone with OpenGL - by TempodiBasic - 07-19-2024, 11:27 PM
RE: Minecraft Clone with OpenGL - by NakedApe - 07-20-2024, 12:05 AM
RE: Minecraft Clone with OpenGL - by Pete - 07-20-2024, 12:22 AM
RE: Minecraft Clone with OpenGL - by aadityap0901 - 07-20-2024, 04:47 PM
RE: Minecraft Clone with OpenGL - by grymmjack - 07-21-2024, 06:37 PM
RE: Minecraft Clone with OpenGL - by aadityap0901 - 07-22-2024, 05:28 PM
RE: Minecraft Clone with OpenGL - by aadityap0901 - 07-23-2024, 07:22 AM
RE: Minecraft Clone with OpenGL - by MasterGy - 07-23-2024, 05:31 PM
RE: Minecraft Clone with OpenGL - by aadityap0901 - 07-24-2024, 04:25 PM
RE: Minecraft Clone with OpenGL - by aadityap0901 - 07-25-2024, 11:03 AM
RE: Minecraft Clone with OpenGL - by aadityap0901 - 07-26-2024, 05:40 PM
RE: Minecraft Clone with OpenGL - by aadityap0901 - 07-27-2024, 08:46 AM
RE: Minecraft Clone with OpenGL - by bplus - 07-27-2024, 02:25 PM
RE: Minecraft Clone with OpenGL - by a740g - 07-27-2024, 03:31 PM
RE: Minecraft Clone with OpenGL - by aadityap0901 - 07-27-2024, 05:05 PM
RE: Minecraft Clone with OpenGL - by aadityap0901 - 08-02-2024, 09:32 AM
RE: Minecraft Clone with OpenGL - by bplus - 08-02-2024, 01:51 PM
RE: Minecraft Clone with OpenGL - by aadityap0901 - 08-03-2024, 03:58 AM
RE: Minecraft Clone with OpenGL - by aadityap0901 - 08-03-2024, 04:29 AM
RE: Minecraft Clone with OpenGL - by aadityap0901 - 08-05-2024, 10:00 AM
RE: Minecraft Clone with OpenGL - by aadityap0901 - 08-05-2024, 05:34 PM
RE: Minecraft Clone with OpenGL - by a740g - 09-19-2024, 04:12 PM
RE: Minecraft Clone with OpenGL - by bplus - 08-06-2024, 12:32 PM
RE: Minecraft Clone with OpenGL - by aadityap0901 - 08-06-2024, 06:01 PM
RE: Minecraft Clone with OpenGL - by MasterGy - 08-06-2024, 06:11 PM
RE: Minecraft Clone with OpenGL - by aadityap0901 - 08-25-2024, 10:21 AM
RE: Minecraft Clone with OpenGL - by aadityap0901 - 09-23-2024, 02:46 PM
RE: Minecraft Clone with OpenGL - by aadityap0901 - 12-14-2024, 01:45 PM
RE: Minecraft Clone with OpenGL - by a740g - 12-14-2024, 03:13 PM
RE: Minecraft Clone with OpenGL - by aadityap0901 - 01-21-2025, 07:59 PM
RE: Minecraft Clone with OpenGL - by bplus - 01-21-2025, 11:55 PM
RE: Minecraft Clone with OpenGL - by MasterGy - 01-23-2025, 05:40 PM
RE: Minecraft Clone with OpenGL - by bplus - 01-23-2025, 07:02 PM
RE: Minecraft Clone with OpenGL - by aadityap0901 - 01-24-2025, 06:07 PM
RE: Minecraft Clone with OpenGL - by MasterGy - 01-24-2025, 07:35 PM
RE: Minecraft Clone with OpenGL - by MasterGy - 01-25-2025, 07:06 PM
RE: Minecraft Clone with OpenGL - by aadityap0901 - 01-27-2025, 09:11 AM
RE: Minecraft Clone with OpenGL - by aadityap0901 - 01-27-2025, 07:13 PM



Users browsing this thread: 4 Guest(s)