Exemple #1
0
Texture::Texture(std::string filename, ResourceInfo* resourceInfo)
{
    m_filename = filename;
    m_resourceInfo = resourceInfo;

    ImageBMP image;
    image.Load(filename);

    // Create one OpenGL texture
    glGenTextures(1, &m_id);
 
    // "Bind" the newly created texture : all future texture functions will modify this texture
    glBindTexture(GL_TEXTURE_2D, m_id);
 
    // Give the image to OpenGL
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, image.Width(), image.Height(), 0, GL_BGR, GL_UNSIGNED_BYTE, image.DataPtr());
    image.FreeData();

    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
}
Exemple #2
0
void Terrain::Initialize(const char* sTexture, const char* sHeightMap, const char* sNormalMap, float fHeight)
{
	SetHeight(fHeight);

	ImageBMP* image = new ImageBMP(m_OpenGL);
	image->Load(sHeightMap);

	m_Texture = new Texture(m_OpenGL);
	TextureID = m_Texture->GetTexture2D(sTexture);

	iWidth = image->GetWidth();
	iHeight = image->GetHeight();

	hs = new float*[image->GetHeight()];
	Normal = new Vector3f*[image->GetHeight()];
	NormalTemp = new Vector3f*[image->GetHeight()];

	for (unsigned int i = 0; i < image->GetHeight(); ++i)
	{
		hs[i] = new float[image->GetWidth()];
		Normal[i] = new Vector3f[image->GetWidth()];
		NormalTemp[i] = new Vector3f[image->GetWidth()];
	}

	for (unsigned int y = 0; y < image->GetHeight(); y++)
	{
		for (unsigned int x = 0; x < image->GetWidth(); x++)
		{
			unsigned char color = (unsigned char)image->GetData()[3 * (y * image->GetWidth() + x)];
			float h = ((color / 255.0f) - 0.5f);
			SetHeight(x, y, h);
		}
	}

	ComputeNormal();
	GenerateTerrain();
	Bind();

	vPosition = Vector3f(0, -20, 0);
}