Click here to Skip to main content
15,895,922 members
Articles / Multimedia / OpenGL

GLSL Shader for Interpolating Two Textures

Rate me:
Please Sign up or sign in to vote.
4.60/5 (5 votes)
24 Jun 2010CPOL2 min read 50.9K   2.4K   10  
A simple shader developed in GLSL for interpolating two textures
#include "StdAfx.h"
#include "GLTexture.h"
#include "GL\Glu.h"

GLTexture::GLTexture(void)
{
	m_nTextureID = 0;
}

GLTexture::~GLTexture(void)
{
	Delete();
}
bool GLTexture::Create(int nWidth, int nHeight, void *pbyData)
{
	if( 0 != m_nTextureID )
	{
		// if this texture already exists then delete it.
		Delete();
	}
	if( 0 == pbyData )
	{
		return false;
	}
	glEnable( GL_TEXTURE_2D );
	glGenTextures( 1, &m_nTextureID );

	glBindTexture( GL_TEXTURE_2D, m_nTextureID );

	glTexParameteri( GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER, GL_LINEAR );
	glTexParameteri( GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER, GL_LINEAR );

	glTexImage2D( GL_TEXTURE_2D, 0, 3, nWidth, nHeight, 0,
		GL_BGR_EXT, GL_UNSIGNED_BYTE, pbyData );

	return ( GL_NO_ERROR == glGetError() );
}

void GLTexture::Delete()
{
	if( 0 != m_nTextureID )
	{
		glDeleteTextures( 1, &m_nTextureID );
		m_nTextureID = 0;
	}
}

void GLTexture::Enable()
{
    glBindTexture( GL_TEXTURE_2D, m_nTextureID );
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
India India
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions