Jump to content

  • Log In with Google      Sign In   
  • Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

Sign up from the right-hand sidebar on our homepage and read Tuesday's newsletter for details!


We're also offering banner ads on our site from just $5! 1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Texture problem on a 3d model


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 oenda   Members   -  Reputation: 139

Like
0Likes
Like

Posted 24 December 2013 - 01:23 PM

This is very strange error.I have an ms3d(milkshape 3d) model.I am rendering it but it doesnt appear correctly.It is covered by repeated white textures.
 
I load textures with sfml.My texture loading code:
 

bool CImage::Load(char * szFilename, bool bMipMap)
{
	m_bMipMap = bMipMap;
	m_szFilename = szFilename;

    sf::Image img_data;
    img_data.loadFromFile(m_szFilename);

    m_uiWidth = img_data.getSize().x;
	m_uiHeight = img_data.getSize().y;


    m_uiImage = 0;

	glGenTextures(1, &m_uiImage);
	glBindTexture(GL_TEXTURE_2D, m_uiImage);
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

	if(m_bMipMap)
	{
		gluBuild2DMipmaps(GL_TEXTURE_2D, 3, m_uiWidth, m_uiHeight, GL_RGB, GL_UNSIGNED_BYTE,  img_data.getPixelsPtr());
	}
	else
	{
		glTexImage2D(GL_TEXTURE_2D, 0, 3, m_uiWidth, m_uiHeight, 0, GL_RGB, GL_UNSIGNED_BYTE,  img_data.getPixelsPtr());
	}

	return true;
}

 

Any help will be appreciated.

Attached Thumbnails

  • pic1.jpg
  • pic2.jpg


Sponsor:

#2 C0lumbo   Crossbones+   -  Reputation: 2343

Like
2Likes
Like

Posted 24 December 2013 - 01:36 PM

Is it possible the UVs need to be normalised?

 

DirectX and OpenGL use normalised texture coordinates. That is, regardless of the texture's width and height, (0,0) and (1,1) will always represent opposite corners of the texture image. It's possible that the ms3d model format (or the loading code you use) uses non-normalised texture coordinates, so that a 512x512 texture would have (0,0) and (512,512) as it's corners.

 

Try dividing the UV coordinates by the texture dimensions and see if that gets you anywhere.



#3 lask1   Members   -  Reputation: 773

Like
0Likes
Like

Posted 24 December 2013 - 08:26 PM

Is it possible the UVs need to be normalised?

 

DirectX and OpenGL use normalised texture coordinates. That is, regardless of the texture's width and height, (0,0) and (1,1) will always represent opposite corners of the texture image. It's possible that the ms3d model format (or the loading code you use) uses non-normalised texture coordinates, so that a 512x512 texture would have (0,0) and (512,512) as it's corners.

 

Try dividing the UV coordinates by the texture dimensions and see if that gets you anywhere.

Possible but not sure. You are definitely on the right track with the UV coordinates. Also @oenda your texture loading code appears to be fine it's probably something like C0lumbo said.



#4 oenda   Members   -  Reputation: 139

Like
0Likes
Like

Posted 25 December 2013 - 03:12 AM

I didn't change anything except texture loading code.I read examples.I found solution at Opengl example.Problem is not related to UV coordinates.It is related to texture loading.The solution is:

    GLuint id = 0;
    {
        sf::Image image;
        if (image.loadFromFile(szFilename))
            {
        glGenTextures(1, &id);
        glBindTexture(GL_TEXTURE_2D, id);
        gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGBA, image.getSize().x, image.getSize().y, GL_RGBA, GL_UNSIGNED_BYTE, image.getPixelsPtr());
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);

            }
    }

m_uiImage = id;

I don't know why but problem has been solved.Thanks for your help.






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS