void HeightMap::BuildMap() {
buildList = glGenLists(1);
glNewList(buildList,GL_COMPILE);
glBindTexture(GL_TEXTURE_2D,grass); // Bind grass texture
glBegin(GL_QUADS);
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
glBegin(GL_QUADS);
// 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);
}
🔒 Locked
Height Map Blending problems
Advertisement
Original Post
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 If anyone can help I would appreciate it. Thanks vbuser
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
Cya vbuser
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.
I am using sdl to set up my window right now and this is the code that does it.
I have also tried using depth buffer bit to 24 but that did not help any.
Thanks for all the help
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
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.
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.
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement