PDA

View Full Version : Texturing problem



jimmythepage
09-07-2006, 12:41 PM
Hi..
I have a problem with a program.I've used the same code,with some difference,of the tutorial for loading milkshape model written by nehe..
My problem is that the program don't show the texture and the mesh appear totally white!!
here the resume of the texturing code

if ( materialIndex >= 0 )
{
glMaterialfv( GL_FRONT, GL_AMBIENT,model->m_pMaterials[materialIndex].m_ambient );
glMaterialfv( GL_FRONT, GL_DIFFUSE, model->m_pMaterials[materialIndex].m_diffuse );
glMaterialfv( GL_FRONT, GL_SPECULAR, model->m_pMaterials[materialIndex].m_specular );
glMaterialfv( GL_FRONT, GL_EMISSION, model->m_pMaterials[materialIndex].m_emissive );
glMaterialf( GL_FRONT, GL_SHININESS, model->m_pMaterials[materialIndex].m_shininess );
if(model->ID_Texture>=100)
{
glEnable( GL_TEXTURE_2D );
glBindTexture(GL_TEXTURE_2D, model->ID_Texture);
}
else
glDisable(GL_TEXTURE_2D);
}
else
{
// Material properties?
glDisable( GL_TEXTURE_2D );
}
void CJtpOglTextureMgr::LoadTextures(IJtpModel *model,jchar* filename)
{

model->ID_Texture=IDTemp;
CreateTextureBmp(filename,model->ID_Texture);
IDTemp++;

};
void CJtpOglTextureMgr::CreateTextureBmp( jchar* strFileName, juint textureID)
{
AUX_RGBImageRec *pBitmap = NULL;

if(!strFileName)
return;

pBitmap = auxDIBImageLoad(strFileName);

if(pBitmap == NULL)
exit(0);

glGenTextures(1, &textureID);

glPixelStorei (GL_UNPACK_ALIGNMENT, 1);

glBindTexture(GL_TEXTURE_2D, textureID);

gluBuild2DMipmaps(GL_TEXTURE_2D, 3, pBitmap->sizeX, pBitmap->sizeY, GL_RGB, GL_UNSIGNED_BYTE, pBitmap->data);


glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTE R,GL_LINEAR_MIPMAP_NEAREST);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTE R,GL_LINEAR_MIPMAP_LINEAR);


if (pBitmap)
{
if (pBitmap->data)
{
free(pBitmap->data);
}

free(pBitmap);
}
}
IJtpModel* model=rendermgr->AddModel("soldier.ms3d",1);
rendermgr->AddTexture(model,"GH.bmp");

void CJtpRenderMgr::AddTexture(IJtpModel* model,jchar* filename)
{
SoftMgr->LoadTexture(model,filename);
};

void CJtpOglMgr::LoadTexture(IJtpModel* model,jchar* filename)
{
texturemgr.LoadTextures(model,filename);
};there is somithing wrong in this chunks???
If the problem aren't here can anyone tell me where i could find it??

PS i have just checked all the glEnable(like texture2d,materialcolor) and relative gldisable(lighting)....

tnx very much

VCarnage
09-08-2006, 12:20 PM
I suggest you turn off lighting and just test if you are texturing correctly, ie texcoords are set correctly. If it does texture correctly, then you have a lighting issue, ie position, type, color, etc... make sure the lighting is set up properly.

-VC

Komat
09-09-2006, 04:49 AM
The textureID parameter of CreateTextureBmp function should be reference. Otherwise the texture id generated by OGL (glGenTextures) is not stored inside the model->ID_Texture which will then contain incorrect value.

Alternatively you may assign the texture id by yourself (which might be what you intended). In that case you need to drop the glGenTextures(1, &textureID); line.

jimmythepage
09-11-2006, 12:22 PM
tnx for the answer very much...

@vcarnage i've tried so turn off the lighting but is still exist the problem..the uv are right i'm sure of it because in other project the same model works well..

@komat i've read only now your answer,tomorrow i'll try...

if still don't work i'll be back ;p

jimmythepage
09-11-2006, 12:34 PM
i've found some pieces of time and i've tried this


