Archived

This topic is now archived and is closed to further replies.

Terrain multitexturing and alpha masks

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

I want to render my terrain in the way it is explained in this tutorial: http://www.gamedev.net/columns/hardcore/geomorph/page2.asp Example: I have a Grass tex + mask, a Mud tex + mask, a Road tex + mask. Now I want to render them as fast as possible on a patch(quad, or whatever). Is this possible using multitexturing (or another technique)?

Share this post


Link to post
Share on other sites
I think the best way to do this is to load the textures and in initialization function to form out of them the big texture of the whole terrain... I''m trying to implement this one now...



It does not matter what you will reach in your life, but the way you will reach it

Share this post


Link to post
Share on other sites
Yeah what you want is possible. I remember when I was trying to do it a lot of people in forums were saying I couldn''t, then I got it to work only to find out it was a standard way of doing it. Anyway, here''s how you would do it.

First if you want to blend 3 textures - grass, rock, mud - for instance, then you draw the grass across the entire terrain, then blend the rock and mud based on rgb and alpha values in a fourth texture, basically an alphamap.

So the way I''ve implemented this is in my alpha map, basically just a bitmap, I draw red where I want rock to show through and green where I want mud to show through, then if you want rock and mud to mix, you just mix red and green basically. But what I did, and I''m not sure if this is a must, but I then copied the green component into the alpha channel, and copied the red component into the green and blue components. So that way, rock is represented by black and white, and mud is represented by the alpha channel. That way you can use only 1 texture for blending 3, instead of 2 different textures for blending 3. I hope that makes sense. Here''s the basic code.


//textures with .bmp files already loaded into them
GLuint grass, rock, mud, alphamap;

//base texture - grass
glActiveTextureARB(GL_TEXTURE0_ARB);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, texture0);
glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_RGB_EXT);
glTexEnvf (GL_TEXTURE_ENV, GL_COMBINE_RGB_EXT, GL_REPLACE);

//alpha texture - RGB (transparency for rock) ALPHA (transparency for mud)
glActiveTextureARB(GL_TEXTURE1_ARB);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, alphamap);

//second texture - rock
glActiveTextureARB(GL_TEXTURE2_ARB);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, rock);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);
glTexEnvi(GL_TEXTURE_ENV,GL_COMBINE_RGB_ARB,GL_INTERPOLATE_ARB);
glTexEnvi(GL_TEXTURE_ENV,GL_SOURCE0_RGB_ARB, GL_TEXTURE0);
glTexEnvi(GL_TEXTURE_ENV,GL_OPERAND0_RGB_ARB,GL_SRC_COLOR);
glTexEnvi(GL_TEXTURE_ENV,GL_SOURCE1_RGB_ARB,GL_TEXTURE2);
glTexEnvi(GL_TEXTURE_ENV,GL_OPERAND1_RGB_ARB,GL_SRC_COLOR);
glTexEnvi(GL_TEXTURE_ENV,GL_SOURCE2_RGB_ARB,GL_TEXTURE1);
glTexEnvi(GL_TEXTURE_ENV,GL_OPERAND2_RGB_ARB,GL_SRC_COLOR);

//third texture - mud
glActiveTextureARB(GL_TEXTURE3_ARB);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, mud);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);
glTexEnvi(GL_TEXTURE_ENV,GL_COMBINE_RGB_ARB,GL_INTERPOLATE_ARB);
glTexEnvi(GL_TEXTURE_ENV,GL_SOURCE0_RGB_ARB,GL_PREVIOUS_ARB);
glTexEnvi(GL_TEXTURE_ENV,GL_OPERAND0_RGB_ARB,GL_SRC_COLOR);
glTexEnvi(GL_TEXTURE_ENV,GL_SOURCE1_RGB_ARB,GL_TEXTURE3);
glTexEnvi(GL_TEXTURE_ENV,GL_OPERAND1_RGB_ARB,GL_SRC_COLOR);
glTexEnvi(GL_TEXTURE_ENV,GL_SOURCE2_RGB_ARB,GL_TEXTURE1);
glTexEnvi(GL_TEXTURE_ENV,GL_OPERAND2_RGB_ARB,GL_SRC_ALPHA);


I hope the code makes sense. Basically what it''s doing is performing a LERP between 2 values using the alpha map as the interpolation value. If you look up information on GL_COMBINE_ARB, you''ll find more information on this. But the above code will work. Also if your card supports pixel shaders, or fragment programs, this is a lot more straightforward, plus you could technically blend 5 textures with 1 alphamap, since you have access to the alphamaps red,green,blue,alpha components separately. But if you don''t want to mess with that, then I''d go with this. Also, http://www.delphi3d.net has a terrain demo that also implements this method, but his demo just assigns the alpha value to each vertices'' color, so I like this method a lot better because it works for irregular sized triangles and such.

Basically how you''ll want to implement this is texturemap the alphamap ONCE across the entire area of triangles, then you could tile every other texture across the area. That way each tiled texture will only ''show'' through based on the alphamap value. Hope this helps. It took me about an ENTIRE month to figure out how to do this on my own, so that''s why i''ve typed so much about it.

Share this post


Link to post
Share on other sites
Thanx for the reactions,

But isnt there a way of combining the mask and the texture then blend all textures together in two passes

example:
blend combine
textureunit0: grassmask -> grasstexure |
textureunit1: mudmask -> mudtexture |-> final image
textureunit2: rockmask -> rocktexture |

I hope you understand what I mean.

[edited by - Trilobyte on November 6, 2003 1:35:07 PM]

Share this post


Link to post
Share on other sites
if your talking about procedural texturing, its fairly simple

i can explain it if you let me know thats what you want

btw, you can download the source code to that tutorial i think

Share this post


Link to post
Share on other sites
well its when you create a texture for your terrain from 4 textures that you specify. it can be more than 4, you could have 256 (but that would look horrible)

basically, you define these height ranges. for instance

1-64,64-128,128-192,192-256

then you go through the pixels in the heightmap, and find which range the current pixel is in, then in the final texture you copy the pixel from the texure specified for that range. the algorithm is also written in a manner so that when a range makes a change over distance, the two textures are blended together (grass going into rock)

most terrain engines support this, as it is a fairly simple operation.

Share this post


Link to post
Share on other sites
yeah it means making one big texture for the terrain

im currently working on modifying the technique to make several textures to increase resolution quality

Share this post


Link to post
Share on other sites
I want to use this method:

firs pass:
base texture (most common texture near the patch)

second pass:
transitions textures (blend using mask)

third pass:
detail texture

But I''m not sure how to implement this, please help me with it.

Share this post


Link to post
Share on other sites
You can do this by rendering to destination alpha. Here is and example:

// Disable blending
glDisable(GL_BLEND);
// Draw only to Destaination Alpha
glColorMask(0, 0, 0, 1);
// Enable Texturing
glEnable(GL_TEXTURE_2D);
// Set texture environment mode to replace
glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE );
// Bind the texture
glBindTexture(GL_TEXTURE_2D, currPtr->alphatex);
// Render vertices using the alpha texture coordinates
// You would stretch this texture over the whole patch.
currPtr->vertarray->RenderAlphaCoords();

// Draw to Everything but Detination Alpha
glColorMask(1,1,1,0);
// Set texture environment mode to modulate
glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
// Enable blending
glEnable(GL_BLEND);
// Render only to areas where alpha is greater that zero
glBlendFunc( GL_DST_ALPHA, GL_ONE_MINUS_DST_ALPHA );
// Bind the texture.
glBindTexture(GL_TEXTURE_2D, currPtr->texture);
// Render using texture coordinates
// These coordinates would be repeating the texture to
// maintain high detail.
currPtr->vertarray->RenderTexCoords();
// Disable blending
glDisable(GL_BLEND);

To setup the alpha texture you would do the following:
// Set pixel store alignment
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
// Generate the texture
glGenTextures(1, &currPtr->alphatex);
// Bind the generated texture
glBindTexture(GL_TEXTURE_2D, currPtr->alphatex);
// Set texture parameters
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
// Copy the data into the texture as alpha values
glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, data_width, data_heigth, 0, GL_ALPHA, GL_FLOAT, alphaarray->data);

The alpha texture is simply an array of alpha values from 0 to 1 that you would use to determine where you want to draw the texture. This texture acts as a mask for each texture layer you are rendering.

You would do this for each one of the layers you plan to use. For example:

Render grass->alpha then Render grass->texture
Render rock->alpha then Render rock->texture.
...

This will allow you to have any number of layers. You can also setup parameters so that the alpha array values are determined by slope or height or a drawn in directly. Ex roads.



[edited by - toddgrayson on November 24, 2003 3:20:33 AM]

Share this post


Link to post
Share on other sites
so basically, you''re rendering an alpha map, then painting the texture over it, but its being blended so that only the parts that have x alpha value show the texture at that spot. Meaning, the texture is only drawn where alpha x is on the terrain.

Makes sense, but where are you getting alpha x from?

I''m interested in knowing more, if you dont mind going into more detail, because this is EXACTLEY what my terrain engine needs, procedural texture generation just isnt enough(and ive taken it as far as i could, lol).

Share this post


Link to post
Share on other sites
quote:
Original post by toddgrayson
You can do this by rendering to destination alpha. Here is and example:

// Disable blending
glDisable(GL_BLEND);
// Draw only to Destaination Alpha
glColorMask(0, 0, 0, 1);
// Enable Texturing
glEnable(GL_TEXTURE_2D);
// Set texture environment mode to replace
glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE );
// Bind the texture
glBindTexture(GL_TEXTURE_2D, currPtr->alphatex);
// Render vertices using the alpha texture coordinates
// You would stretch this texture over the whole patch.
currPtr->vertarray->RenderAlphaCoords();

// Draw to Everything but Detination Alpha
glColorMask(1,1,1,0);
// Set texture environment mode to modulate
glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
// Enable blending
glEnable(GL_BLEND);
// Render only to areas where alpha is greater that zero
glBlendFunc( GL_DST_ALPHA, GL_ONE_MINUS_DST_ALPHA );
// Bind the texture.
glBindTexture(GL_TEXTURE_2D, currPtr->texture);
// Render using texture coordinates
// These coordinates would be repeating the texture to
// maintain high detail.
currPtr->vertarray->RenderTexCoords();
// Disable blending
glDisable(GL_BLEND);

To setup the alpha texture you would do the following:
// Set pixel store alignment
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
// Generate the texture
glGenTextures(1, &currPtr->alphatex);
// Bind the generated texture
glBindTexture(GL_TEXTURE_2D, currPtr->alphatex);
// Set texture parameters
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
// Copy the data into the texture as alpha values
glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, data_width, data_heigth, 0, GL_ALPHA, GL_FLOAT, alphaarray->data);

The alpha texture is simply an array of alpha values from 0 to 1 that you would use to determine where you want to draw the texture. This texture acts as a mask for each texture layer you are rendering.

You would do this for each one of the layers you plan to use. For example:

Render grass->alpha then Render grass->texture
Render rock->alpha then Render rock->texture.
...

This will allow you to have any number of layers. You can also setup parameters so that the alpha array values are determined by slope or height or a drawn in directly. Ex roads.

An example screenshot is at:
http://www31.brinkster.com/btgco/images/worldeditor_screen01.jpg


i tried you''re method and it isnt working, could you explain some more things??

all i get is a black terrain..

im getting my float alpha values from a bitmap, and converting each point by dividing it by 255. This gives you a number between 0 and 1 for each pixel on the "alpha map" (its just a greyscale bitmap, with colors 0 - 255 greyscale), and i set up the alpha texture just like you said

then i render it first, using the method you''ve posted, then i render the regular texture, using the second section you posted, and the terrain just turns out black

any ideas?

also, i tried drawing the alpha texture onto a quad, just to see what it looked like, and it just made this stripe pattern across it, but since its a different type of format "GL_ALPHA" and it uses values of type "GL_FLOAT", i didnt expect it to resemble the original image anywas (plus dividing by 255 changes it a lot too)

Share this post


Link to post
Share on other sites
fireking,

There are some pre-requisites in this method.

First, you will have to have at least an 8 bit alpha buffer. Second, your video card and drivers must support rendering to destination alpha. You should also have windows in 32bpp mode.

To setup your pixelformatdescriptor using the following code:

// pfd Tells Windows How We Want Things To Be
PIXELFORMATDESCRIPTOR pfd=
{
sizeof(PIXELFORMATDESCRIPTOR),// Pixel Format Descriptor Size
1, // Version Number
PFD_DRAW_TO_WINDOW | // Format Must Support Window
PFD_SUPPORT_OPENGL | // Format Must Support OpenGL
PFD_DOUBLEBUFFER, // Must Support Double Buffering
PFD_TYPE_RGBA, // Request An RGBA Format
0, // Select Our Color Depth
0, 0, 0, 0, 0, 0, // Color Bits Ignored
8, // Alpha Buffer
0, // Shift Bit Ignored
0, // No Accumulation Buffer
0, 0, 0, 0, // Accumulation Bits Ignored
16, // 16Bit Z-Buffer (Depth Buffer)
0, // No Stencil Buffer
0, // No Auxiliary Buffer
PFD_MAIN_PLANE, // Main Drawing Layer
0, // Reserved
0, 0, 0 // Layer Masks Ignored
};

The alpha values from alphaarray->data are an array of floats with a range of 0 to 1 just like you are doing.

I don't know what the method whould be called so I can't point you in the right direction so far as searching for it, though you could look up "rendering to destination alpha" on the opengl forums on the opengl.org site.

Example source code can be downloaded at:
http://www.btgconsulting.ca/downloads/terrain.zip




[edited by - toddgrayson on November 24, 2003 3:27:43 AM]

Share this post


Link to post
Share on other sites
damnit this is rediculous, my code is almost exactley like yours now, except mine doesnt work and yours does... grr

if i hit escape (which exits my app), i can see the terrain as its supposed to be for a brief second as the window is being destroyed, do you know what might cause my terrain to still be black, but show up normal for a brief second while the window is being destroyed?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
You are welcome.

Everything looks good except for:
RenderHeightMap(g_HeightMap,0,&g_Frustum);

It looks like it is still seeing detail as true when rendering.

I copied and pasted the RenderHeightMap funtion into my code minus all the sections containing if(detail) and all works fine.

Try commenting out all the if(detail) code and try again. If that does not work then the only other place I could see a problem being is in the actual initialization code. Ie set pixel format.

Share this post


Link to post
Share on other sites
that sucks

cuz i have detail=false by default in the header declaration of that function (and there are break points in the RenderHeightMap in each of the detail branches, it never breaks there, so detail is indeed false) so nope its not going into those detail parts (hence the reason i wrote the SetTexturecoordNoDetail function)

and i copied your set pixel format desciptor from your code since its a very mobile section of code (you can copy + paste from one app to another app without problems), so im using your settings there

Share this post


Link to post
Share on other sites
oh no....

i just messed around some more with the code, and its really bad now..

i was trying something else, some nice sky, and render the terrain like normal again, only this time it wont render normal like before, its still black! i go back and look through everything, how is it possible for this to be black im saying? turns out, i had some backwards culling, some undefined fog (which i think just makes every black if you dont ever call fog functions, yet you enable it), and all sorts of stuff

after i fixed that, to make things even worse, i enabled my model to be drawn in the scene, and now everything looks different (actually better, but why?) i check the model drawing functions (and any other function thats called in its branch), and nothing is happening other than switching the culling to front, draw the model, switch culling back to back face...

and to go even WORSE, the sky flickers now, as i move over the terrain. if i stand still, the sky stays the same color, if i move, it changes colors rapidly. If i move the camera and dont see any of the terrain, the sky stays the same color, so much confusion. Once again, i turn on the model to be drawn, and now the sky doesnt flicker at all... jesus... this is such a mess

im going to my room now, to build an open gl wrapper to prevent this from happening again

ill try your method again, with all the problems i found

thanks for being so patient with me

ignore spelling mistakes, grammer errors, and incorrect punctuation please.

Share this post


Link to post
Share on other sites