View Full Version : help with heightmaps
01-11-2011, 10:36 AM
Hi, I have a program that loads in a heightmap data from a text file. The problem i have is i don't really have a clue what do do with it.
I have to call glTexImage2D to set up the text, how would i use that? Oh and the data from the heightmap text file is stored in a floating point array.
Any tutorials or help os very welcome and much appreciate.
My OpenGL isn't very good to be honest.
Thanks in advanced.
01-11-2011, 11:20 AM
First step: load the heightmap data into an array (how you do this depends on your programming language). Once you have that, create an OpenGL texture and upload this data (see here: http://www.opengl.org/wiki/Texture).
Afterwards, create a vertex buffer object (http://www.opengl.org/wiki/Vertex_Buffer_Object) with a uniform square grid with the same size as your texture.
Finally, create a vertex shader (http://www.opengl.org/wiki/Vertex_Shader) that samples your heightmap texture and offsets the grid according to it (each 'texel' of the texture provides the elevation of a specific point on the grid).
There are a lot of concepts and the learning curve is rather steep, but everything will start making sense soon - trust me!
01-12-2011, 10:00 AM
Thanks a lot for the reply.
I am using c++ for this project. Is there any change you could show me some code on how to create the texture? I've been trying for a few days now and i think im missing something on the concept but im not sure what it is.
Is this how i would create an openGL Texture:
glTexImage2D(GL_TEXTURE_2D, 0, 1, w, h, 0, GL_BGR_EXT, GL_UNSIGNED_BYTE, ifile);
Thanks again man.
Powered by vBulletin® Version 4.2.2 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.