void CJtpOglTextureMgr::CreateTextureBmp(jchar* strFileName)
{

AUX_RGBImageRec *pBitmap = NULL;

if(!strFileName)
return;

pBitmap = auxDIBImageLoad(strFileName);

if(pBitmap == NULL)
exit(0);

glGenTextures(1, &IDTemp);


glBindTexture(GL_TEXTURE_2D, IDTemp);


gluBuild2DMipmaps(GL_TEXTURE_2D, 3, pBitmap->sizeX, pBitmap->sizeY, GL_RGB, GL_UNSIGNED_BYTE, pBitmap->data);


glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTE R,GL_LINEAR_MIPMAP_NEAREST);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTE R,GL_LINEAR);


if (pBitmap)
{
if (pBitmap->data)
{
free(pBitmap->data);
}

free(pBitmap);
}

}
public:
CJtpOglTextureMgr();
void LoadTextures(IJtpModel *model,jchar* filename);
~CJtpOglTextureMgr();
AUX_RGBImageRec *CreateTextureBmp2(const jchar* strFileName);
juint LoadGLTexture( const jchar *filename );
void CreateTextureBmp(jchar* strFileName);
private:
juint IDTemp;
void CJtpOglTextureMgr::LoadTextures(IJtpModel *model,jchar* filename)
{
model->Texture_ID=IDTemp;
CreateTextureBmp(filename);
IDTemp++;


}; is what you mean or i haven't undertand??

in this way don't work too..

jimmythepage
09-11-2006, 12:42 PM
CJtpOglTextureMgr::CJtpOglTextureMgr()
{
IDTemp=100;
}; this is the idtemp assignment..

jide
09-11-2006, 02:16 PM
This is not related to GL, at least not directly.
When using this function:


glGenTextures(1, &textureID);textureID will be modified by GL, giving it a value. So, whether don't use it, whether use something else to detect if your model has a texture or not.

Komat
09-11-2006, 02:17 PM
This is not what I meant.


One possible alternative I mentioned was:


