Trending
ABUAD, academic stakeholders demand strong action on stroke control in Africa is trending now Expert explainer: Strategies to improve childhood vaccination uptake is trending now NAFDAC joins £3.7m project to develop technologies for detecting fake vaccines is trending now WHO Chief Says Ebola Outbreak is Outpacing Response as Aid Workers Strike over Pay is trending now Vast Martian honeycombs featured in new Curiosity panorama is trending now NASA is helping to fund 18 innovation concepts for future space exploration is trending now Total solar eclipse Aug. 12, 2026 live updates — 6 days to totality is trending now Real Madrid make Vinicius Jr improved contract offer is trending now WAFCON 2026: Two quarter-final fixtures confirmed is trending now Iran anthem protest: Female footballers ‘proud’ to become Australian is trending now Falcons thrash Egypt 6-2 to reach WAFCON quarter-final is trending now Rotimi Salami Mourns Allwell Ademola With Heartfelt Tribute Ahead of 50th Posthumous Birt… is trending now ABUAD, academic stakeholders demand strong action on stroke control in Africa is trending now Expert explainer: Strategies to improve childhood vaccination uptake is trending now NAFDAC joins £3.7m project to develop technologies for detecting fake vaccines is trending now WHO Chief Says Ebola Outbreak is Outpacing Response as Aid Workers Strike over Pay is trending now Vast Martian honeycombs featured in new Curiosity panorama is trending now NASA is helping to fund 18 innovation concepts for future space exploration is trending now Total solar eclipse Aug. 12, 2026 live updates — 6 days to totality is trending now Real Madrid make Vinicius Jr improved contract offer is trending now WAFCON 2026: Two quarter-final fixtures confirmed is trending now Iran anthem protest: Female footballers ‘proud’ to become Australian is trending now Falcons thrash Egypt 6-2 to reach WAFCON quarter-final is trending now Rotimi Salami Mourns Allwell Ademola With Heartfelt Tribute Ahead of 50th Posthumous Birt… is trending now
Animation

Drawing Mountains in OpenGL Using Bitmap Loaders

Drawing Mountains in OpenGL Using Bitmap Loaders

