Saturday, May 5, 2018

Procedural Terrain Generation

I had written a post on texture generation using procedural noise. I use the same technique to generate a terrain. The explanation of this code is in this site: http://lodev.org/cgtutor/randomnoise.html


Here is a snapshot:


Here is the code.

Friday, May 4, 2018

Diamond Square Algorithm in C/C++

I have implemented the Diamond Square Algorithm as depicted in this site =>https://www.bluh.org/code-the-diamond-square-algorithm/
It is a way of generating height maps for computer graphics. These height maps can be used as textures or landscapes. It is a slightly better algorithm than the three-dimensional implementation of the midpoint displacement algorithm which produces two-dimensional landscapes. It is also known as the random midpoint displacement fractal, the cloud fractal or the plasma fractal, because of the plasma effect produced when applied.


I chanced upon this topic while searching for Fractal Terrain Generation.

Snapshots:


Here is the code.

Wednesday, May 2, 2018

Object Model Loader in C++ using OpenGL

There was demand from some students to have an object model loader in C++ and I was trying it since so many days.

The one I am posting is incomplete. It has some issues such as elephant and teddy not loaded properly.

As you can see when I plot each vertex in the object model it seems fine:




But when I draw the triangles It comes with holes.

As shown here:




The model must be incomplete or the program has some bugs, I am not sure what is going on. If anyone could point out the flaw its hugely welcome. On further probing I found that the error seems to be while parsing the input .OBJ file. Certain files have two white spaces between f and the vertex index and some files have an extra blank at the end of each line. I have worked with same files in JAVA and there because of robust string handling functions these minor hiccups do not arise.

Here is the code in C++.