void CJtpOglTextureMgr::LoadTextures(IJtpModel *model,jchar* filename)
{

//////////////////// REMOVED: model->ID_Texture=IDTemp;
model->ID_Texture = 0 ; //////////////////// ADDED
CreateTextureBmp(filename,model->ID_Texture);
//////////////////// REMOVED: IDTemp++;

};
void CJtpOglTextureMgr::CreateTextureBmp( jchar* strFileName, juint & textureID) /////////// Added the & before the textureID
{The second alternative I mentioned was:


void CJtpOglTextureMgr::LoadTextures(IJtpModel *model,jchar* filename)
{

model->ID_Texture=IDTemp;
CreateTextureBmp(filename,model->ID_Texture);
IDTemp++;

};

void CJtpOglTextureMgr::CreateTextureBmp( jchar* strFileName, juint textureID)
{
AUX_RGBImageRec *pBitmap = NULL;

if(!strFileName)
return;

pBitmap = auxDIBImageLoad(strFileName);

if(pBitmap == NULL)
exit(0);

//////////////////// REMOVED: glGenTextures(1, &textureID);

glPixelStorei (GL_UNPACK_ALIGNMENT, 1);

glBindTexture(GL_TEXTURE_2D, textureID);EDIT: The first alternative is probably better since you can use the value of the ID_Texture to determine if texture was created (nonzero) or not (zero).

jimmythepage
09-11-2006, 04:42 PM
tnx for the new hint,for me it's little hard to understand english so i'm very happy to see example code...

But the problem don't go away from my project,i've tried the two methods but my cube is still white...With the debugger i've noticed that the id in all parts of the program are correct,the first texture have ever id=100..i don't know if this is a good think,but for logic it means that the id is not the problem,isn't it??

However i don't really know where to looking for...Any other precious hint??
And for the light,you think that is the same problem that block the two things??

tnx again..

ps:if it is useful to see other parts of code tell me,i don't show other parts because i don't know what i have to show,and the project it's quite large...

Komat
09-12-2006, 12:08 PM
Originally posted by jimmythepage:

But the problem don't go away from my project,i've tried the two methods but my cube is still white...With the debugger i've noticed that the id in all parts of the program are correct,the first texture have ever id=100..i don't know if this is a good think,but for logic it means that the id is not the problem,isn't it??
In the second alternative I mentioned, the id starting from 100 might be correct. In the first alternative the id will almost certainly start from lower value. You can use the glIntercept (http://glintercept.nutty.org/) tool to record which textures are used and what OGL calls are made. If you send me that recording, I will try to look at it.

jide
09-12-2006, 12:32 PM
Also, can you show more piece of codes (recent one, plus the rendering code).

Also, some other pices of advice, sorry if it has already said, I haven't read the full topic. Just put something like a boolean value in each of your models so that you can easily know if it has a texture or not. And doing this way you'll also be able to easily enable/disable texturing for each model.

Give the asked information.

jimmythepage
09-13-2006, 07:39 AM
first of all tnx for patience and for the help again..

@jide:
Before i've founf this problem there was a texture boolean for the model,but for trying to solve this problem i've erase it..after solving i'll reput the variable..

@Komat: i try with glintercept but when i put the dll into my exe folder the program crash..

however this is the file that appear:

GL Intercept Log. Version : 0.5 Compile Date: Dec 3 2005 Run on: Wed Sep 13 15:33:20 2006

================================================== =
Function glGenTextures is being called before context creation
Call to glGenTextures made outside of context/init
Function glPixelStorei is being called before context creation
Call to glPixelStorei made outside of context/init
Function glBindTexture is being called before context creation
Call to glBindTexture made outside of context/init
Function glGetError is being called before context creation
Call to glGetError made outside of context/init
Function glGetIntegerv is being called before context creation
Call to glGetIntegerv made outside of context/init
Function glGetError is being called before context creation
Call to glGetError made outside of context/init
Function glGetIntegerv is being called before context creation
Call to glGetIntegerv made outside of context/init
Function glGetError is being called before context creation
Call to glGetError made outside of context/init
Function glGetIntegerv is being called before context creation
Call to glGetIntegerv made outside of context/init
Function glGetError is being called before context creation
Call to glGetError made outside of context/init
Function glGetIntegerv is being called before context creation
Call to glGetIntegerv made outside of context/init
Function glGetError is being called before context creation
Call to glGetError made outside of context/init
Function glGetIntegerv is being called before context creation
Call to glGetIntegerv made outside of context/init
Function glGetError is being called before context creation
Call to glGetError made outside of context/init
Function glGetIntegerv is being called before context creation
Call to glGetIntegerv made outside of context/init
Function glGetError is being called before context creation
Call to glGetError made outside of context/init
Function glGetIntegerv is being called before context creation
Call to glGetIntegerv made outside of context/init
Function glGetError is being called before context creation
Call to glGetError made outside of context/init
Function glGetIntegerv is being called before context creation
Call to glGetIntegerv made outside of context/init
Function glGetError is being called before context creation
Call to glGetError made outside of context/init
Function glGetIntegerv is being called before context creation
Call to glGetIntegerv made outside of context/init
Function glGetError is being called before context creation
Call to glGetError made outside of context/init
Function glGetIntegerv is being called before context creation
Call to glGetIntegerv made outside of context/init
Function glGetError is being called before context creation
Call to glGetError made outside of context/init
Function glGetIntegerv is being called before context creation
Call to glGetIntegerv made outside of context/init
Function glGetError is being called before context creation
Call to glGetError made outside of context/init
Function glGetIntegerv is being called before context creation
Call to glGetIntegerv made outside of context/init
Function glGetError is being called before context creation
Call to glGetError made outside of context/init
Function glGetIntegerv is being called before context creation
Call to glGetIntegerv made outside of context/init
Function glGetError is being called before context creation
Call to glGetError made outside of context/init
================================================== =
Log End.

jimmythepage
09-13-2006, 09:38 AM
it's a stupid logic if the error write above is the error that i have to fix(my program assign a texture before the rendering context creation)?

jimmythepage
09-13-2006, 11:26 AM
the problem is what glintercept said!!!

Tnx u for the helping!!!veryvery tnx!!