View Full Version : Heightmapped Terrain
01-07-2010, 12:14 PM
I am new to this forum and I have a problem regarding OpenGL heightmaps.
My goal is to create an image reading function then create a 3D terrain from the image read.
I am using the SOIL library , which does come with a heightmap function, but I am not sure what it does. Here is the 'help file':
/* load an image as a heightmap, forcing greyscale (so channels should be 1) */
int width, height, channels;
unsigned char *ht_map = SOIL_load_image
&width, &height, &channels,
I could probably work out drawing code from an array, but how do I load an image into an array?
If anyone knows anything about the SOIL library, or a useable alternative, please help.
Thanks in advance
Yann LE PETITCORPS
01-07-2010, 03:56 PM
You can load the tga file using a tga loader with something like
and make your terrain such as width x height quads when the (x,y,z) values of vertices are (x,y,imageData[y*width+x]) where 0<=x<width and 0<=y<height.
The imageData[y*width+x] is now the height of the vertex at the position (x,y)
(but this work only with a greyscale file, with a rgb file you can handle something like a displacement map with x,y,z=r,g,b )
Something, it's exactely the type of things that I project to make using geometry/vertex/fragment shaders and/or instanciation or something like this for to can use a basic quad (or very more that only one ...) where I can easily bumpmap and display a video stream on it (for to handle realistics animated waves for example).
01-08-2010, 09:45 AM
Thankyou very much, this was just what I was looking for. I read one nehe tutorial which was designed for windows and just assumed they were all.
P.S. I'm a MAC
Yann LE PETITCORPS
01-08-2010, 01:36 PM
There is a Mac OS X/Cocoa version at the end of the page.
And you can too use gcc and/or g++ with a makefile on MacOS
Here is a makefile that I use with gcc and g++ on the MacOS plateform with SDL, GLUT and AVCODEC libraries
all : vdj vdj2
frameworks = -framework SDL -framework Cocoa -framework GLUT -framework OpenGL
includes = -I/Library/Frameworks/SDL.framework/Headers
links = -L/usr/local/lib -lavcodec -lavutil -lavformat -lswscale -lz -lbz2 -I/usr/local/include/ffmpeg/
vdj : vdj.* shader.* avread.h cube.*
gcc $(includes) vdj.c SDLmain.m shader.c cube.c $(frameworks) -o vdj $(links)
vdj2 : vdj.* shader.* avread.h cube.*
g++ $(includes) vdj.c SDLmain.m shader.c cube.c $(frameworks) -o vdj2 $(links) -D__STDC_CONSTANT_MACROS
rm vdj vdj2
(this is for a program that display/mix in real time various audio/video files/streams on a 3D rotated cube)
You can find alls frameworks (and a lot of others) at http://www.macports.org
01-11-2010, 09:15 AM
Thankyou for the advice. I am actually using Xcode but I have solved my problem now.
01-11-2010, 01:48 PM
NEHE Lesson 45 also loads a heightmap, you could check it out to "extend" your own loader if you want ;)
Powered by vBulletin® Version 4.2.2 Copyright © 2014 vBulletin Solutions, Inc. All rights reserved.