Using the OpenGL Glut library, we have created numerous straightforward and intricate programs, but none of them have used texturing or image loading. We tried to find how to load image in the Opengl? The stackoverflow question pertaining to "Loading images in openGL" yielded the best response.Images Loading in OpenGL Graphics ProgrammingWe can claim that working with OpenGL graphics programmiong, the image loading is seems to be difficult task. External libraries such as stb_image.h, DevIL (Developer's Image Library), FreeImage, and SOIL (Simple OpenGL Image Library) are used to read and decode images into raw pixel data; OpenGL does not import image files directly. This data is then sent to the GPU as a texture using OpenGL methods such as glGenTextures, glBindTexture, and glTexImage2D for rendering.In addition to images/photos/pictures, textures can be used to contain a sizable collection of arbitrary data that can be sent to the shaders for rendering the object.Drawing Mountains in OpenGLIn this Computer graphics Open project we are going to generate the mountains using the image texture with use of bitmap loaders.1. Grass Like Texture to MountainsWe are randomly generating the mountains using a normalized pseudo-random number generator and fractal techniques. The windows are displayed differently each time you resize them or start the project program application. This application relies on GLUT and uses a bitmap for the grass texture. Therefore, they were loaded into the program for use using BitmapLoader.h.2. Random Number for (Gaussian) distributionLet first define the randomNormal utility function, which uses the central limit theorem approximation (sum of uniform random variables) to produce a random number with a normal (Gaussian) distribution. double randomNormal (double mu, double sigma) { double sum = 0; for(int i = 0; i < 12; i++) sum = sum + (double)rand()/RAND_MAX; sum -= 6; return sigma*sum + mu; } 3. Texture Creation and Circle Drawing FunctionsUsing raw bitmap data, createTexture1 loads a texture into OpenGL and sets its filtering mode to nearest neighbor (pixelated look) and wrapping mode to clamp.Draw_circle uses a polygon of 36 vertices (one every 10 degrees) to approximate a 2D filled circle. This might stand in for the sun or another round object in the picture.See Also - How to draw circle in OpenGL4. Fractal Mountain Generation FunctionBy periodically splitting a quadrilateral and applying a random height displacement, this recursive program creates fractal landscape.Lighting effects are used to draw the quad once it is sufficiently small (perim <= tolerance). Using the Lambertian model, the lighting simulates diffuse light by shading the polygon according to its normal and light positions.In order to produce four smaller quads recursively and add height perturbations for realistic terrain detail, it computes a displaced midpoint if it is not small enough.5. Initialization of OpenGL and TexturesUses the external method LoadBitmapFile to load the grass bitmap texture from the file. The program exits and prints an error if loading is unsuccessful. Specifies the scene's clipping volume and sets up the OpenGL projection matrix with an orthographic projection (no perspective). transforms the clean background into a dark gray.Running the Program to get Desire ResultBefore compiling the program place the grass image in the source folder, let the program load and run pefectly. If the grass image not present then comiplation will be error free but non loading of image lead to failure of outcome.DownloadsSource code will be provie for both main program and header file including the bitmap image on request by you to our email id [email protected]

Using the OpenGL Glut library, we have created numerous straightforward and intricate programs, but none of them have used texturing or image loading. We tried to find how to load image in the Opengl? The stackoverflow question pertaining to "Loading images in openGL" yielded the best response.

Images Loading in OpenGL Graphics Programming

We can claim that working with OpenGL graphics programmiong, the image loading is seems to be difficult task. External libraries such as stb_image.h, DevIL (Developer's Image Library), FreeImage, and SOIL (Simple OpenGL Image Library) are used to read and decode images into raw pixel data; OpenGL does not import image files directly. This data is then sent to the GPU as a texture using OpenGL methods such as glGenTextures, glBindTexture, and glTexImage2D for rendering.

In addition to images/photos/pictures, textures can be used to contain a sizable collection of arbitrary data that can be sent to the shaders for rendering the object.

Drawing Mountains in OpenGL

In this Computer graphics Open project we are going to generate the mountains using the image texture with use of bitmap loaders.



1. Grass Like Texture to Mountains

We are randomly generating the mountains using a normalized pseudo-random number generator and fractal techniques. The windows are displayed differently each time you resize them or start the project program application. This application relies on GLUT and uses a bitmap for the grass texture. Therefore, they were loaded into the program for use using BitmapLoader.h.

2. Random Number for (Gaussian) distribution

Let first define the randomNormal utility function, which uses the central limit theorem approximation (sum of uniform random variables) to produce a random number with a normal (Gaussian) distribution.

double randomNormal (double mu, double sigma)
{
double sum = 0;
for(int i = 0; i < 12; i++)
sum = sum + (double)rand()/RAND_MAX;
sum -= 6;
return sigma*sum + mu;
} 

3. Texture Creation and Circle Drawing Functions

Using raw bitmap data, createTexture1 loads a texture into OpenGL and sets its filtering mode to nearest neighbor (pixelated look) and wrapping mode to clamp.

Draw_circle uses a polygon of 36 vertices (one every 10 degrees) to approximate a 2D filled circle. This might stand in for the sun or another round object in the picture.


4. Fractal Mountain Generation Function

By periodically splitting a quadrilateral and applying a random height displacement, this recursive program creates fractal landscape.
Lighting effects are used to draw the quad once it is sufficiently small (perim <= tolerance). Using the Lambertian model, the lighting simulates diffuse light by shading the polygon according to its normal and light positions.
In order to produce four smaller quads recursively and add height perturbations for realistic terrain detail, it computes a displaced midpoint if it is not small enough.

5. Initialization of OpenGL and Textures

Uses the external method LoadBitmapFile to load the grass bitmap texture from the file. The program exits and prints an error if loading is unsuccessful. Specifies the scene's clipping volume and sets up the OpenGL projection matrix with an orthographic projection (no perspective). transforms the clean background into a dark gray.

Running the Program to get Desire Result

Before compiling the program place the grass image in the source folder, let the program load and run pefectly. If the grass image not present then comiplation will be error free but non loading of image lead to failure of outcome.

Downloads

Source code will be provie for both main program and header file including the bitmap image on request by you to our email id [email protected]
View original source →

Related

More from OpenGL Projects