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; }
No comments:
Post a Comment