Page 1 of 2 12 LastLast
Results 1 to 10 of 14

Thread: Texturing problem

  1. #1
    Junior Member Newbie
    Join Date
    Aug 2006
    Location
    Italy
    Posts
    12

    Texturing problem

    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
    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 );
    			}
    Code :
    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_FILTER,GL_LINEAR_MIPMAP_NEAREST);
    		glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR_MIPMAP_LINEAR);
     
     
    		if (pBitmap)						
    		{
    			if (pBitmap->data)							
    			{
    				free(pBitmap->data);					
    			}
     
    			free(pBitmap);								
    		}
    	}
    Code :
      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
    JimmyThePage

  2. #2
    Junior Member Newbie
    Join Date
    Feb 2005
    Posts
    23

    Re: Texturing problem

    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

  3. #3
    Senior Member Frequent Contributor
    Join Date
    May 2005
    Location
    Prague, Czech Republic
    Posts
    913

    Re: Texturing problem

    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.

  4. #4
    Junior Member Newbie
    Join Date
    Aug 2006
    Location
    Italy
    Posts
    12

    Re: Texturing problem

    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

  5. #5
    Junior Member Newbie
    Join Date
    Aug 2006
    Location
    Italy
    Posts
    12

    Re: Texturing problem

    i've found some pieces of time and i've tried this

    Code :
     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_FILTER,GL_LINEAR_MIPMAP_NEAREST);
    		glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
     
     
    		if (pBitmap)										
    		{
    			if (pBitmap->data)							
    			{
    				free(pBitmap->data);			
    			}
     
    			free(pBitmap);								
    		}
     
    	}
    Code :
     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;
    Code :
    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

  6. #6
    Junior Member Newbie
    Join Date
    Aug 2006
    Location
    Italy
    Posts
    12

    Re: Texturing problem

    Code :
     CJtpOglTextureMgr::CJtpOglTextureMgr()
    	{
    		IDTemp=100;
    	};
    this is the idtemp assignment..
    JimmyThePage

  7. #7
    Senior Member OpenGL Pro
    Join Date
    Jul 2001
    Location
    France
    Posts
    1,662

    Re: Texturing problem

    This is not related to GL, at least not directly.
    When using this function:

    Code :
    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.

  8. #8
    Senior Member Frequent Contributor
    Join Date
    May 2005
    Location
    Prague, Czech Republic
    Posts
    913

    Re: Texturing problem

    This is not what I meant.


    One possible alternative I mentioned was:

    Code :
    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:

    Code :
    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).

  9. #9
    Junior Member Newbie
    Join Date
    Aug 2006
    Location
    Italy
    Posts
    12

    Re: Texturing problem

    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...
    JimmyThePage

  10. #10
    Senior Member Frequent Contributor
    Join Date
    May 2005
    Location
    Prague, Czech Republic
    Posts
    913

    Re: Texturing problem

    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 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.

Page 1 of 2 12 LastLast

Similar Threads

  1. Texturing Problem
    By Henners in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 07-23-2010, 07:17 AM
  2. ogl texturing problem
    By gl_CodER in forum OpenGL: Advanced Coding
    Replies: 8
    Last Post: 03-06-2006, 02:05 PM
  3. texturing problem
    By powerpad in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 03-30-2005, 07:46 AM
  4. Problem with Texturing...
    By Setzer in forum OpenGL: Basic Coding
    Replies: 7
    Last Post: 07-19-2002, 10:16 PM
  5. MDI and texturing problem?
    By asdiel in forum OpenGL: Advanced Coding
    Replies: 3
    Last Post: 12-06-2000, 10:40 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean