Trouble with Heightmaps
I am trying to combine the material I leaned in lesson 32 (The picking tutorial which used the TGA loader) with the material I learned in lesson 34 (The heightmap tutorial). I have gotten my heightmap to show up but it will only render if I comment out the function which loads all the .TGA textures. Does anyone know why this could be happening? My code goes as follows.
BOOL Initialize (GL_Window* window, Keys* keys) // Any OpenGL Initialization Goes Here
{
g_window = window;
g_keys = keys;
srand( (unsigned)time( NULL ) ); // Randomize Things
LoadRawFile("Data/Terrain.raw", MAP_SIZE * MAP_SIZE, g_HeightMap); //Loads the Heightmap
if(!textureSelector()) return FALSE; //Loads the .TGA textures
BuildFont(); // Build Our Font Display List
//New GL commands.
glShadeModel(GL_SMOOTH); // Enable Smooth Shading
glDepthFunc(GL_LEQUAL); // The Type Of Depth Testing To Do
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // Really Nice Perspective Calculations
//End New GL commands
glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // Black Background
glClearDepth(1.0f); // Depth Buffer Setup
glDepthFunc(GL_LEQUAL); // Type Of Depth Testing
glEnable(GL_DEPTH_TEST); // Enable Depth Testing
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // Enable Alpha Blending (disable alpha testing)
glEnable(GL_BLEND); // Enable Blending (disable alpha testing)
// glAlphaFunc(GL_GREATER,0.1f); // Set Alpha Testing (disable blending)
// glEnable(GL_ALPHA_TEST); // Enable Alpha Testing (disable blending)
glEnable(GL_TEXTURE_2D); // Enable Texture Mapping
glEnable(GL_CULL_FACE); // Remove Back Face
for (int loop=0; loop<30; loop++) // Loop Through 30 Objects
InitObject(loop); // Initialize Each Object
return TRUE; // Return TRUE (Initialization Successful)
}
Thanks a ton in advance for everyones help. You guys are the greatest. =)
My guess would be that you're trying to render your heightmap untextured, so you don't provide texture coordinates. The problem is most likely that you leave texturing enabled. When you do not call the function that loads textures you never bind a valid texture and therefore the heightmap is textured with the default texture object, which happens to be white. This is therefore equivalent to being untextured.
When you do call the function which loads textures you end up with a valid bound texture and so the heightmap is textured with a single texel from your last loaded texture, which probably happens to be black or at least very dark.
To solve this simply disable texturing before rendering the heightmap (and reenable afterwards) or else provide valid texture coordinates for your heightmap (if you want it textured).
Enigma
When you do call the function which loads textures you end up with a valid bound texture and so the heightmap is textured with a single texel from your last loaded texture, which probably happens to be black or at least very dark.
To solve this simply disable texturing before rendering the heightmap (and reenable afterwards) or else provide valid texture coordinates for your heightmap (if you want it textured).
Enigma
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement