PDA

View Full Version : why the tree can't be displayed



victorswan
04-22-2003, 06:39 PM
when I create a empty project only displaying tree, the tree can be displayed, but when I put these code into another project with terrain, the tree can not be displayed, I wonder why?
struct plantmodelstruct
{ GLuint masktexture;
GLuint texture;
float sizex;
float sizey;
};
plantmodelstruct plantmodel;
int nPlantList;

void LoadTextu(char *file, GLuint *ptexture)
{
AUX_RGBImageRec *TextureImage[1];
memset(TextureImage, 0, sizeof(void *));
TextureImage[0] = auxDIBImageLoad(file);

glBindTexture(GL_TEXTURE_2D, *ptexture);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTE R,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTE R,GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[0]->sizeX, TextureImage[0]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data);

free(TextureImage[0]->data);
free(TextureImage[0]);

}

void CDrawCulvertView::LoadPlants()
{
plantmodel.sizex = 64;
plantmodel.sizey = 128;
//textures
glGenTextures(1, &plantmodel.masktexture);
glGenTextures(1, &plantmodel.texture);
LoadTextu("texture\\pflmask.bmp", &plantmodel.masktexture);
LoadTextu("texture\\pfl.bmp", &plantmodel.texture);
}

void DrawPlants()
{
nPlantList = ModelPlant();
glPushMatrix();
glTranslatef(0,-50,-300);
glCallList(nPlantList);
glPopMatrix();
}

int ModelPlant()
{
int nModel,j;
glEnable(GL_BLEND);
glDisable(GL_DEPTH_TEST);
glEnable(GL_TEXTURE_2D);
nModel = glGenLists(1);
glNewList(nModel,GL_COMPILE_AND_EXECUTE);
glColor3f(1, 1, 1);

for(j=0; j<4; j++)
{ //mask
if(j%2 == 0)
{
glBindTexture(GL_TEXTURE_2D, plantmodel.masktexture);
glBlendFunc(GL_DST_COLOR, GL_ZERO);
}
//image
else
{
glBindTexture(GL_TEXTURE_2D, plantmodel.texture);
glBlendFunc(GL_ONE, GL_ONE);
}
if(j==2)
glRotatef(-90, 0, 1, 0);
glBegin(GL_QUADS);
glTexCoord2f(0, 1); glVertex3f(-plantmodel.sizex, plantmodel.sizey, 0);
glTexCoord2f(1, 1); glVertex3f(plantmodel.sizex, plantmodel.sizey, 0);
glTexCoord2f(1, 0); glVertex3f(plantmodel.sizex, 0, 0);
glTexCoord2f(0, 0); glVertex3f(-plantmodel.sizex, 0, 0);
glEnd();
}
glEndList();
return nModel;
}

victorswan
04-23-2003, 03:59 AM
Please delete this post, since no one help me, I want to post it on the advanced forum

Deiussum
04-23-2003, 04:56 AM
A little patience can be a good thing, sometimes. You post this the evening of the 22, and are upset that you haven't gotten an answer by the early morning of the next day? (At least for those of us in my half of the world.)

Anyway, I see you are using a display list. And you appear to be creating the display list every time you display the tree. Usually you would only create the list upon startup.

Now, since you are using a display list and you say if you add it to code that displays a terrain, it doesn't show up. There are numerous reasons this might be, and your code doesn't show any of them because you're not showing it within the other project.

1. You could potentially be over-writing the display list with a display list for the terrain.

2. Your tree might be getting clipped by the viewing volume.

3. Your tree might be getting rejected by depth testing if your terrain is in front of the tree.

victorswan
04-24-2003, 05:32 AM
the reason why I don't put those codes is they are too long
since I have used
glDisable(GL_DEPTH_TEST);

the tree still can be rejected by depth testing?
after I draw the tree, I got a black screen, so I wonder the reason might be gluLookAt(),but I still havn't solved?

Deiussum
04-24-2003, 06:26 AM
If you got a black screen, you probably are drawing everything outside of the viewing volume. Show how you setup your PROJECTION and MODELVIEW matrices.

victorswan
04-24-2003, 05:12 PM
It is very strange, the black screen is only to those rendering with glColor3f() parts, that means the material rendering parts, not to the texture mapped parts, e.g, I use multi-texture to terrain, the terrain can be seen, I use glColor3f() to road on the terrain, when the tree begin to draw,the road then become black screen. I don't know what is the reason?

Deiussum
04-25-2003, 04:11 AM
What are the relative sizes of your tree and terrain? Maybe your tree is huge in relation and you are seeing the back-side of some of the faces covering the screen.

Without seeing more code, there's not much more I can do to help. If you want, you can e-mail me your project and I'll take a look at it for you. My e-mail is in my profile.