Click here to Skip to main content
12,354,543 members (61,126 online)
Click here to Skip to main content
Articles » Multimedia » OpenGL » General » Downloads

Stats

94.8K views
12.1K downloads
106 bookmarked
Posted

Zoom An Image With Different Interpolation Types

, 21 Sep 2011 CPOL
Implementation of different interpolations[Bi-Linear and Bi-Cubic] with OpenGL.
ZoomInterpolation.exe
ZoomInterpolation.exe
ZoomInterpolation
pixel_shader_Bell.cg
pixel_shader_BiCubic.cg
pixel_shader_BiLinear.cg
pixel_shader_BSpline.cg
pixel_shader_CatMull.cg
res
Flower.bmp
ZoomInterpolation.ico
ZoomInterpolation.dsp
ZoomInterpolation.dsw
pixel_shader_Bell.cg
pixel_shader_BiCubic.cg
pixel_shader_BiLinear.cg
pixel_shader_BSpline.cg
pixel_shader_CatMull.cg
Flower.bmp
ZoomInterpolation.ico
ZoomInterpolation.dsp
ZoomInterpolation.dsw
#include "StdAfx.h"
#include "GLSLShader.h"
#include "GL\gl.h"
#include "AppError.h"

GLSLShader::GLSLShader(void)
{

    m_hProgramObject = 0;
    m_hShaderHandle = 0;
}

GLSLShader::~GLSLShader(void)
{
    DeleteShader();
}

bool GLSLShader::CreateProgram( const int nProgramID_i, GLenum glSlShaderType_i )
{

    m_hProgramObject = GLExtension::GetInstance().glCreateProgramObjectARB();

    HRSRC hrResInfo = FindResource( 0, MAKEINTRESOURCE( nProgramID_i ),TEXT("GLSL_SHADER"));
    if( 0 == hrResInfo )
    {
        // Set Error messages.
        AppError::SetError( CString(L"FindResource returns NULL for shader ID.") );
        return false;
    }
    HGLOBAL hRcResource =  LoadResource(0, hrResInfo  );
    CHAR* pBufferResData = (CHAR* )LockResource( hRcResource );
    
    m_hShaderHandle = GLExtension::GetInstance().glCreateShaderObjectARB( GL_FRAGMENT_PROGRAM_ARB );
    if( 0 == m_hShaderHandle )
    {
        // Set Error messages.
        AppError::SetError( CString(L"0 == m_hShaderHandle GL_FRAGMENT_PROGRAM_ARB shader creation failed") );
        return false;
    }

    int nLENGTH = SizeofResource( 0, hrResInfo );
    TCHAR tcBuffer[333];
    swprintf( tcBuffer, L"LOG %d", nLENGTH );
    OutputDebugString(tcBuffer);
    BYTE* pbyShaderData = new BYTE[nLENGTH + 100];
    memcpy( pbyShaderData, pBufferResData, nLENGTH );
    pbyShaderData[nLENGTH] = 0;

    GLExtension::GetInstance().glShaderSourceARB( m_hShaderHandle, strlen( pBufferResData ), (const GLcharARB**)&pbyShaderData, &nLENGTH );
    GLExtension::GetInstance().glCompileShader( m_hShaderHandle );
    
    int nLen = 0; 
    char cBuffer[800];
    GLExtension::GetInstance().glGetInfoLogARB(m_hShaderHandle, 800,&nLen,(GLbyte*)cBuffer);
    if( nLen )
    {
        WCHAR *pWideChar = new WCHAR[nLen + 1];
        int nOutCount = 0;
        //MultiByteToWideChar( CP_ACP, MB_PRECOMPOSED,cBuffer,nLen, pWideChar, nOutCount );
        for( int nStr =0; nStr < nLen; nStr++)
        {
            short s = cBuffer[nStr];
            pWideChar[nStr] = s;
        }
        pWideChar[nLen] = 0;
        // Set Error messages.
        AppError::SetError( CString( L"Shader Compilation failed.\n Error:\n" )+ CString( pWideChar ) );
        TRACE(  CString( L"Shader Compilation failed.\n Error:\n" )+ CString( pWideChar ) );
        delete[] pWideChar;
        // return false;
    }
    GLExtension::GetInstance().glAttachObjectARB( m_hProgramObject, m_hShaderHandle );
    delete[] pbyShaderData;
    return true;
}

bool GLSLShader::DeleteShader()
{
    if( m_hShaderHandle )
    {
        GLExtension::GetInstance().glDeleteObjectARB( m_hShaderHandle );
        m_hShaderHandle = 0;
    }
    if( GLSLShader::m_hProgramObject )
    {
        GLExtension::GetInstance().glDeleteObjectARB( GLSLShader::m_hProgramObject );
        GLSLShader::m_hProgramObject = 0;
    }
    return true;
}

bool GLSLShader::EnableShader()
{
    GLExtension::GetInstance().glLinkProgramARB( m_hProgramObject );
    return true;
}
bool GLSLShader::DisableShader()
{
    int nErr = 0;
    GLExtension::GetInstance().glUseProgramObjectARB( 0 );
    return true;
}

bool GLSLShader::SetTexture( const CHAR* pParamName_i, const int nTextureID_i )
{
    GLExtension::GetInstance().glUseProgramObjectARB( m_hProgramObject );
    GLint nParamObj = GLExtension::GetInstance().glGetUniformLocationARB( m_hProgramObject, (const GLbyte*)pParamName_i );
    if( -1 == nParamObj )
    {
        return false;
    }

    GLExtension::GetInstance().glActiveTexture( GL_TEXTURE0 + nTextureID_i );
    glBindTexture(GL_TEXTURE_2D, nTextureID_i);

    GLExtension::GetInstance().glUniform1iARB( nParamObj, nTextureID_i );

    GLExtension::GetInstance().glActiveTexture( GL_TEXTURE0 );
    glBindTexture(GL_TEXTURE_2D, nTextureID_i);

    return ( GL_NO_ERROR == glGetError() );
}
bool GLSLShader::SetParam( const CHAR* pParamName_i, const float fValue_i )
{
    GLExtension::GetInstance().glUseProgramObjectARB( m_hProgramObject );
    GLint nParamObj = GLExtension::GetInstance().glGetUniformLocationARB( m_hProgramObject, (const GLbyte*)pParamName_i );
    if( -1 == nParamObj )
    {
        return false;
    }

    GLExtension::GetInstance().glUniform1fARB( nParamObj, fValue_i );
    return ( GL_NO_ERROR == glGetError() );
}

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)

Share

About the Author

Santhosh G_
India India
No Biography provided

You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.160621.1 | Last Updated 21 Sep 2011
Article Copyright 2011 by Santhosh G_
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid