quote:Original post by toddgrayson
If the terrain is showing up black that means that you are not getting alpha values. Try creating an array of all 1''s and use that for the alpha layer texture and render only 1 layer. If this still doesn''t work I would check to see what is rendering before and after the terrain, also check to see if lighting is enabled when you are rendering the terrain as this may also have some effect. I am assuming that the demo works for you. If nothing else works send me the section of your code that you are using this for and I will see if anything catches my eye.
i tried an array of all 1''s, and i also tried rendering only the terrain, still doesnt work... and ive been rendering only one layer the whole time too..
the alpha values are ok, ive checked by debugging at runtime, i pause the app inside the for loop for setting each value in the array, and every value is definately getting applied.
yeah your demo works for me
yes lighting is off
im not sure what i should send to ya, ill show you my frame routine, my routine for drawing terrains, and my routine for creating the alpha texture, since those seem like the most logical functions that apply to this specific technique
beware, this code has been growing for 3 weeks, in a very un-tidy manner, i basically test anything and everything that has to do with terrain stuff in this app...
the create alpha texture
bool CreateAlphaTexture(UINT &texture, LPSTR strFileName){ float *mydata=NULL; mydata=new float[1024*1024]; AUX_RGBImageRec *pImage=NULL; pImage=auxDIBImageLoad(strFileName); int x,y; for(x=0;x < 1024;x++) { for(y=0;y < 1024;y++) { mydata[x+y*1024]=1.0f; //mydata[x+y*1024]=(float)pImage->data[x+y*1024*3]/255; } } delete[ ] pImage->data; pImage=NULL; glPixelStorei(GL_UNPACK_ALIGNMENT,1); glGenTextures(1,&texture); glBindTexture(GL_TEXTURE_2D,texture); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexImage2D(GL_TEXTURE_2D,0,GL_ALPHA,1024,1024,0,GL_ALPHA,GL_FLOAT,mydata); return true;}
//the render terrain function (different from draw terrain)
void RenderHeightMap(BYTE *pHeightMap,int pass,CFrustum *aFrustum,float modx,float mody,float modz,bool detail){ if(!pHeightMap) return; if(detail) { glActiveTextureARB(GL_TEXTURE0_ARB); glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D,g_Texture[pass]); if(g_bDetail) { glActiveTextureARB(GL_TEXTURE1_ARB); glEnable(GL_TEXTURE_2D); glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB); glTexEnvi(GL_TEXTURE_ENV, GL_RGB_SCALE_ARB, 2); glBindTexture(GL_TEXTURE_2D, g_Texture[4]); glMatrixMode(GL_TEXTURE); glLoadIdentity(); glScalef((float)g_DetailScale,(float)g_DetailScale,1); glMatrixMode(GL_MODELVIEW); } } int ix; int iz; glBegin(GL_TRIANGLES); for(iz=0;iz < MAP_SIZE-STEP_SIZE;iz+=STEP_SIZE) { //glBegin(GL_TRIANGLES); for(ix=0;ix < MAP_SIZE-STEP_SIZE;ix+=STEP_SIZE) { if(aFrustum->CubeInFrustum((ix*SCALE)+(modx*SCALE),(Height(pHeightMap,ix,iz)*HEIGHT_RATIO*SCALE)+(mody*SCALE),(iz*SCALE)+(modz*SCALE),STEP_SIZE*SCALE)) { float tmpx1,tmpx2,tmpx3; float tmpy1,tmpy2,tmpy3; float tmpz1,tmpz2,tmpz3; tmpx1=ix; tmpy1=Height(pHeightMap,ix,iz)*HEIGHT_RATIO; tmpz1=iz; tmpx2=ix; tmpy2=Height(pHeightMap,ix,iz+STEP_SIZE)*HEIGHT_RATIO; tmpz2=iz+STEP_SIZE; tmpx3=ix+STEP_SIZE; tmpy3=Height(pHeightMap,ix+STEP_SIZE,iz)*HEIGHT_RATIO; tmpz3=iz; if(aFrustum->TriangleInFrustum(tmpx1*SCALE,tmpy1*SCALE,tmpz1*SCALE,tmpx2*SCALE,tmpy2*SCALE,tmpz2*SCALE,tmpx3*SCALE,tmpy2*SCALE,tmpz3*SCALE,modx*SCALE,mody*SCALE,modz*SCALE)) { if(detail) { SetTextureCoord(tmpx1,tmpz1); glVertex3f(tmpx1,tmpy1,tmpz1); SetTextureCoord(tmpx2,tmpz2); glVertex3f(tmpx2,tmpy2,tmpz2); SetTextureCoord(tmpx3,tmpz3); glVertex3f(tmpx3,tmpy3,tmpz3); gtrianglesdrawn++; } else { SetTextureCoordNoDetail(tmpx1,tmpz1); glVertex3f(tmpx1,tmpy1,tmpz1); SetTextureCoordNoDetail(tmpx2,tmpz2); glVertex3f(tmpx2,tmpy2,tmpz2); SetTextureCoordNoDetail(tmpx3,tmpz3); glVertex3f(tmpx3,tmpy3,tmpz3); gtrianglesdrawn++; } } tmpx1=ix; tmpy1=Height(pHeightMap,ix,iz+STEP_SIZE)*HEIGHT_RATIO; tmpz1=iz+STEP_SIZE; tmpx2=ix+STEP_SIZE; tmpy2=Height(pHeightMap,ix+STEP_SIZE,iz+STEP_SIZE)*HEIGHT_RATIO; tmpz2=iz+STEP_SIZE; tmpx3=ix+STEP_SIZE; tmpy3=Height(pHeightMap,ix+STEP_SIZE,iz)*HEIGHT_RATIO; tmpz3=iz; if(aFrustum->TriangleInFrustum(tmpx1*SCALE,tmpy1*SCALE,tmpz1*SCALE,tmpx2*SCALE,tmpy2*SCALE,tmpz2*SCALE,tmpx3*SCALE,tmpy3*SCALE,tmpz3*SCALE,modx*SCALE,mody*SCALE,modz*SCALE)) { if(detail) { SetTextureCoord(tmpx1,tmpz1); glVertex3f(tmpx1,tmpy1,tmpz1); SetTextureCoord(tmpx2,tmpz2); glVertex3f(tmpx2,tmpy2,tmpz2); SetTextureCoord(tmpx3,tmpz3); glVertex3f(tmpx3,tmpy3,tmpz3); gtrianglesdrawn++; } else { SetTextureCoordNoDetail(tmpx1,tmpz1); glVertex3f(tmpx1,tmpy1,tmpz1); SetTextureCoordNoDetail(tmpx2,tmpz2); glVertex3f(tmpx2,tmpy2,tmpz2); SetTextureCoordNoDetail(tmpx3,tmpz3); glVertex3f(tmpx3,tmpy3,tmpz3); gtrianglesdrawn++; } } } } //glEnd(); } glEnd(); if(detail) { glActiveTextureARB(GL_TEXTURE1_ARB); glDisable(GL_TEXTURE_2D); glActiveTextureARB(GL_TEXTURE0_ARB); glDisable(GL_TEXTURE_2D); }}
yeah, dont say anything about that, haha, its messy
//texture coord function for nodetail texturing
void SetTextureCoordNoDetail(float x, float z){ float u = x / ((float)MAP_SIZE-(float)STEP_SIZE); float v = z / ((float)MAP_SIZE-(float)STEP_SIZE); glTexCoord2f(u,1-v);}
//frame function!
void RenderScene(){ gtrianglesdrawn=0; glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); /*if(keys[VK_LEFT]) {g_3DModel.RotateMe(200);} if(keys[VK_RIGHT]) {g_3DModel.RotateMe(-200);} if(keys[VK_UP]) {g_3DModel.ChangeAnimationRun();g_3DModel.MoveMD2Forward(1000.0f);} if(!keys[VK_UP]) g_3DModel.ChangeAnimationIdle(); g_3DModel.ClingToTerrain(g_HeightMap); g_Camera.SetThirdPerson(g_3DModel.Position.x,g_3DModel.Direction.y,g_3DModel.Position.z); g_Camera.SetLookAt(g_3DModel.Position.x,g_3DModel.Position.y,g_3DModel.Position.z);*/ g_Camera.Look(); g_Frustum.CalculateFrustum(); //g_3DModel.UpdateMe(); DrawTerrain(); //DrawModel(); //DrawSkyBox(); //DrawWater(); //DrawFog(); char mytext[30]; sprintf(mytext,"Triangles: %i\n",gtrianglesdrawn); SetWindowText(g_hWnd,mytext); SwapBuffers(g_hDC); }
//finally (is exhausted from so much copy and pasting)
the draw terrain function
void DrawTerrain(){ glPushMatrix(); glScalef((float)SCALE,(float)SCALE,(float)SCALE); glDisable(GL_BLEND); glColorMask(0,0,0,1); glEnable(GL_TEXTURE_2D); glTexEnvi(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_REPLACE); glBindTexture(GL_TEXTURE_2D,g_Texture[1]); glColor4f(1,1,1,1); RenderHeightMap(g_HeightMap,1,&g_Frustum); glColorMask(1,1,1,0); glTexEnvi(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_MODULATE); glEnable(GL_BLEND); glBlendFunc(GL_DST_ALPHA,GL_ONE_MINUS_DST_ALPHA); glBindTexture(GL_TEXTURE_2D,g_Texture[0]); glColor4f(1,1,1,1); RenderHeightMap(g_HeightMap,0,&g_Frustum); glDisable(GL_BLEND); glPopMatrix();}
hopefully it doesnt take all your energy to weed through the mess, thanks for helping so far