# Height Map Blending problems

This topic is 4852 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I am working on terrain transitioning for heightmaps but I am having problems with the blending. What is happening I think is terrain behind bumps get rendered even though they are behind others. But I do not know how to get it to not render stuff that shouldn't be or not get rid of the little yellow spots. I have tried rending closest to farthest and farthest to closest but I can't get ride of the spots. I have also tried changing the perspective and it does not help either. Here is a screen shot of what is happening. HeightMap. I don't know how to fix this so can someone please help. I will post a little code
void HeightMap::BuildMap() {
buildList = glGenLists(1);
glNewList(buildList,GL_COMPILE);

glBindTexture(GL_TEXTURE_2D,grass); // Bind grass texture
for(int z = 0;z < Map_Size - 1;z++) {
for(int x = 0;x < Map_Size - 1;x++) {
float alpha1,alpha2,alpha3,alpha4;
alpha1 = 1.0f - (Alpha(x,z + 1) / 255.0f);
alpha2 = 1.0f - (Alpha(x,z) / 255.0f);
alpha3 = 1.0f - (Alpha(x + 1,z) / 255.0f);
alpha4 = 1.0f - (Alpha(x + 1,z + 1) / 255.0f);

if(alpha1 == 0.0f && alpha2 == 0.0f && alpha3 == 0.0f && alpha4 == 0.0f) {
}
else {
glTexCoord2f(x / 10.0f,(z + 1) / 10.0f);
glColor4f(1.0f,1.0f,1.0f,alpha1);
glVertex3f(x * STEP_SIZE,Height(x,z + 1),-((z + 1)* STEP_SIZE));
glTexCoord2f(x / 10.0f,z / 10.0f);
glColor4f(1.0f,1.0f,1.0f,alpha2);
glVertex3f(x * STEP_SIZE,Height(x,z),-(z * STEP_SIZE));
glTexCoord2f((x + 1) / 10.0f,z / 10.0f);
glColor4f(1.0f,1.0f,1.0f,alpha3);
glVertex3f((x + 1) * STEP_SIZE,Height(x + 1,z),-(z * STEP_SIZE));
glTexCoord2f((x + 1) / 10.0f,(z + 1) / 10.0f);
glColor4f(1.0f,1.0f,1.0f,alpha4);
glVertex3f((x + 1) * STEP_SIZE,Height(x + 1,z + 1),-((z + 1) * STEP_SIZE));
}
}
}
glEnd();

glBindTexture(GL_TEXTURE_2D,sand); // Bind sand texture
// Draw sand
for(int z = 0;z < Map_Size - 1;z++) {
for(int x = 0;x < Map_Size - 1;x++) {
float alpha1,alpha2,alpha3,alpha4;
alpha1 = Alpha(x,z + 1) / 255.0f;
alpha2 = Alpha(x,z) / 255.0f;
alpha3 = Alpha(x + 1,z) / 255.0f;
alpha4 = Alpha(x + 1,z + 1) / 255.0f;

if(alpha1 == 0.0f && alpha2 == 0.0f && alpha3 == 0.0f && alpha4 == 0.0f) {
}
else {
glTexCoord2f(x / 2.0f,(z + 1) / 2.0f);
glColor4f(1.0f,1.0f,1.0f,alpha1);
glVertex3f(x * STEP_SIZE,Height(x,z + 1),-((z + 1)* STEP_SIZE));
glTexCoord2f(x / 2.0f,z / 2.0f);
glColor4f(1.0f,1.0f,1.0f,alpha2);
glVertex3f(x * STEP_SIZE,Height(x,z),-(z * STEP_SIZE));
glTexCoord2f((x + 1) / 2.0f,z / 2.0f);
glColor4f(1.0f,1.0f,1.0f,alpha3);
glVertex3f((x + 1) * STEP_SIZE,Height(x + 1,z),-(z * STEP_SIZE));
glTexCoord2f((x + 1) / 2.0f,(z + 1) / 2.0f);
glColor4f(1.0f,1.0f,1.0f,alpha4);
glVertex3f((x + 1) * STEP_SIZE,Height(x + 1,z + 1),-((z + 1) * STEP_SIZE));
}
}
}
glEnd();

glEndList();
}
void HeightMap::Render() {
glColor4f(1.0f,1.0f,1.0l,1.0f);  // Reset color

glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_MODULATE);
glEnable(GL_TEXTURE_2D);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA,GL_ONE);

glPushMatrix();
glCallList(buildList);  // Draw the map
glDisable(GL_BLEND);
glPopMatrix();          // Restore the matrix
glColor4f(1.0f,1.0f,1.0f,1.0f);
}


If anyone can help I would appreciate it. Thanks vbuser

##### Share on other sites
Render your first layer unblended with each vertex colour set to glColor3f(vertexAlpha, vertexAlpha, vertexAlpha). Then render subsequent layers blended as you do at the moment.

Enigma.

##### Share on other sites
Thanks that helped a lot of trying to get the blending problem gone. But now there is still little dots on the second layer being draw. There are not many one the screen and they are very small but when you are moving they are really noticible and are quite annoying. I tried things like changing glColor4f(1.0f, 1.0f,1.0f,alpha...) to glColor4f(alpha..., alpha..., alpha..., alpha...) but that fixed the dots but the transitios got really dark and did not work. I tried the glColor3f(alpha..,alpha...,alpha...) for both layers and that did not work. Although they are not nearly as big as before they still need to be fixed. Thanks for the help that you gave me to fix it partially.
Cya vbuser

##### Share on other sites
set your depth buffer precision to 24

there was a bug in the choosepixel format function when you requested a 32 bit depthbuffer it chose a 16 bit precision depthbuffer which let to stepping artifacts

maybe that s the problem

##### Share on other sites
Thanks for the suggestion and I tried that alreay and it still doesn't help any so I have to screw around with it to see if I can get it fixed or at least minimized.

##### Share on other sites
You can try disabling depth buffer writes on your second pass with
glDepthMask(GL_FALSE);
and enable them later

##### Share on other sites
I don't think that'll help Gaenor since I think Basiror has hit the nail on the head that it's a depth buffer precision problem.

vbuser1338: What does your gluPerspective/glFrustum call look like?

Enigma

##### Share on other sites
I am using sdl to set up my window right now and this is the code that does it.
bool CEngine::InitVideo(int width,int height) {	// Load SDL	if(SDL_Init(SDL_INIT_VIDEO) < 0) {		// Failed		MessageBox(NULL,"Failed to initialized video.","ERROR",0);		return false;	}	atexit(SDL_Quit);	// Run quit on exit		// Now set up for opengl	const SDL_VideoInfo *info = SDL_GetVideoInfo();	if(!info) {		// Should not happen		MessageBox(NULL,"Video query failed.","ERROR",0);		return false;	}		int bpp = info->vfmt->BitsPerPixel;	// Get bpp		// Set up bits    SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5);    SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5);    SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5);  	// Set up color depth    SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 32);	// Set up double buffering    SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, true);      	    // Now set it to let opengl do drawing    if (SDL_SetVideoMode(width, height, bpp, SDL_OPENGL | SDL_SWSURFACE) == 0) {    	MessageBox(NULL,"Unable to set video mode.","ERROR",0);	    return false;  	}  	  	ToProj(width,height);	// Setup the opengl window  	return true;}void CEngine::ToProj(int width,int height) {	glViewport(0,0,(GLsizei)(width),(GLsizei)(height));	glMatrixMode(GL_PROJECTION);		glLoadIdentity();		gluPerspective(60.0f,(GLfloat)width/(GLfloat)height,1.0f,1600.0f);   		glMatrixMode(GL_MODELVIEW);		glLoadIdentity();		glClearDepth(1.0f);		    	glEnable(GL_DEPTH_TEST);    	glDepthFunc(GL_LEQUAL);	   }

I have also tried using depth buffer bit to 24 but that did not help any.
Thanks for all the help

##### Share on other sites
are you using 16 bit colors?

##### Share on other sites
I am using whatever is right there. I tried switching the color to this code
SDL_GL_SetAttribute(SDL_GL_RED_SIZE,8 - info->vfmt->Rloss);
SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8 - info->vfmt->Gloss);
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8 - info->vfmt->Bloss);
which is from some of Nehe's new tutorial but that did not help anything. The way I have it is how most of the people have it set up when I do a search so I don't know really if it is a problem with setting up opengl.
Thanks for all the help.

1. 1
Rutin
49
2. 2
3. 3
4. 4
5. 5

• 10
• 28
• 20
• 9
• 20
• ### Forum Statistics

• Total Topics
633410
• Total Posts
3011723
• ### Who's Online (See full list)

There are no registered users currently online

×