Click here to Skip to main content
15,887,683 members
Articles / Multimedia / OpenGL

Zoom An Image With Different Interpolation Types

Rate me:
Please Sign up or sign in to vote.
4.91/5 (57 votes)
21 Sep 2011CPOL13 min read 224.7K   14.6K   109  
Implementation of different interpolations[Bi-Linear and Bi-Cubic] with OpenGL.
#include "StdAfx.h"
#include "GLTexture.h"
#include "GLExtension.h"
#include "GL\Glu.h"
#include "math.h"

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

GLTexture::~GLTexture(void)
{
	Delete();
}
bool GLTexture::Create(int nWidth, int nHeight, void *pbyData, int nFormat_i, int nInternalFormat_i)
{
    int nError = glGetError();
	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 );
    glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP );
    glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP );

    glTexImage2D( GL_TEXTURE_2D, 0, nInternalFormat_i, nWidth, nHeight, 0,
	    nFormat_i, GL_UNSIGNED_BYTE, pbyData );
    return ( GL_NO_ERROR == glGetError() );
}

void GLTexture::SetFilterType( const GLint FilterType_i, const GLint FilterValue_i )
{
    glBindTexture( GL_TEXTURE_2D, m_nTextureID );

    glTexParameteri( GL_TEXTURE_2D, FilterType_i, FilterValue_i );
}

bool GLTexture::GetData( BYTE*& pbyData )
{
    if( m_nTextureID )
    {
        glBindTexture( GL_TEXTURE_2D, m_nTextureID );
        glGetTexImage( GL_TEXTURE_2D, 0,GL_BGR_EXT, GL_UNSIGNED_BYTE, pbyData );
        return true;
    }
    return false;
}
void GLTexture::Delete()
{
	if( 0 != m_nTextureID )
	{
		glDeleteTextures( 1, &m_nTextureID );
		m_nTextureID = 0;
	}
}

void GLTexture::Enable()
{
    glEnable( GL_TEXTURE_2D );
    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