Click here to Skip to main content
15,897,273 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 51K   2.4K   10  
A simple shader developed in GLSL for interpolating two textures
#include "StdAfx.h"
#include "GLSetup.h"

GLSetup::GLSetup(void)
{
	m_hRenderContext = 0;
	m_hDeviceContext = 0;
	m_hRenderWindow = 0;
}

GLSetup::~GLSetup(void)
{
	Exit();
}

// Function for creating a rendering context and make it as current rendering context.
bool GLSetup::InitGL( HWND pRenderWindow_i )
{
	m_hRenderWindow = pRenderWindow_i;
	GLuint PixelFormat;

	PIXELFORMATDESCRIPTOR pfd;
	memset(&pfd, 0, sizeof(PIXELFORMATDESCRIPTOR));

	pfd.nSize      = sizeof(PIXELFORMATDESCRIPTOR);
	pfd.nVersion   = 1;
	pfd.dwFlags    = PFD_DRAW_TO_WINDOW |PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
	pfd.iPixelType = PFD_TYPE_RGBA;
	pfd.cColorBits = 16;
	pfd.cDepthBits = 16;

	m_hDeviceContext = ::GetDC( m_hRenderWindow );
	PixelFormat = ChoosePixelFormat( m_hDeviceContext, &pfd );
	SetPixelFormat( m_hDeviceContext, PixelFormat, &pfd);
	m_hRenderContext = wglCreateContext( m_hDeviceContext );
	wglMakeCurrent( m_hDeviceContext, m_hRenderContext );

	// Check opengl error before exiting.
	return( GL_NO_ERROR == glGetError());
}

bool GLSetup::CheckExtension( const CHAR* pExtensionToCheck_i )
{
    const CHAR* pExtension = (const CHAR*)glGetString( GL_EXTENSIONS );
    if( 0 == pExtension )
    {
        return false;
    }
    if( 0 < strstr( pExtension, pExtensionToCheck_i ))
    {
        return true;
    }
    return false;
}


void GLSetup::Exit()
{
	if( m_hRenderContext != NULL )
	{
		wglMakeCurrent( NULL, NULL );
		wglDeleteContext( m_hRenderContext );
		m_hRenderContext = NULL;
	}

	if( m_hDeviceContext != NULL )
	{
		ReleaseDC( m_hRenderWindow, m_hDeviceContext );
		m_hDeviceContext = NULL;
	}
}

void GLSetup::Draw()
{
	SwapBuffers( m_hDeviceContext );
}

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